plumber: add -f (foreground) option (#288)

In MacOS, services run by launchd must run in the foreground, since
launchd manages forking and other resources.
This commit is contained in:
Jason Felice 2019-10-29 10:07:10 -04:00 committed by Dan Cross
parent 1309450668
commit b0aecb4ba5
4 changed files with 19 additions and 5 deletions

View file

@ -4,6 +4,9 @@ plumber \- file system for interprocess messaging
.SH SYNOPSIS .SH SYNOPSIS
.B plumber .B plumber
[ [
.B -f
]
[
.B -p .B -p
.I plumbing .I plumbing
] ]
@ -23,7 +26,7 @@ in the format of
Its services are posted via Its services are posted via
.IR 9pserve (4) .IR 9pserve (4)
as as
.BR plumb . .BR plumb ,
and consist of two and consist of two
pre-defined files, pre-defined files,
.B plumb/send .B plumb/send
@ -95,6 +98,10 @@ Thus the rule set may be edited dynamically with a traditional text editor.
However, ports are never deleted dynamically; if a new set of rules does not However, ports are never deleted dynamically; if a new set of rules does not
include a port that was defined in earlier rules, that port will still exist (although include a port that was defined in earlier rules, that port will still exist (although
no new messages will be delivered there). no new messages will be delivered there).
.PP
The
.B -f
option causes the process to run in the foreground.
.SH FILES .SH FILES
.TF $HOME/lib/plumbing .TF $HOME/lib/plumbing
.TP .TP

View file

@ -186,7 +186,7 @@ getclock(void)
} }
void void
startfsys(void) startfsys(int foreground)
{ {
int p[2]; int p[2];
@ -199,7 +199,10 @@ startfsys(void)
if(post9pservice(p[1], "plumb", nil) < 0) if(post9pservice(p[1], "plumb", nil) < 0)
sysfatal("post9pservice plumb: %r"); sysfatal("post9pservice plumb: %r");
close(p[1]); close(p[1]);
proccreate(fsysproc, nil, Stack); if(foreground)
fsysproc(nil);
else
proccreate(fsysproc, nil, Stack);
} }
static void static void

View file

@ -7,6 +7,7 @@
#include "plumber.h" #include "plumber.h"
int debug; int debug;
int foreground=0;
char *plumbfile; char *plumbfile;
char *user; char *user;
char *home; char *home;
@ -37,6 +38,9 @@ threadmain(int argc, char *argv[])
case 'd': case 'd':
debug = 1; debug = 1;
break; break;
case 'f':
foreground = 1;
break;
case 'p': case 'p':
plumbfile = ARGF(); plumbfile = ARGF();
break; break;
@ -69,7 +73,7 @@ threadmain(int argc, char *argv[])
*/ */
printerrors = 0; printerrors = 0;
makeports(rules); makeports(rules);
startfsys(); startfsys(foreground);
threadexits(nil); threadexits(nil);
} }

View file

@ -72,7 +72,7 @@ void* emalloc(long);
void* erealloc(void*, long); void* erealloc(void*, long);
char* estrdup(char*); char* estrdup(char*);
Ruleset** readrules(char*, int); Ruleset** readrules(char*, int);
void startfsys(void); void startfsys(int);
Exec* matchruleset(Plumbmsg*, Ruleset*); Exec* matchruleset(Plumbmsg*, Ruleset*);
void freeexec(Exec*); void freeexec(Exec*);
char* startup(Ruleset*, Exec*); char* startup(Ruleset*, Exec*);