mirror of
https://github.com/troglobit/finit.git
synced 2026-11-01 13:10:32 +00:00
Fix #246: conditions for running/halted services
This change adds the following service conditions, which can be used to synchronize other stanzas: - service/foo/running - service/foo/halted - service/foo/missing - service/foo/crashed - service/foo/stopped - service/foo/busy - service/foo/restart Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
30fb9780d7
commit
82cc10be88
2 files changed
+44
-2
No files matched your search
+26
-2
@@ -21,6 +21,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <ftw.h>
|
||||
#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
@@ -132,6 +133,25 @@ static int cond_checkpath(const char *path)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Intended for 'service/foo/`, nothing else */
|
||||
static void cond_delpath(const char *path)
|
||||
{
|
||||
char fn[PATH_MAX];
|
||||
struct dirent *d;
|
||||
DIR *dir;
|
||||
|
||||
dir = opendir(path);
|
||||
if (!dir)
|
||||
return;
|
||||
|
||||
while ((d = readdir(dir))) {
|
||||
paste(fn, sizeof(fn), path, d->d_name);
|
||||
remove(fn);
|
||||
}
|
||||
closedir(dir);
|
||||
unlink(path);
|
||||
}
|
||||
|
||||
int cond_set_path(const char *path, enum cond_state next)
|
||||
{
|
||||
enum cond_state prev;
|
||||
@@ -155,8 +175,12 @@ int cond_set_path(const char *path, enum cond_state next)
|
||||
break;
|
||||
|
||||
case COND_OFF:
|
||||
if (unlink(path) && errno != ENOENT)
|
||||
_pe("Failed removing condition '%s'", path);
|
||||
if (unlink(path)) {
|
||||
if (errno == ENOENT)
|
||||
_pe("Failed removing condition '%s'", path);
|
||||
if (errno == EISDIR)
|
||||
cond_delpath(path);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
Reference in new issue
Block a user