mirror of
https://github.com/troglobit/finit.git
synced 2026-11-08 16:11:10 +00:00
Refactor, change from static array of svc_t to linked list
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
d7401b2a96
commit
0f1f51b5ad
7 files changed
+102
-163
No files matched your search
+1
-2
@@ -95,14 +95,13 @@ static void pidfile_callback(void *arg, int fd, int events)
|
|||||||
static void pidfile_reconf(void *arg)
|
static void pidfile_reconf(void *arg)
|
||||||
{
|
{
|
||||||
static char cond[MAX_COND_LEN];
|
static char cond[MAX_COND_LEN];
|
||||||
int pos;
|
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
int restart = 0;
|
int restart = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
restart = 0;
|
restart = 0;
|
||||||
|
|
||||||
for (svc = svc_iterator1(&pos, 1); svc; svc = svc_iterator1(&pos, 0)) {
|
for (svc = svc_iterator(NULL); svc; svc = svc_iterator(svc)) {
|
||||||
mkcond(cond, sizeof(cond), svc->cmd);
|
mkcond(cond, sizeof(cond), svc->cmd);
|
||||||
if (svc->state == SVC_RUNNING_STATE &&
|
if (svc->state == SVC_RUNNING_STATE &&
|
||||||
!svc_is_changed(svc) &&
|
!svc_is_changed(svc) &&
|
||||||
|
|||||||
@@ -225,6 +225,7 @@ static void send_svc(int sd, svc_t *svc)
|
|||||||
static void api_cb(uev_t *w, void *arg, int events)
|
static void api_cb(uev_t *w, void *arg, int events)
|
||||||
{
|
{
|
||||||
int sd, lvl;
|
int sd, lvl;
|
||||||
|
static svc_t *svc;
|
||||||
struct init_request rq;
|
struct init_request rq;
|
||||||
|
|
||||||
sd = accept(w->fd, NULL, NULL);
|
sd = accept(w->fd, NULL, NULL);
|
||||||
@@ -345,7 +346,13 @@ static void api_cb(uev_t *w, void *arg, int events)
|
|||||||
|
|
||||||
case INIT_CMD_SVC_ITER:
|
case INIT_CMD_SVC_ITER:
|
||||||
_d("svc iter, first: %d", rq.runlevel);
|
_d("svc iter, first: %d", rq.runlevel);
|
||||||
send_svc(sd, svc_iterator(rq.runlevel));
|
/*
|
||||||
|
* XXX: This severly limits the number of
|
||||||
|
* simultaneous client connections, but will
|
||||||
|
* have to do for now.
|
||||||
|
*/
|
||||||
|
svc = svc_iterator(rq.runlevel ? NULL : svc);
|
||||||
|
send_svc(sd, svc);
|
||||||
goto leave;
|
goto leave;
|
||||||
|
|
||||||
case INIT_CMD_SVC_QUERY:
|
case INIT_CMD_SVC_QUERY:
|
||||||
|
|||||||
+1
-2
@@ -88,11 +88,10 @@ static int svc_has_cond(svc_t *svc)
|
|||||||
|
|
||||||
static void cond_update(const char *name)
|
static void cond_update(const char *name)
|
||||||
{
|
{
|
||||||
int pos;
|
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
_d("%s", name);
|
_d("%s", name);
|
||||||
for (svc = svc_iterator1(&pos, 1); svc; svc = svc_iterator1(&pos, 0)) {
|
for (svc = svc_iterator(NULL); svc; svc = svc_iterator(svc)) {
|
||||||
if (!svc_has_cond(svc) || !cond_affects(name, svc->cond))
|
if (!svc_has_cond(svc) || !cond_affects(name, svc->cond))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
+2
-4
@@ -225,11 +225,10 @@ static void socket_cb(uev_t *w, void *arg, int events)
|
|||||||
*/
|
*/
|
||||||
int inetd_check_loop(struct sockaddr *sa, socklen_t len, char *name)
|
int inetd_check_loop(struct sockaddr *sa, socklen_t len, char *name)
|
||||||
{
|
{
|
||||||
int pos;
|
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
char pname[NI_MAXHOST];
|
char pname[NI_MAXHOST];
|
||||||
|
|
||||||
for (svc = svc_inetd_iterator(&pos, 1); svc; svc = svc_inetd_iterator(&pos, 0)) {
|
for (svc = svc_inetd_iterator(NULL); svc; svc = svc_inetd_iterator(svc)) {
|
||||||
inetd_t *i = &svc->inetd;
|
inetd_t *i = &svc->inetd;
|
||||||
|
|
||||||
if (!i->builtin || i->type != SOCK_DGRAM)
|
if (!i->builtin || i->type != SOCK_DGRAM)
|
||||||
@@ -666,10 +665,9 @@ int inetd_filter_str(inetd_t *inetd, char *str, size_t len)
|
|||||||
|
|
||||||
svc_t *inetd_find_svc(char *path, char *service, char *proto)
|
svc_t *inetd_find_svc(char *path, char *service, char *proto)
|
||||||
{
|
{
|
||||||
int pos;
|
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
for (svc = svc_inetd_iterator(&pos, 1); svc; svc = svc_inetd_iterator(&pos, 0)) {
|
for (svc = svc_inetd_iterator(NULL); svc; svc = svc_inetd_iterator(svc)) {
|
||||||
if (strncmp(path, svc->cmd, strlen(svc->cmd)))
|
if (strncmp(path, svc->cmd, strlen(svc->cmd)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
+2
-4
@@ -1023,10 +1023,9 @@ void service_step_all(int types)
|
|||||||
*/
|
*/
|
||||||
void service_runtask_clean(void)
|
void service_runtask_clean(void)
|
||||||
{
|
{
|
||||||
int pos;
|
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
for (svc = svc_iterator1(&pos, 1); svc; svc = svc_iterator1(&pos, 0)) {
|
for (svc = svc_iterator(NULL); svc; svc = svc_iterator(svc)) {
|
||||||
if (!svc_is_runtask(svc))
|
if (!svc_is_runtask(svc))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -1053,10 +1052,9 @@ void service_runtask_clean(void)
|
|||||||
*/
|
*/
|
||||||
int service_runtask_completed(int skip)
|
int service_runtask_completed(int skip)
|
||||||
{
|
{
|
||||||
int pos;
|
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
for (svc = svc_iterator1(&pos, 1); svc; svc = svc_iterator1(&pos, 0)) {
|
for (svc = svc_iterator(NULL); svc; svc = svc_iterator(svc)) {
|
||||||
if (!svc_is_runtask(svc))
|
if (!svc_is_runtask(svc))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <lite/queue.h> /* BSD sys/queue.h API */
|
||||||
|
|
||||||
#include "finit.h"
|
#include "finit.h"
|
||||||
#include "svc.h"
|
#include "svc.h"
|
||||||
@@ -35,21 +36,7 @@
|
|||||||
|
|
||||||
/* Each svc_t needs a unique job# */
|
/* Each svc_t needs a unique job# */
|
||||||
static int jobcounter = 1;
|
static int jobcounter = 1;
|
||||||
static svc_t *svc_list = NULL;
|
static TAILQ_HEAD(head, svc) svc_list = TAILQ_HEAD_INITIALIZER(svc_list);
|
||||||
|
|
||||||
static svc_t *__connect_shm(void)
|
|
||||||
{
|
|
||||||
if (svc_list)
|
|
||||||
return svc_list;
|
|
||||||
|
|
||||||
svc_list = calloc(MAX_NUM_SVC, sizeof(svc_t));
|
|
||||||
if (!svc_list) {
|
|
||||||
warn("Failed allocating static list of services, error %d", errno);
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
return svc_list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* svc_new - Create a new service
|
* svc_new - Create a new service
|
||||||
@@ -62,11 +49,12 @@ static svc_t *__connect_shm(void)
|
|||||||
*/
|
*/
|
||||||
svc_t *svc_new(char *cmd, int id, int type)
|
svc_t *svc_new(char *cmd, int id, int type)
|
||||||
{
|
{
|
||||||
int i, pos, job = -1;
|
int job = -1;
|
||||||
svc_t *svc, *list = __connect_shm();
|
char *desc;
|
||||||
|
svc_t *svc;
|
||||||
|
|
||||||
/* Find first job n:o if registering multiple instances */
|
/* Find first job n:o if registering multiple instances */
|
||||||
for (svc = svc_iterator1(&pos, 1); svc; svc = svc_iterator1(&pos, 0)) {
|
for (svc = svc_iterator(NULL); svc; svc = svc_iterator(svc)) {
|
||||||
if (!strcmp(svc->cmd, cmd)) {
|
if (!strcmp(svc->cmd, cmd)) {
|
||||||
job = svc->job;
|
job = svc->job;
|
||||||
break;
|
break;
|
||||||
@@ -75,32 +63,26 @@ svc_t *svc_new(char *cmd, int id, int type)
|
|||||||
if (job == -1)
|
if (job == -1)
|
||||||
job = jobcounter++;
|
job = jobcounter++;
|
||||||
|
|
||||||
for (i = 0; i < MAX_NUM_SVC; i++) {
|
svc = calloc(1, sizeof(*svc));
|
||||||
svc_t *svc = &list[i];
|
if (!svc)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (svc->type == SVC_TYPE_FREE) {
|
svc->type = type;
|
||||||
char *desc;
|
svc->job = job;
|
||||||
|
svc->id = id;
|
||||||
|
strlcpy(svc->cmd, cmd, sizeof(svc->cmd));
|
||||||
|
|
||||||
memset(svc, 0, sizeof(*svc));
|
/* Default description, if missing */
|
||||||
svc->type = type;
|
desc = rindex(cmd, '/');
|
||||||
svc->job = job;
|
if (desc)
|
||||||
svc->id = id;
|
desc++;
|
||||||
strlcpy(svc->cmd, cmd, sizeof(svc->cmd));
|
else
|
||||||
|
desc = cmd;
|
||||||
|
strlcpy(svc->desc, desc, sizeof(svc->desc));
|
||||||
|
|
||||||
/* Default description, if missing */
|
TAILQ_INSERT_TAIL(&svc_list, svc, link);
|
||||||
desc = rindex(cmd, '/');
|
|
||||||
if (desc)
|
|
||||||
desc++;
|
|
||||||
else
|
|
||||||
desc = cmd;
|
|
||||||
strlcpy(svc->desc, desc, sizeof(svc->desc));
|
|
||||||
|
|
||||||
return svc;
|
return svc;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
errno = ENOMEM;
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -112,71 +94,45 @@ svc_t *svc_new(char *cmd, int id, int type)
|
|||||||
*/
|
*/
|
||||||
int svc_del(svc_t *svc)
|
int svc_del(svc_t *svc)
|
||||||
{
|
{
|
||||||
svc->type = SVC_TYPE_FREE;
|
TAILQ_REMOVE(&svc_list, svc, link);
|
||||||
|
memset(svc, 0, sizeof(*svc));
|
||||||
|
free(svc);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* svc_iterator1 - Naive iterator over all registered services.
|
* svc_iterator - Naive iterator over all registered services.
|
||||||
* @pos: Iterator variable, preserves state between calls
|
* @iter: %NULL for first entry, use returned value for subsequent calls
|
||||||
* @first: Get first &svc_t object, or next until end.
|
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* The first &svc_t when @first is set, otherwise the next &svc_t until
|
* The first &svc_t when %NULL is given as argument, otherwise the next
|
||||||
* the end when %NULL is returned.
|
* &svc_t until the end when %NULL is returned.
|
||||||
*/
|
*/
|
||||||
svc_t *svc_iterator1(int *pos, int first)
|
svc_t *svc_iterator(svc_t *iter)
|
||||||
{
|
{
|
||||||
int i;
|
if (!iter)
|
||||||
svc_t *list = __connect_shm();
|
return TAILQ_FIRST(&svc_list);
|
||||||
|
|
||||||
if (first)
|
if (iter && iter != TAILQ_END(&svc_list))
|
||||||
i = 0;
|
return TAILQ_NEXT(iter, link);
|
||||||
else
|
|
||||||
i = *(int *)pos;
|
|
||||||
|
|
||||||
while (i < MAX_NUM_SVC) {
|
|
||||||
svc_t *svc = &list[i++];
|
|
||||||
|
|
||||||
if (svc->type != SVC_TYPE_FREE) {
|
|
||||||
*(int *)pos = i;
|
|
||||||
return svc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* svc_iterator - Naive iterator over all registered services.
|
|
||||||
* @first: Get first &svc_t object, or next until end.
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* The first &svc_t when @first is set, otherwise the next &svc_t until
|
|
||||||
* the end when %NULL is returned.
|
|
||||||
*/
|
|
||||||
svc_t *svc_iterator(int first)
|
|
||||||
{
|
|
||||||
static int i;
|
|
||||||
|
|
||||||
return svc_iterator1(&i, first);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* svc_inetd_iterator - Naive iterator over all registered inetd services.
|
* svc_inetd_iterator - Naive iterator over all registered inetd services.
|
||||||
* @pos: Iterator variable, preserves state between calls
|
* @iter: %NULL for first entry, use returned value for subsequent calls
|
||||||
* @first: Get first &svc_t object, or next until end.
|
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* The first inetd &svc_t when @first is set, otherwise the next
|
* The first inetd &svc_t when %NULL is given as argument, otherwise the
|
||||||
* inetd &svc_t until the end when %NULL is returned.
|
* next inetd &svc_t until the end when %NULL is returned.
|
||||||
*/
|
*/
|
||||||
svc_t *svc_inetd_iterator(int *pos, int first)
|
svc_t *svc_inetd_iterator(svc_t *iter)
|
||||||
{
|
{
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
for (svc = svc_iterator1(pos, first); svc; svc = svc_iterator1(pos, 0)) {
|
for (svc = svc_iterator(iter); svc; svc = svc_iterator(svc)) {
|
||||||
if (svc_is_inetd(svc))
|
if (svc_is_inetd(svc))
|
||||||
return svc;
|
return svc;
|
||||||
}
|
}
|
||||||
@@ -187,18 +143,18 @@ svc_t *svc_inetd_iterator(int *pos, int first)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* svc_dynamic_iterator - Naive iterator over all registered dynamic services.
|
* svc_dynamic_iterator - Naive iterator over all registered dynamic services.
|
||||||
* @pos: Iterator variable, preserves state between calls
|
* @iter: %NULL for first entry, use returned value for subsequent calls
|
||||||
* @first: Get first &svc_t object, or next until end.
|
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* The first dynamically loaded &svc_t when @first is set, otherwise the
|
* The first dynamically loaded &svc_t when %NULL is given as argument,
|
||||||
* next dynamically loaded &svc_t until the end when %NULL is returned.
|
* otherwise the next dynamically loaded &svc_t until the end when %NULL
|
||||||
|
* is returned.
|
||||||
*/
|
*/
|
||||||
svc_t *svc_dynamic_iterator(int *pos, int first)
|
svc_t *svc_dynamic_iterator(svc_t *iter)
|
||||||
{
|
{
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
for (svc = svc_iterator1(pos, first); svc; svc = svc_iterator1(pos, 0)) {
|
for (svc = svc_iterator(iter); svc; svc = svc_iterator(svc)) {
|
||||||
if (svc->mtime.tv_sec)
|
if (svc->mtime.tv_sec)
|
||||||
return svc;
|
return svc;
|
||||||
}
|
}
|
||||||
@@ -209,20 +165,19 @@ svc_t *svc_dynamic_iterator(int *pos, int first)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* svc_named_iterator - Iterates over all instances of a service.
|
* svc_named_iterator - Iterates over all instances of a service.
|
||||||
* @pos: Iterator variable, preserves state between calls
|
* @iter: %NULL for first entry, use returned value for subsequent calls
|
||||||
* @first: Get first &svc_t object, or next until end.
|
* @cmd: Service name to look for.
|
||||||
* @cmd: Service name to look for.
|
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* The first matching &svc_t when @first is set, otherwise the next
|
* The first matching &svc_t when %NULL is given as argument, otherwise
|
||||||
* &svc_t instance with the same @cmd until the end when %NULL is
|
* the next &svc_t with the same @cmd name until the end when %NULL is
|
||||||
* returned.
|
* returned.
|
||||||
*/
|
*/
|
||||||
svc_t *svc_named_iterator(int *pos, int first, char *cmd)
|
svc_t *svc_named_iterator(svc_t *iter, char *cmd)
|
||||||
{
|
{
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
for (svc = svc_iterator1(pos, first); svc; svc = svc_iterator1(pos, 0)) {
|
for (svc = svc_iterator(iter); svc; svc = svc_iterator(svc)) {
|
||||||
char *name = basename(svc->cmd);
|
char *name = basename(svc->cmd);
|
||||||
|
|
||||||
if (!strncmp(name, cmd, strlen(name)))
|
if (!strncmp(name, cmd, strlen(name)))
|
||||||
@@ -235,20 +190,19 @@ svc_t *svc_named_iterator(int *pos, int first, char *cmd)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* svc_job_iterator - Iterates over all instances of a service.
|
* svc_job_iterator - Iterates over all instances of a service.
|
||||||
* @pos: Iterator variable, preserves state between calls
|
* @iter: %NULL for first entry, use returned value for subsequent calls
|
||||||
* @first: Get first &svc_t object, or next until end.
|
* @job: Job to look for.
|
||||||
* @job: Job to look for.
|
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* The first matching &svc_t when @first is set, otherwise the next
|
* The first matching &svc_t when %NULL is given as argument, otherwise
|
||||||
* &svc_t instance with the same @job until the end when %NULL is
|
* the next &svc_t with the same @job ID until the end when %NULL is
|
||||||
* returned.
|
* returned.
|
||||||
*/
|
*/
|
||||||
svc_t *svc_job_iterator(int *pos, int first, int job)
|
svc_t *svc_job_iterator(svc_t *iter, int job)
|
||||||
{
|
{
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
for (svc = svc_iterator1(pos, first); svc; svc = svc_iterator1(pos, 0)) {
|
for (svc = svc_iterator(iter); svc; svc = svc_iterator(svc)) {
|
||||||
if (svc->job == job)
|
if (svc->job == job)
|
||||||
return svc;
|
return svc;
|
||||||
}
|
}
|
||||||
@@ -263,13 +217,12 @@ svc_t *svc_job_iterator(int *pos, int first, int job)
|
|||||||
*/
|
*/
|
||||||
void svc_foreach(void (*cb)(svc_t *))
|
void svc_foreach(void (*cb)(svc_t *))
|
||||||
{
|
{
|
||||||
int pos;
|
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
if (!cb)
|
if (!cb)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (svc = svc_iterator1(&pos, 1); svc; svc = svc_iterator1(&pos, 0))
|
for (svc = svc_iterator(NULL); svc; svc = svc_iterator(svc))
|
||||||
cb(svc);
|
cb(svc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,13 +233,12 @@ void svc_foreach(void (*cb)(svc_t *))
|
|||||||
*/
|
*/
|
||||||
void svc_foreach_dynamic(void (*cb)(svc_t *))
|
void svc_foreach_dynamic(void (*cb)(svc_t *))
|
||||||
{
|
{
|
||||||
int pos;
|
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
if (!cb)
|
if (!cb)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (svc = svc_dynamic_iterator(&pos, 1); svc; svc = svc_dynamic_iterator(&pos, 0))
|
for (svc = svc_dynamic_iterator(NULL); svc; svc = svc_dynamic_iterator(svc))
|
||||||
cb(svc);
|
cb(svc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,13 +250,12 @@ void svc_foreach_dynamic(void (*cb)(svc_t *))
|
|||||||
*/
|
*/
|
||||||
void svc_foreach_type(int types, void (*cb)(svc_t *))
|
void svc_foreach_type(int types, void (*cb)(svc_t *))
|
||||||
{
|
{
|
||||||
int pos;
|
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
if (!cb)
|
if (!cb)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (svc = svc_iterator1(&pos, 1); svc; svc = svc_iterator1(&pos, 0)) {
|
for (svc = svc_iterator(NULL); svc; svc = svc_iterator(svc)) {
|
||||||
if (!(svc->type & types))
|
if (!(svc->type & types))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -322,10 +273,9 @@ void svc_foreach_type(int types, void (*cb)(svc_t *))
|
|||||||
*/
|
*/
|
||||||
svc_t *svc_stop_completed(void)
|
svc_t *svc_stop_completed(void)
|
||||||
{
|
{
|
||||||
int pos;
|
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
for (svc = svc_iterator1(&pos, 1); svc; svc = svc_iterator1(&pos, 0)) {
|
for (svc = svc_iterator(NULL); svc; svc = svc_iterator(svc)) {
|
||||||
if (svc->state == SVC_STOPPING_STATE)
|
if (svc->state == SVC_STOPPING_STATE)
|
||||||
return svc;
|
return svc;
|
||||||
}
|
}
|
||||||
@@ -342,10 +292,9 @@ svc_t *svc_stop_completed(void)
|
|||||||
*/
|
*/
|
||||||
svc_t *svc_find(char *cmd, int id)
|
svc_t *svc_find(char *cmd, int id)
|
||||||
{
|
{
|
||||||
int pos;
|
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
for (svc = svc_iterator1(&pos, 1); svc; svc = svc_iterator1(&pos, 0)) {
|
for (svc = svc_iterator(NULL); svc; svc = svc_iterator(svc)) {
|
||||||
if (svc->id == id && !strncmp(svc->cmd, cmd, strlen(svc->cmd)))
|
if (svc->id == id && !strncmp(svc->cmd, cmd, strlen(svc->cmd)))
|
||||||
return svc;
|
return svc;
|
||||||
}
|
}
|
||||||
@@ -362,10 +311,9 @@ svc_t *svc_find(char *cmd, int id)
|
|||||||
*/
|
*/
|
||||||
svc_t *svc_find_by_pid(pid_t pid)
|
svc_t *svc_find_by_pid(pid_t pid)
|
||||||
{
|
{
|
||||||
int pos;
|
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
for (svc = svc_iterator1(&pos, 1); svc; svc = svc_iterator1(&pos, 0)) {
|
for (svc = svc_iterator(NULL); svc; svc = svc_iterator(svc)) {
|
||||||
if (svc->pid == pid)
|
if (svc->pid == pid)
|
||||||
return svc;
|
return svc;
|
||||||
}
|
}
|
||||||
@@ -383,10 +331,9 @@ svc_t *svc_find_by_pid(pid_t pid)
|
|||||||
*/
|
*/
|
||||||
svc_t *svc_find_by_jobid(int job, int id)
|
svc_t *svc_find_by_jobid(int job, int id)
|
||||||
{
|
{
|
||||||
int pos;
|
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
for (svc = svc_iterator1(&pos, 1); svc; svc = svc_iterator1(&pos, 0)) {
|
for (svc = svc_iterator(NULL); svc; svc = svc_iterator(svc)) {
|
||||||
if (svc->job == job && svc->id == id)
|
if (svc->job == job && svc->id == id)
|
||||||
return svc;
|
return svc;
|
||||||
}
|
}
|
||||||
@@ -404,11 +351,10 @@ svc_t *svc_find_by_jobid(int job, int id)
|
|||||||
*/
|
*/
|
||||||
svc_t *svc_find_by_nameid(char *name, int id)
|
svc_t *svc_find_by_nameid(char *name, int id)
|
||||||
{
|
{
|
||||||
int pos;
|
|
||||||
char *ptr;
|
char *ptr;
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
for (svc = svc_iterator1(&pos, 1); svc; svc = svc_iterator1(&pos, 0)) {
|
for (svc = svc_iterator(NULL); svc; svc = svc_iterator(svc)) {
|
||||||
ptr = strrchr(svc->cmd, '/');
|
ptr = strrchr(svc->cmd, '/');
|
||||||
if (ptr)
|
if (ptr)
|
||||||
ptr++;
|
ptr++;
|
||||||
@@ -434,12 +380,11 @@ svc_t *svc_find_by_nameid(char *name, int id)
|
|||||||
*/
|
*/
|
||||||
void svc_mark_dynamic(void)
|
void svc_mark_dynamic(void)
|
||||||
{
|
{
|
||||||
int pos;
|
svc_t *svc = svc_dynamic_iterator(NULL);
|
||||||
svc_t *svc = svc_dynamic_iterator(&pos, 1);
|
|
||||||
|
|
||||||
while (svc) {
|
while (svc) {
|
||||||
*((int *)&svc->dirty) = -1;
|
*((int *)&svc->dirty) = -1;
|
||||||
svc = svc_dynamic_iterator(&pos, 0);
|
svc = svc_dynamic_iterator(svc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -473,15 +418,14 @@ void svc_check_dirty(svc_t *svc, struct timeval *mtime)
|
|||||||
*/
|
*/
|
||||||
void svc_clean_dynamic(void (*cb)(svc_t *))
|
void svc_clean_dynamic(void (*cb)(svc_t *))
|
||||||
{
|
{
|
||||||
int pos;
|
svc_t *svc = svc_dynamic_iterator(NULL);
|
||||||
svc_t *svc = svc_dynamic_iterator(&pos, 1);
|
|
||||||
|
|
||||||
while (svc) {
|
while (svc) {
|
||||||
if (svc->dirty == -1 && cb) {
|
if (svc->dirty == -1 && cb) {
|
||||||
cb(svc);
|
cb(svc);
|
||||||
svc_mark_clean(svc);
|
svc_mark_clean(svc);
|
||||||
}
|
}
|
||||||
svc = svc_dynamic_iterator(&pos, 0);
|
svc = svc_dynamic_iterator(svc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -512,10 +456,9 @@ int svc_clean_bootstrap(svc_t *svc)
|
|||||||
*/
|
*/
|
||||||
void svc_prune_bootstrap(void)
|
void svc_prune_bootstrap(void)
|
||||||
{
|
{
|
||||||
int pos;
|
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
for (svc = svc_iterator1(&pos, 1); svc; svc = svc_iterator1(&pos, 0)) {
|
for (svc = svc_iterator(NULL); svc; svc = svc_iterator(svc)) {
|
||||||
if (!svc->pid)
|
if (!svc->pid)
|
||||||
svc_clean_bootstrap(svc);
|
svc_clean_bootstrap(svc);
|
||||||
}
|
}
|
||||||
@@ -547,10 +490,10 @@ int svc_enabled(svc_t *svc)
|
|||||||
/* Same base service, return unique ID */
|
/* Same base service, return unique ID */
|
||||||
int svc_next_id(char *cmd)
|
int svc_next_id(char *cmd)
|
||||||
{
|
{
|
||||||
int pos, id = 0;
|
int id = 0;
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
for (svc = svc_iterator1(&pos, 1); svc; svc = svc_iterator1(&pos, 0)) {
|
for (svc = svc_iterator(NULL); svc; svc = svc_iterator(svc)) {
|
||||||
if (!strcmp(svc->cmd, cmd) && id < svc->id)
|
if (!strcmp(svc->cmd, cmd) && id < svc->id)
|
||||||
id = svc->id;
|
id = svc->id;
|
||||||
}
|
}
|
||||||
@@ -560,12 +503,10 @@ int svc_next_id(char *cmd)
|
|||||||
|
|
||||||
int svc_is_unique(svc_t *svc)
|
int svc_is_unique(svc_t *svc)
|
||||||
{
|
{
|
||||||
svc_t *list = __connect_shm();
|
svc_t *s;
|
||||||
int i, unique = 1;
|
int unique = 1;
|
||||||
|
|
||||||
for (i = 0; i < MAX_NUM_SVC; i++) {
|
|
||||||
svc_t *s = &list[i];
|
|
||||||
|
|
||||||
|
for (s = svc_iterator(NULL); s; s = svc_iterator(svc)) {
|
||||||
if (svc->type == SVC_TYPE_FREE)
|
if (svc->type == SVC_TYPE_FREE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -603,16 +544,14 @@ int svc_parse_jobstr(char *str, size_t len, int (*found)(svc_t *), int (not_foun
|
|||||||
int job = atonum(token);
|
int job = atonum(token);
|
||||||
|
|
||||||
if (!ptr) {
|
if (!ptr) {
|
||||||
int pos;
|
svc = svc_job_iterator(NULL, job);
|
||||||
|
|
||||||
svc = svc_job_iterator(&pos, 1, job);
|
|
||||||
if (!svc && not_found)
|
if (!svc && not_found)
|
||||||
result += not_found(NULL, job);
|
result += not_found(NULL, job);
|
||||||
|
|
||||||
while (svc) {
|
while (svc) {
|
||||||
if (found)
|
if (found)
|
||||||
result += found(svc);
|
result += found(svc);
|
||||||
svc = svc_job_iterator(&pos, 0, job);
|
svc = svc_job_iterator(svc, job);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
*ptr++ = 0;
|
*ptr++ = 0;
|
||||||
@@ -627,16 +566,14 @@ int svc_parse_jobstr(char *str, size_t len, int (*found)(svc_t *), int (not_foun
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!ptr) {
|
if (!ptr) {
|
||||||
int pos;
|
svc = svc_named_iterator(NULL, token);
|
||||||
|
|
||||||
svc = svc_named_iterator(&pos, 1, token);
|
|
||||||
if (!svc && not_found)
|
if (!svc && not_found)
|
||||||
result += not_found(token, id);
|
result += not_found(token, id);
|
||||||
|
|
||||||
while (svc) {
|
while (svc) {
|
||||||
if (found)
|
if (found)
|
||||||
result += found(svc);
|
result += found(svc);
|
||||||
svc = svc_named_iterator(&pos, 0, token);
|
svc = svc_named_iterator(svc, token);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
*ptr++ = 0;
|
*ptr++ = 0;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <sys/types.h> /* pid_t */
|
#include <sys/types.h> /* pid_t */
|
||||||
#include <lite/lite.h>
|
#include <lite/lite.h>
|
||||||
|
#include <lite/queue.h> /* BSD sys/queue.h API */
|
||||||
|
|
||||||
#include "inetd.h"
|
#include "inetd.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
@@ -70,7 +71,6 @@ typedef enum {
|
|||||||
#define MAX_COND_LEN (MAX_ARG_LEN * 3)
|
#define MAX_COND_LEN (MAX_ARG_LEN * 3)
|
||||||
#define MAX_USER_LEN 16
|
#define MAX_USER_LEN 16
|
||||||
#define MAX_NUM_FDS 64 /* Max number of I/O plugins */
|
#define MAX_NUM_FDS 64 /* Max number of I/O plugins */
|
||||||
#define MAX_NUM_SVC 64 /* Enough? */
|
|
||||||
#define MAX_NUM_SVC_ARGS 32
|
#define MAX_NUM_SVC_ARGS 32
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -80,6 +80,8 @@ typedef enum {
|
|||||||
* initctl <stop|start|restart> service
|
* initctl <stop|start|restart> service
|
||||||
*/
|
*/
|
||||||
typedef struct svc {
|
typedef struct svc {
|
||||||
|
TAILQ_ENTRY(svc) link;
|
||||||
|
|
||||||
/* Instance specifics */
|
/* Instance specifics */
|
||||||
int job, id; /* JOB:ID */
|
int job, id; /* JOB:ID */
|
||||||
|
|
||||||
@@ -135,12 +137,11 @@ svc_t *svc_find_by_pid (pid_t pid);
|
|||||||
svc_t *svc_find_by_jobid (int job, int id);
|
svc_t *svc_find_by_jobid (int job, int id);
|
||||||
svc_t *svc_find_by_nameid (char *name, int id);
|
svc_t *svc_find_by_nameid (char *name, int id);
|
||||||
|
|
||||||
svc_t *svc_iterator (int first);
|
svc_t *svc_iterator (svc_t *iter);
|
||||||
svc_t *svc_iterator1 (int *pos, int first);
|
svc_t *svc_inetd_iterator (svc_t *iter);
|
||||||
svc_t *svc_inetd_iterator (int *pos, int first);
|
svc_t *svc_dynamic_iterator (svc_t *iter);
|
||||||
svc_t *svc_dynamic_iterator (int *pos, int first);
|
svc_t *svc_named_iterator (svc_t *iter, char *cmd);
|
||||||
svc_t *svc_named_iterator (int *pos, int first, char *cmd);
|
svc_t *svc_job_iterator (svc_t *iter, int job);
|
||||||
svc_t *svc_job_iterator (int *pos, int first, int job);
|
|
||||||
|
|
||||||
void svc_foreach (void (*cb)(svc_t *));
|
void svc_foreach (void (*cb)(svc_t *));
|
||||||
void svc_foreach_dynamic (void (*cb)(svc_t *));
|
void svc_foreach_dynamic (void (*cb)(svc_t *));
|
||||||
|
|||||||
Reference in new issue
Block a user