@@ -1341,10 +1341,9 @@ static int hyper_loop(void)
13411341 return 0 ;
13421342}
13431343
1344- int main ( int argc , char * argv [] )
1344+ static int hyper_setup_init_process ( void )
13451345{
1346- char * cmdline , * ctl_serial , * tty_serial ;
1347-
1346+ /* mount the base file systems */
13481347 if (mount ("proc" , "/proc" , "proc" , MS_NOSUID | MS_NODEV | MS_NOEXEC , NULL ) == -1 ) {
13491348 perror ("mount proc failed" );
13501349 return -1 ;
@@ -1381,12 +1380,27 @@ int main(int argc, char *argv[])
13811380 return -1 ;
13821381 }
13831382
1384- cmdline = read_cmdline ();
1385-
1383+ /* become the session leader */
13861384 setsid ();
13871385
1386+ /* set the controlling terminal */
13881387 ioctl (STDIN_FILENO , TIOCSCTTY , 1 );
13891388
1389+ setenv ("PATH" , "/bin:/sbin/:/usr/bin/:/usr/sbin/" , 1 );
1390+
1391+ return 0 ;
1392+ }
1393+
1394+ int main (int argc , char * argv [])
1395+ {
1396+ char * cmdline , * ctl_serial , * tty_serial ;
1397+
1398+ if (hyper_setup_init_process () < 0 ) {
1399+ return -1 ;
1400+ }
1401+
1402+ cmdline = read_cmdline ();
1403+
13901404#ifdef WITH_VBOX
13911405 ctl_serial = "/dev/ttyS0" ;
13921406 tty_serial = "/dev/ttyS1" ;
@@ -1401,8 +1415,6 @@ int main(int argc, char *argv[])
14011415 tty_serial = "sh.hyper.channel.1" ;
14021416#endif
14031417
1404- setenv ("PATH" , "/bin:/sbin/:/usr/bin/:/usr/sbin/" , 1 );
1405-
14061418 hyper_epoll .ctl .fd = hyper_setup_ctl_channel (ctl_serial );
14071419 if (hyper_epoll .ctl .fd < 0 ) {
14081420 fprintf (stderr , "fail to setup hyper control serial port\n" );
0 commit comments