Skip to content

Commit

Permalink
Replace --foreground with --background
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
WhyNotHugo committed Nov 25, 2023
1 parent 360619c commit 5581395
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Version 1.1.1
- Unify and improve log message output
- Improve README.md with project description, installation, contributing and
usage sections
- The "--foreground" flag has been removed; usbmuxd now runs in foreground by
default. For the previous behaviour, use "--background" to run in
background instead.

Version 1.1.0
~~~~~~~~~~~~~
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions docs/usbmuxd.8
Original file line number Diff line number Diff line change
Expand Up @@ -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 \-f, \-\-background
Daemonize (double fork and run in background).
.TP
.B \-n, \-\-disable-hotplug
Disables automatic discovery of devices on hotplug. Starting another instance
Expand Down
16 changes: 8 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -537,7 +537,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'},
Expand Down Expand Up @@ -577,8 +577,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;
Expand All @@ -602,7 +602,7 @@ static void parse_opts(int argc, char **argv)
#ifdef HAVE_SYSTEMD
case 's':
opt_enable_exit = 1;
foreground = 1;
background = 0;
break;
#endif
case 'n':
Expand Down Expand Up @@ -675,7 +675,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 {
Expand Down Expand Up @@ -751,7 +751,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!");
Expand Down

0 comments on commit 5581395

Please sign in to comment.