| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- /* Shared service definitions and the VFS/tty protocol used by init and the
- * `service` CLI/GUI. */
- #ifndef SERVICE_PROTO_H
- #define SERVICE_PROTO_H
- #include "syscall.h"
- #define SVC_MAX 8
- #define SVC_LOG_MAX (32u * 1024u)
- #define SVC_INIT_STATE "/share/init.state"
- #define SVC_INIT_LOG "/share/init.log"
- #define SVC_STATE_MAGIC "NBSVC1\n"
- #define SVC_INIT_MAGIC "NBINIT1\n"
- #define SVC_CTL_MAGIC "NBI1"
- #define SVC_AUTOSTART 0x1
- enum svc_phase {
- SVC_STOPPED = 0,
- SVC_STARTING,
- SVC_RUNNING,
- SVC_STOPPING,
- SVC_RESTARTING
- };
- struct svc_def {
- const char *name;
- const char *path;
- const char *args;
- const char *desc;
- unsigned int flags;
- };
- extern const struct svc_def svc_defs[];
- extern const unsigned int svc_def_count;
- struct svc_state {
- char name[16];
- unsigned int state;
- unsigned int desired; /* 0 stopped, 1 running */
- unsigned int pid;
- unsigned int tty;
- unsigned int started; /* uptime ms */
- };
- struct init_state {
- unsigned int pid;
- unsigned int ctl;
- unsigned int wm;
- unsigned int valid;
- };
- const char *svc_state_name(unsigned int state);
- int svc_state_from_name(const char *s);
- int svc_find(const char *name);
- int svc_make_state_path(char *out, unsigned int max, const char *name);
- int svc_make_log_path(char *out, unsigned int max, const char *name);
- int svc_parse_state(const char *buf, unsigned int len, struct svc_state *out);
- int svc_format_state(char *out, unsigned int max, const struct svc_state *st);
- int svc_parse_init_state(const char *buf, unsigned int len,
- struct init_state *out);
- int svc_format_init_state(char *out, unsigned int max,
- const struct init_state *st);
- /* Send one control request to init and wait for its response.
- * Returns 0 on a response, -1 on timeout, -2 when init is not running and
- * -3 when the control/response tty could not be used. */
- int svc_request(const char *op, const char *name, unsigned int wait_ms,
- int *code, int *pid, char *msg, unsigned int msgmax);
- #endif
|