mirror of
https://github.com/pygos/init.git
synced 2024-11-25 20:40:48 +01:00
Add service respawn limit
Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
This commit is contained in:
parent
09115f9a97
commit
160ef94e8b
3 changed files with 40 additions and 0 deletions
10
initd/main.c
10
initd/main.c
|
@ -43,6 +43,16 @@ static void handle_exited(service_t *svc)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (svc->rspwn_limit > 0) {
|
||||||
|
svc->rspwn_limit -= 1;
|
||||||
|
|
||||||
|
if (svc->rspwn_limit == 0) {
|
||||||
|
print_status(svc->desc, STATUS_FAIL, false);
|
||||||
|
delsvc(svc);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
svc->pid = runlst(svc->exec, svc->num_exec, svc->ctty);
|
svc->pid = runlst(svc->exec, svc->num_exec, svc->ctty);
|
||||||
if (svc->pid == -1) {
|
if (svc->pid == -1) {
|
||||||
print_status(svc->desc, STATUS_FAIL, false);
|
print_status(svc->desc, STATUS_FAIL, false);
|
||||||
|
|
|
@ -53,6 +53,8 @@ typedef struct service_t {
|
||||||
size_t num_exec; /* number of command lines */
|
size_t num_exec; /* number of command lines */
|
||||||
char *ctty; /* controlling tty or log file */
|
char *ctty; /* controlling tty or log file */
|
||||||
|
|
||||||
|
int rspwn_limit; /* maximum respawn count */
|
||||||
|
|
||||||
char **before; /* services that must be executed later */
|
char **before; /* services that must be executed later */
|
||||||
size_t num_before;
|
size_t num_before;
|
||||||
char **after; /* services that must be executed first */
|
char **after; /* services that must be executed first */
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "service.h"
|
#include "service.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
@ -132,6 +133,32 @@ static int svc_target(service_t *svc, char *arg,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int svc_rspwn_limit(service_t *svc, char *arg,
|
||||||
|
const char *filename, size_t lineno)
|
||||||
|
{
|
||||||
|
const char *ptr;
|
||||||
|
|
||||||
|
svc->rspwn_limit = 0;
|
||||||
|
|
||||||
|
if (!isdigit(*arg))
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
for (ptr = arg; isdigit(*ptr); ++ptr)
|
||||||
|
svc->rspwn_limit = svc->rspwn_limit * 10 + (*ptr - '0');
|
||||||
|
|
||||||
|
if (*ptr != '\0')
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
free(arg);
|
||||||
|
return 0;
|
||||||
|
fail:
|
||||||
|
fprintf(stderr,
|
||||||
|
"%s: %zu: expected numeric argument for respawn limit\n",
|
||||||
|
filename, lineno);
|
||||||
|
free(arg);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static const struct {
|
static const struct {
|
||||||
const char *key;
|
const char *key;
|
||||||
|
@ -147,6 +174,7 @@ static const struct {
|
||||||
{ "tty", svc_tty },
|
{ "tty", svc_tty },
|
||||||
{ "before", svc_before },
|
{ "before", svc_before },
|
||||||
{ "after", svc_after },
|
{ "after", svc_after },
|
||||||
|
{ "respawn_limit", svc_rspwn_limit },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue