summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2023-01-27 13:29:33 +0100
committerKenny Levinsen <kl@kl.wtf>2023-01-28 22:58:19 +0100
commitdb9ee6d1277b119d213f58bfce6052458cdfecd1 (patch)
treebe1c9a64795e08b508a8be450092d4416b42f3ab /main.c
parentbd2dfec9ae0111b1858d5fab44f0f4fac4117d07 (diff)
Add --ready-fd
This implements a readiness notification mechanism which works on both systemd and s6. References: https://github.com/swaywm/swaylock/pull/42 References: https://github.com/swaywm/swaylock/pull/275
Diffstat (limited to 'main.c')
-rw-r--r--main.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/main.c b/main.c
index 7b86168..68c7bac 100644
--- a/main.c
+++ b/main.c
@@ -579,6 +579,7 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
{"debug", no_argument, NULL, 'd'},
{"ignore-empty-password", no_argument, NULL, 'e'},
{"daemonize", no_argument, NULL, 'f'},
+ {"ready-fd", required_argument, NULL, 'R'},
{"help", no_argument, NULL, 'h'},
{"image", required_argument, NULL, 'i'},
{"disable-caps-lock-text", no_argument, NULL, 'L'},
@@ -645,6 +646,8 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
"Show current count of failed authentication attempts.\n"
" -f, --daemonize "
"Detach from the controlling terminal after locking.\n"
+ " -R, --ready-fd <fd> "
+ "File descriptor to send readiness notifications to.\n"
" -h, --help "
"Show help message and quit.\n"
" -i, --image [[<output>]:]<path> "
@@ -754,7 +757,7 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
optind = 1;
while (1) {
int opt_idx = 0;
- c = getopt_long(argc, argv, "c:deFfhi:kKLlnrs:tuvC:", long_options,
+ c = getopt_long(argc, argv, "c:deFfhi:kKLlnrs:tuvC:R:", long_options,
&opt_idx);
if (c == -1) {
break;
@@ -788,6 +791,11 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
state->args.daemonize = true;
}
break;
+ case 'R':
+ if (state) {
+ state->args.ready_fd = strtol(optarg, NULL, 10);
+ }
+ break;
case 'i':
if (state) {
load_image(optarg, state);
@@ -1182,7 +1190,8 @@ int main(int argc, char **argv) {
.show_keyboard_layout = false,
.hide_keyboard_layout = false,
.show_failed_attempts = false,
- .indicator_idle_visible = false
+ .indicator_idle_visible = false,
+ .ready_fd = -1,
};
wl_list_init(&state.images);
set_default_colors(&state.args.colors);
@@ -1311,6 +1320,17 @@ int main(int argc, char **argv) {
state.locked = true;
}
+ if (state.args.ready_fd >= 0) {
+ // s6 wants a newline and ignores any text before that, systemd wants
+ // READY=1, so use the least common denominator
+ const char ready_str[] = "READY=1\n";
+ if (write(state.args.ready_fd, ready_str, strlen(ready_str)) != strlen(ready_str)) {
+ swaylock_log(LOG_ERROR, "Failed to send readiness notification");
+ return 2;
+ }
+ close(state.args.ready_fd);
+ state.args.ready_fd = -1;
+ }
if (state.args.daemonize) {
daemonize();
}