@@ -63,8 +63,7 @@ static bool input_is_interactive_terminal(const parseinfo_T *pinfo)
6363
6464/* the process ID of the shell */
6565pid_t shell_pid ;
66- /* the initial/current process group ID of the shell */
67- static pid_t initial_pgid ;
66+ /* the process group ID of the shell */
6867pid_t shell_pgid ;
6968
7069/* an equivalent to the -f flag for "exit" builtin */
@@ -209,7 +208,7 @@ int main(int argc, char **argv)
209208 /* `shell_pid' must be initialized after the options have been parsed.
210209 * This is required for the `set_monitor_option' function to work. */
211210 shell_pid = getpid ();
212- initial_pgid = shell_pgid = getpgrp ();
211+ shell_pgid = getpgrp ();
213212 init_cmdhash ();
214213 init_homedirhash ();
215214 init_variables ();
@@ -273,7 +272,8 @@ int main(int argc, char **argv)
273272 if (is_interactive || do_job_control )
274273 open_ttyfd ();
275274 set_signals ();
276- set_own_pgid ();
275+ if (do_job_control )
276+ ensure_foreground ();
277277 set_positional_parameters (wargv + xoptind );
278278 if (getuid () == geteuid () && getgid () == getegid ()) {
279279 if (!noprofile )
@@ -370,23 +370,9 @@ void exit_shell_with_status(int status)
370370 finalize_history ();
371371#endif
372372 }
373- finalize_shell ();
374373 exit (exitstatus );
375374}
376375
377- /* Does what to do before exiting/suspending the shell.
378- * The EXIT trap should be executed beforehand if needed. */
379- void finalize_shell (void )
380- {
381- reset_own_pgid ();
382- }
383-
384- /* Cancels `finalize_shell'. */
385- void reinitialize_shell (void )
386- {
387- set_own_pgid ();
388- }
389-
390376/* Prints the help message to stdout */
391377void print_help (void )
392378{
@@ -456,39 +442,6 @@ void print_version(void)
456442}
457443
458444
459- /* If job control is active, sets the process group ID of the shell to its
460- * process ID. */
461- void set_own_pgid (void )
462- {
463- if (doing_job_control_now && initial_pgid > 0 && shell_pgid != shell_pid ) {
464- if (setpgid (0 , 0 ) == 0 ) {
465- shell_pgid = shell_pid ;
466- put_foreground (shell_pgid );
467- }
468- }
469- }
470-
471- /* If job control is active, resets the process group ID of the shell.
472- * The initial process group ID is restored. */
473- void reset_own_pgid (void )
474- {
475- if (doing_job_control_now && initial_pgid > 0
476- && initial_pgid != shell_pgid ) {
477- if (setpgid (0 , initial_pgid ) == 0 ) {
478- shell_pgid = initial_pgid ;
479- put_foreground (shell_pgid );
480- }
481- }
482- }
483-
484- /* Forgets the value of `initial_pgid' so that `reset_own_pgid' is no longer
485- * effective. */
486- void forget_initial_pgid (void )
487- {
488- initial_pgid = 0 ;
489- }
490-
491-
492445/********** Functions to execute commands **********/
493446
494447/* Parses a multibyte string and executes the commands.
@@ -746,19 +699,19 @@ int suspend_builtin(int argc, void **argv)
746699 }
747700 if (argc != xoptind )
748701 goto print_usage ;
749- if (!force && is_interactive_now && getsid (0 ) == initial_pgid ) {
702+ if (!force && is_interactive_now && getsid (0 ) == shell_pgid ) {
750703 xerror (0 , Ngt ("refusing to suspend because of possible deadlock.\n"
751704 "Use the -f option to suspend anyway." ));
752705 return Exit_FAILURE ;
753706 }
754707
755708 bool ok ;
756709
757- finalize_shell ();
758710 ok = send_sigstop_to_myself ();
759711 if (!ok )
760712 xerror (errno , Ngt ("cannot send SIGSTOP signal" ));
761- reinitialize_shell ();
713+ if (doing_job_control_now )
714+ ensure_foreground ();
762715 return ok ? Exit_SUCCESS : Exit_FAILURE ;
763716}
764717
0 commit comments