commit 57a8ac5bc9091ad760b8c2ef887dbc01ca0efa44
parent 3333c196e2dd892a6300495091a98b3e32253dc6
Author: Friedel Schön <[email protected]>
Date: Wed, 31 May 2023 10:38:52 +0200
adding is_depends to serial + fixing w/u-compatiblity
Diffstat:
4 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/include/service.h b/include/service.h
@@ -81,8 +81,9 @@ typedef struct service {
int return_code; // return code or signal
uint8_t fail_count; // current fail cound
bool is_log_service; // is a log service
- bool paused;
- struct service* 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[];
@@ -116,3 +117,4 @@ void service_stop(service_t* s);
int service_supervise(const char* service_dir, const char* runlevel);
void service_update_dependency(service_t* s);
void service_update_status(service_t* s);
+bool service_is_dependency(service_t* s);
diff --git a/internal/serialize.txt b/internal/serialize.txt
@@ -26,8 +26,9 @@ FLAGS
-----
+--+--+--+--+--+--+--+--+
-| --- |RSFIL|RSMAN|LSTEX|
+|--|ID|RSFIL|RSMAN|LSTEX|
+--+--+--+--+--+--+--+--+
+ID = is dependency
RSFIL = restart file (0 = down, 2 = once, 3 = restart)
RSMAN = restart manual override (0 = down, 1 = force down, 2 = once, 3 = restart)
LSTEX = last exit (0 = never exitted, 1 = normally, 2 = signaled)
diff --git a/src/serialize.c b/src/serialize.c
@@ -59,7 +59,8 @@ void service_encode(service_t* s, service_serial_t* buffer) {
buffer->return_code = s->return_code;
buffer->fail_count = s->fail_count;
- buffer->flags = (s->restart_file << 4) |
+ buffer->flags = (service_is_dependency(s) << 6) |
+ (s->restart_file << 4) |
(s->restart_manual << 2) |
(s->last_exit << 0);
@@ -69,7 +70,7 @@ void service_encode(service_t* s, service_serial_t* buffer) {
buffer->pid[3] = (s->pid >> 24) & 0xff;
buffer->paused = s->paused;
- buffer->restart = service_need_restart(s);
+ buffer->restart = service_need_restart(s) ? 'u' : 'd';
buffer->force_down = s->restart_manual == S_FORCE_DOWN;
buffer->state_runit = state_runit;
}
@@ -90,6 +91,7 @@ void service_decode(service_t* s, const service_serial_t* buffer) {
s->state = buffer->state;
s->return_code = buffer->return_code;
s->fail_count = buffer->fail_count;
+ s->is_dependency = (buffer->flags >> 6) & 0x01;
s->restart_file = (buffer->flags >> 4) & 0x03;
s->restart_manual = (buffer->flags >> 2) & 0x03;
s->last_exit = (buffer->flags >> 0) & 0x03;
@@ -100,5 +102,5 @@ void service_decode(service_t* s, const service_serial_t* buffer) {
(buffer->pid[3] << 24);
s->paused = buffer->paused;
- s->restart_final = buffer->restart;
+ s->restart_final = buffer->restart == 'u';
}
diff --git a/src/service.c b/src/service.c
@@ -86,7 +86,7 @@ int service_refresh_directory(void) {
}
-static bool is_dependency(service_t* d) {
+bool service_is_dependency(service_t* d) {
service_t* s;
for (int i = 0; i < depends_size; i++) {
@@ -99,11 +99,11 @@ static bool is_dependency(service_t* d) {
bool service_need_restart(service_t* s) {
if (s->restart_manual == S_FORCE_DOWN)
- return is_dependency(s);
+ return service_is_dependency(s);
return s->restart_file == S_ONCE ||
s->restart_file == S_RESTART ||
s->restart_manual == S_ONCE ||
s->restart_manual == S_RESTART ||
- is_dependency(s);
+ service_is_dependency(s);
}