Changeset 2417


Ignore:
Timestamp:
Jul 19, 2007, 1:27:52 AM (15 years ago)
Author:
joshe
Message:

Add compat code for if daemon() function isn't available.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.ac

    r2412 r2417  
    1717AC_HEADER_STDC
    1818AC_HEADER_TIME
    19 AC_CHECK_FUNCS([lrintf strlcpy strlcat])
     19AC_CHECK_FUNCS([lrintf strlcpy strlcat daemon])
    2020AC_PROG_INSTALL
    2121AC_PROG_MAKE_SET
  • trunk/daemon/misc.c

    r2400 r2417  
    203203    return buf;
    204204}
     205
     206#ifndef HAVE_DAEMON
     207
     208int
     209daemon( int nochdir, int noclose )
     210{
     211    pid_t child;
     212    int   null;
     213
     214    child = fork();
     215    if( 0 > child )
     216        return -1;
     217    else if( 0 != child )
     218        exit( 0 );
     219
     220    if( 0 > setsid() )
     221        return -1;
     222
     223    if( !nochdir && 0 > chdir( "/" ) )
     224        return -1;
     225
     226    if( !noclose )
     227    {
     228        null = open( "/dev/null", O_RDWR );
     229        if( 0 > null )
     230            return -1;
     231        if( 0 > dup2( null, 0 ) || 0 > dup2( null, 1 ) || 0 > dup2( null, 2 ) )
     232            return -1;
     233        close( null );
     234    }
     235
     236    return -1;
     237}
     238
     239#endif
  • trunk/daemon/misc.h

    r2416 r2417  
    149149uint8_t *    readfile  ( const char *, size_t * );
    150150
     151#ifndef HAVE_DAEMON
     152int daemon( int, int );
     153#endif
     154
    151155#endif /* TR_DAEMON_MISC_H */
Note: See TracChangeset for help on using the changeset viewer.