From d4886a3cd5e33d672a95521c854754fd772d3757 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 7 Jul 2018 18:36:49 +0100 Subject: [PATCH] swaylock: daemonize after locking --- main.c | 10 ++++++++-- swaylock.1.scd | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 1c0cef2..73c2b5d 100644 --- a/main.c +++ b/main.c @@ -38,6 +38,7 @@ static void daemonize() { exit(1); } if (fork() == 0) { + setsid(); close(fds[0]); int devnull = open("/dev/null", O_RDWR); dup2(STDOUT_FILENO, devnull); @@ -406,7 +407,7 @@ int main(int argc, char **argv) { " -v, --version Show the version number and quit.\n" " -i, --image [:] Display the given image.\n" " -u, --no-unlock-indicator Disable the unlock indicator.\n" - " -f, --daemonize Detach from the controlling terminal.\n"; + " -f, --daemonize Detach from the controlling terminal after locking.\n"; state.args = (struct swaylock_args){ .mode = BACKGROUND_MODE_SOLID_COLOR, @@ -454,7 +455,7 @@ int main(int argc, char **argv) { state.args.show_indicator = false; break; case 'f': - daemonize(); + state.args.daemonize = true; break; default: fprintf(stderr, "%s", usage); @@ -510,6 +511,11 @@ int main(int argc, char **argv) { create_layer_surface(surface); } + if (state.args.daemonize) { + wl_display_roundtrip(state.display); + daemonize(); + } + state.run_display = true; while (wl_display_dispatch(state.display) != -1 && state.run_display) { // This space intentionally left blank diff --git a/swaylock.1.scd b/swaylock.1.scd index 35d6444..1b3366f 100644 --- a/swaylock.1.scd +++ b/swaylock.1.scd @@ -37,6 +37,9 @@ Locks your Wayland session. *-u, --no-unlock-indicator* Disable the unlock indicator. +*-f, --daemonize* + Detach from the controlling terminal after locking. + *-v, --version* Show the version number and quit.