util: polkit: Fix polkit agent startup

Commit 0b36b0e9 broke polkit agent startup when attempting to fix a
coverity warning. Refactor it properly so that we don't need the 'cmd'
intermediate variable.
This commit is contained in:
Peter Krempa 2016-05-09 11:02:51 +02:00
parent a391a9c5b1
commit 4e8b81e5c4

View File

@ -167,7 +167,6 @@ virPolkitAgentPtr
virPolkitAgentCreate(void) virPolkitAgentCreate(void)
{ {
virPolkitAgentPtr agent = NULL; virPolkitAgentPtr agent = NULL;
virCommandPtr cmd = virCommandNewArgList(PKTTYAGENT, "--process", NULL);
int pipe_fd[2] = {-1, -1}; int pipe_fd[2] = {-1, -1};
struct pollfd pollfd; struct pollfd pollfd;
int outfd = STDOUT_FILENO; int outfd = STDOUT_FILENO;
@ -181,18 +180,18 @@ virPolkitAgentCreate(void)
if (VIR_ALLOC(agent) < 0) if (VIR_ALLOC(agent) < 0)
goto error; goto error;
agent->cmd = cmd;
cmd = NULL;
virCommandAddArgFormat(cmd, "%lld", (long long int) getpid()); agent->cmd = virCommandNewArgList(PKTTYAGENT, "--process", NULL);
virCommandAddArg(cmd, "--notify-fd");
virCommandAddArgFormat(cmd, "%d", pipe_fd[1]); virCommandAddArgFormat(agent->cmd, "%lld", (long long int) getpid());
virCommandAddArg(cmd, "--fallback"); virCommandAddArg(agent->cmd, "--notify-fd");
virCommandSetInputFD(cmd, STDIN_FILENO); virCommandAddArgFormat(agent->cmd, "%d", pipe_fd[1]);
virCommandSetOutputFD(cmd, &outfd); virCommandAddArg(agent->cmd, "--fallback");
virCommandSetErrorFD(cmd, &errfd); virCommandSetInputFD(agent->cmd, STDIN_FILENO);
virCommandPassFD(cmd, pipe_fd[1], VIR_COMMAND_PASS_FD_CLOSE_PARENT); virCommandSetOutputFD(agent->cmd, &outfd);
if (virCommandRunAsync(cmd, NULL) < 0) virCommandSetErrorFD(agent->cmd, &errfd);
virCommandPassFD(agent->cmd, pipe_fd[1], VIR_COMMAND_PASS_FD_CLOSE_PARENT);
if (virCommandRunAsync(agent->cmd, NULL) < 0)
goto error; goto error;
pollfd.fd = pipe_fd[0]; pollfd.fd = pipe_fd[0];
@ -207,7 +206,6 @@ virPolkitAgentCreate(void)
VIR_FORCE_CLOSE(pipe_fd[0]); VIR_FORCE_CLOSE(pipe_fd[0]);
VIR_FORCE_CLOSE(pipe_fd[1]); VIR_FORCE_CLOSE(pipe_fd[1]);
virPolkitAgentDestroy(agent); virPolkitAgentDestroy(agent);
virCommandFree(cmd);
return NULL; return NULL;
} }