mirror of
https://github.com/troglobit/finit.git
synced 2026-10-19 11:09:35 +00:00
.conf: don't rely on mtime to determine if service needs reloading
Until now Finit has used mtime to determine if a file has been changed, or simply touched to request reload, when `initctl reload` is called. Using mtime for this purpose is a monumentally bad idea since time can be changed at any point: a user may adjust the time, NTP continously tunes the clock, and time stamps are stored as the walltime. So if we compare timestamps against the last time we (booted or) did reload, we would miss .conf file changes. This patch replaces the mtime mistake with an inotify watcher for the following files: /etc/finit.d/*.conf, /etc/finit.d/available/*.conf, and /etc/finit.conf. All file changes between (bootstraps and) calls to `initctl reload` are tracked, like the mtime backend it replaces. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
bb3d9c8670
commit
b439ac670d
10 files changed
+261
-90
No files matched your search
@@ -90,22 +90,8 @@ void tty_mark(void)
|
||||
{
|
||||
tty_node_t *tty;
|
||||
|
||||
LIST_FOREACH(tty, &tty_list, link) {
|
||||
if (tty->mtime.tv_sec)
|
||||
tty->dirty = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void tty_check(tty_node_t *tty, struct timeval *mtime)
|
||||
{
|
||||
if (mtime && timercmp(&tty->mtime, mtime, !=))
|
||||
tty->dirty = 1; /* Modified, restart */
|
||||
else
|
||||
tty->dirty = 0; /* Not modified */
|
||||
|
||||
/* Update mtime, if given */
|
||||
tty->mtime.tv_sec = mtime ? mtime->tv_sec : 0;
|
||||
tty->mtime.tv_usec = mtime ? mtime->tv_usec : 0;
|
||||
LIST_FOREACH(tty, &tty_list, link)
|
||||
tty->dirty = -1;
|
||||
}
|
||||
|
||||
void tty_sweep(void)
|
||||
@@ -113,14 +99,15 @@ void tty_sweep(void)
|
||||
tty_node_t *tty, *tmp;
|
||||
|
||||
LIST_FOREACH_SAFE(tty, &tty_list, link, tmp) {
|
||||
if (tty->mtime.tv_sec && tty->dirty) {
|
||||
_d("TTY %s dirty, stopping ...", tty->data.name);
|
||||
tty_stop(&tty->data);
|
||||
if (!tty->dirty)
|
||||
continue;
|
||||
|
||||
if (tty->dirty == -1) {
|
||||
_d("TTY %s removed, cleaning up.", tty->data.name);
|
||||
tty_unregister(tty);
|
||||
}
|
||||
_d("TTY %s dirty, stopping ...", tty->data.name);
|
||||
tty_stop(&tty->data);
|
||||
|
||||
if (tty->dirty == -1) {
|
||||
_d("TTY %s removed, cleaning up.", tty->data.name);
|
||||
tty_unregister(tty);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,7 +116,7 @@ void tty_sweep(void)
|
||||
* tty_register - Register a getty on a device
|
||||
* @line: Configuration, text after initial "tty"
|
||||
* @rlimit: Limits for this service/task/run/inetd, may be global limits
|
||||
* @mtime: Modification time, to propagate to lower layers
|
||||
* @file: The file name TTY was loaded from
|
||||
*
|
||||
* A Finit tty line can use the internal getty implementation or an
|
||||
* external one, like the BusyBox getty for instance. This function
|
||||
@@ -147,7 +134,7 @@ void tty_sweep(void)
|
||||
* Different getty implementations prefer the TTY device argument in
|
||||
* different order, so take care to investigate this first.
|
||||
*/
|
||||
int tty_register(char *line, struct rlimit rlimit[], struct timeval *mtime)
|
||||
int tty_register(char *line, struct rlimit rlimit[], char *file)
|
||||
{
|
||||
tty_node_t *entry;
|
||||
int insert = 0, noclear = 0, nowait = 0;
|
||||
@@ -282,7 +269,10 @@ int tty_register(char *line, struct rlimit rlimit[], struct timeval *mtime)
|
||||
/* Register configured limits */
|
||||
memcpy(entry->data.rlimit, rlimit, sizeof(entry->data.rlimit));
|
||||
|
||||
tty_check(entry, mtime);
|
||||
if (file && conf_changed(file))
|
||||
entry->dirty = 1; /* Modified, restart */
|
||||
else
|
||||
entry->dirty = 0; /* Not modified */
|
||||
_d("TTY %s is %sdirty", dev, entry->dirty ? "" : "NOT ");
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in new issue
Block a user