/* This file is part of genrc Copyryght (C) 2018 Sergey Poznyakoff License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "grecs.h" #include "wordsplit.h" void setprogname(char const *s); void genrc_error(char const *fmt, ...); void usage_error(char const *fmt, ...); void system_error(int ec, char const *fmt, ...); #define xmalloc grecs_malloc #define xzalloc grecs_zalloc #define xcalloc grecs_calloc #define xrealloc grecs_realloc #define xstrdup grecs_strdup void *x2nrealloc(void *p, size_t *pn, size_t s); #define SHELL "/bin/sh" pid_t file_read_pid(char const *filename); typedef struct transform *TRANSFORM; char *transform_string(TRANSFORM tf, const char *input); char *transform_string_if_match(TRANSFORM tf, const char *input); TRANSFORM compile_transform_expr(const char *expr, int cflags); struct pidlist { pid_t *pidv; size_t pidc; size_t pidn; }; typedef struct pidlist PIDLIST; void pidlist_init(PIDLIST *); void pidlist_free(PIDLIST *); void pidlist_clear(PIDLIST *plist); void pidlist_add(PIDLIST *, pid_t); ssize_t pidlist_index(PIDLIST *plist, pid_t p); int pidlist_member(PIDLIST *plist, pid_t p); int pidlist_remove(PIDLIST *plist, size_t i); void pidlist_kill(PIDLIST *plist, int sig); pid_t strtopid(char const *str); int pid_is_running(pid_t pid); void runas(void); enum { MATCH_REGEX, /* extended POSIX regexp match (default) */ MATCH_PCRE, /* PCRE match (not implemented) */ MATCH_GLOB, /* glob pattern match */ MATCH_EXACT, /* exact match */ }; #define MATCH_DEFAULT MATCH_REGEX enum { PROCF_ICASE = 0x01, /* ignore case */ PROCF_ALL = 0x02, /* use all pids */ PROCF_CMDLINE = 0x04, /* match against entire command line */ PROCF_EXE = 0x08 /* match against executable name */ }; #define PROCF_DEFAULT 0 struct procscanbuf { int match; /* match type */ int flags; /* match flags */ void *pattern; }; typedef struct procscanbuf *PROCSCANBUF; PROCSCANBUF procscan_init(char const *pattern, char const *flagstr); void procscan_free(PROCSCANBUF buf); int procscan_match(PROCSCANBUF buf, char const *arg); void match_exact_init(PROCSCANBUF buf, char const *pattern); void match_exact_free(PROCSCANBUF buf); int match_exact(PROCSCANBUF buf, char const *arg); void match_glob_init(PROCSCANBUF buf, char const *pattern); void match_glob_free(PROCSCANBUF buf); int match_glob(PROCSCANBUF buf, char const *arg); void match_regex_init(PROCSCANBUF buf, char const *pattern); void match_regex_free(PROCSCANBUF buf); int match_regex(PROCSCANBUF buf, char const *arg); void match_pcre_init(PROCSCANBUF buf, char const *pattern); void match_pcre_free(PROCSCANBUF buf); int match_pcre(PROCSCANBUF buf, char const *arg); struct genrc_pid_closure { char const *name; int (*pid)(struct genrc_pid_closure *, PIDLIST *); }; typedef struct genrc_pid_closure GENRC_PID_CLOSURE; GENRC_PID_CLOSURE *get_pid_closure(char const *str); int get_pid_list(GENRC_PID_CLOSURE *, PIDLIST *); GENRC_PID_CLOSURE *genrc_pid_file_init(int argc, char **argv); GENRC_PID_CLOSURE *genrc_pid_config_init(int argc, char **argv); GENRC_PID_CLOSURE *genrc_pid_grep_init(int argc, char **argv); GENRC_PID_CLOSURE *genrc_pid_proc_init(int argc, char **argv); GENRC_PID_CLOSURE *genrc_pid_ps_init(int argc, char **argv); extern char *genrc_command; extern char *genrc_program; extern char *genrc_pid_from; extern unsigned genrc_timeout; extern int genrc_no_reload; extern int genrc_signal_reload; extern int genrc_signal_stop; extern GENRC_PID_CLOSURE *genrc_pid_closure; extern char *genrc_create_pidfile; extern int genrc_verbose; int sentinel(void); int com_start(void); int com_status(void); int com_stop(void); int com_restart(void); int com_reload(void);