Skip to content

Commit 6b0b00d

Browse files
committed
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.
1 parent 360619c commit 6b0b00d

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ Version 1.1.1
3434
- Unify and improve log message output
3535
- Improve README.md with project description, installation, contributing and
3636
usage sections
37+
- The "--foreground" flag has been removed; usbmuxd now runs in foreground by
38+
default. For the previous behaviour, use "--background" to run in
39+
background instead.
3740

3841
Version 1.1.0
3942
~~~~~~~~~~~~~

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ The daemon also manages pairing records with iOS devices and the host in
103103

104104
Ensure proper permissions are setup for the daemon to access the directory.
105105

106-
For debugging purposes it is helpful to start usbmuxd using the foreground `-f`
107-
argument and enable verbose mode `-v` to get suitable logs.
106+
For debugging purposes it is helpful to enable verbose mode `-v` to get
107+
suitable logs.
108108

109109
Please consult the usage information or manual page for a full documentation of
110110
available command line options:

docs/usbmuxd.8

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ Ensure proper permissions are setup for the daemon to access the directory.
3232
.B \-U, \-\-user USER
3333
Change to this user after startup (needs USB privileges).
3434
.TP
35-
.B \-f, \-\-foreground
36-
Do not daemonize (implies one -v).
35+
.B \-f, \-\-background
36+
Daemonize (double fork and run in background).
3737
.TP
3838
.B \-n, \-\-disable-hotplug
3939
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
4444
device is attached.
4545
.TP
4646
.B \-u, \-\-udev
47-
Run in udev operation mode (implies -n and -z).
47+
Run in udev operation mode (implies -n, -b and -z).
4848
.TP
4949
.B \-s, \-\-systemd
5050
Run in systemd operation mode (implies -z and -f).

src/main.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int no_preflight = 0;
6565

6666
// Global state for main.c
6767
static int verbose = 0;
68-
static int foreground = 0;
68+
static int background = 0;
6969
static int drop_privileges = 0;
7070
static const char *drop_user = NULL;
7171
static int opt_disable_hotplug = 0;
@@ -504,15 +504,15 @@ static void usage()
504504
printf("OPTIONS:\n");
505505
printf(" -h, --help\t\tPrint this message.\n");
506506
printf(" -v, --verbose\t\tBe verbose (use twice or more to increase).\n");
507-
printf(" -f, --foreground\tDo not daemonize (implies one -v).\n");
507+
printf(" -b, --background\tDaemonize (double fork immediately).\n");
508508
printf(" -U, --user USER\tChange to this user after startup (needs USB privileges).\n");
509509
printf(" -n, --disable-hotplug\tDisables automatic discovery of devices on hotplug.\n");
510510
printf(" \tStarting another instance will trigger discovery instead.\n");
511511
printf(" -z, --enable-exit\tEnable \"--exit\" request from other instances and exit\n");
512512
printf(" \tautomatically if no device is attached.\n");
513513
printf(" -p, --no-preflight\tDisable lockdownd preflight on new device.\n");
514514
#ifdef HAVE_UDEV
515-
printf(" -u, --udev\t\tRun in udev operation mode (implies -n and -z).\n");
515+
printf(" -u, --udev\t\tRun in udev operation mode (implies -n, -b and -z).\n");
516516
#endif
517517
#ifdef HAVE_SYSTEMD
518518
printf(" -s, --systemd\t\tRun in systemd operation mode (implies -z and -f).\n");
@@ -537,7 +537,7 @@ static void parse_opts(int argc, char **argv)
537537
{
538538
static struct option longopts[] = {
539539
{"help", no_argument, NULL, 'h'},
540-
{"foreground", no_argument, NULL, 'f'},
540+
{"background", no_argument, NULL, 'b'},
541541
{"verbose", no_argument, NULL, 'v'},
542542
{"user", required_argument, NULL, 'U'},
543543
{"disable-hotplug", no_argument, NULL, 'n'},
@@ -577,8 +577,8 @@ static void parse_opts(int argc, char **argv)
577577
case 'h':
578578
usage();
579579
exit(0);
580-
case 'f':
581-
foreground = 1;
580+
case 'b':
581+
background = 1;
582582
break;
583583
case 'v':
584584
++verbose;
@@ -597,12 +597,13 @@ static void parse_opts(int argc, char **argv)
597597
case 'u':
598598
opt_disable_hotplug = 1;
599599
opt_enable_exit = 1;
600+
background = 1;
600601
break;
601602
#endif
602603
#ifdef HAVE_SYSTEMD
603604
case 's':
604605
opt_enable_exit = 1;
605-
foreground = 1;
606+
background = 0;
606607
break;
607608
#endif
608609
case 'n':
@@ -675,7 +676,7 @@ int main(int argc, char *argv[])
675676
argc -= optind;
676677
argv += optind;
677678

678-
if (!foreground && !use_logfile) {
679+
if (background && !use_logfile) {
679680
verbose += LL_WARNING;
680681
log_enable_syslog();
681682
} else {
@@ -751,7 +752,7 @@ int main(int argc, char *argv[])
751752
goto terminate;
752753
}
753754

754-
if (!foreground) {
755+
if (background) {
755756
if ((res = daemonize()) < 0) {
756757
fprintf(stderr, "usbmuxd: FATAL: Could not daemonize!\n");
757758
usbmuxd_log(LL_FATAL, "Could not daemonize!");

0 commit comments

Comments
 (0)