fiss

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

commit ac1fb98f6086066abb3f790c068847dd67983515
parent 59de2eb1ab962e05b08e2dc029d6589cca457e41
Author: Friedel Schön <[email protected]>
Date:   Thu,  8 Jun 2023 13:55:11 +0200

restructuring repository

Diffstat:
MMakefile | 97++++++++++++++++---------------------------------------------------------------
Rsrc/exec/chpst.c -> bin/chpst.c | 0
Rsrc/exec/finit.c -> bin/finit.c | 0
Rsrc/exec/fsvc.c -> bin/fsvc.c | 0
Rsrc/exec/fsvs.c -> bin/fsvs.c | 0
Rsrc/exec/halt.c -> bin/halt.c | 0
Rsrc/exec/init.lnk -> bin/init.lnk | 0
Rsrc/exec/modules-load.c -> bin/modules-load.c | 0
Rsrc/exec/poweroff.lnk -> bin/poweroff.lnk | 0
Rsrc/exec/reboot.lnk -> bin/reboot.lnk | 0
Rsrc/exec/seedrng.c -> bin/seedrng.c | 0
Rsrc/exec/shutdown.sh -> bin/shutdown.sh | 0
Rsrc/exec/sigremap.c -> bin/sigremap.c | 0
Rsrc/exec/vlogger.c -> bin/vlogger.c | 0
Rsrc/exec/zzz.c -> bin/zzz.c | 0
Dcommon/dracut/10-runit-void.conf | 3---
Rsrc/docs/index.txt -> docs/index.txt | 0
Rsrc/man/chpst.8.txt -> man/chpst.8.txt | 0
Rsrc/man/finit.8.txt -> man/finit.8.txt | 0
Rsrc/man/fsvc.8.txt -> man/fsvc.8.txt | 0
Rsrc/man/fsvs.8.txt -> man/fsvs.8.txt | 0
Rsrc/man/halt.8.txt -> man/halt.8.txt | 0
Rsrc/man/modules-load.8.txt -> man/modules-load.8.txt | 0
Rsrc/man/shutdown.8.txt -> man/shutdown.8.txt | 0
Rsrc/man/sigremap.8.txt -> man/sigremap.8.txt | 0
Rsrc/man/vlogger.1.txt -> man/vlogger.1.txt | 0
Rsrc/man/zzz.8.txt -> man/zzz.8.txt | 0
Amk/binary.mk | 33+++++++++++++++++++++++++++++++++
Amk/config.mk | 32++++++++++++++++++++++++++++++++
Amk/target.mk | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/decode.c | 33+++++++++++++++++++++++++++++++++
Asrc/encode.c | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/serialize.c | 112-------------------------------------------------------------------------------
Msrc/status.c | 25+++++++++++++++++++++++++
Rdocs/assets/github-mark-white.svg -> target/docs/assets/github-mark-white.svg | 0
Rdocs/assets/github-mark.svg -> target/docs/assets/github-mark.svg | 0
Rdocs/assets/style.css -> target/docs/assets/style.css | 0
Rdocs/assets/toggle-dark.js -> target/docs/assets/toggle-dark.js | 0
Rdocs/chpst.8.html -> target/docs/chpst.8.html | 0
Rdocs/finit.8.html -> target/docs/finit.8.html | 0
Rdocs/fsvc.8.html -> target/docs/fsvc.8.html | 0
Rdocs/fsvs.8.html -> target/docs/fsvs.8.html | 0
Rdocs/halt.8.html -> target/docs/halt.8.html | 0
Rdocs/index.html -> target/docs/index.html | 0
Rdocs/modules-load.8.html -> target/docs/modules-load.8.html | 0
Rdocs/shutdown.8.html -> target/docs/shutdown.8.html | 0
Rdocs/sigremap.8.html -> target/docs/sigremap.8.html | 0
Rdocs/vlogger.1.html -> target/docs/vlogger.1.html | 0
Rdocs/zzz.8.html -> target/docs/zzz.8.html | 0
Rman/chpst.8 -> target/man/chpst.8 | 0
Rman/finit.8 -> target/man/finit.8 | 0
Rman/fsvc.8 -> target/man/fsvc.8 | 0
Rman/fsvs.8 -> target/man/fsvs.8 | 0
Rman/halt.8 -> target/man/halt.8 | 0
Rman/modules-load.8 -> target/man/modules-load.8 | 0
Rman/shutdown.8 -> target/man/shutdown.8 | 0
Rman/sigremap.8 -> target/man/sigremap.8 | 0
Rman/vlogger.1 -> target/man/vlogger.1 | 0
Rman/zzz.8 -> target/man/zzz.8 | 0
59 files changed, 249 insertions(+), 193 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,54 +1,31 @@ -VERSION := 0.3.3 - -# Directories -SRC_DIR := src -BUILD_DIR := build -INCLUDE_DIR := include -BIN_DIR := bin -EXEC_DIR := src/exec -MAN_DIR := src/man -TEMPL_DIR := src/docs -ROFF_DIR := man -DOCS_DIR := docs -ASSETS_DIR := assets -DOC_AST_DIR := docs/assets -MAKE_DOCS := tools/make-docs.py -MAKE_MAN := tools/make-man.py - -# Compiler Options -CC ?= gcc -CFLAGS += -I$(INCLUDE_DIR) -DVERSION=\"$(VERSION)\" -g -std=gnu99 -Wall -Wextra -Wpedantic -Wno-gnu-zero-variadic-macro-arguments -LDFLAGS += -fPIE - -SED ?= sed -PYTHON ?= python3 -AWK ?= awk +include mk/config.mk +include mk/binary.mk -# Executable-specific flags -finit_FLAGS := -static +VERSION := 0.3.3 -# File lists SOURCE_FILES := $(wildcard $(SRC_DIR)/*.c) -EXEC_FILES := $(wildcard $(EXEC_DIR)/*) -OBJ_FILES := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SOURCE_FILES)) -BIN_FILES := $(patsubst $(EXEC_DIR)/%.c,$(BIN_DIR)/%,$(EXEC_FILES)) \ - $(patsubst $(EXEC_DIR)/%.sh,$(BIN_DIR)/%,$(EXEC_FILES)) \ - $(patsubst $(EXEC_DIR)/%.lnk,$(BIN_DIR)/%,$(EXEC_FILES)) +EXEC_FILES := $(wildcard $(BIN_DIR)/*) +OBJ_FILES := $(patsubst $(SRC_DIR)/%.c,$(TARGET_OBJECT_DIR)/%.o,$(SOURCE_FILES)) +BIN_FILES := $(patsubst $(BIN_DIR)/%.c,$(TARGET_BIN_DIR)/%,$(EXEC_FILES)) \ + $(patsubst $(BIN_DIR)/%.sh,$(TARGET_BIN_DIR)/%,$(EXEC_FILES)) \ + $(patsubst $(BIN_DIR)/%.lnk,$(TARGET_BIN_DIR)/%,$(EXEC_FILES)) INCLUDE_FILES := $(wildcard $(INCLUDE_DIR)/*.h) MAN_FILES := $(wildcard $(MAN_DIR)/*.txt) -TEMPL_FILES := $(wildcard $(TEMPL_DIR)/*.txt) +TEMPL_FILES := $(wildcard $(DOCS_DIR)/*.txt) -ROFF_FILES := $(patsubst $(MAN_DIR)/%.txt,$(ROFF_DIR)/%,$(MAN_FILES)) -DOCS_FILES := $(patsubst $(TEMPL_DIR)/%.txt,$(DOCS_DIR)/%.html,$(TEMPL_FILES)) \ - $(patsubst $(MAN_DIR)/%.txt,$(DOCS_DIR)/%.html,$(MAN_FILES)) +ROFF_FILES := $(patsubst $(MAN_DIR)/%.txt,$(TARGET_MAN_DIR)/%,$(MAN_FILES)) +DOCS_FILES := $(patsubst $(DOCS_DIR)/%.txt,$(TARGET_DOCS_DIR)/%.html,$(TEMPL_FILES)) \ + $(patsubst $(MAN_DIR)/%.txt,$(TARGET_DOCS_DIR)/%.html,$(MAN_FILES)) -INTERMED_DIRS := $(BIN_DIR) $(BUILD_DIR) $(ROFF_DIR) $(DOCS_DIR) +ifeq ($(VERBOSE),) +SILENT := @ +endif # Magic targets .PHONY: all clean manual binary documentation -.PRECIOUS: $(OBJ_FILES) +.PRECIOUS: $(OBJ_FILES) $(patsubst $(BIN_DIR)/%.c,$(TARGET_OBJECT_DIR)/%.o,$(EXEC_FILES)) # Default target @@ -56,7 +33,8 @@ all: compile_flags.txt binary manual documentation # Clean target clean: - rm -rf $(INTERMED_DIRS) + @echo "[RM] $(TARGET_DIRS)" + $(SILENT)rm -rf $(TARGET_DIRS) binary: $(BIN_FILES) @@ -64,40 +42,4 @@ manual: $(ROFF_FILES) documentation: $(DOCS_FILES) -# Directory rules -$(INTERMED_DIRS): - mkdir -p $@ - -$(DOC_AST_DIR): $(ASSETS_DIR) | $(DOCS_DIR) - mkdir -p $@ - cp -rv $</* $@ - - -# Object rules -$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c $(INCLUDE_FILES) | $(BUILD_DIR) - $(CC) -o $@ -c $(CFLAGS) $< - -# Executables -$(BIN_DIR)/%: $(EXEC_DIR)/%.c $(INCLUDE_FILES) $(OBJ_FILES) | $(BIN_DIR) - $(CC) -o $@ $(CFLAGS) $< $(OBJ_FILES) $($(notdir $@)_FLAGS) $(LDFLAGS) - -$(BIN_DIR)/%: $(EXEC_DIR)/%.sh | $(BIN_DIR) - cp $< $@ - chmod +x $@ - -$(BIN_DIR)/%: $(EXEC_DIR)/%.lnk | $(BIN_DIR) - ln -sf $(shell cat $<) $@ - -# Documentation and Manual -$(DOCS_DIR)/%.html: $(TEMPL_DIR)/%.txt $(DOC_AST_DIR) $(MAKE_DOCS) | $(DOCS_DIR) - $(SED) 's/%VERSION%/$(VERSION)/' $< | $(PYTHON) $(MAKE_DOCS) > $@ - -$(DOCS_DIR)/%.html: $(MAN_DIR)/%.txt $(DOC_AST_DIR) $(MAKE_DOCS) | $(DOCS_DIR) - $(SED) 's/%VERSION%/$(VERSION)/' $< | $(PYTHON) $(MAKE_DOCS) > $@ - -$(ROFF_DIR)/%: $(MAN_DIR)/%.txt $(MAKE_MAN) | $(ROFF_DIR) - $(SED) 's/%VERSION%/$(VERSION)/' $< | $(PYTHON) $(MAKE_MAN) | $(AWK) '/./ { print }' > $@ - -# Debug -compile_flags.txt: - echo $(CFLAGS) | tr " " "\n" > compile_flags.txt -\ No newline at end of file +include mk/target.mk diff --git a/src/exec/chpst.c b/bin/chpst.c diff --git a/src/exec/finit.c b/bin/finit.c diff --git a/src/exec/fsvc.c b/bin/fsvc.c diff --git a/src/exec/fsvs.c b/bin/fsvs.c diff --git a/src/exec/halt.c b/bin/halt.c diff --git a/src/exec/init.lnk b/bin/init.lnk diff --git a/src/exec/modules-load.c b/bin/modules-load.c diff --git a/src/exec/poweroff.lnk b/bin/poweroff.lnk diff --git a/src/exec/reboot.lnk b/bin/reboot.lnk diff --git a/src/exec/seedrng.c b/bin/seedrng.c diff --git a/src/exec/shutdown.sh b/bin/shutdown.sh diff --git a/src/exec/sigremap.c b/bin/sigremap.c diff --git a/src/exec/vlogger.c b/bin/vlogger.c diff --git a/src/exec/zzz.c b/bin/zzz.c diff --git a/common/dracut/10-runit-void.conf b/common/dracut/10-runit-void.conf @@ -1,3 +0,0 @@ -add_dracutmodules+=" resume " -omit_dracutmodules+=" systemd " -i18n_vars="/etc/rc.conf:KEYMAP,FONT,FONT_MAP,FONT_UNIMAP" diff --git a/src/docs/index.txt b/docs/index.txt diff --git a/src/man/chpst.8.txt b/man/chpst.8.txt diff --git a/src/man/finit.8.txt b/man/finit.8.txt diff --git a/src/man/fsvc.8.txt b/man/fsvc.8.txt diff --git a/src/man/fsvs.8.txt b/man/fsvs.8.txt diff --git a/src/man/halt.8.txt b/man/halt.8.txt diff --git a/src/man/modules-load.8.txt b/man/modules-load.8.txt diff --git a/src/man/shutdown.8.txt b/man/shutdown.8.txt diff --git a/src/man/sigremap.8.txt b/man/sigremap.8.txt diff --git a/src/man/vlogger.1.txt b/man/vlogger.1.txt diff --git a/src/man/zzz.8.txt b/man/zzz.8.txt diff --git a/mk/binary.mk b/mk/binary.mk @@ -0,0 +1,33 @@ +chpst_OBJECTS := parse.o util.o + +finit_OBJECTS := message.o util.o + +fsvc_OBJECTS := message.o util.o decode.o signame.o + +fsvs_OBJECTS := message.o util.o supervise.o service.o start.o stop.o \ + register.o handle_exit.o handle_command.o encode.o \ + parse.o dependency.o pattern.o status.o + +halt_OBJECTS := wtmp.o util.o + +modules-load_OBJECTS := util.o + +seedrng_OBJECTS := + +sigremap_OBJECTS := message.o signame.o + +vlogger_OBJECTS := message.o + +zzz_OBJECTS := + +chpst_FLAGS := +finit_FLAGS := -static +fsvc_FLAGS := +fsvs_FLAGS := +halt_FLAGS := +modules-load_FLAGS := +seedrng_FLAGS := +sigremap_FLAGS := +vlogger_FLAGS := +zzz_FLAGS := + diff --git a/mk/config.mk b/mk/config.mk @@ -0,0 +1,31 @@ +SRC_DIR := src +INCLUDE_DIR := include +BIN_DIR := bin +MAN_DIR := man +DOCS_DIR := docs +ASSETS_DIR := assets +TOOLS_DIR := tools +TARGET_DIR := target + +TARGET_OBJECT_DIR := $(TARGET_DIR)/obj +TARGET_BIN_DIR := $(TARGET_DIR)/bin +TARGET_MAN_DIR := $(TARGET_DIR)/man +TARGET_DOCS_DIR := $(TARGET_DIR)/docs +TARGET_ASSETS_DIR := $(TARGET_DOCS_DIR)/assets + +TARGET_DIRS := $(TARGET_DIR) $(TARGET_OBJECT_DIR) $(TARGET_BIN_DIR) \ + $(TARGET_DOCS_DIR) $(TARGET_MAN_DIR) + +# Compiler Options +CC ?= gcc +CFLAGS += -I$(INCLUDE_DIR) -DVERSION=\"$(VERSION)\" -g -std=gnu99 -Wall -Wextra -Wpedantic -Wno-gnu-zero-variadic-macro-arguments +LDFLAGS += -fPIE + +# Utilities +SED ?= sed +PYTHON ?= python3 +AWK ?= awk +MAKE_DOCS ?= $(TOOLS_DIR)/make-docs.py +MAKE_MAN ?= $(TOOLS_DIR)/make-man.py + +VERBOSE := +\ No newline at end of file diff --git a/mk/target.mk b/mk/target.mk @@ -0,0 +1,51 @@ +# Directory rules +$(TARGET_DIRS): + @echo "[MKDIR] $@" + $(SILENT)mkdir -p $@ + +$(TARGET_ASSETS_DIR): $(ASSETS_DIR) | $(TARGET_DOCS_DIR) + @echo "[CP] $@" + $(SILENT)mkdir -p $@ + $(SILENT)cp -rv $</* $@ + + +# Object rules +$(TARGET_OBJECT_DIR)/%.o: $(SRC_DIR)/%.c $(INCLUDE_FILES) | $(TARGET_OBJECT_DIR) + @echo "[CC] $@" + $(SILENT)$(CC) -o $@ -c $(CFLAGS) $< + +$(TARGET_OBJECT_DIR)/%.o: $(BIN_DIR)/%.c $(INCLUDE_FILES) | $(TARGET_OBJECT_DIR) + @echo "[CC] $@" + $(SILENT)$(CC) -o $@ -c $(CFLAGS) $< + +# Executables +$(TARGET_BIN_DIR)/%: $(TARGET_OBJECT_DIR)/%.o $(OBJ_FILES) | $(TARGET_BIN_DIR) + @echo "[LD] $@" + $(SILENT)$(CC) -o $@ $< $(patsubst %,$(TARGET_OBJECT_DIR)/%,$($(notdir $@)_OBJECTS)) $($(notdir $@)_FLAGS) $(LDFLAGS) + +$(TARGET_BIN_DIR)/%: $(BIN_DIR)/%.sh | $(TARGET_BIN_DIR) + @echo "[CP] $@" + $(SILENT)cp $< $@ + $(SILENT)chmod +x $@ + +$(TARGET_BIN_DIR)/%: $(BIN_DIR)/%.lnk | $(TARGET_BIN_DIR) + @echo "[LN] $@" + $(SILENT)ln -sf $(shell cat $<) $@ + +# Documentation and Manual +$(TARGET_DOCS_DIR)/%.html: $(DOCS_DIR)/%.txt $(TARGET_ASSETS_DIR) $(MAKE_DOCS) | $(TARGET_DOCS_DIR) + @echo "[MKDOC] $@" + $(SILENT)$(SED) 's/%VERSION%/$(VERSION)/' $< | $(PYTHON) $(MAKE_DOCS) > $@ + +$(TARGET_DOCS_DIR)/%.html: $(MAN_DIR)/%.txt $(TARGET_ASSETS_DIR) $(MAKE_DOCS) | $(TARGET_DOCS_DIR) + @echo "[MKDOC] $@" + $(SILENT)$(SED) 's/%VERSION%/$(VERSION)/' $< | $(PYTHON) $(MAKE_DOCS) > $@ + +$(TARGET_MAN_DIR)/%: $(MAN_DIR)/%.txt $(MAKE_MAN) | $(TARGET_MAN_DIR) + @echo "[MKMAN] $@" + $(SILENT)$(SED) 's/%VERSION%/$(VERSION)/' $< | $(PYTHON) $(MAKE_MAN) | $(AWK) '/./ { print }' > $@ + +# Debug +compile_flags.txt: Makefile + @echo "[ECHO] $@" + $(SILENT)echo $(CFLAGS) | tr " " "\n" > compile_flags.txt +\ No newline at end of file diff --git a/src/decode.c b/src/decode.c @@ -0,0 +1,33 @@ +#include "service.h" + + +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) | + ((uint64_t) buffer->status_change[3] << 32) | + ((uint64_t) buffer->status_change[4] << 24) | + ((uint64_t) buffer->status_change[5] << 16) | + ((uint64_t) buffer->status_change[6] << 8) | + ((uint64_t) buffer->status_change[7]); + + s->status_change = tai - 4611686018427387914ULL; + + 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; + + s->pid = (buffer->pid[0] << 0) | + (buffer->pid[1] << 8) | + (buffer->pid[2] << 16) | + (buffer->pid[3] << 24); + + s->paused = buffer->paused; + s->restart_final = buffer->restart == 'u'; +} diff --git a/src/encode.c b/src/encode.c @@ -0,0 +1,55 @@ +#include "service.h" + + +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; + + switch (s->state) { + case STATE_INACTIVE: + case STATE_DEAD: + state_runit = 0; + break; + case STATE_SETUP: + case STATE_STARTING: + case STATE_ACTIVE_DUMMY: + case STATE_ACTIVE_FOREGROUND: + case STATE_ACTIVE_BACKGROUND: + case STATE_STOPPING: + state_runit = 1; + break; + case STATE_FINISHING: + state_runit = 2; + break; + } + + buffer->status_change[0] = (tai >> 56) & 0xff; + buffer->status_change[1] = (tai >> 48) & 0xff; + buffer->status_change[2] = (tai >> 40) & 0xff; + buffer->status_change[3] = (tai >> 32) & 0xff; + buffer->status_change[4] = (tai >> 24) & 0xff; + buffer->status_change[5] = (tai >> 16) & 0xff; + buffer->status_change[6] = (tai >> 8) & 0xff; + buffer->status_change[7] = (tai >> 0) & 0xff; + + buffer->state = s->state; + buffer->return_code = s->return_code; + buffer->fail_count = s->fail_count; + + buffer->flags = (service_is_dependency(s) << 6) | + (s->restart_file << 4) | + (s->restart_manual << 2) | + (s->last_exit << 0); + + buffer->pid[0] = (s->pid >> 0) & 0xff; + buffer->pid[1] = (s->pid >> 8) & 0xff; + buffer->pid[2] = (s->pid >> 16) & 0xff; + buffer->pid[3] = (s->pid >> 24) & 0xff; + + buffer->paused = s->paused; + buffer->restart = service_need_restart(s) ? 'u' : 'd'; + buffer->force_down = s->restart_manual == S_FORCE_DOWN; + buffer->state_runit = state_runit; +} diff --git a/src/serialize.c b/src/serialize.c @@ -1,112 +0,0 @@ -#include "service.h" - - -const char* service_status_name(service_t* s) { - switch (s->state) { - case STATE_SETUP: - return "setup"; - case STATE_STARTING: - return "starting"; - case STATE_ACTIVE_FOREGROUND: - return "run"; - case STATE_ACTIVE_BACKGROUND: - return "run-background"; - case STATE_ACTIVE_DUMMY: - return "run-dummy"; - case STATE_FINISHING: - return "finishing"; - case STATE_STOPPING: - return "stopping"; - case STATE_INACTIVE: - return "down"; - case STATE_DEAD: - return "dead"; - default: - return NULL; - } -} - -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; - - switch (s->state) { - case STATE_INACTIVE: - case STATE_DEAD: - state_runit = 0; - break; - case STATE_SETUP: - case STATE_STARTING: - case STATE_ACTIVE_DUMMY: - case STATE_ACTIVE_FOREGROUND: - case STATE_ACTIVE_BACKGROUND: - case STATE_STOPPING: - state_runit = 1; - break; - case STATE_FINISHING: - state_runit = 2; - break; - } - - buffer->status_change[0] = (tai >> 56) & 0xff; - buffer->status_change[1] = (tai >> 48) & 0xff; - buffer->status_change[2] = (tai >> 40) & 0xff; - buffer->status_change[3] = (tai >> 32) & 0xff; - buffer->status_change[4] = (tai >> 24) & 0xff; - buffer->status_change[5] = (tai >> 16) & 0xff; - buffer->status_change[6] = (tai >> 8) & 0xff; - buffer->status_change[7] = (tai >> 0) & 0xff; - - buffer->state = s->state; - buffer->return_code = s->return_code; - buffer->fail_count = s->fail_count; - - buffer->flags = (service_is_dependency(s) << 6) | - (s->restart_file << 4) | - (s->restart_manual << 2) | - (s->last_exit << 0); - - buffer->pid[0] = (s->pid >> 0) & 0xff; - buffer->pid[1] = (s->pid >> 8) & 0xff; - buffer->pid[2] = (s->pid >> 16) & 0xff; - buffer->pid[3] = (s->pid >> 24) & 0xff; - - buffer->paused = s->paused; - buffer->restart = service_need_restart(s) ? 'u' : 'd'; - buffer->force_down = s->restart_manual == S_FORCE_DOWN; - buffer->state_runit = state_runit; -} - - -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) | - ((uint64_t) buffer->status_change[3] << 32) | - ((uint64_t) buffer->status_change[4] << 24) | - ((uint64_t) buffer->status_change[5] << 16) | - ((uint64_t) buffer->status_change[6] << 8) | - ((uint64_t) buffer->status_change[7]); - - s->status_change = tai - 4611686018427387914ULL; - - 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; - - s->pid = (buffer->pid[0] << 0) | - (buffer->pid[1] << 8) | - (buffer->pid[2] << 16) | - (buffer->pid[3] << 24); - - s->paused = buffer->paused; - s->restart_final = buffer->restart == 'u'; -} diff --git a/src/status.c b/src/status.c @@ -65,3 +65,28 @@ void service_write(service_t* s) { renameat(s->dir, "supervise/stat.new", s->dir, "supervise/stat"); renameat(s->dir, "supervise/pid.new", s->dir, "supervise/pid"); } + +const char* service_status_name(service_t* s) { + switch (s->state) { + case STATE_SETUP: + return "setup"; + case STATE_STARTING: + return "starting"; + case STATE_ACTIVE_FOREGROUND: + return "run"; + case STATE_ACTIVE_BACKGROUND: + return "run-background"; + case STATE_ACTIVE_DUMMY: + return "run-dummy"; + case STATE_FINISHING: + return "finishing"; + case STATE_STOPPING: + return "stopping"; + case STATE_INACTIVE: + return "down"; + case STATE_DEAD: + return "dead"; + default: + return NULL; + } +} diff --git a/docs/assets/github-mark-white.svg b/target/docs/assets/github-mark-white.svg diff --git a/docs/assets/github-mark.svg b/target/docs/assets/github-mark.svg diff --git a/docs/assets/style.css b/target/docs/assets/style.css diff --git a/docs/assets/toggle-dark.js b/target/docs/assets/toggle-dark.js diff --git a/docs/chpst.8.html b/target/docs/chpst.8.html diff --git a/docs/finit.8.html b/target/docs/finit.8.html diff --git a/docs/fsvc.8.html b/target/docs/fsvc.8.html diff --git a/docs/fsvs.8.html b/target/docs/fsvs.8.html diff --git a/docs/halt.8.html b/target/docs/halt.8.html diff --git a/docs/index.html b/target/docs/index.html diff --git a/docs/modules-load.8.html b/target/docs/modules-load.8.html diff --git a/docs/shutdown.8.html b/target/docs/shutdown.8.html diff --git a/docs/sigremap.8.html b/target/docs/sigremap.8.html diff --git a/docs/vlogger.1.html b/target/docs/vlogger.1.html diff --git a/docs/zzz.8.html b/target/docs/zzz.8.html diff --git a/man/chpst.8 b/target/man/chpst.8 diff --git a/man/finit.8 b/target/man/finit.8 diff --git a/man/fsvc.8 b/target/man/fsvc.8 diff --git a/man/fsvs.8 b/target/man/fsvs.8 diff --git a/man/halt.8 b/target/man/halt.8 diff --git a/man/modules-load.8 b/target/man/modules-load.8 diff --git a/man/shutdown.8 b/target/man/shutdown.8 diff --git a/man/sigremap.8 b/target/man/sigremap.8 diff --git a/man/vlogger.1 b/target/man/vlogger.1 diff --git a/man/zzz.8 b/target/man/zzz.8