fiss

Friedel's Initialization and Service Supervision
Log | Files | Refs | LICENSE

commit abc15b44174e3802fd0bf620e8a0815a5e7bfe48
parent a4f0154cb866284baca3645bbe43a7a0a36fb390
Author: Friedel Schon <[email protected]>
Date:   Mon, 17 Apr 2023 14:19:52 +0200

type string -> const char*

Diffstat:
Minclude/config.h | 6+++---
Minclude/service.h | 18+++++++++---------
Minclude/util.h | 6++----
Msrc/command.c | 4++--
Msrc/exec/finit.c | 4++--
Msrc/exec/fsvc.c | 6+++---
Msrc/exec/fsvs.c | 24++++++------------------
Msrc/exec/seedrng.c | 4++--
Msrc/exec/vlogger.c | 6+++---
Msrc/register.c | 2+-
Msrc/script/shutdown.sh | 2+-
Msrc/service.c | 6+++---
Msrc/supervise.c | 2+-
Msrc/util.c | 2+-
14 files changed, 39 insertions(+), 53 deletions(-)

diff --git a/include/config.h b/include/config.h @@ -15,7 +15,7 @@ // default runlevel #define SV_RUNLEVEL "default" // path to service-dir -#define SV_SERVICE_DIR "/etc/fiss/service" +#define SV_SERVICE_DIR "/etc/fiss/service.d" // path to start-script #define SV_START_EXEC "/etc/fiss/start" // path to stop-script @@ -40,4 +40,4 @@ #define SV_ARGUMENTS_MAX 16 #define SV_ENV_MAX 16 -#define SV_LOG_DIR "/run/fiss/log" -\ No newline at end of file +#define SV_LOG_DIR "/var/fiss/log" +\ No newline at end of file diff --git a/include/service.h b/include/service.h @@ -77,29 +77,29 @@ typedef struct dependency { } dependency_t; -extern string command_error[]; -extern string command_string[]; +extern const char* command_error[]; +extern const char* command_string[]; extern service_t services[]; extern int services_size; extern char runlevel[]; +extern const char* service_dir; extern int null_fd; extern int control_socket; extern bool daemon_running; extern bool verbose; -extern string service_dir; extern dependency_t depends[]; extern int depends_size; -char service_get_command(string command); -int service_command(char command, char extra, string service, service_t* response, int response_max); +char service_get_command(const char* command); +int service_command(char command, char extra, const char* service, service_t* response, int response_max); int service_handle_command(void* s, sv_command_t command, uint8_t extra, service_t** response); -int service_pattern(string name, service_t** dest, int dest_max); +int service_pattern(const char* name, service_t** dest, int dest_max); int service_refresh(); -int service_supervise(string service_dir, string runlevel, bool force_socket); -service_t* service_get(string name); -service_t* service_register(string name, bool is_log_service); +int service_supervise(const char* service_dir, const char* runlevel, bool force_socket); +service_t* service_get(const char* name); +service_t* service_register(const char* name, bool is_log_service); void service_check_state(service_t* s, bool signaled, int return_code); void service_handle_socket(int client); void service_load(service_t* s, const uint8_t* buffer); // for fsvc diff --git a/include/util.h b/include/util.h @@ -10,8 +10,6 @@ #define print_error(msg, ...) (fprintf(stderr, "error: " msg ": %s\n", ##__VA_ARGS__, strerror(errno))) #define print_warning(msg, ...) (fprintf(stderr, "warning: " msg ": %s\n", ##__VA_ARGS__, strerror(errno))) -typedef const char* string; - typedef struct { int read; int write; @@ -19,4 +17,4 @@ typedef struct { ssize_t dgetline(int fd, char* line, size_t line_buffer); ssize_t readstr(int fd, char* str); -ssize_t writestr(int fd, string str); -\ No newline at end of file +ssize_t writestr(int fd, const char* str); +\ No newline at end of file diff --git a/src/command.c b/src/command.c @@ -8,7 +8,7 @@ #include <sys/un.h> -string command_error[] = { +const char* command_error[] = { [0] = "success", [EBADCMD] = "command not found", [ENOSV] = "service required", @@ -16,7 +16,7 @@ string command_error[] = { [EBEXT] = "invalid extra" }; -int service_command(char command, char extra, string service, service_t* response, int response_max) { +int service_command(char command, char extra, const char* service, service_t* response, int response_max) { char request[2] = { command, extra }; int sockfd = socket(AF_UNIX, SOCK_STREAM, 0); diff --git a/src/exec/finit.c b/src/exec/finit.c @@ -19,7 +19,7 @@ void sigblock_all(bool unblock); -int handle_initctl(int argc, string* argv) { +int handle_initctl(int argc, const char** argv) { if (argc != 2 || argv[1][1] != '\0' || (argv[1][0] != '0' && argv[1][0] != '6')) { printf("Usage: %s <0|6>\n", argv[0]); return 1; @@ -48,7 +48,7 @@ static void signal_interrupt(int signum) { } -int main(int argc, string* argv) { +int main(int argc, const char** argv) { int ttyfd; sigset_t ss; diff --git a/src/exec/fsvc.c b/src/exec/fsvc.c @@ -61,8 +61,8 @@ void print_status(service_t* s, char* state, size_t size) { strcpy(state, "dead"); break; } - time_t diff = time(NULL) - s->status_change; - string diff_unit = "sec"; + time_t diff = time(NULL) - s->status_change; + const char* diff_unit = "sec"; if (diff >= 60) { diff /= 60; diff_unit = "min"; @@ -206,7 +206,7 @@ int main(int argc, char** argv) { return 1; } - string command_str = argv[0]; + const char* command_str = argv[0]; argv++; argc--; diff --git a/src/exec/fsvs.c b/src/exec/fsvs.c @@ -30,12 +30,10 @@ static const char HELP_MESSAGE[] = " %s [options] <runlevel>\n" "\n" "Options:\n" - " -h, --help ............... prints this and exits\n" - " -i, --as-init ............ execute start/stop script\n" - " -o, --stdout ............. print service stdout/stderr in console\n" - " -s, --service-dir <path> . using service-dir (default: " SV_SERVICE_DIR ")\n" - " -v, --verbose ............ print more info\n" - " -V, --version ............ prints current version and exits\n" + " -h, --help ........ prints this and exits\n" + " -v, --verbose ..... print more info\n" + " -V, --version ..... prints current version and exits\n" + " -f, --force ....... forces socket\n" "\n"; static const char VERSION_MESSAGE[] = @@ -50,17 +48,13 @@ static const char VERSION_MESSAGE[] = "\n"; static const struct option long_options[] = { - { "autostart", no_argument, 0, 'a' }, { "help", no_argument, 0, 'h' }, { "verbose", no_argument, 0, 'v' }, { "version", no_argument, 0, 'V' }, - { "force-socket", no_argument, 0, 'f' }, + { "force", no_argument, 0, 'f' }, { 0 } }; -static bool consider_autostart = false; -static bool stdout_redirect = false; - static void signal_interrupt(int signum) { (void) signum; @@ -71,18 +65,12 @@ int main(int argc, char** argv) { bool force_socket = false; int c; - while ((c = getopt_long(argc, argv, ":ahiosf:vV", long_options, NULL)) > 0) { + while ((c = getopt_long(argc, argv, ":hvVf", long_options, NULL)) > 0) { switch (c) { - case 'a': - consider_autostart = true; - break; case 'h': printf(VERSION_MESSAGE, "<runlevel>"); printf(HELP_MESSAGE, argv[0]); return 0; - case 'o': - stdout_redirect = true; - break; case 'v': verbose = true; break; diff --git a/src/exec/seedrng.c b/src/exec/seedrng.c @@ -344,7 +344,7 @@ static int seed_rng(uint8_t* seed, size_t len, bool credit) { return ret ? -1 : 0; } -static int seed_from_file_if_exists(string filename, int dfd, bool credit, struct blake2s_state* hash) { +static int seed_from_file_if_exists(const char* filename, int dfd, bool credit, struct blake2s_state* hash) { uint8_t seed[MAX_SEED_LEN]; ssize_t seed_len; int fd = -1, ret = 0; @@ -388,7 +388,7 @@ out: } static bool skip_credit(void) { - string skip = getenv("SEEDRNG_SKIP_CREDIT"); + const char* skip = getenv("SEEDRNG_SKIP_CREDIT"); return skip && (!strcmp(skip, "1") || !strcasecmp(skip, "true") || !strcasecmp(skip, "yes") || !strcasecmp(skip, "y")); } diff --git a/src/exec/vlogger.c b/src/exec/vlogger.c @@ -13,8 +13,8 @@ extern char* __progname; static char pwd[PATH_MAX]; typedef struct { - string const c_name; - int c_val; + const char* const c_name; + int c_val; } CODE; CODE prioritynames[] = { @@ -58,7 +58,7 @@ CODE facilitynames[] = { }; static void -strpriority(string s, int* facility, int* level) { +strpriority(const char* s, int* facility, int* level) { char* p; CODE* cp; diff --git a/src/register.c b/src/register.c @@ -9,7 +9,7 @@ #include <sys/stat.h> #include <unistd.h> -service_t* service_register(string name, bool is_log_service) { +service_t* service_register(const char* name, bool is_log_service) { service_t* s; if ((s = service_get(name)) == NULL) { diff --git a/src/script/shutdown.sh b/src/script/shutdown.sh @@ -1,5 +1,5 @@ #!/bin/sh -# shutdown - shutdown(8) lookalike for runit +# shutdown - shutdown(8) lookalike for fiss single() { fsvc chlevel single diff --git a/src/service.c b/src/service.c @@ -22,7 +22,7 @@ service_t services[SV_SERVICE_MAX]; int services_size = 0; char runlevel[SV_NAME_MAX]; -string service_dir; +const char* service_dir; int control_socket; int null_fd; bool verbose = false; @@ -30,7 +30,7 @@ dependency_t depends[SV_DEPENDENCY_MAX]; int depends_size; -service_t* service_get(string name) { +service_t* service_get(const char* name) { for (int i = 0; i < services_size; i++) { if (streq(services[i].name, name)) return &services[i]; @@ -38,7 +38,7 @@ service_t* service_get(string name) { return NULL; } -int service_pattern(string name, service_t** dest, int dest_max) { +int service_pattern(const char* name, service_t** dest, int dest_max) { int size = 0; for (int i = 0; i < services_size && size < dest_max; i++) { if (pattern_test(name, services[i].name)) diff --git a/src/supervise.c b/src/supervise.c @@ -93,7 +93,7 @@ static void accept_socket() { } } -int service_supervise(string service_dir_, string runlevel_, bool force_socket) { +int service_supervise(const char* service_dir_, const char* runlevel_, bool force_socket) { struct sigaction sigact = { 0 }; sigact.sa_handler = signal_child; sigaction(SIGCHLD, &sigact, NULL); diff --git a/src/util.c b/src/util.c @@ -33,7 +33,7 @@ ssize_t readstr(int fd, char* str) { return rc == -1 ? -1 : len; } -ssize_t writestr(int fd, string str) { +ssize_t writestr(int fd, const char* str) { if (str == NULL) return write(fd, "", 1); return write(fd, str, strlen(str) + 1);