summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorGravatar Hugo Osvaldo Barrera2023-11-25 23:39:51 +0800
committerGravatar Nikias Bassen2026-11-20 02:07:00 +0100
commit60ec5e06a03f516511948daed5ee124740591d7a (patch)
tree33f564d292c6ed36f59b05f3212820e1ff0f0e8b /src/main.c
parent3ded00c9985a5108cfc7591a309f9a23d57a8cba (diff)
downloadusbmuxd-60ec5e06a03f516511948daed5ee124740591d7a.tar.gz
usbmuxd-60ec5e06a03f516511948daed5ee124740591d7a.tar.bz2
Replace --foreground with --background
Always run in foreground by default. Service manager and supervisors expect services to run in foreground, so they can track the lifetime of the child process. Those that don't implement their own logic to fork daemons anyway. For users running usbmuxd manually, running in background by default provides a confusing experience, since it gives the impression that usbmuxd has exited immediately. Anyone needing to run usbmuxd in background can use the --background option.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/main.c b/src/main.c
index b09a187..1bb334a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -65,7 +65,7 @@ int no_preflight = 0;
// Global state for main.c
static int verbose = 0;
-static int foreground = 0;
+static int background = 0;
static int drop_privileges = 0;
static const char *drop_user = NULL;
static int opt_disable_hotplug = 0;
@@ -504,7 +504,7 @@ static void usage()
printf("OPTIONS:\n");
printf(" -h, --help\t\tPrint this message.\n");
printf(" -v, --verbose\t\tBe verbose (use twice or more to increase).\n");
- printf(" -f, --foreground\tDo not daemonize (implies one -v).\n");
+ printf(" -b, --background\tDaemonize (double fork immediately).\n");
printf(" -U, --user USER\tChange to this user after startup (needs USB privileges).\n");
printf(" -n, --disable-hotplug\tDisables automatic discovery of devices on hotplug.\n");
printf(" \tStarting another instance will trigger discovery instead.\n");
@@ -512,7 +512,7 @@ static void usage()
printf(" \tautomatically if no device is attached.\n");
printf(" -p, --no-preflight\tDisable lockdownd preflight on new device.\n");
#ifdef HAVE_UDEV
- printf(" -u, --udev\t\tRun in udev operation mode (implies -n and -z).\n");
+ printf(" -u, --udev\t\tRun in udev operation mode (implies -n, -b and -z).\n");
#endif
#ifdef HAVE_SYSTEMD
printf(" -s, --systemd\t\tRun in systemd operation mode (implies -z and -f).\n");
@@ -538,7 +538,7 @@ static void parse_opts(int argc, char **argv)
{
static struct option longopts[] = {
{"help", no_argument, NULL, 'h'},
- {"foreground", no_argument, NULL, 'f'},
+ {"background", no_argument, NULL, 'b'},
{"verbose", no_argument, NULL, 'v'},
{"user", required_argument, NULL, 'U'},
{"disable-hotplug", no_argument, NULL, 'n'},
@@ -562,11 +562,11 @@ static void parse_opts(int argc, char **argv)
int c;
#ifdef HAVE_SYSTEMD
- const char* opts_spec = "hfvVuU:xXsnzl:pC:S:P:";
+ const char* opts_spec = "hbvVuU:xXsnzl:pC:S:P:";
#elif HAVE_UDEV
- const char* opts_spec = "hfvVuU:xXnzl:pC:S:P:";
+ const char* opts_spec = "hbvVuU:xXnzl:pC:S:P:";
#else
- const char* opts_spec = "hfvVU:xXnzl:pC:S:P:";
+ const char* opts_spec = "hbvVU:xXnzl:pC:S:P:";
#endif
while (1) {
@@ -579,8 +579,8 @@ static void parse_opts(int argc, char **argv)
case 'h':
usage();
exit(0);
- case 'f':
- foreground = 1;
+ case 'b':
+ background = 1;
break;
case 'v':
++verbose;
@@ -599,12 +599,13 @@ static void parse_opts(int argc, char **argv)
case 'u':
opt_disable_hotplug = 1;
opt_enable_exit = 1;
+ background = 1;
break;
#endif
#ifdef HAVE_SYSTEMD
case 's':
opt_enable_exit = 1;
- foreground = 1;
+ background = 0;
break;
#endif
case 'n':
@@ -685,7 +686,7 @@ int main(int argc, char *argv[])
argc -= optind;
argv += optind;
- if (!foreground && !use_logfile) {
+ if (background && !use_logfile) {
verbose += LL_WARNING;
log_enable_syslog();
} else {
@@ -761,7 +762,7 @@ int main(int argc, char *argv[])
goto terminate;
}
- if (!foreground) {
+ if (background) {
if ((res = daemonize()) < 0) {
fprintf(stderr, "usbmuxd: FATAL: Could not daemonize!\n");
usbmuxd_log(LL_FATAL, "Could not daemonize!");