]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Add --exit and --reconfigure
authorJohan Malm <jgm323@gmail.com>
Thu, 6 Oct 2022 20:54:49 +0000 (21:54 +0100)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Fri, 14 Oct 2022 22:19:18 +0000 (00:19 +0200)
docs/labwc.1.scd
src/main.c

index 32ba3c610cfcdde290001cf11d0135a16f5428fa..ed2f317fafc49f6a039516508fefa1bcabe6e964 100644 (file)
@@ -24,6 +24,10 @@ kill -s <signal> $LABWC_PID
 killall -s <signal> labwc
 ```
 
+Each running instance of labwc sets the environment variable `LABWC_PID` to
+its PID. This is useful for sending signals to a specific instance and is what
+the `--exit` and `--reconfigure` options use.
+
 # OPTIONS
 
 *-c, --config* <config-file>
@@ -35,9 +39,15 @@ killall -s <signal> labwc
 *-d, --debug*
        Enable full logging, including debug information
 
+*-e, --exit*
+       Exit the compositor
+
 *-h, --help*
        Show help message and quit
 
+*-r, --reconfigure*
+       Reload the compositor configuration
+
 *-s, --startup* <command>
        Run command on startup
 
index 88b304d606fd527245ac7c6d7302cdb95470f5db..04d020cb950935feb3c300d82a56da41fcab1d64 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 #define _POSIX_C_SOURCE 200809L
+#include <signal.h>
 #include <string.h>
 #include <unistd.h>
 #include "common/dir.h"
@@ -18,7 +19,9 @@ static const struct option long_options[] = {
        {"config", required_argument, NULL, 'c'},
        {"config-dir", required_argument, NULL, 'C'},
        {"debug", no_argument, NULL, 'd'},
+       {"exit", no_argument, NULL, 'e'},
        {"help", no_argument, NULL, 'h'},
+       {"reconfigure", no_argument, NULL, 'r'},
        {"startup", required_argument, NULL, 's'},
        {"version", no_argument, NULL, 'v'},
        {"verbose", no_argument, NULL, 'V'},
@@ -30,7 +33,9 @@ static const char labwc_usage[] =
 "  -c, --config <file>      Specify config file (with path)\n"
 "  -C, --config-dir <dir>   Specify config directory\n"
 "  -d, --debug              Enable full logging, including debug information\n"
+"  -e, --exit               Exit the compositor\n"
 "  -h, --help               Show help message and quit\n"
+"  -r, --reconfigure        Reload the compositor configuration\n"
 "  -s, --startup <command>  Run command on startup\n"
 "  -v, --version            Show version number and quit\n"
 "  -V, --verbose            Enable more verbose logging\n";
@@ -42,6 +47,22 @@ usage(void)
        exit(0);
 }
 
+static void
+send_signal_to_labwc_pid(int signal)
+{
+       char *labwc_pid = getenv("LABWC_PID");
+       if (!labwc_pid) {
+               wlr_log(WLR_ERROR, "LABWC_PID not set");
+               exit(EXIT_FAILURE);
+       }
+       int pid = atoi(labwc_pid);
+       if (!pid) {
+               wlr_log(WLR_ERROR, "should not send signal to pid 0");
+               exit(EXIT_FAILURE);
+       }
+       kill(pid, signal);
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -57,7 +78,7 @@ main(int argc, char *argv[])
        int c;
        while (1) {
                int index = 0;
-               c = getopt_long(argc, argv, "c:C:dhs:vV", long_options, &index);
+               c = getopt_long(argc, argv, "c:C:dehrs:vV", long_options, &index);
                if (c == -1) {
                        break;
                }
@@ -71,6 +92,12 @@ main(int argc, char *argv[])
                case 'd':
                        verbosity = WLR_DEBUG;
                        break;
+               case 'e':
+                       send_signal_to_labwc_pid(SIGTERM);
+                       exit(0);
+               case 'r':
+                       send_signal_to_labwc_pid(SIGHUP);
+                       exit(0);
                case 's':
                        startup_cmd = optarg;
                        break;