Merge pull request #62 from mattiaswal/fix-fluxstate

Fix fluxstate
This commit is contained in:
Joachim Nilsson authored and GitHub committed 2017-01-11 17:21:27 +01:00
commit e272710e36
6 files changed
+38 -19

No files matched your search

+8 -5
View File
@@ -27,6 +27,7 @@
#include <string.h> #include <string.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <lite/lite.h> #include <lite/lite.h>
#include <sys/time.h>
#include "finit.h" #include "finit.h"
#include "cond.h" #include "cond.h"
@@ -293,7 +294,7 @@ static void parse_static(char *line)
} }
if (MATCH_CMD(line, "startx ", x)) { if (MATCH_CMD(line, "startx ", x)) {
service_register(SVC_TYPE_SERVICE, strip_line(x), 0, username); service_register(SVC_TYPE_SERVICE, strip_line(x), NULL, username);
return; return;
} }
@@ -332,7 +333,7 @@ static void parse_static(char *line)
} }
} }
static void parse_dynamic(char *line, time_t mtime) static void parse_dynamic(char *line, struct timeval *mtime)
{ {
char *x; char *x;
@@ -385,7 +386,7 @@ static void tabstospaces(char *line)
} }
} }
static int parse_conf_dynamic(char *file, time_t mtime) static int parse_conf_dynamic(char *file, struct timeval *mtime)
{ {
FILE *fp = fopen(file, "r"); FILE *fp = fopen(file, "r");
@@ -453,7 +454,7 @@ static int parse_conf(char *file)
_d("conf: %s", line); _d("conf: %s", line);
parse_static(line); parse_static(line);
parse_dynamic(line, 0); parse_dynamic(line, NULL);
} }
fclose(fp); fclose(fp);
@@ -481,6 +482,7 @@ void conf_reload_dynamic(void)
char *name = e[i]->d_name; char *name = e[i]->d_name;
char path[CMD_SIZE]; char path[CMD_SIZE];
struct stat st; struct stat st;
struct timeval mtime;
snprintf(path, sizeof(path), "%s/%s", dir, name); snprintf(path, sizeof(path), "%s/%s", dir, name);
@@ -498,7 +500,8 @@ void conf_reload_dynamic(void)
continue; continue;
} }
parse_conf_dynamic(path, st.st_mtime); TIMESPEC_TO_TIMEVAL(&mtime, &st.st_mtim);
parse_conf_dynamic(path, &mtime);
} }
while (num--) while (num--)
+18 -5
View File
@@ -30,6 +30,7 @@
#include "../cond.h" #include "../cond.h"
#include "../helpers.h" #include "../helpers.h"
#include "../plugin.h" #include "../plugin.h"
#include "../service.h"
struct context { struct context {
int fd; int fd;
@@ -88,16 +89,28 @@ static void pidfile_callback(void *UNUSED(arg), int fd, int UNUSED(events))
static void pidfile_reconf(void *_null) static void pidfile_reconf(void *_null)
{ {
static char name[MAX_ARG_LEN]; static char name[MAX_ARG_LEN];
svc_t *svc; svc_t *svc;
(void)(_null); (void)(_null);
int restart = 0;
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) { do {
if (svc->state == SVC_RUNNING_STATE && !svc_is_changed(svc) && !svc_is_starting(svc)) { restart = 0;
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
snprintf(name, MAX_ARG_LEN, "svc%s", svc->cmd); snprintf(name, MAX_ARG_LEN, "svc%s", svc->cmd);
cond_set_path(cond_path(name), COND_ON); if (svc->state == SVC_RUNNING_STATE &&
!svc_is_changed(svc) &&
!svc_is_starting(svc) &&
cond_get(name) != COND_ON) {
cond_set_path(cond_path(name), COND_ON);
restart = 1;
}
} }
}
if (restart)
service_step_all(SVC_TYPE_SERVICE | SVC_TYPE_INETD);
} while (restart);
} }
static void pidfile_init(void *arg) static void pidfile_init(void *arg)
+1 -1
View File
@@ -538,7 +538,7 @@ void service_runlevel(int newlevel)
* Returns: * Returns:
* POSIX OK(0) on success, or non-zero errno exit status on failure. * POSIX OK(0) on success, or non-zero errno exit status on failure.
*/ */
int service_register(int type, char *line, time_t mtime, char *username) int service_register(int type, char *line, struct timeval *mtime, char *username)
{ {
int i = 0; int i = 0;
int id = 1; /* Default to ID:1 */ int id = 1; /* Default to ID:1 */
+1 -1
View File
@@ -28,7 +28,7 @@
#include "svc.h" #include "svc.h"
void service_runlevel (int newlevel); void service_runlevel (int newlevel);
int service_register (int type, char *line, time_t mtime, char *username); int service_register (int type, char *line, struct timeval *mtime, char *username);
void service_unregister (svc_t *svc); void service_unregister (svc_t *svc);
int service_enabled (svc_t *svc); int service_enabled (svc_t *svc);
+7 -4
View File
@@ -24,6 +24,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <strings.h> #include <strings.h>
#include <sys/time.h>
#include "finit.h" #include "finit.h"
#include "svc.h" #include "svc.h"
@@ -172,7 +173,7 @@ svc_t *svc_dynamic_iterator(int first)
svc_t *svc; svc_t *svc;
for (svc = svc_iterator(first); svc; svc = svc_iterator(0)) { for (svc = svc_iterator(first); svc; svc = svc_iterator(0)) {
if (svc->mtime) if (svc->mtime.tv_sec)
return svc; return svc;
} }
@@ -415,13 +416,15 @@ void svc_mark_clean(svc_t *svc)
*((int *)&svc->dirty) = 0; *((int *)&svc->dirty) = 0;
} }
void svc_check_dirty(svc_t *svc, time_t mtime) void svc_check_dirty(svc_t *svc, struct timeval *mtime)
{ {
if (svc->mtime != mtime) if (mtime && timercmp(&svc->mtime, mtime, !=))
svc_mark_dirty(svc); svc_mark_dirty(svc);
else else
svc_mark_clean(svc); svc_mark_clean(svc);
svc->mtime = mtime;
svc->mtime.tv_sec = mtime ? mtime->tv_sec : 0;
svc->mtime.tv_usec = mtime ? mtime->tv_usec : 0;
} }
/** /**
+3 -3
View File
@@ -86,7 +86,7 @@ typedef struct svc {
pid_t pid; pid_t pid;
const svc_state_t state; /* Paused, Reloading, Restart, Running, ... */ const svc_state_t state; /* Paused, Reloading, Restart, Running, ... */
svc_type_t type; svc_type_t type;
time_t mtime; /* Modification time for .conf from /etc/finit.d/ */ struct timeval mtime; /* Modification time for .conf from /etc/finit.d/ */
const int dirty; /* Set if old mtime != new mtime => reloaded, const int dirty; /* Set if old mtime != new mtime => reloaded,
* or -1 when marked for removal */ * or -1 when marked for removal */
int starting; /* ... waiting for pidfile to be re-asserted */ int starting; /* ... waiting for pidfile to be re-asserted */
@@ -160,7 +160,7 @@ void svc_foreach_type (int types, void (*cb)(svc_t *));
int svc_stop_completed (void); int svc_stop_completed (void);
void svc_mark_dynamic (void); void svc_mark_dynamic (void);
void svc_check_dirty (svc_t *svc, time_t mtime); void svc_check_dirty (svc_t *svc, struct timeval *mtime);
void svc_mark_dirty (svc_t *svc); void svc_mark_dirty (svc_t *svc);
void svc_mark_clean (svc_t *svc); void svc_mark_clean (svc_t *svc);
void svc_clean_dynamic (void (*cb)(svc_t *)); void svc_clean_dynamic (void (*cb)(svc_t *));
@@ -177,7 +177,7 @@ static inline void svc_starting (svc_t *svc) { svc->starting = 1; }
static inline void svc_started (svc_t *svc) { svc->starting = 0; } static inline void svc_started (svc_t *svc) { svc->starting = 0; }
static inline int svc_is_starting (svc_t *svc) { return 0 != svc->starting; } static inline int svc_is_starting (svc_t *svc) { return 0 != svc->starting; }
static inline int svc_is_dynamic (svc_t *svc) { return svc && 0 != svc->mtime; } static inline int svc_is_dynamic (svc_t *svc) { return svc && 0 != svc->mtime.tv_sec; }
static inline int svc_is_removed (svc_t *svc) { return svc && -1 == svc->dirty; } static inline int svc_is_removed (svc_t *svc) { return svc && -1 == svc->dirty; }
static inline int svc_is_changed (svc_t *svc) { return svc && 0 != svc->dirty; } static inline int svc_is_changed (svc_t *svc) { return svc && 0 != svc->dirty; }
static inline int svc_is_updated (svc_t *svc) { return svc && 1 == svc->dirty; } static inline int svc_is_updated (svc_t *svc) { return svc && 1 == svc->dirty; }