Hi,
This ensures that the GETTY_SPACING check remains useful if
the system clock is set backwards.
The time comparison is meaningless unless the timespec is set,
so there's no reason to go to the kernel to get the time unless
we have something to look at. And unless I'm missing something
there isn't any reason to continue retrieving the current time
in the parent process if we're doing the comparison in the child
process, so I've moved the system call into that block.
ok?
--
Scott Cheloha
Index: sbin/init/init.c
===================================================================
RCS file: /cvs/src/sbin/init/init.c,v
retrieving revision 1.66
diff -u -p -r1.66 init.c
--- sbin/init/init.c 6 Jan 2018 16:26:12 -0000 1.66
+++ sbin/init/init.c 30 Jan 2018 01:25:19 -0000
@@ -143,7 +143,7 @@ void setctty(char *);
typedef struct init_session {
int se_index; /* index of entry in ttys file */
pid_t se_process; /* controlling process */
- time_t se_started; /* used to avoid thrashing */
+ struct timespec se_started; /* used to avoid thrashing */
int se_flags; /* status of session */
#define SE_SHUTDOWN 0x1 /* session won't be restarted */
#define SE_PRESENT 0x2 /* session is in /etc/ttys */
@@ -1007,7 +1007,7 @@ start_getty(session_t *sp)
{
pid_t pid;
sigset_t mask;
- time_t current_time = time(NULL);
+ struct timespec current_time, elapsed;
int p[2], new = 1;
if (sp->se_flags & SE_DEVEXISTS)
@@ -1060,11 +1060,15 @@ start_getty(session_t *sp)
sleep(1);
}
- if (current_time > sp->se_started &&
- current_time - sp->se_started < GETTY_SPACING) {
- warning("getty repeating too quickly on port %s, sleeping",
- sp->se_device);
- sleep(GETTY_SLEEP);
+ if (timespecisset(&sp->se_started)) {
+ clock_gettime(CLOCK_MONOTONIC, ¤t_time);
+ timespecsub(¤t_time, &sp->se_started, &elapsed);
+ if (elapsed.tv_sec < GETTY_SPACING) {
+ warning(
+ "getty repeating too quickly on port %s, sleeping",
+ sp->se_device);
+ sleep(GETTY_SLEEP);
+ }
}
if (sp->se_window) {
@@ -1121,7 +1125,7 @@ collect_child(pid_t pid)
}
sp->se_process = pid;
- sp->se_started = time(NULL);
+ clock_gettime(CLOCK_MONOTONIC, &sp->se_started);
add_session(sp);
}
@@ -1188,7 +1192,7 @@ f_multi_user(void)
break;
}
sp->se_process = pid;
- sp->se_started = time(NULL);
+ clock_gettime(CLOCK_MONOTONIC, &sp->se_started);
add_session(sp);
}