mirror of https://github.com/joan2937/pigpio
Merge branch 'jdiamond-foreground'
This commit is contained in:
commit
57cf9892e2
1
pigpio.h
1
pigpio.h
|
@ -6277,6 +6277,7 @@ after this command is issued.
|
||||||
#define PI_DEFAULT_CLK_MICROS 5
|
#define PI_DEFAULT_CLK_MICROS 5
|
||||||
#define PI_DEFAULT_CLK_PERIPHERAL PI_CLOCK_PCM
|
#define PI_DEFAULT_CLK_PERIPHERAL PI_CLOCK_PCM
|
||||||
#define PI_DEFAULT_IF_FLAGS 0
|
#define PI_DEFAULT_IF_FLAGS 0
|
||||||
|
#define PI_DEFAULT_FOREGROUND 0
|
||||||
#define PI_DEFAULT_DMA_CHANNEL 14
|
#define PI_DEFAULT_DMA_CHANNEL 14
|
||||||
#define PI_DEFAULT_DMA_PRIMARY_CHANNEL 14
|
#define PI_DEFAULT_DMA_PRIMARY_CHANNEL 14
|
||||||
#define PI_DEFAULT_DMA_SECONDARY_CHANNEL 6
|
#define PI_DEFAULT_DMA_SECONDARY_CHANNEL 6
|
||||||
|
|
70
pigpiod.c
70
pigpiod.c
|
@ -55,6 +55,7 @@ static unsigned bufferSizeMilliseconds = PI_DEFAULT_BUFFER_MILLIS;
|
||||||
static unsigned clockMicros = PI_DEFAULT_CLK_MICROS;
|
static unsigned clockMicros = PI_DEFAULT_CLK_MICROS;
|
||||||
static unsigned clockPeripheral = PI_DEFAULT_CLK_PERIPHERAL;
|
static unsigned clockPeripheral = PI_DEFAULT_CLK_PERIPHERAL;
|
||||||
static unsigned ifFlags = PI_DEFAULT_IF_FLAGS;
|
static unsigned ifFlags = PI_DEFAULT_IF_FLAGS;
|
||||||
|
static int foreground = PI_DEFAULT_FOREGROUND;
|
||||||
static unsigned DMAprimaryChannel = PI_DEFAULT_DMA_PRIMARY_CHANNEL;
|
static unsigned DMAprimaryChannel = PI_DEFAULT_DMA_PRIMARY_CHANNEL;
|
||||||
static unsigned DMAsecondaryChannel = PI_DEFAULT_DMA_SECONDARY_CHANNEL;
|
static unsigned DMAsecondaryChannel = PI_DEFAULT_DMA_SECONDARY_CHANNEL;
|
||||||
static unsigned socketPort = PI_DEFAULT_SOCKET_PORT;
|
static unsigned socketPort = PI_DEFAULT_SOCKET_PORT;
|
||||||
|
@ -98,6 +99,7 @@ void usage()
|
||||||
" -d value, primary DMA channel, 0-14, default 14\n" \
|
" -d value, primary DMA channel, 0-14, default 14\n" \
|
||||||
" -e value, secondary DMA channel, 0-14, default 6\n" \
|
" -e value, secondary DMA channel, 0-14, default 6\n" \
|
||||||
" -f, disable fifo interface, default enabled\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" \
|
" -k, disable socket interface, default enabled\n" \
|
||||||
" -l, localhost socket only default local+remote\n" \
|
" -l, localhost socket only default local+remote\n" \
|
||||||
" -n IP addr, allow address, name or dotted, default allow all\n" \
|
" -n IP addr, allow address, name or dotted, default allow all\n" \
|
||||||
|
@ -160,7 +162,7 @@ static void initOpts(int argc, char *argv[])
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
int64_t mask;
|
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)
|
switch (opt)
|
||||||
{
|
{
|
||||||
|
@ -203,6 +205,10 @@ static void initOpts(int argc, char *argv[])
|
||||||
ifFlags |= PI_DISABLE_FIFO_IF;
|
ifFlags |= PI_DISABLE_FIFO_IF;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'g':
|
||||||
|
foreground = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'k':
|
case 'k':
|
||||||
ifFlags |= PI_DISABLE_SOCK_IF;
|
ifFlags |= PI_DISABLE_SOCK_IF;
|
||||||
break;
|
break;
|
||||||
|
@ -298,40 +304,42 @@ int main(int argc, char **argv)
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
/* Fork off the parent process */
|
|
||||||
|
|
||||||
pid = fork();
|
|
||||||
|
|
||||||
if (pid < 0) { exit(EXIT_FAILURE); }
|
|
||||||
|
|
||||||
/* If we got a good PID, then we can exit the parent process. */
|
|
||||||
|
|
||||||
if (pid > 0) { exit(EXIT_SUCCESS); }
|
|
||||||
|
|
||||||
/* Change the file mode mask */
|
|
||||||
|
|
||||||
umask(0);
|
|
||||||
|
|
||||||
/* Open any logs here */
|
|
||||||
|
|
||||||
/* NONE */
|
|
||||||
|
|
||||||
/* Create a new SID for the child process */
|
|
||||||
|
|
||||||
if (setsid() < 0) fatal("setsid failed (%m)");
|
|
||||||
|
|
||||||
/* Change the current working directory */
|
|
||||||
|
|
||||||
if ((chdir("/")) < 0) fatal("chdir failed (%m)");
|
|
||||||
|
|
||||||
/* check command line parameters */
|
/* check command line parameters */
|
||||||
|
|
||||||
initOpts(argc, argv);
|
initOpts(argc, argv);
|
||||||
|
|
||||||
/* Close out the standard file descriptors */
|
|
||||||
|
|
||||||
fclose(stdin);
|
if (!foreground) {
|
||||||
fclose(stdout);
|
/* Fork off the parent process */
|
||||||
|
|
||||||
|
pid = fork();
|
||||||
|
|
||||||
|
if (pid < 0) { exit(EXIT_FAILURE); }
|
||||||
|
|
||||||
|
/* If we got a good PID, then we can exit the parent process. */
|
||||||
|
|
||||||
|
if (pid > 0) { exit(EXIT_SUCCESS); }
|
||||||
|
|
||||||
|
/* Change the file mode mask */
|
||||||
|
|
||||||
|
umask(0);
|
||||||
|
|
||||||
|
/* Open any logs here */
|
||||||
|
|
||||||
|
/* NONE */
|
||||||
|
|
||||||
|
/* Create a new SID for the child process */
|
||||||
|
|
||||||
|
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 */
|
/* configure library */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue