commit 90e2dfc13105dcab6539a3bba7ddd577d681aaa7
parent 8be66b2a0d7df39d851422638fab95c9aa852aeb
Author: Friedel Schön <[email protected]>
Date: Mon, 5 Jun 2023 14:07:56 +0200
renaming enums and structs
Diffstat:
4 files changed, 59 insertions(+), 53 deletions(-)
diff --git a/include/service.h b/include/service.h
@@ -8,7 +8,7 @@
#include <time.h>
-typedef enum service_command {
+enum service_command {
X_UP = 'u', // starts the services, pin as started
X_DOWN = 'd', // stops the service, pin as stopped
X_XUP = 'U', // starts the service, set restart (d = down, f = force_down, o = once, u = up)
@@ -26,34 +26,34 @@ typedef enum service_command {
X_USR1 = '1', // sends usr1
X_USR2 = '2', // sends usr2
X_EXIT = 'x', // does nothing
-} service_command_t;
+};
-typedef enum service_state {
- STATE_INACTIVE = 0,
- STATE_SETUP = 1,
- STATE_STARTING = 2,
- STATE_ACTIVE_FOREGROUND = 3,
- STATE_ACTIVE_BACKGROUND = 4,
- STATE_ACTIVE_DUMMY = 5,
- STATE_STOPPING = 6,
- STATE_FINISHING = 7,
- STATE_DEAD = 8,
-} service_state_t;
+enum service_state {
+ STATE_INACTIVE,
+ STATE_SETUP,
+ STATE_STARTING,
+ STATE_ACTIVE_FOREGROUND,
+ STATE_ACTIVE_BACKGROUND,
+ STATE_ACTIVE_DUMMY,
+ STATE_STOPPING,
+ STATE_FINISHING,
+ STATE_DEAD,
+};
-typedef enum service_exit {
- EXIT_NONE = 0,
- EXIT_NORMAL = 1,
- EXIT_SIGNALED = 2,
-} service_exit_t;
+enum service_exit {
+ EXIT_NONE,
+ EXIT_NORMAL,
+ EXIT_SIGNALED,
+};
-typedef enum service_restart {
- S_DOWN = 0,
- S_FORCE_DOWN = 1, // force down (manual)
- S_ONCE = 2,
- S_RESTART = 3,
-} service_restart_t;
+enum service_restart {
+ S_DOWN,
+ S_FORCE_DOWN, // force down (manual)
+ S_ONCE,
+ S_RESTART,
+};
-typedef struct service_serial {
+struct service_serial {
uint8_t status_change[8];
uint8_t state;
uint8_t return_code;
@@ -64,26 +64,26 @@ typedef struct service_serial {
uint8_t restart;
uint8_t force_down;
uint8_t state_runit;
-} service_serial_t;
+};
typedef struct service {
- char name[SV_NAME_MAX]; // name of service
- int dir; // dirfd
- service_state_t state;
- int control; // fd to supervise/control
- pid_t pid; // pid of run
- time_t status_change; // last status change
- pipe_t log_pipe; // pipe for logging
- service_restart_t restart_manual; // should restart on exit
- service_restart_t restart_file; // should restart on exit
- bool restart_final; // combined restart + dependency (only set client-side)
- service_exit_t last_exit; // stopped signaled or exited
- int return_code; // return code or signal
- uint8_t fail_count; // current fail cound
- bool is_log_service; // is a log service
- bool paused; // is paused
- struct service* log_service; // has a log_server otherwise NULL
- bool is_dependency; // only set by service_load
+ char name[SV_NAME_MAX]; // name of service
+ int dir; // dirfd
+ int state;
+ int control; // fd to supervise/control
+ pid_t pid; // pid of run
+ time_t status_change; // last status change
+ pipe_t log_pipe; // pipe for logging
+ int restart_manual; // should restart on exit
+ int restart_file; // should restart on exit
+ bool restart_final; // combined restart + dependency (only set client-side)
+ int last_exit; // stopped signaled or exited
+ int return_code; // return code or signal
+ uint8_t fail_count; // current fail cound
+ bool is_log_service; // is a log service
+ bool paused; // is paused
+ struct service* log_service; // has a log_server otherwise NULL
+ bool is_dependency; // only set by service_load
} service_t;
extern service_t services[];
@@ -97,11 +97,11 @@ extern int depends_size;
extern const char* service_dir_path;
-void service_decode(service_t* s, const service_serial_t* buffer); // for fsvc
-void service_encode(service_t* s, service_serial_t* buffer); // for fsvs
+void service_decode(service_t* s, const void* buffer); // for fsvc
+void service_encode(service_t* s, void* buffer); // for fsvs
service_t* service_get(const char* name);
void service_handle_client(int client);
-void service_handle_command(service_t* s, service_command_t command, char data);
+void service_handle_command(service_t* s, char command, char data);
void service_handle_exit(service_t* s, bool signaled, int return_code);
void service_kill(service_t* s, int signal);
bool service_need_restart(service_t* s);
diff --git a/src/handle_command.c b/src/handle_command.c
@@ -17,7 +17,7 @@ static int runit_signals[] = {
[X_USR2] = SIGUSR2,
};
-void service_handle_command(service_t* s, service_command_t command, char data) {
+void service_handle_command(service_t* s, char command, char data) {
switch (command) {
case X_UP:
s->restart_manual = S_RESTART;
@@ -88,7 +88,7 @@ void service_handle_command(service_t* s, service_command_t command, char data)
case X_QUIT:
case X_USR1:
case X_USR2:
- service_kill(s, runit_signals[command]);
+ service_kill(s, runit_signals[(int) command]);
break;
case X_RESET:
if (s->paused) {
diff --git a/src/serialize.c b/src/serialize.c
@@ -21,10 +21,14 @@ const char* service_status_name(service_t* s) {
return "down";
case STATE_DEAD:
return "dead";
+ default:
+ return NULL;
}
}
-void service_encode(service_t* s, service_serial_t* buffer) {
+void service_encode(service_t* s, void* buffer_ptr) {
+ struct service_serial* buffer = buffer_ptr;
+
uint64_t tai = (uint64_t) s->status_change + 4611686018427387914ULL;
int state_runit;
@@ -76,7 +80,9 @@ void service_encode(service_t* s, service_serial_t* buffer) {
}
-void service_decode(service_t* s, const service_serial_t* buffer) {
+void service_decode(service_t* s, const void* buffer_ptr) {
+ const struct service_serial* buffer = buffer_ptr;
+
uint64_t tai = ((uint64_t) buffer->status_change[0] << 56) |
((uint64_t) buffer->status_change[1] << 48) |
((uint64_t) buffer->status_change[2] << 40) |
diff --git a/src/status.c b/src/status.c
@@ -12,9 +12,9 @@
static void service_update_status(service_t* s) {
- int fd;
- const char* stat_human;
- service_serial_t stat_runit;
+ int fd;
+ const char* stat_human;
+ struct service_serial stat_runit;
if ((fd = openat(s->dir, "supervise/status.new", O_CREAT | O_WRONLY | O_TRUNC, 0644)) == -1) {
print_error("cannot open supervise/status: %s\n");