Browse Source

Only use pidfile(3) on FreeBSD

June 1 month ago
parent
commit
ca58a35095
Signed by: Curtis McEnroe <june@causal.agency> GPG Key ID: CEA2F97ADCFCD77C
3 changed files with 11 additions and 2 deletions
  1. 1
    1
      README
  2. 8
    1
      server.c
  3. 2
    0
      torus.1

+ 1
- 1
README View File

@@ -39,7 +39,7 @@ DESCRIPTION
39 39
      -h      Write help page data to standard output and exit.
40 40
 
41 41
      -p pidfile
42
-             Daemonize and write PID to pidfile.
42
+             Daemonize and write PID to pidfile.  Only available on FreeBSD.
43 43
 
44 44
      -s sock
45 45
              Set path to UNIX-domain socket.  The default path is torus.sock.

+ 8
- 1
server.c View File

@@ -19,7 +19,6 @@
19 19
 #include <err.h>
20 20
 #include <errno.h>
21 21
 #include <fcntl.h>
22
-#include <libutil.h>
23 22
 #include <signal.h>
24 23
 #include <stdbool.h>
25 24
 #include <stdint.h>
@@ -34,6 +33,10 @@
34 33
 #include <time.h>
35 34
 #include <unistd.h>
36 35
 
36
+#ifdef __FreeBSD__
37
+#include <libutil.h>
38
+#endif
39
+
37 40
 #include "torus.h"
38 41
 
39 42
 static struct Tile *tiles;
@@ -371,11 +374,13 @@ int main(int argc, char *argv[]) {
371 374
 		}
372 375
 	}
373 376
 
377
+#ifdef __FreeBSD__
374 378
 	struct pidfh *pid = NULL;
375 379
 	if (pidPath) {
376 380
 		pid = pidfile_open(pidPath, 0600, NULL);
377 381
 		if (!pid) err(EX_CANTCREAT, "%s", pidPath);
378 382
 	}
383
+#endif
379 384
 
380 385
 	tilesMap(dataPath);
381 386
 
@@ -390,11 +395,13 @@ int main(int argc, char *argv[]) {
390 395
 	error = bind(server, (struct sockaddr *)&addr, SUN_LEN(&addr));
391 396
 	if (error) err(EX_CANTCREAT, "%s", sockPath);
392 397
 
398
+#ifdef __FreeBSD__
393 399
 	if (pid) {
394 400
 		error = daemon(0, 0);
395 401
 		if (error) err(EX_OSERR, "daemon");
396 402
 		pidfile_write(pid);
397 403
 	}
404
+#endif
398 405
 
399 406
 	error = listen(server, 0);
400 407
 	if (error) err(EX_OSERR, "listen");

+ 2
- 0
torus.1 View File

@@ -101,6 +101,8 @@ Write help page data to standard output and exit.
101 101
 .It Fl p Ar pidfile
102 102
 Daemonize and write PID to
103 103
 .Ar pidfile .
104
+Only available on
105
+.Fx .
104 106
 .
105 107
 .It Fl s Ar sock
106 108
 Set path to UNIX-domain socket.

Loading…
Cancel
Save