Add support for one-shot conditions, like most hooks

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2018-01-14 11:24:29 +01:00
1 parent e1b87d707f
commit cc186334e0
2 files changed
+40 -17

No files matched your search

+33 -11
View File
@@ -59,9 +59,27 @@ static void cond_bump_reconf(void)
cond_set_gen(COND_RECONF, rgen); cond_set_gen(COND_RECONF, rgen);
} }
int cond_set_path(const char *path, enum cond_state new) static int cond_checkpath(const char *path)
{ {
char buf[MAX_ARG_LEN], *dir; char buf[MAX_ARG_LEN], *dir;
strlcpy(buf, path, sizeof(buf));
dir = dirname(buf);
if (!dir) {
_e("Invalid path '%s' for condition", path);
return 1;
}
if (makepath(dir) && errno != EEXIST) {
_pe("Failed creating dir '%s' for condition '%s'", dir, path);
return 1;
}
return 0;
}
int cond_set_path(const char *path, enum cond_state new)
{
enum cond_state old; enum cond_state old;
unsigned int rgen; unsigned int rgen;
@@ -77,16 +95,8 @@ int cond_set_path(const char *path, enum cond_state new)
switch (new) { switch (new) {
case COND_ON: case COND_ON:
strlcpy(buf, path, sizeof(buf)); if (cond_checkpath(path))
dir = dirname(buf); return 0;
if (!dir) {
_e("Invalid path '%s' for condition", path);
return 0;
}
if (makepath(dir) && errno != EEXIST) {
_pe("Failed creating dir '%s' for condition '%s'", dir, path);
return 0;
}
cond_set_gen(path, rgen); cond_set_gen(path, rgen);
break; break;
@@ -145,6 +155,18 @@ void cond_set(const char *name)
cond_update(name); cond_update(name);
} }
void cond_set_oneshot(const char *name)
{
const char *path = cond_path(name);
_d("s => %s", name, path);
if (cond_checkpath(path))
return;
symlink(COND_RECONF, path);
cond_update(name);
}
void cond_clear(const char *name) void cond_clear(const char *name)
{ {
_d("%s", name); _d("%s", name);
+7 -6
View File
@@ -21,12 +21,13 @@ enum cond_state cond_get (const char *name);
enum cond_state cond_get_agg (const char *names); enum cond_state cond_get_agg (const char *names);
int cond_affects (const char *name, const char *names); int cond_affects (const char *name, const char *names);
int cond_set_path(const char *path, enum cond_state new); int cond_set_path (const char *path, enum cond_state new);
void cond_set (const char *name); void cond_set (const char *name);
void cond_clear (const char *name); void cond_set_oneshot (const char *name);
void cond_reload (void); void cond_clear (const char *name);
void cond_reassert(const char *pat); void cond_reload (void);
void cond_init (void); void cond_reassert (const char *pat);
void cond_init (void);
#endif /* FINIT_COND_H_ */ #endif /* FINIT_COND_H_ */