No functional change, just refactoring.
#include "exec-util.h"
#include "log.h"
#include "process-util.h"
-#include "terminal-util.h"
static pid_t agent_pid = 0;
if (agent_pid > 0)
return 0;
- /* Check if we have a controlling terminal. If not (ENXIO here), we aren't actually invoked
- * interactively on a terminal, hence fail. */
- r = get_ctty_devnr(0, NULL);
- if (r == -ENXIO)
- return 0;
- if (r < 0)
+ r = shall_fork_agent();
+ if (r <= 0)
return r;
- if (!is_main_thread())
- return -EPERM;
-
r = fork_agent("(sd-askpwagent)",
NULL, 0,
&agent_pid,
return -errno;
}
+int shall_fork_agent(void) {
+ int r;
+
+ /* Check if we have a controlling terminal. If not (ENXIO here), we aren't actually invoked
+ * interactively on a terminal, hence fail. */
+ r = get_ctty_devnr(0, NULL);
+ if (r == -ENXIO)
+ return false;
+ if (r < 0)
+ return r;
+
+ if (!is_main_thread())
+ return -EPERM;
+
+ return true;
+}
+
int _fork_agent(const char *name, const int except[], size_t n_except, pid_t *ret_pid, const char *path, ...) {
size_t n, i;
va_list ap;
int fexecve_or_execve(int executable_fd, const char *executable, char *const argv[], char *const envp[]);
+int shall_fork_agent(void);
int _fork_agent(const char *name, const int except[], size_t n_except, pid_t *ret_pid, const char *path, ...) _sentinel_;
#define fork_agent(name, ...) _fork_agent(name, __VA_ARGS__, NULL)
#include "polkit-agent.h"
#include "process-util.h"
#include "stdio-util.h"
-#include "terminal-util.h"
#include "time-util.h"
#if ENABLE_POLKIT
if (geteuid() == 0)
return 0;
- /* Check if we have a controlling terminal. If not (ENXIO here), we aren't actually invoked
- * interactively on a terminal, hence fail. */
- r = get_ctty_devnr(0, NULL);
- if (r == -ENXIO)
- return 0;
- if (r < 0)
+ r = shall_fork_agent();
+ if (r <= 0)
return r;
- if (!is_main_thread())
- return -EPERM;
-
if (pipe2(pipe_fd, 0) < 0)
return -errno;