mirror of
https://github.com/linux-msm/qrtr.git
synced 2026-01-18 01:30:08 +01:00
ns: Add argument to stay in foreground
When running in Android we want to keep qrtr-ns in the foreground, so that init's service handler can keep track of it. Add the -f flag to skip the fork(). Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
27
src/ns.c
27
src/ns.c
@@ -750,7 +750,7 @@ static void usage(void)
|
||||
{
|
||||
extern char *__progname;
|
||||
|
||||
fprintf(stderr, "%s [<node-id>]\n", __progname);
|
||||
fprintf(stderr, "%s [-f] [<node-id>]\n", __progname);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -762,19 +762,33 @@ int main(int argc, char **argv)
|
||||
unsigned long addr = (unsigned long)-1;
|
||||
struct waiter *w;
|
||||
socklen_t sl = sizeof(sq);
|
||||
bool foreground = false;
|
||||
char *ep;
|
||||
int opt;
|
||||
int rc;
|
||||
|
||||
if (argc == 2) {
|
||||
addr = strtoul(argv[1], &ep, 10);
|
||||
while ((opt = getopt(argc, argv, "f")) != -1) {
|
||||
switch (opt) {
|
||||
case 'f':
|
||||
foreground = true;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc) {
|
||||
addr = strtoul(argv[optind], &ep, 10);
|
||||
if (argv[1][0] == '\0' || *ep != '\0' || addr >= UINT_MAX)
|
||||
usage();
|
||||
|
||||
qrtr_set_address(addr);
|
||||
} else if (argc > 2) {
|
||||
usage();
|
||||
optind++;
|
||||
}
|
||||
|
||||
if (optind != argc)
|
||||
usage();
|
||||
|
||||
w = waiter_create();
|
||||
if (w == NULL)
|
||||
errx(1, "unable to create waiter");
|
||||
@@ -807,7 +821,8 @@ int main(int argc, char **argv)
|
||||
if (rc)
|
||||
err(1, "unable to say hello");
|
||||
|
||||
if (fork() != 0) {
|
||||
/* If we're going to background, fork and exit parent */
|
||||
if (!foreground && fork() != 0) {
|
||||
close(ctx.sock);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user