aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenny Levinsen <kl@kl.wtf>2022-02-26 19:05:49 +0100
committerKenny Levinsen <kl@kl.wtf>2022-02-26 19:17:26 +0100
commit9bbdf0f0b8d383edd1d621507c04db0a5382a5af (patch)
tree319802f0b4a9bc6a406b9e04ed6954a7eef5dcc0
parent3eb0db57bb1c23b5157279223f248d58d9662aae (diff)
seatd: Command-line argument for loglevel
SEATD_LOGLEVEL was used to set the loglevel despite already having getopt in place. Remove the environment variable and make a command-line argument for it instead.
-rw-r--r--man/seatd-launch.1.scd4
-rw-r--r--man/seatd.1.scd16
-rw-r--r--seatd-launch/seatd-launch.c23
-rw-r--r--seatd/seatd.c35
4 files changed, 39 insertions, 39 deletions
diff --git a/man/seatd-launch.1.scd b/man/seatd-launch.1.scd
index 9234203..d66ad3e 100644
--- a/man/seatd-launch.1.scd
+++ b/man/seatd-launch.1.scd
@@ -10,6 +10,10 @@ seatd-launch - Start a process with its own seatd instance
# OPTIONS
+*-l <loglevel>*
+ Log-level to pass to seatd. See *seatd*(1) for information about
+ available log-levels.
+
*-h*
Show help message and quit.
diff --git a/man/seatd.1.scd b/man/seatd.1.scd
index de95843..2de4326 100644
--- a/man/seatd.1.scd
+++ b/man/seatd.1.scd
@@ -27,6 +27,10 @@ seatd - A seat management daemon
*-s <path>*
Where to create the seatd socket. Defaults to `/run/seatd.sock`.
+*-l <loglevel>*
+ Log-level to use. Must be one of debug, info, error or silent. Defaults
+ to error.
+
*-v*
Show the version number and quit.
@@ -38,18 +42,6 @@ such as displays and input devices in a multi-session, multi-seat environment.
seatd operates over a UNIX domain socket, with *libseat* providing the
client-side of the protocol.
-# ENVIRONMENT
-
-[[ *VARIABLE*
-:[ *VALUES*
-:< *DESCRIPTION*
-| SEATD_SOCK
-: File path
-: Informs libseat of the socket location, needed if it differs from `/run/seatd.sock`
-| SEATD_LOGLEVEL
-: silent, error, info, debug
-: Sets the seatd log level. Defaults to "error"
-
# SEE ALSO
The libseat library, *<libseat.h>*, *seatd-launch*(1)
diff --git a/seatd-launch/seatd-launch.c b/seatd-launch/seatd-launch.c
index d03a50f..f8ab8d4 100644
--- a/seatd-launch/seatd-launch.c
+++ b/seatd-launch/seatd-launch.c
@@ -13,13 +13,19 @@
int main(int argc, char *argv[]) {
const char *usage = "Usage: seatd-launch [options] [--] command\n"
"\n"
- " -h Show this help message\n"
- " -v Show the version number\n"
+ " -l <loglevel> Log-level to pass to seatd\n"
+ " -h Show this help message\n"
+ " -v Show the version number\n"
"\n";
int c;
- while ((c = getopt(argc, argv, "vh")) != -1) {
+ char loglevel[16] = "info";
+ while ((c = getopt(argc, argv, "vhl:")) != -1) {
switch (c) {
+ case 'l':
+ strncpy(loglevel, optarg, sizeof loglevel);
+ loglevel[sizeof loglevel - 1] = '\0';
+ break;
case 'v':
printf("seatd-launch version %s\n", SEATD_VERSION);
return 0;
@@ -60,15 +66,8 @@ int main(int argc, char *argv[]) {
char pipebuf[16] = {0};
snprintf(pipebuf, sizeof pipebuf, "%d", readiness_pipe[1]);
- char *env[2] = {NULL, NULL};
- char loglevelbuf[32] = {0};
- char *cur_loglevel = getenv("SEATD_LOGLEVEL");
- if (cur_loglevel != NULL) {
- snprintf(loglevelbuf, sizeof loglevelbuf, "SEATD_LOGLEVEL=%s", cur_loglevel);
- env[0] = loglevelbuf;
- }
-
- char *command[] = {"seatd", "-n", pipebuf, "-s", sockpath, NULL};
+ char *env[1] = {NULL};
+ char *command[] = {"seatd", "-n", pipebuf, "-s", sockpath, "-l", loglevel, NULL};
execve(SEATD_INSTALLPATH, command, env);
perror("Could not start seatd");
_exit(1);
diff --git a/seatd/seatd.c b/seatd/seatd.c
index 0d9274b..2a41146 100644
--- a/seatd/seatd.c
+++ b/seatd/seatd.c
@@ -57,20 +57,6 @@ error:
}
int main(int argc, char *argv[]) {
- char *loglevel = getenv("SEATD_LOGLEVEL");
- enum libseat_log_level level = LIBSEAT_LOG_LEVEL_ERROR;
- if (loglevel != NULL) {
- if (strcmp(loglevel, "silent") == 0) {
- level = LIBSEAT_LOG_LEVEL_SILENT;
- } else if (strcmp(loglevel, "info") == 0) {
- level = LIBSEAT_LOG_LEVEL_INFO;
- } else if (strcmp(loglevel, "debug") == 0) {
- level = LIBSEAT_LOG_LEVEL_DEBUG;
- }
- }
- log_init();
- libseat_set_log_level(level);
-
const char *usage = "Usage: seatd [options]\n"
"\n"
" -h Show this help message\n"
@@ -78,14 +64,16 @@ int main(int argc, char *argv[]) {
" -u <user> User to own the seatd socket\n"
" -g <group> Group to own the seatd socket\n"
" -s <path> Where to create the seatd socket\n"
+ " -l <loglevel> Log-level, one of debug, info, error or silent\n"
" -v Show the version number\n"
"\n";
int c;
int uid = -1, gid = -1;
int readiness = -1;
+ enum libseat_log_level level = LIBSEAT_LOG_LEVEL_ERROR;
const char *socket_path = SEATD_DEFAULTPATH;
- while ((c = getopt(argc, argv, "vhn:s:g:u:")) != -1) {
+ while ((c = getopt(argc, argv, "vhn:s:g:u:l:")) != -1) {
switch (c) {
case 'n':
readiness = atoi(optarg);
@@ -117,6 +105,20 @@ int main(int argc, char *argv[]) {
}
break;
}
+ case 'l':
+ if (strcmp(optarg, "debug") == 0) {
+ level = LIBSEAT_LOG_LEVEL_DEBUG;
+ } else if (strcmp(optarg, "info") == 0) {
+ level = LIBSEAT_LOG_LEVEL_INFO;
+ } else if (strcmp(optarg, "error") == 0) {
+ level = LIBSEAT_LOG_LEVEL_ERROR;
+ } else if (strcmp(optarg, "silent") == 0) {
+ level = LIBSEAT_LOG_LEVEL_SILENT;
+ } else {
+ fprintf(stderr, "Invalid loglevel: %s\n", optarg);
+ return 1;
+ }
+ break;
case 'v':
printf("seatd version %s\n", SEATD_VERSION);
return 0;
@@ -131,6 +133,9 @@ int main(int argc, char *argv[]) {
}
}
+ log_init();
+ libseat_set_log_level(level);
+
struct stat st;
if (stat(socket_path, &st) == 0) {
if (!S_ISSOCK(st.st_mode)) {