From: Michael D. Lowis Date: Mon, 31 Dec 2018 04:09:48 +0000 (-0500) Subject: added daemonization code to the registrar service X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=4fb9b9152426c8cd5e8f4cb609c33bc07298f771;p=projs%2Ftide.git added daemonization code to the registrar service --- diff --git a/Makefile b/Makefile index 9a805de..e83abd3 100644 --- a/Makefile +++ b/Makefile @@ -27,8 +27,7 @@ clean: $(RM) $(BINS) $(TEST_BINS) flaws.txt install: - mkdir -p $(PREFIX)/bin - cp -f tide $(PREFIX)/bin + cp -f bin/* $(PREFIX)/bin uninstall: rm -f $(PREFIX)/bin/tide diff --git a/TODO.md b/TODO.md index 53840db..4228879 100644 --- a/TODO.md +++ b/TODO.md @@ -8,7 +8,6 @@ ## STAGING * group by hostname or group env var in registrar -* daemonize registrar and tide executables * Ctrl+D should not pass tag name as arg when executing tag commands * 'Get' tag with argument currently segfaults * registrar doesnt match open windows when new file created and is then opened for edit or line number @@ -19,17 +18,14 @@ * Line - Get the current line number(s) containing the selection * gap buffer does not handle UTF-8 currently -## UNCERTAIN - -* refactor selection handling to avoid swapping manually (use buf_selbeg and buf_selend) -* encode EOL setting in log entries? - ## BACKLOG * move mouse handlers back into tide.c * Add matching logic for "", '', ``, and <> * B2+B1 click executes command with selection as argument * implement script for toggling between header and source file +* refactor selection handling to avoid swapping manually (use buf_selbeg and buf_selend) +* encode EOL setting in log entries? Tags: diff --git a/config.mk b/config.mk index feefa5f..1de3ee6 100644 --- a/config.mk +++ b/config.mk @@ -4,8 +4,7 @@ MAKEFLAGS += -j # Install location -#PREFIX = $(HOME) -PREFIX = /usr/local +PREFIX = $(HOME) # OSX X11 Flags INCS += -I/usr/X11/include \ diff --git a/src/registrar.c b/src/registrar.c index d0d6be5..fc0c4ed 100644 --- a/src/registrar.c +++ b/src/registrar.c @@ -109,7 +109,33 @@ void propnotify(XConf* x, XEvent* e) { } } +int daemonize(void) +{ + int status; + /* fork into the background first */ + if ((status = fork()) < 0) + return -1; + else if (status > 0) + _exit(0); + + /* create a new session */ + if (setsid() < 0) return -1; + + /* fork again so we don't reattach to the terminal */ + if ((status = fork()) < 0) + return -1; + else if (status > 0) + _exit(0); + + /* clear any inherited umask(2) value */ + umask(0); + chdir("/"); + close(0), close(1), close(2); + return 0; +} + int main(void) { + if (daemonize() != 0) return 1; XConf x = {0}; x11_init(&x); x11_mkwin(&x, 1, 1, PropertyChangeMask);