@@ -73,6 +73,7 @@ static int gpiostatusled = 0;
7373static int gpiobutton = 0 ;
7474
7575static pid_t hcxpid = 0 ;
76+ static pid_t hcxsid = 0 ;
7677
7778static unsigned int seed = 7 ;
7879
@@ -5373,8 +5374,13 @@ fprintf(stdout, "--tot=<digit> : enable timeout timer in minutes\n"
53735374 " default: 0 (GPIO not in use)\n"
53745375 "--gpio_statusled=<digit> : Raspberry Pi GPIO number of status LED (2...27)\n"
53755376 " default: 0 (GPIO not in use)\n"
5377+ "--daemonize : daemonize\n"
5378+ " status messages are suppressed\n"
5379+ " to terminate %s send SIGTERM to its PID\n"
5380+ " or press push button (modified Raspberry Pi)\n"
53765381 "--help : show additional help (example and trouble shooting)\n"
5377- "--version : show version\n\n" );
5382+ "--version : show version\n\n" ,
5383+ eigenname );
53785384exit (EXIT_SUCCESS );
53795385}
53805386/*---------------------------------------------------------------------------*/
@@ -5418,6 +5424,8 @@ static bool interfacefrequencyflag = false;
54185424static bool interfacelistflag = false;
54195425static bool interfacelistshortflag = false;
54205426static bool rooterrorflag = false;
5427+ static bool daemon = false;
5428+
54215429static char * essidlistname = NULL ;
54225430static char * userchannellistname = NULL ;
54235431static char * userfrequencylistname = NULL ;
@@ -5451,6 +5459,7 @@ static const struct option long_options[] =
54515459 {"gpio_statusled" , required_argument , NULL , HCX_GPIO_STATUSLED },
54525460 {"rds" , required_argument , NULL , HCX_RDS },
54535461 {"rdt" , no_argument , NULL , HCX_RDT },
5462+ {"daemonize" , no_argument , NULL , HCX_DAEMON },
54545463 {"rcascan" , required_argument , NULL , HCX_RCASCAN },
54555464 {"version" , no_argument , NULL , HCX_VERSION },
54565465 {"help" , no_argument , NULL , HCX_HELP_ADDITIONAL },
@@ -5697,7 +5706,10 @@ while((auswahl = getopt_long(argc, argv, short_options, long_options, &index)) !
56975706 fprintf (stderr , "combination of --rcascan and -w is not allowed\n" );
56985707 exit (EXIT_FAILURE );
56995708 }
5709+ break ;
57005710
5711+ case HCX_DAEMON :
5712+ daemon = true;
57015713 break ;
57025714
57035715 case HCX_HELP :
@@ -5869,6 +5881,28 @@ if(set_timer() == false)
58695881 fprintf (stderr , "failed to initialize timer\n" );
58705882 goto byebye ;
58715883 }
5884+
5885+ if (daemon == true)
5886+ {
5887+ if ((hcxpid = fork ()) < 0 )
5888+ {
5889+ fprintf (stdout , "failed to daamonize %s\n" , basename (argv [0 ]));
5890+ goto byebye ;
5891+ }
5892+ if (hcxpid > 0 )
5893+ {
5894+ fprintf (stdout , "daemonize %s (pid: %d)\n" , basename (argv [0 ]), hcxpid );
5895+ goto byebye ;
5896+ }
5897+ if ((hcxsid = setsid ()) < 0 )
5898+ {
5899+ fprintf (stdout , "failed to daemonize %s\n" , basename (argv [0 ]));
5900+ goto byebye ;
5901+ }
5902+ close (STDIN_FILENO );
5903+ close (STDOUT_FILENO );
5904+ close (STDERR_FILENO );
5905+ }
58725906/*---------------------------------------------------------------------------*/
58735907tspecifo .tv_sec = 5 ;
58745908tspecifo .tv_nsec = 0 ;
0 commit comments