Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit bfc5002

Browse files
author
Damien Lespiau
committed
init: regroup init process setup code in a single function
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
1 parent 1572625 commit bfc5002

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/init.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)