2018-11-23 13:13:23 +01:00
|
|
|
/* SPDX-License-Identifier: ISC */
|
2018-02-25 14:33:19 +01:00
|
|
|
#ifndef SERVICE_H
|
|
|
|
#define SERVICE_H
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2018-09-16 21:52:46 +02:00
|
|
|
#include "util.h"
|
|
|
|
|
2018-02-25 14:33:19 +01:00
|
|
|
enum {
|
2018-03-24 22:31:05 +01:00
|
|
|
/*
|
|
|
|
Start the service in the background and continue with
|
|
|
|
other services. The service will eventually terminate.
|
|
|
|
*/
|
2018-02-25 14:33:19 +01:00
|
|
|
SVC_ONCE = 0,
|
2018-03-24 22:31:05 +01:00
|
|
|
SVC_WAIT, /* run service and wait until it finishes */
|
|
|
|
|
|
|
|
/*
|
|
|
|
Similar to SVC_ONCE, but restart the service when
|
|
|
|
it terminates.
|
|
|
|
*/
|
2018-02-25 14:33:19 +01:00
|
|
|
SVC_RESPAWN,
|
2018-11-23 14:13:52 +01:00
|
|
|
|
|
|
|
SVC_MAX
|
2018-02-25 14:33:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2018-03-24 22:31:05 +01:00
|
|
|
TGT_BOOT = 0, /* run service when the system boots */
|
|
|
|
TGT_SHUTDOWN, /* run service when at system shut down */
|
|
|
|
TGT_REBOOT, /* run service when during system reboot */
|
2018-02-25 14:33:19 +01:00
|
|
|
|
|
|
|
TGT_MAX
|
|
|
|
};
|
|
|
|
|
2018-04-21 22:51:28 +02:00
|
|
|
enum {
|
|
|
|
RDSVC_NO_FNAME = 0x01, /* do not store a copy of the filename */
|
|
|
|
RDSVC_NO_EXEC = 0x02, /* do not store executable script */
|
|
|
|
RDSVC_NO_CTTY = 0x04, /* do not store the controlling tty */
|
|
|
|
RDSVC_NO_DEPS = 0x08, /* do not store dependencies */
|
|
|
|
};
|
|
|
|
|
2018-07-22 17:57:13 +02:00
|
|
|
enum {
|
|
|
|
/* truncate stdout */
|
|
|
|
SVC_FLAG_TRUNCATE_OUT = 0x01,
|
2019-03-20 15:27:13 +01:00
|
|
|
|
|
|
|
SVC_FLAG_HAS_EXEC = 0x10,
|
2019-03-28 14:15:39 +01:00
|
|
|
SVC_FLAG_ADMIN_STOPPED = 0x20,
|
2018-07-22 17:57:13 +02:00
|
|
|
};
|
|
|
|
|
2018-02-25 14:33:19 +01:00
|
|
|
typedef struct service_t {
|
2018-04-11 13:29:13 +02:00
|
|
|
struct service_t *next;
|
|
|
|
|
2018-04-21 22:19:43 +02:00
|
|
|
char *fname; /* source file name */
|
|
|
|
|
2018-02-25 14:33:19 +01:00
|
|
|
int type; /* SVC_* service type */
|
|
|
|
int target; /* TGT_* service target */
|
|
|
|
char *desc; /* description string */
|
|
|
|
char *ctty; /* controlling tty or log file */
|
2018-03-26 00:34:00 +02:00
|
|
|
int rspwn_limit; /* maximum respawn count */
|
2018-07-22 17:57:13 +02:00
|
|
|
unsigned int flags; /* SVC_FLAG_* bit field */
|
2018-03-26 00:34:00 +02:00
|
|
|
|
2018-04-04 18:54:59 +02:00
|
|
|
/* linked list of command lines to execute */
|
|
|
|
exec_t *exec;
|
|
|
|
|
2018-04-11 16:07:20 +02:00
|
|
|
char *before; /* services that must be executed later */
|
|
|
|
char *after; /* services that must be executed first */
|
2018-04-04 18:54:59 +02:00
|
|
|
|
2018-04-11 16:07:20 +02:00
|
|
|
int num_before;
|
|
|
|
int num_after;
|
2018-02-25 14:33:19 +01:00
|
|
|
|
|
|
|
pid_t pid;
|
|
|
|
int status; /* process exit status */
|
2019-03-28 13:44:28 +01:00
|
|
|
int id; /* service ID used by initd */
|
2018-02-25 14:33:19 +01:00
|
|
|
|
2018-04-11 13:29:13 +02:00
|
|
|
char name[]; /* canonical service name */
|
2018-02-25 14:33:19 +01:00
|
|
|
} service_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
service_t *targets[TGT_MAX];
|
|
|
|
} service_list_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Read a service from a file.
|
|
|
|
*/
|
2018-04-21 22:51:28 +02:00
|
|
|
service_t *rdsvc(int dirfd, const char *filename, int flags);
|
2018-02-25 14:33:19 +01:00
|
|
|
|
2018-03-25 12:14:06 +02:00
|
|
|
void delsvc(service_t *svc);
|
2018-02-25 14:33:19 +01:00
|
|
|
|
2018-03-24 22:31:05 +01:00
|
|
|
/*
|
|
|
|
Rebuild a service list by scanning a directory and parsing all
|
|
|
|
service descriptions.
|
|
|
|
|
|
|
|
Returns 0 on success, -1 on failure. The function takes care of
|
|
|
|
printing error messages on failure.
|
|
|
|
*/
|
2018-04-21 22:51:28 +02:00
|
|
|
int svcscan(const char *directory, service_list_t *list, int flags);
|
2018-02-25 14:33:19 +01:00
|
|
|
|
2018-03-25 12:14:06 +02:00
|
|
|
void del_svc_list(service_list_t *list);
|
2018-02-25 14:33:19 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Sort a list of services by dependencies.
|
|
|
|
*/
|
2018-03-25 12:14:06 +02:00
|
|
|
service_t *svc_tsort(service_t *list);
|
2018-02-25 14:33:19 +01:00
|
|
|
|
2018-03-25 01:55:08 +01:00
|
|
|
const char *svc_type_to_string(int type);
|
|
|
|
|
|
|
|
int svc_type_from_string(const char *type);
|
|
|
|
|
|
|
|
const char *svc_target_to_string(int target);
|
|
|
|
|
|
|
|
int svc_target_from_string(const char *target);
|
|
|
|
|
2018-02-25 14:33:19 +01:00
|
|
|
#endif /* SERVICE_H */
|