summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--README.md4
-rw-r--r--docs/usbmuxd.86
-rw-r--r--src/main.c25
3 files changed, 18 insertions, 17 deletions
diff --git a/README.md b/README.md
index 0725e31..cb53d85 100644
--- a/README.md
+++ b/README.md
@@ -103,8 +103,8 @@ The daemon also manages pairing records with iOS devices and the host in
Ensure proper permissions are setup for the daemon to access the directory.
-For debugging purposes it is helpful to start usbmuxd using the foreground `-f`
-argument and enable verbose mode `-v` to get suitable logs.
+For debugging purposes it is helpful to enable verbose mode `-v` to get
+suitable logs.
Please consult the usage information or manual page for a full documentation of
available command line options:
diff --git a/docs/usbmuxd.8 b/docs/usbmuxd.8
index 590afdc..c40760c 100644
--- a/docs/usbmuxd.8
+++ b/docs/usbmuxd.8
@@ -32,8 +32,8 @@ Ensure proper permissions are setup for the daemon to access the directory.
.B \-U, \-\-user USER
Change to this user after startup (needs USB privileges).
.TP
-.B \-f, \-\-foreground
-Do not daemonize (implies one -v).
+.B \-b, \-\-background
+Daemonize (double fork and run in background).
.TP
.B \-n, \-\-disable-hotplug
Disables automatic discovery of devices on hotplug. Starting another instance
@@ -44,7 +44,7 @@ Enable "--exit" request from other instances and exit automatically if no
device is attached.
.TP
.B \-u, \-\-udev
-Run in udev operation mode (implies -n and -z).
+Run in udev operation mode (implies -n, -b and -z).
.TP
.B \-s, \-\-systemd
Run in systemd operation mode (implies -z and -f).
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!");