From 2c06b902f4fcf8466102784cbfc78f6065b26905 Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Tue, 4 Oct 2022 21:48:57 +0100 Subject: [PATCH] Set environment variable LABWC_PID ...to the pid of the compositor so that SIGHUP and SIGTERM can be sent to specific instances using `kill -s ` rather than `killall -s labwc` Issue #573 --- src/main.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main.c b/src/main.c index 8ca6fe09..dc811f28 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only #define _POSIX_C_SOURCE 200809L #include +#include #include "common/dir.h" #include "common/fd_util.h" #include "common/font.h" @@ -81,6 +82,19 @@ main(int argc, char *argv[]) session_environment_init(rc.config_dir); rcxml_read(config_file); + /* + * Set environment variable LABWC_PID to the pid of the compositor + * so that SIGHUP and SIGTERM can be sent to specific instances using + * `kill -s ` rather than `killall -s labwc` + */ + char pid[32]; + snprintf(pid, sizeof(pid), "%d", getpid()); + if (setenv("LABWC_PID", pid, true) < 0) { + wlr_log_errno(WLR_ERROR, "unable to set LABWC_PID"); + } else { + wlr_log(WLR_DEBUG, "LABWC_PID=%s", pid); + } + if (!getenv("XDG_RUNTIME_DIR")) { wlr_log(WLR_ERROR, "XDG_RUNTIME_DIR is unset"); exit(EXIT_FAILURE);