80 lines
2.1 KiB
Diff
80 lines
2.1 KiB
Diff
diff --git a/init/job_class.c b/init/job_class.c
|
|
index eeec83d..00eb13d 100644
|
|
--- a/init/job_class.c
|
|
+++ b/init/job_class.c
|
|
@@ -219,6 +219,8 @@ job_class_new (const void *parent,
|
|
class->chroot = NULL;
|
|
class->chdir = NULL;
|
|
|
|
+ class->utmp_id = NULL;
|
|
+
|
|
class->deleted = FALSE;
|
|
class->debug = FALSE;
|
|
|
|
diff --git a/init/job_class.h b/init/job_class.h
|
|
index d40e750..e5b5190 100644
|
|
--- a/init/job_class.h
|
|
+++ b/init/job_class.h
|
|
@@ -145,6 +145,7 @@ typedef struct job_class {
|
|
struct rlimit *limits[RLIMIT_NLIMITS];
|
|
char *chroot;
|
|
char *chdir;
|
|
+ char *utmp_id;
|
|
|
|
int deleted;
|
|
int debug;
|
|
diff --git a/init/job_process.c b/init/job_process.c
|
|
index 70fa2bf..544f5e3 100644
|
|
--- a/init/job_process.c
|
|
+++ b/init/job_process.c
|
|
@@ -361,11 +361,13 @@ job_process_spawn (JobClass *class,
|
|
char * const *env,
|
|
int trace)
|
|
{
|
|
- sigset_t child_set, orig_set;
|
|
- pid_t pid;
|
|
- int i, fds[2];
|
|
- char filename[PATH_MAX];
|
|
- FILE *fd;
|
|
+ sigset_t child_set, orig_set;
|
|
+ pid_t pid;
|
|
+ int i, fds[2];
|
|
+ char filename[PATH_MAX];
|
|
+ FILE *fd;
|
|
+ struct utmpx utmp;
|
|
+ struct timeval tv;
|
|
|
|
nih_assert (class != NULL);
|
|
|
|
@@ -558,6 +560,20 @@ job_process_spawn (JobClass *class,
|
|
}
|
|
}
|
|
|
|
+ /* Write utmp INIT_PROCESS entry */
|
|
+ if (class->utmp_id) {
|
|
+ memset(&utmp, 0, sizeof(struct utmpx));
|
|
+ strncpy(utmp.ut_id, class->utmp_id, sizeof(utmp.ut_id));
|
|
+ utmp.ut_pid = getpid();
|
|
+ utmp.ut_type = INIT_PROCESS;
|
|
+ gettimeofday(&tv, NULL);
|
|
+ utmp.ut_tv.tv_sec = tv.tv_sec;
|
|
+ utmp.ut_tv.tv_usec = tv.tv_usec;
|
|
+ setutxent();
|
|
+ pututxline(&utmp);
|
|
+ endutxent();
|
|
+ }
|
|
+
|
|
/* Execute the process, if we escape from here it failed */
|
|
if (execvp (argv[0], argv) < 0) {
|
|
nih_error_raise_system ();
|
|
@@ -1176,6 +1192,10 @@ job_process_terminated (Job *job,
|
|
memset(utmptr->ut_user, 0, UT_NAMESIZE);
|
|
memset(utmptr->ut_host, 0, UT_HOSTSIZE);
|
|
utmptr->ut_time = 0;
|
|
+
|
|
+ /* Set class utmp_id for next spawn */
|
|
+ job->class->utmp_id = nih_strdup (job->class, utmptr->ut_id);
|
|
+
|
|
/* Update existing utmp file. */
|
|
pututxline(utmptr);
|
|
|