transmission-2.42 daemon patch fvdw-sl-10

transmission-2.42 daemon patch fvdw-sl-10

Postby fvdw » Wed Nov 16, 2011 7:21 pm

It appeared that on the spd8020 the transmission-daemon failed after several minutes. Nobody reported a problem with it on the other devices.

I have been able to make a patch for transmission-2.42 daemon source code that seems to solve this problem
Its running now for more then 1 day on my spd8020 without failing.
For those who have problems with the 2.42 transmission daemon in fvdw-sl-10-0 this patch might cure it.

patch removed solved in fvdw-sl-10-1
fvdw
Site Admin - expert
 
Posts: 13471
Joined: Tue Apr 12, 2011 2:30 pm
Location: Netherlands

Re: transmission-2.42 daemon patch fvdw-sl-10

Postby fvdw » Wed Nov 16, 2011 7:45 pm

for those interested below the old and new code used in daemon.c code of transmission
Would be nice if someone can explain why this makes a difference.

old code
Code: Select all
tr_daemon( int nochdir, int noclose )
{
#if defined(USE_OS_DAEMON)

    return daemon( nochdir, noclose );

#elif defined(USE_TR_DAEMON)

    /* this is loosely based off of glibc's daemon() implementation
     * http://sourceware.org/git/?p=glibc.git;a=blob_plain;f=misc/daemon.c */

    switch( fork( ) ) {
        case -1: return -1;
        case 0: break;
        default: _exit(0);
    }

    if( setsid( ) == -1 )
        return -1;

    if( !nochdir )
        chdir( "/" );

    if( !noclose ) {
        int fd = open( "/dev/null", O_RDWR, 0 );
        dup2( fd, STDIN_FILENO );
        dup2( fd, STDOUT_FILENO );
        dup2( fd, STDERR_FILENO );
        close( fd );
    }

    return 0;

#else /* USE_NO_DAEMON */
    return 0;
#endif
}


new code
Code: Select all
tr_daemon( int nochdir, int noclose )
{
#if defined(USE_OS_DAEMON)

    return daemon( nochdir, noclose );

#elif defined(USE_TR_DAEMON)
    pid_t pid = fork( );
    if( pid < 0 )
        return -1;
    else if( pid > 0 )
        _exit( 0 );
    else {
        pid = setsid( );
        if( pid < 0 )
            return -1;

        pid = fork( );
        if( pid < 0 )
            return -1;
        else if( pid > 0 )
            _exit( 0 );
        else {

            if( !nochdir )
                if( chdir( "/" ) < 0 )
                    return -1;

            umask( (mode_t)0 );

            if( !noclose ) {
                /* send stdin, stdout, and stderr to /dev/null */
                int i;
                int fd = open( "/dev/null", O_RDWR, 0 );
                if( fd < 0 )
                    fprintf( stderr, "unable to open /dev/null: %s\n", tr_strerror(errno) );
                for( i=0; i<3; ++i ) {
                    if( close( i ) )
                        return -1;
                    dup2( fd, i );
                }
                close( fd );
            }

            return 0;
        }
    }
#else /* USE_NO_DAEMON */
    return 0;
#endif
}
fvdw
Site Admin - expert
 
Posts: 13471
Joined: Tue Apr 12, 2011 2:30 pm
Location: Netherlands


Return to Development

Who is online

Users browsing this forum: Bing Bot and 4 guests