From 5bab32917811c616b041e19957d1ef994b062f69 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Wed, 17 Aug 2016 18:43:49 +0200 Subject: [PATCH] UTMP: Only account for getty processes This patch removes accounting for all processes to instead implement the traditional SysV getty accounting. (Telnet/SSH et al maintain their own accounding for UTMP.) TODO: WTMP support Signed-off-by: Joachim Nilsson --- exec.c | 3 --- service.c | 8 -------- tty.c | 4 ++++ 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/exec.c b/exec.c index d0e3fc58..73a5374a 100644 --- a/exec.c +++ b/exec.c @@ -106,9 +106,6 @@ int run(char *cmd) for (i = 1; i < NSIG; i++) DFLSIG(sa, i, 0); - /* Set INIT_PROCESS UTMP entry */ - utmp_set_init(ttyname(0), 0); - /* Always redirect stdio for run() */ fp = fopen("/dev/null", "w"); if (fp) { diff --git a/service.c b/service.c index 7e56be72..17776814 100755 --- a/service.c +++ b/service.c @@ -152,7 +152,6 @@ static int service_start(svc_t *svc) pid = fork(); if (pid == 0) { int status; - char id[5]; char *home = NULL; #ifdef ENABLE_STATIC int uid = 0; /* XXX: Fix better warning that dropprivs is disabled. */ @@ -161,10 +160,6 @@ static int service_start(svc_t *svc) #endif char *args[MAX_NUM_SVC_ARGS]; - /* Set INIT_PROCESS UTMP entry */ - snprintf(id, sizeof(id), "%d", svc->job); - utmp_set_init(ttyname(0), id); - /* Set desired user */ if (uid >= 0) { setuid(uid); @@ -667,9 +662,6 @@ void service_monitor(pid_t lost) svc_t *svc; char pidfile[MAX_ARG_LEN]; - /* Set DEAD_PROCESS UTMP entry */ - utmp_set_dead(lost); - if (fexist(SYNC_SHUTDOWN) || lost <= 1) return; diff --git a/tty.c b/tty.c index 50617768..1d37f989 100644 --- a/tty.c +++ b/tty.c @@ -31,6 +31,7 @@ #include "conf.h" #include "helpers.h" #include "tty.h" +#include "utmp-api.h" LIST_HEAD(, tty_node) tty_list = LIST_HEAD_INITIALIZER(); @@ -198,6 +199,9 @@ int tty_respawn(pid_t pid) if (!entry) return 0; + /* Set DEAD_PROCESS UTMP entry */ + utmp_set_dead(pid); + /* Clear PID to be able to respawn it. */ entry->data.pid = 0;