summaryrefslogtreecommitdiffstats
path: root/swaylock
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2018-07-07 18:36:49 +0100
committerLibravatar emersion <contact@emersion.fr>2018-07-07 18:36:49 +0100
commitceb08b6365d2a085aca5271570c332b3202d305a (patch)
treeebcc4bd77c588ba2ce018238ea4a4de3d4659bf2 /swaylock
parentMerge pull request #2225 from martinetd/swaylock-verified (diff)
downloadsway-ceb08b6365d2a085aca5271570c332b3202d305a.tar.gz
sway-ceb08b6365d2a085aca5271570c332b3202d305a.tar.zst
sway-ceb08b6365d2a085aca5271570c332b3202d305a.zip
swaylock: daemonize after locking
Diffstat (limited to 'swaylock')
-rw-r--r--swaylock/main.c10
-rw-r--r--swaylock/swaylock.1.scd3
2 files changed, 11 insertions, 2 deletions
diff --git a/swaylock/main.c b/swaylock/main.c
index 1c0cef2b..73c2b5d6 100644
--- a/swaylock/main.c
+++ b/swaylock/main.c
@@ -38,6 +38,7 @@ static void daemonize() {
38 exit(1); 38 exit(1);
39 } 39 }
40 if (fork() == 0) { 40 if (fork() == 0) {
41 setsid();
41 close(fds[0]); 42 close(fds[0]);
42 int devnull = open("/dev/null", O_RDWR); 43 int devnull = open("/dev/null", O_RDWR);
43 dup2(STDOUT_FILENO, devnull); 44 dup2(STDOUT_FILENO, devnull);
@@ -406,7 +407,7 @@ int main(int argc, char **argv) {
406 " -v, --version Show the version number and quit.\n" 407 " -v, --version Show the version number and quit.\n"
407 " -i, --image [<output>:]<path> Display the given image.\n" 408 " -i, --image [<output>:]<path> Display the given image.\n"
408 " -u, --no-unlock-indicator Disable the unlock indicator.\n" 409 " -u, --no-unlock-indicator Disable the unlock indicator.\n"
409 " -f, --daemonize Detach from the controlling terminal.\n"; 410 " -f, --daemonize Detach from the controlling terminal after locking.\n";
410 411
411 state.args = (struct swaylock_args){ 412 state.args = (struct swaylock_args){
412 .mode = BACKGROUND_MODE_SOLID_COLOR, 413 .mode = BACKGROUND_MODE_SOLID_COLOR,
@@ -454,7 +455,7 @@ int main(int argc, char **argv) {
454 state.args.show_indicator = false; 455 state.args.show_indicator = false;
455 break; 456 break;
456 case 'f': 457 case 'f':
457 daemonize(); 458 state.args.daemonize = true;
458 break; 459 break;
459 default: 460 default:
460 fprintf(stderr, "%s", usage); 461 fprintf(stderr, "%s", usage);
@@ -510,6 +511,11 @@ int main(int argc, char **argv) {
510 create_layer_surface(surface); 511 create_layer_surface(surface);
511 } 512 }
512 513
514 if (state.args.daemonize) {
515 wl_display_roundtrip(state.display);
516 daemonize();
517 }
518
513 state.run_display = true; 519 state.run_display = true;
514 while (wl_display_dispatch(state.display) != -1 && state.run_display) { 520 while (wl_display_dispatch(state.display) != -1 && state.run_display) {
515 // This space intentionally left blank 521 // This space intentionally left blank
diff --git a/swaylock/swaylock.1.scd b/swaylock/swaylock.1.scd
index 35d6444c..1b3366f0 100644
--- a/swaylock/swaylock.1.scd
+++ b/swaylock/swaylock.1.scd
@@ -37,6 +37,9 @@ Locks your Wayland session.
37*-u, --no-unlock-indicator* 37*-u, --no-unlock-indicator*
38 Disable the unlock indicator. 38 Disable the unlock indicator.
39 39
40*-f, --daemonize*
41 Detach from the controlling terminal after locking.
42
40*-v, --version* 43*-v, --version*
41 Show the version number and quit. 44 Show the version number and quit.
42 45