mirror of
https://github.com/troglobit/finit.git
synced 2026-10-02 05:52:48 +07:00
Add support for one-shot conditions, like most hooks
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
+33
-11
@@ -59,9 +59,27 @@ static void cond_bump_reconf(void)
|
||||
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;
|
||||
|
||||
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;
|
||||
unsigned int rgen;
|
||||
|
||||
@@ -77,16 +95,8 @@ int cond_set_path(const char *path, enum cond_state new)
|
||||
|
||||
switch (new) {
|
||||
case COND_ON:
|
||||
strlcpy(buf, path, sizeof(buf));
|
||||
dir = dirname(buf);
|
||||
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;
|
||||
}
|
||||
if (cond_checkpath(path))
|
||||
return 0;
|
||||
cond_set_gen(path, rgen);
|
||||
break;
|
||||
|
||||
@@ -145,6 +155,18 @@ void cond_set(const char *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)
|
||||
{
|
||||
_d("%s", name);
|
||||
|
||||
+7
-6
@@ -21,12 +21,13 @@ enum cond_state cond_get (const char *name);
|
||||
enum cond_state cond_get_agg (const char *names);
|
||||
int cond_affects (const char *name, const char *names);
|
||||
|
||||
int cond_set_path(const char *path, enum cond_state new);
|
||||
void cond_set (const char *name);
|
||||
void cond_clear (const char *name);
|
||||
void cond_reload (void);
|
||||
void cond_reassert(const char *pat);
|
||||
void cond_init (void);
|
||||
int cond_set_path (const char *path, enum cond_state new);
|
||||
void cond_set (const char *name);
|
||||
void cond_set_oneshot (const char *name);
|
||||
void cond_clear (const char *name);
|
||||
void cond_reload (void);
|
||||
void cond_reassert (const char *pat);
|
||||
void cond_init (void);
|
||||
|
||||
#endif /* FINIT_COND_H_ */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user