static unsigned clockMicros = PI_DEFAULT_CLK_MICROS;
static unsigned clockPeripheral = PI_DEFAULT_CLK_PERIPHERAL;
static unsigned ifFlags = PI_DEFAULT_IF_FLAGS;
+static int foreground = PI_DEFAULT_FOREGROUND;
static unsigned DMAprimaryChannel = PI_DEFAULT_DMA_PRIMARY_CHANNEL;
static unsigned DMAsecondaryChannel = PI_DEFAULT_DMA_SECONDARY_CHANNEL;
static unsigned socketPort = PI_DEFAULT_SOCKET_PORT;
" -d value, primary DMA channel, 0-14, default 14\n" \
" -e value, secondary DMA channel, 0-14, default 6\n" \
" -f, disable fifo interface, default enabled\n" \
+ " -g, run in foreground (do not fork), default disabled\n" \
" -k, disable socket interface, default enabled\n" \
" -l, localhost socket only default local+remote\n" \
" -n IP addr, allow address, name or dotted, default allow all\n" \
uint32_t addr;
int64_t mask;
- while ((opt = getopt(argc, argv, "a:b:c:d:e:fkln:p:s:t:x:vV")) != -1)
+ while ((opt = getopt(argc, argv, "a:b:c:d:e:fgkln:p:s:t:x:vV")) != -1)
{
switch (opt)
{
ifFlags |= PI_DISABLE_FIFO_IF;
break;
+ case 'g':
+ foreground = 1;
+ break;
+
case 'k':
ifFlags |= PI_DISABLE_SOCK_IF;
break;
pid_t pid;
int flags;
- /* Fork off the parent process */
+ /* check command line parameters */
- pid = fork();
+ initOpts(argc, argv);
- if (pid < 0) { exit(EXIT_FAILURE); }
+ if (!foreground) {
+ /* Fork off the parent process */
- /* If we got a good PID, then we can exit the parent process. */
+ pid = fork();
- if (pid > 0) { exit(EXIT_SUCCESS); }
+ if (pid < 0) { exit(EXIT_FAILURE); }
- /* Change the file mode mask */
+ /* If we got a good PID, then we can exit the parent process. */
- umask(0);
-
- /* Open any logs here */
+ if (pid > 0) { exit(EXIT_SUCCESS); }
- /* NONE */
-
- /* Create a new SID for the child process */
+ /* Change the file mode mask */
- if (setsid() < 0) fatal("setsid failed (%m)");
+ umask(0);
- /* Change the current working directory */
+ /* Open any logs here */
- if ((chdir("/")) < 0) fatal("chdir failed (%m)");
-
- /* check command line parameters */
+ /* NONE */
- initOpts(argc, argv);
-
- /* Close out the standard file descriptors */
+ /* Create a new SID for the child process */
- fclose(stdin);
- fclose(stdout);
+ if (setsid() < 0) fatal("setsid failed (%m)");
+
+ /* Change the current working directory */
+
+ if ((chdir("/")) < 0) fatal("chdir failed (%m)");
+
+ /* Close out the standard file descriptors */
+
+ fclose(stdin);
+ fclose(stdout);
+ }
/* configure library */