mirror of
https://github.com/pygos/init.git
synced 2024-11-22 11:19:45 +01:00
Add start/stop commands to init socket
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
parent
9e7478397a
commit
ba12700080
6 changed files with 67 additions and 0 deletions
|
@ -9,6 +9,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <endian.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
|
@ -70,6 +71,10 @@ bool supervisor_process_queues(void);
|
||||||
void supervisor_answer_status_request(int fd, const void *dest_addr,
|
void supervisor_answer_status_request(int fd, const void *dest_addr,
|
||||||
size_t addrlen, E_SERVICE_STATE filter);
|
size_t addrlen, E_SERVICE_STATE filter);
|
||||||
|
|
||||||
|
void supervisor_start(int id);
|
||||||
|
|
||||||
|
void supervisor_stop(int id);
|
||||||
|
|
||||||
/********** signal_<platform>.c **********/
|
/********** signal_<platform>.c **********/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -64,6 +64,14 @@ retry:
|
||||||
supervisor_answer_status_request(sockfd, &addr, addrlen,
|
supervisor_answer_status_request(sockfd, &addr, addrlen,
|
||||||
rq.arg.status.filter);
|
rq.arg.status.filter);
|
||||||
break;
|
break;
|
||||||
|
case EIR_START:
|
||||||
|
rq.arg.startstop.id = be32toh(rq.arg.startstop.id);
|
||||||
|
supervisor_start(rq.arg.startstop.id);
|
||||||
|
break;
|
||||||
|
case EIR_STOP:
|
||||||
|
rq.arg.startstop.id = be32toh(rq.arg.startstop.id);
|
||||||
|
supervisor_stop(rq.arg.startstop.id);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,9 @@ static void handle_terminated_service(service_t *svc)
|
||||||
if (target == TGT_REBOOT || target == TGT_SHUTDOWN)
|
if (target == TGT_REBOOT || target == TGT_SHUTDOWN)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if (svc->flags & SVC_FLAG_ADMIN_STOPPED)
|
||||||
|
break;
|
||||||
|
|
||||||
if (svc->rspwn_limit > 0) {
|
if (svc->rspwn_limit > 0) {
|
||||||
svc->rspwn_limit -= 1;
|
svc->rspwn_limit -= 1;
|
||||||
|
|
||||||
|
@ -221,3 +224,42 @@ void supervisor_answer_status_request(int fd, const void *dst, size_t addrlen,
|
||||||
return;
|
return;
|
||||||
init_socket_send_status(fd, dst, addrlen, ESS_NONE, NULL);
|
init_socket_send_status(fd, dst, addrlen, ESS_NONE, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void supervisor_start(int id)
|
||||||
|
{
|
||||||
|
service_t *svc;
|
||||||
|
|
||||||
|
for (svc = completed; svc != NULL; svc = svc->next) {
|
||||||
|
if (svc->id == id)
|
||||||
|
goto found;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (svc = failed; svc != NULL; svc = svc->next) {
|
||||||
|
if (svc->id == id)
|
||||||
|
goto found;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
found:
|
||||||
|
if (svc->type == SVC_RESPAWN)
|
||||||
|
svc->rspwn_limit = 0;
|
||||||
|
|
||||||
|
svc->flags &= ~SVC_FLAG_ADMIN_STOPPED;
|
||||||
|
svc->next = queue;
|
||||||
|
queue = svc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void supervisor_stop(int id)
|
||||||
|
{
|
||||||
|
service_t *svc;
|
||||||
|
|
||||||
|
for (svc = running; svc != NULL; svc = svc->next) {
|
||||||
|
if (svc->id == id)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (svc != NULL) {
|
||||||
|
/* TODO: something more sophisticated? */
|
||||||
|
svc->flags |= SVC_FLAG_ADMIN_STOPPED;
|
||||||
|
kill(svc->pid, SIGTERM);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
EIR_STATUS = 0x00,
|
EIR_STATUS = 0x00,
|
||||||
|
EIR_START = 0x01,
|
||||||
|
EIR_STOP = 0x02,
|
||||||
} E_INIT_REQUEST;
|
} E_INIT_REQUEST;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -30,6 +32,10 @@ typedef struct {
|
||||||
uint8_t filter;
|
uint8_t filter;
|
||||||
uint8_t padd[3];
|
uint8_t padd[3];
|
||||||
} status;
|
} status;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
uint32_t id;
|
||||||
|
} startstop;
|
||||||
} arg;
|
} arg;
|
||||||
} init_request_t;
|
} init_request_t;
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ enum {
|
||||||
SVC_FLAG_TRUNCATE_OUT = 0x01,
|
SVC_FLAG_TRUNCATE_OUT = 0x01,
|
||||||
|
|
||||||
SVC_FLAG_HAS_EXEC = 0x10,
|
SVC_FLAG_HAS_EXEC = 0x10,
|
||||||
|
SVC_FLAG_ADMIN_STOPPED = 0x20,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct service_t {
|
typedef struct service_t {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <endian.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
@ -21,6 +22,10 @@ int init_socket_send_request(int fd, E_INIT_REQUEST rq, ...)
|
||||||
case EIR_STATUS:
|
case EIR_STATUS:
|
||||||
request.arg.status.filter = va_arg(ap, E_SERVICE_STATE);
|
request.arg.status.filter = va_arg(ap, E_SERVICE_STATE);
|
||||||
break;
|
break;
|
||||||
|
case EIR_START:
|
||||||
|
case EIR_STOP:
|
||||||
|
request.arg.startstop.id = htobe32(va_arg(ap, int));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue