write pid of forked process

This commit is contained in:
Axel Kittenberger 2017-01-09 13:13:05 +01:00
parent 3f78514273
commit 544f6066b7
3 changed files with 23 additions and 14 deletions

View File

@ -1,6 +1,7 @@
????-??-??: 2.2.2 ????-??-??: 2.2.2
fix: checkgauge 'insist' fix: checkgauge 'insist'
fix: no partial path exlusion tests fix: no partial path exlusion tests
fix: write pid of forked process in pidfile
2017-01-05: 2.2.1 2017-01-05: 2.2.1
enhancement: now always using filter lists with rysnc enhancement: now always using filter lists with rysnc

View File

@ -677,7 +677,8 @@ non_block_fd( int fd )
| Writes a pid file. | Writes a pid file.
*/ */
static void static void
write_pidfile( write_pidfile
(
lua_State *L, lua_State *L,
const char *pidfile const char *pidfile
) )
@ -970,12 +971,13 @@ user_obs_tidy( struct observance *obs )
} }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~* /******************************.
( Library calls for the runner ) * Library calls for the runner *
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ '******************************/
static void daemonize( lua_State *L ); static void daemonize( lua_State *L, const char *pidfile );
int l_stackdump( lua_State* L ); int l_stackdump( lua_State* L );
@ -1612,16 +1614,11 @@ l_configure( lua_State *L )
openlog( log_ident, 0, settings.log_facility ); openlog( log_ident, 0, settings.log_facility );
} }
if( settings.pidfile )
{
write_pidfile( L, settings.pidfile );
}
if( !settings.nodaemon && !is_daemon ) if( !settings.nodaemon && !is_daemon )
{ {
logstring( "Normal", "--- Startup, daemonizing ---" ); logstring( "Normal", "--- Startup, daemonizing ---" );
daemonize( L ); daemonize( L, settings.pidfile );
} }
else else
{ {
@ -2053,7 +2050,10 @@ load_runner_func(
| might actually close the monitors fd! | might actually close the monitors fd!
*/ */
static void static void
daemonize( lua_State *L ) daemonize(
lua_State *L, // the lua state
const char *pidfile // if not NULL write pidfile
)
{ {
pid_t pid, sid; pid_t pid, sid;
@ -2070,14 +2070,21 @@ daemonize( lua_State *L )
exit( -1 ); exit( -1 );
} }
if (pid > 0) if( pid > 0 )
{ {
// parent process returns to shell // parent process returns to shell
exit( 0 ); exit( 0 );
} }
if( pidfile )
{
write_pidfile( L, pidfile );
}
// detaches the new process from the parent process // detaches the new process from the parent process
sid = setsid( ); sid = setsid( );
if( sid < 0 ) if( sid < 0 )
{ {
printlogf( printlogf(

View File

@ -4967,7 +4967,8 @@ runner.fsEventsEvent = Fsevents.event
-- --
-- Collector for every child process that finished in startup phase -- Collector for every child process that finished in startup phase
-- --
function runner.collector( function runner.collector
(
pid, -- pid of the child process pid, -- pid of the child process
exitcode -- exitcode of the child process exitcode -- exitcode of the child process
) )