When I call systemd-run "--user" "--pipe" "echo" "hello"
I get the expected output "hello" (plus some systemd unit info) without a password popup.
But when I run systemd-run
using the exact same arguments from inside a C++ program via execvp()
or execvpe()
it launches a popup window with Authentication is required to start transient unit
.
Example:
#include <unistd.h>
int main(int argc, char const* const argv[], char const* const envp[])
{
char const* argp[] =
{
"--user",
"--pipe",
"echo",
"hello",
nullptr,
};
//::execvp("systemd-run", const_cast<char**>(argp)); // alternative call, same result
::execvpe("systemd-run", const_cast<char**>(argp), const_cast<char**>(envp));
}
Can I avoid this authentication popup requirement (while still using C++)? Preferably using a default systemd with no policy modification.
(I'm trying to make a quick tool to run a subcommand while preventing accidental file modification outside of specified directories, eg for a "safe" build).
When I call systemd-run "--user" "--pipe" "echo" "hello"
I get the expected output "hello" (plus some systemd unit info) without a password popup.
But when I run systemd-run
using the exact same arguments from inside a C++ program via execvp()
or execvpe()
it launches a popup window with Authentication is required to start transient unit
.
Example:
#include <unistd.h>
int main(int argc, char const* const argv[], char const* const envp[])
{
char const* argp[] =
{
"--user",
"--pipe",
"echo",
"hello",
nullptr,
};
//::execvp("systemd-run", const_cast<char**>(argp)); // alternative call, same result
::execvpe("systemd-run", const_cast<char**>(argp), const_cast<char**>(envp));
}
Can I avoid this authentication popup requirement (while still using C++)? Preferably using a default systemd with no policy modification.
(I'm trying to make a quick tool to run a subcommand while preventing accidental file modification outside of specified directories, eg for a "safe" build).
Share Improve this question edited Feb 2 at 11:02 Toby Speight 31k50 gold badges76 silver badges113 bronze badges asked Feb 2 at 2:26 xaxazakxaxazak 8307 silver badges19 bronze badges 6 | Show 1 more comment1 Answer
Reset to default 1The program
is missing in argp
, try this :
#include <unistd.h>
int main(int argc, char const* const argv[], char const* const envp[])
{
char const* argp[] =
{
"systemd-run", // <=========== notice this.
"--user",
"--pipe",
"echo",
"hello",
nullptr,
};
//::execvp("systemd-run", const_cast<char**>(argp)); // alternative call, same result
::execvpe("systemd-run", const_cast<char**>(argp), const_cast<char**>(envp));
}
Your version is running this command: systemd-run --pipe echo hello
, reason why it asks for password.
systemd-run
, but have you tried adding the--no-ask-password
option that the manual mentions? – tink Commented Feb 2 at 2:32Failed to start transient service unit: Interactive authentication required.
– xaxazak Commented Feb 2 at 2:36root
and there will be no popup window. – Lewis Commented Feb 2 at 3:52