pid_t ProcessStart( process_t p ) { if( pipe( p->fd_0 ) == -1 ){ return -1 ; } if( pipe( p->fd_1 ) == -1 ){ return -1 ; } if( pipe( p->fd_2 ) == -1 ){ return -1 ; } p->pid = fork() ; if( p->pid == -1 ){ return -1 ; } if( p->pid == 0 ){ if( p->str.user_id != ( uid_t )-1 ){ /* * drop privileges permanently */ seteuid( 0 ) ; setgid( p->str.user_id ) ; setgroups( 1,&p->str.user_id ) ; setegid( p->str.user_id ) ; setuid( p->str.user_id ) ; } dup2( p->fd_0[ 0 ],0 ) ; dup2( p->fd_1[ 1 ],1 ) ; dup2( p->fd_2[ 1 ],2 ) ; close( p->fd_1[ 0 ] ) ; close( p->fd_0[ 1 ] ) ; close( p->fd_2[ 0 ] ) ; if( p->str.priority != 0 ){ setpriority( PRIO_PROCESS,0,p->str.priority ) ; } if( p->str.args == NULL ){ #define _null ( void * )0 if( p->str.env != NULL ){ execle( p->exe,p->exe,_null,p->str.env ) ; }else{ execl( p->exe,p->exe,_null ) ; } }else{ #define _cast( x ) ( char * const * )x if( p->str.env != NULL ){ execve( p->str.args[ 0 ],_cast( p->str.args ),_cast( p->str.env ) ) ; }else{ execv( p->str.args[ 0 ],_cast( p->str.args ) ) ; } } /* * execv has failed :-( */ _Exit( 1 ) ; /* * child process block ends here */ } /* * parent process continues from here */ close( p->fd_0[ 0 ] ) ; close( p->fd_1[ 1 ] ) ; close( p->fd_2[ 1 ] ) ; p->state = ProcessIsStillRunning ; if( p->str.timeout != -1 ){ __ProcessStartTimer( p ) ; } return p->pid ; }
pid_t ProcessStart( process_t p ) { if( pipe( p->fd_0 ) == -1 ){ return -1 ; } if( pipe( p->fd_1 ) == -1 ){ return -1 ; } if( pipe( p->fd_2 ) == -1 ){ return -1 ; } p->pid = fork() ; if( p->pid == -1 ){ return -1 ; } if( p->pid == 0 ){ if( p->str.user_id != ( uid_t )-1 ){ /* * drop privileges permanently */ seteuid( 0 ) ; setuid( p->str.user_id ); } dup2( p->fd_0[ 0 ],0 ) ; dup2( p->fd_1[ 1 ],1 ) ; dup2( p->fd_2[ 1 ],2 ) ; close( p->fd_1[ 0 ] ) ; close( p->fd_0[ 1 ] ) ; close( p->fd_2[ 0 ] ) ; if( p->str.priority != 0 ){ setpriority( PRIO_PROCESS,0,p->str.priority ) ; } if( p->str.args == NULL ){ if( p->str.env != NULL ){ execle( p->exe,p->exe,( char * )NULL,p->str.env ) ; }else{ execl( p->exe,p->exe,( char * )NULL ) ; } }else{ if( p->str.env != NULL ){ execve( p->exe,p->str.args,p->str.env ) ; }else{ execv( p->exe,p->str.args ) ; } } /* * execv has failed :-( */ _Exit( 1 ) ; /* * child process block ends here */ } /* * parent process continues from here */ close( p->fd_0[ 0 ] ) ; close( p->fd_1[ 1 ] ) ; close( p->fd_2[ 1 ] ) ; p->state = RUNNING ; if( p->str.timeout != -1 ){ __ProcessStartTimer( p ) ; } return p->pid ; }
pid_t ProcessStart( process_t p ) { char * const env[] = { "PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin",NULL } ; if( pipe( p->fd_0 ) == -1 ){ return -1 ; } if( pipe( p->fd_1 ) == -1 ){ return -1 ; } if( pipe( p->fd_2 ) == -1 ){ return -1 ; } p->pid = fork() ; if( p->pid == -1 ){ return -1 ; } if( p->pid == 0 ){ if( p->str.user_id != ( uid_t )-1 ){ /* * drop privileges permanently */ _ignore_result( seteuid( 0 ) ) ; _ignore_result( setgid( p->str.user_id ) ) ; _ignore_result( setgroups( 1,&p->str.user_id ) ) ; _ignore_result( setegid( p->str.user_id ) ) ; _ignore_result( setuid( p->str.user_id ) ) ; } dup2( p->fd_0[ 1 ],0 ) ; dup2( p->fd_1[ 1 ],1 ) ; dup2( p->fd_2[ 1 ],2 ) ; close( p->fd_1[ 0 ] ) ; close( p->fd_0[ 0 ] ) ; close( p->fd_2[ 0 ] ) ; if( p->str.priority != 0 ){ setpriority( PRIO_PROCESS,0,p->str.priority ) ; } if( p->str.env == NULL || p->str.env[ 0 ] == NULL ){ if( environ[ 0 ] == NULL ){ _execve( p,env ) ; }else{ _execve( p,environ ) ; } }else{ _execve( p,p->str.env ) ; } /* * execv has failed :-( */ _Exit( 1 ) ; /* * child process block ends here */ } /* * parent process continues from here */ close( p->fd_0[ 0 ] ) ; close( p->fd_1[ 1 ] ) ; close( p->fd_2[ 1 ] ) ; p->state = ProcessIsStillRunning ; if( p->str.timeout != -1 ){ __ProcessStartTimer( p ) ; } return p->pid ; }