mirror of
https://github.com/transmission/transmission
synced 2024-12-23 08:13:27 +00:00
Add compat code for if daemon() function isn't available.
This commit is contained in:
parent
32e3f9a8e6
commit
ceb66c2de7
3 changed files with 40 additions and 1 deletions
|
@ -16,7 +16,7 @@ AC_PROG_CC
|
|||
AC_PROG_CXX
|
||||
AC_HEADER_STDC
|
||||
AC_HEADER_TIME
|
||||
AC_CHECK_FUNCS([lrintf strlcpy strlcat])
|
||||
AC_CHECK_FUNCS([lrintf strlcpy strlcat daemon])
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_MAKE_SET
|
||||
AC_PROG_RANLIB
|
||||
|
|
|
@ -202,3 +202,38 @@ readfile( const char * name, size_t * len )
|
|||
|
||||
return buf;
|
||||
}
|
||||
|
||||
#ifndef HAVE_DAEMON
|
||||
|
||||
int
|
||||
daemon( int nochdir, int noclose )
|
||||
{
|
||||
pid_t child;
|
||||
int null;
|
||||
|
||||
child = fork();
|
||||
if( 0 > child )
|
||||
return -1;
|
||||
else if( 0 != child )
|
||||
exit( 0 );
|
||||
|
||||
if( 0 > setsid() )
|
||||
return -1;
|
||||
|
||||
if( !nochdir && 0 > chdir( "/" ) )
|
||||
return -1;
|
||||
|
||||
if( !noclose )
|
||||
{
|
||||
null = open( "/dev/null", O_RDWR );
|
||||
if( 0 > null )
|
||||
return -1;
|
||||
if( 0 > dup2( null, 0 ) || 0 > dup2( null, 1 ) || 0 > dup2( null, 2 ) )
|
||||
return -1;
|
||||
close( null );
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -148,4 +148,8 @@ void absolutify( char *, size_t, const char * );
|
|||
int writefile ( const char *, uint8_t *, ssize_t );
|
||||
uint8_t * readfile ( const char *, size_t * );
|
||||
|
||||
#ifndef HAVE_DAEMON
|
||||
int daemon( int, int );
|
||||
#endif
|
||||
|
||||
#endif /* TR_DAEMON_MISC_H */
|
||||
|
|
Loading…
Reference in a new issue