]> git.mdlowis.com Git - projs/tide.git/commitdiff
added daemonization code to the registrar service
authorMichael D. Lowis <mike@mdlowis.com>
Mon, 31 Dec 2018 04:09:48 +0000 (23:09 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Mon, 31 Dec 2018 04:09:48 +0000 (23:09 -0500)
Makefile
TODO.md
config.mk
src/registrar.c

index 9a805de855840d12ca4c3151993cee5badc5162b..e83abd3733e4658b9b9bd0ec5fcc86a51c807efe 100644 (file)
--- 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 53840dbc54069d3cc66fb88b05de280e93512b25..4228879cdb5a5d403d725358e16ecb369a86db44 100644 (file)
--- 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
 * 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:
 
index feefa5f4d965342180f021e357f996ee7ba0b45c..1de3ee6e01bd0db51e9016d783dabfc04b7a8319 100644 (file)
--- 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           \
index d0d6be562f14d0a030651685fe4d3ce4359bac3b..fc0c4edf402f7723e340d44955652823b92f8a6d 100644 (file)
@@ -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);