From b5b8c19df66710e40791aeae46da53813943c436 Mon Sep 17 00:00:00 2001 From: Trumeet Date: Sat, 24 Dec 2022 10:02:52 -0800 Subject: Use setproctitle(3) --- main.c | 7 ++++++- sd.c | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 0be6f54..e8339fb 100644 --- a/main.c +++ b/main.c @@ -6,6 +6,7 @@ #include #include #include +#include #include struct auth_env a_env; @@ -19,7 +20,8 @@ struct proc_env p_env = { static void interrupt_int(int signum) { } -int main(int argc, char **argv) { +int main(int argc, char **argv, char **envp) { + setproctitle_init(argc, argv, envp); if (argc != 2 && argc != 3) { fprintf(stderr, "Usage: %s consent|password|auth [prompt]\n", argv[0]); @@ -48,6 +50,8 @@ int main(int argc, char **argv) { a_env.pid = getppid(); a_env.usr = getuid(); + setproctitle("master"); + ssize_t len; snprintf(a_env.exe, sizeof(a_env.exe) - 1, "/proc/%d/exe", a_env.pid); if ((len = readlink(a_env.exe, a_env.exe, sizeof(a_env.exe) - 1)) == -1) { @@ -59,6 +63,7 @@ int main(int argc, char **argv) { pid_t chld; /* Detach from the current session. */ if (!(chld = fork())) { + setproctitle("auth"); /* Because we need to frequently dup(2). */ setbuf(stdout, NULL); signal(SIGHUP, SIG_IGN); diff --git a/sd.c b/sd.c index d1e6730..ad67db5 100644 --- a/sd.c +++ b/sd.c @@ -14,6 +14,7 @@ if (ioctl(a, b, __VA_ARGS__) < 0) { LOGFV("ioctl(%d, 0x%x): %m", a, b, errno); r #include #include #include +#include #include #include @@ -81,6 +82,7 @@ static int find_current_tty(void) { } static int main_sak(void) { + setproctitle("sak"); /* We have to take the ownership here - otherwise SAK will kill the parent. */ if (setsid() == -1) { LOGFV("Cannot set session ID: %m.", errno); -- cgit v1.2.3