@@ -29,7 +29,7 @@ struct stdio_config {
2929};
3030
3131static int hyper_release_exec (struct hyper_exec * );
32- static void hyper_exec_process (struct hyper_exec * exec , struct stdio_config * io );
32+ static void hyper_exec_process (struct hyper_exec * exec , int pipe , struct stdio_config * io );
3333
3434static int send_exec_finishing (uint64_t seq , int len , int code )
3535{
@@ -500,7 +500,6 @@ static int hyper_do_exec_cmd(struct hyper_exec *exec, int pipe, struct stdio_con
500500
501501 if (hyper_enter_sandbox (exec -> pod , pipe ) < 0 ) {
502502 perror ("enter pidns of pod init failed" );
503- hyper_send_type (pipe , -1 );
504503 goto out ;
505504 }
506505
@@ -530,13 +529,14 @@ static int hyper_do_exec_cmd(struct hyper_exec *exec, int pipe, struct stdio_con
530529 else
531530 unsetenv ("TERM" );
532531
533- hyper_exec_process (exec , io );
532+ hyper_exec_process (exec , pipe , io );
534533out :
534+ hyper_send_type (pipe , -1 );
535535 _exit (125 );
536536}
537537
538538// do the exec, no return
539- static void hyper_exec_process (struct hyper_exec * exec , struct stdio_config * io )
539+ static void hyper_exec_process (struct hyper_exec * exec , int pipe , struct stdio_config * io )
540540{
541541 bool defaultPath = false;
542542 if (sigprocmask (SIG_SETMASK , & orig_mask , NULL ) < 0 ) {
@@ -563,9 +563,12 @@ static void hyper_exec_process(struct hyper_exec *exec, struct stdio_config *io)
563563
564564 setsid ();
565565
566+ //send success notification before stdio was installed, otherwise the debug log in hyper_send_type() will be sent to user tty.
567+ hyper_send_type (pipe , 0 );
568+
566569 if (hyper_install_process_stdio (exec , io ) < 0 ) {
567570 fprintf (stderr , "dup pts to exec stdio failed\n" );
568- goto exit ;
571+ goto exit_nosend ;
569572 }
570573
571574 if (execvp (exec -> argv [0 ], exec -> argv ) < 0 ) {
@@ -581,6 +584,8 @@ static void hyper_exec_process(struct hyper_exec *exec, struct stdio_config *io)
581584 }
582585
583586exit :
587+ hyper_send_type (pipe , -1 );
588+ exit_nosend :
584589 fflush (NULL );
585590 _exit (125 );
586591}
@@ -626,7 +631,7 @@ int hyper_run_process(struct hyper_exec *exec)
626631{
627632 int pipe [2 ] = {-1 , -1 };
628633 int pid , ret = -1 ;
629- uint32_t type ;
634+ uint32_t cpid , type ;
630635 struct stdio_config io = {-1 , -1 ,-1 , -1 ,-1 , -1 };
631636
632637 if (exec -> argv == NULL || exec -> seq == 0 || exec -> container_id == NULL || strlen (exec -> container_id ) == 0 ) {
@@ -652,14 +657,14 @@ int hyper_run_process(struct hyper_exec *exec)
652657 } else if (pid == 0 ) {
653658 if (strcmp (exec -> container_id , HYPERSTART_EXEC_CONTAINER ) == 0 ) {
654659 hyper_send_type (pipe [1 ], getpid ());
655- hyper_exec_process (exec , & io );
660+ hyper_exec_process (exec , pipe [ 1 ], & io );
656661 _exit (125 );
657662 }
658663 hyper_do_exec_cmd (exec , pipe [1 ], & io );
659664 }
660665 fprintf (stdout , "prerequisite process pid %d\n" , pid );
661666
662- if (hyper_get_type (pipe [0 ], & type ) < 0 || (int )type < 0 ) {
667+ if (hyper_get_type (pipe [0 ], & cpid ) < 0 || (int )cpid < 0 ) {
663668 fprintf (stderr , "run process failed\n" );
664669 goto close_tty ;
665670 }
@@ -669,7 +674,13 @@ int hyper_run_process(struct hyper_exec *exec)
669674 goto close_tty ;
670675 }
671676
672- exec -> pid = type ;
677+ if (hyper_get_type (pipe [0 ], & type ) < 0 || (int )type < 0 ) {
678+ fprintf (stderr , "container process %u exec failed\n" , cpid );
679+ goto close_tty ;
680+ }
681+
682+ //two message may come back in reversed sequence
683+ exec -> pid = (type == 0 ) ? cpid : type ;
673684 list_add_tail (& exec -> list , & exec -> pod -> exec_head );
674685 exec -> ref ++ ;
675686 fprintf (stdout , "%s process pid %d\n" , __func__ , exec -> pid );
0 commit comments