summaryrefslogtreecommitdiff
path: root/src/tty-ask-password-agent
diff options
context:
space:
mode:
authorFranck Bui <fbui@suse.com>2019-09-19 16:38:16 +0200
committerFranck Bui <fbui@suse.com>2019-10-05 08:08:24 +0200
commit1322757061e1e41cabf7098c4dc99b83520612e8 (patch)
treeea6b91169f56f4aa923ce417f6f2b99368c43e61 /src/tty-ask-password-agent
parent998c6da8ca37326dfc38e16fdf0d30b1c6c20d97 (diff)
downloadsystemd-1322757061e1e41cabf7098c4dc99b83520612e8.tar.gz
tty-ask-pwd-agent: share the same init code for --query and --watch
Previously we would have skipped the init code which consists in setting the signal handling up and the wall tty block thingie.
Diffstat (limited to 'src/tty-ask-password-agent')
-rw-r--r--src/tty-ask-password-agent/tty-ask-password-agent.c47
1 files changed, 25 insertions, 22 deletions
diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c
index 81eca2ec41..8bea524952 100644
--- a/src/tty-ask-password-agent/tty-ask-password-agent.c
+++ b/src/tty-ask-password-agent/tty-ask-password-agent.c
@@ -490,10 +490,10 @@ static int process_password_files(void) {
return r;
}
-static int process_and_watch_password_files(void) {
+static int process_and_watch_password_files(bool watch) {
enum {
- FD_INOTIFY,
FD_SIGNAL,
+ FD_INOTIFY,
_FD_MAX
};
@@ -506,26 +506,29 @@ static int process_and_watch_password_files(void) {
(void) mkdir_p_label("/run/systemd/ask-password", 0755);
- notify = inotify_init1(IN_CLOEXEC);
- if (notify < 0)
- return log_error_errno(errno, "Failed to allocate directory watch: %m");
-
- r = inotify_add_watch_and_warn(notify, "/run/systemd/ask-password", IN_CLOSE_WRITE|IN_MOVED_TO);
- if (r < 0)
- return r;
-
assert_se(sigemptyset(&mask) >= 0);
assert_se(sigset_add_many(&mask, SIGTERM, -1) >= 0);
assert_se(sigprocmask(SIG_SETMASK, &mask, NULL) >= 0);
- signal_fd = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC);
- if (signal_fd < 0)
- return log_error_errno(errno, "Failed to allocate signal file descriptor: %m");
+ if (watch) {
+ signal_fd = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC);
+ if (signal_fd < 0)
+ return log_error_errno(errno, "Failed to allocate signal file descriptor: %m");
- pollfd[FD_INOTIFY].fd = notify;
- pollfd[FD_INOTIFY].events = POLLIN;
- pollfd[FD_SIGNAL].fd = signal_fd;
- pollfd[FD_SIGNAL].events = POLLIN;
+ pollfd[FD_SIGNAL].fd = signal_fd;
+ pollfd[FD_SIGNAL].events = POLLIN;
+
+ notify = inotify_init1(IN_CLOEXEC);
+ if (notify < 0)
+ return log_error_errno(errno, "Failed to allocate directory watch: %m");
+
+ r = inotify_add_watch_and_warn(notify, "/run/systemd/ask-password", IN_CLOSE_WRITE|IN_MOVED_TO);
+ if (r < 0)
+ return r;
+
+ pollfd[FD_INOTIFY].fd = notify;
+ pollfd[FD_INOTIFY].events = POLLIN;
+ }
for (;;) {
int timeout = -1;
@@ -541,7 +544,10 @@ static int process_and_watch_password_files(void) {
log_error_errno(r, "Failed to process password: %m");
}
- if (poll(pollfd, _FD_MAX, timeout) < 0) {
+ if (!watch)
+ break;
+
+ if (poll(pollfd, watch ? _FD_MAX : _FD_MAX-1, timeout) < 0) {
if (errno == EINTR)
continue;
@@ -862,10 +868,7 @@ static int run(int argc, char *argv[]) {
(void) release_terminal();
}
- if (IN_SET(arg_action, ACTION_WATCH, ACTION_WALL))
- return process_and_watch_password_files();
- else
- return process_password_files();
+ return process_and_watch_password_files(arg_action != ACTION_QUERY);
}
DEFINE_MAIN_FUNCTION(run);