GNU/Linux POSIX BASH Development Patches for jobs.c .......................... ........ ............"...................................... ................ ........
6c6
< /* Copyright (C) 1989-2015 Free Software Foundation, Inc.
---
> /* Copyright (C) 1989-2017 Free Software Foundation, Inc.
70a71
> #include "parser.h"
74a76,77
> #include "typemax.h"
>
95c98
< # define MAX_CHILD_MAX 8192
---
> # define MAX_CHILD_MAX 32768
165,173d167
< extern int subshell_environment, line_number;
< extern int posixly_correct, shell_level;
< extern int last_command_exit_value, last_command_exit_signal;
< extern int loop_level, breaking;
< extern int executing_list;
< extern int sourcelevel;
< extern int running_trap;
< extern sh_builtin_func_t *this_shell_builtin;
< extern char *shell_name, *this_command_name;
175,177d168
< extern procenv_t wait_intr_buf;
< extern int wait_intr_flag;
< extern int wait_signal_received;
220,227d210
< #if 0
< /* The job which is current; i.e. the one that `%+' stands for. */
< int current_job = NO_JOB;
<
< /* The previous job; i.e. the one that `%-' stands for. */
< int previous_job = NO_JOB;
< #endif
<
253a237,238
> void debug_print_pgrps (void);
>
286a272
> static void job_message_messenger_interpreter __P((void));
301a288
> static void job_interpret_notified_review __P((int));
317a305,306
> static struct pipeline_saver *alloc_pipeline_saver __P((void));
>
471c460
< struct pipeline_saver *
---
> static struct pipeline_saver *
647a637,638
> if (pipefail_opt)
> newjob->flags |= J_PIPEFAIL;
706c697
< * !!!!! NOTE !!!!! (chet@ins.cwru.edu)
---
> * !!!!! NOTE !!!!! (chet@po.cwru.edu)
754c745
< ps_index_t nsize;
---
> ps_index_t nsize, nsize_cur, nsize_max;
768,769c759,769
< while (nsize < js.c_childmax)
< nsize *= 2;
---
> nsize_max = TYPE_MAXIMUM (ps_index_t);
> nsize_cur = (ps_index_t)js.c_childmax;
> if (nsize_cur < 0) /* overflow */
> nsize_cur = MAX_CHILD_MAX;
>
> while (nsize > 0 && nsize < nsize_cur) /* > 0 should catch
overflow */
> nsize <<= 1;
> if (nsize > nsize_max || nsize <= 0) /* overflow? */
> nsize = nsize_max;
> if (nsize > MAX_CHILD_MAX)
> nsize = nsize_max = MAX_CHILD_MAX; /* hard cap */
771c771
< if (bgpids.nalloc < js.c_childmax)
---
> if (bgpids.nalloc < nsize_cur && bgpids.nalloc < nsize_max)
788,790c788
< ps_index_t psi;
<
< if (bgpids.nalloc < js.c_childmax || bgpids.head >= bgpids.nalloc)
---
> if (bgpids.nalloc < (ps_index_t)js.c_childmax || bgpids.head >=
bgpids.nalloc)
815,816c813,828
< bucket = pshash_getbucket (pid);
< psi = bgp_getindex ();
---
> /* bucket == existing chain of pids hashing to same value
> psi = where were going to put this pid/status */
>
> bucket = pshash_getbucket (pid); /* index into pidstat_table */
> psi = bgp_getindex (); /* bgpids.head, index into storage */
>
> /* XXX - what if psi == *bucket? */
> if (psi == *bucket)
> {
> #ifdef DEBUG
> internal_warning ("hashed pid %d (pid %d) collides with
bgpids.head, skipping", psi, pid);
> #endif
> bgpids.storage[psi].pid = NO_PID; /* make sure */
> psi = bgp_getindex (); /* skip to next one */
> }
>
843a856
> ps_index_t *bucket;
849c862
< if (ps->bucket_next != NO_PID)
---
> if (ps->bucket_next != NO_PIDSTAT)
851c864
< if (ps->bucket_prev != NO_PID)
---
> if (ps->bucket_prev != NO_PIDSTAT)
854c867,874
< *(pshash_getbucket (ps->pid)) = ps->bucket_next;
---
> {
> bucket = pshash_getbucket (ps->pid);
> *bucket = ps->bucket_next; /* deleting chain head in hash
table */
> }
>
> /* clear out this cell, in case it gets reused. */
> ps->pid = NO_PID;
> ps->bucket_next = ps->bucket_prev = NO_PIDSTAT;
861c881
< ps_index_t psi;
---
> ps_index_t psi, orig_psi;
867,869c887,896
< for (psi = *(pshash_getbucket (pid)); psi != NO_PIDSTAT; psi =
bgpids.storage[psi].bucket_next)
< if (bgpids.storage[psi].pid == pid)
< break;
---
> for (orig_psi = psi = *(pshash_getbucket (pid)); psi != NO_PIDSTAT;
psi = bgpids.storage[psi].bucket_next)
> {
> if (bgpids.storage[psi].pid == pid)
> break;
> if (orig_psi == bgpids.storage[psi].bucket_next) /* catch
reported bug */
> {
> internal_warning ("bgp_delete: LOOP: psi (%d) ==
storage[psi].bucket_next", psi);
> return 0;
> }
> }
907c934
< ps_index_t psi;
---
> ps_index_t psi, orig_psi;
913,915c940,949
< for (psi = *(pshash_getbucket (pid)); psi != NO_PIDSTAT; psi =
bgpids.storage[psi].bucket_next)
< if (bgpids.storage[psi].pid == pid)
< return (bgpids.storage[psi].status);
---
> for (orig_psi = psi = *(pshash_getbucket (pid)); psi != NO_PIDSTAT;
psi = bgpids.storage[psi].bucket_next)
> {
> if (bgpids.storage[psi].pid == pid)
> return (bgpids.storage[psi].status);
> if (orig_psi == bgpids.storage[psi].bucket_next) /* catch
reported bug */
> {
> internal_warning ("bgp_search: LOOP: psi (%d) ==
storage[psi].bucket_next", psi);
> return -1;
> }
> }
976a1011
> PROCESS *discard;
1001c1036
< discard_pipeline (last_procsub_child);
---
> discard = last_procsub_child;
1002a1038
> discard_pipeline (discard);
1963a2000,2002
> /* If this ends up being changed to modify or use `command' in the
> child process, go back and change callers who free `command' in
> the child process when this returns. */
2336,2337c2375,2376
< jobs table, it returns 127. If FLAGS doesn't include 1, we
< suppress the error message if PID isn't found. */
---
> jobs table, it returns 127. If FLAGS doesn't include JWAIT_PERROR,
> we suppress the error message if PID isn't found. */
2346c2385
< int r, job;
---
> int r, job, alive;
2361c2400
< if (flags & 1)
---
> if (flags & JWAIT_PERROR)
2366c2405,2416
< r = wait_for (pid);
---
> alive = 0;
> do
> {
> r = wait_for (pid);
> if ((flags & JWAIT_FORCE) == 0)
> break;
>
> BLOCK_CHILD (set, oset);
> alive = PALIVE (child);
> UNBLOCK_CHILD (oset);
> }
> while (alive);
2390c2440,2441
< register int i, r, waited_for;
---
> register int i, r;
> int any_stopped, check_async;
2394c2445
< for (waited_for = 0;;)
---
> for (any_stopped = 0, check_async = 1;;)
2407a2459,2464
> if (jobs[i] && STOPPED (i))
> {
> builtin_warning ("job %d[%d] stopped", i+1, find_last_pid
(i, 0));
> any_stopped = 1;
> }
>
2422,2423c2479,2480
< r = wait_for_single_pid (pid, 1);
< if (r == -1)
---
> r = wait_for_single_pid (pid, JWAIT_PERROR);
> if (r == -1 && errno == ECHILD)
2426,2427c2483,2484
< if (errno == ECHILD)
< mark_all_jobs_as_dead ();
---
> check_async = 0;
> mark_all_jobs_as_dead ();
2429,2430d2485
< else
< waited_for++;
2432a2488,2508
> #if defined (PROCESS_SUBSTITUTION)
> if (last_procsub_child && last_procsub_child->pid != NO_PID)
> r = wait_for (last_procsub_child->pid);
> wait_procsubs ();
> reap_procsubs ();
> #if 1
> /* We don't want to wait indefinitely if we have stopped children. */
> /* XXX - should add a loop that goes through the list of process
> substitutions and waits for each proc in turn before this code. */
> if (any_stopped == 0)
> {
> /* Check whether or not we have any unreaped children. */
> while ((r = wait_for (ANY_PID)) >= 0)
> {
> QUIT;
> CHECK_WAIT_INTR;
> }
> }
> #endif
> #endif
>
2571a2648
> #if 0
2572a2650,2652
> #else
> if (jobs[job]->flags & J_PIPEFAIL)
> #endif
2656c2736,2746
< old_sigint_handler = set_signal_handler (SIGINT,
wait_sigint_handler);
---
> SigHandler *temp_sigint_handler;
>
> temp_sigint_handler = set_signal_handler (SIGINT,
wait_sigint_handler);
> if (temp_sigint_handler == wait_sigint_handler)
> {
> #if defined (DEBUG)
> internal_warning ("wait_for: recursively setting
old_sigint_handler to wait_sigint_handler: running_trap = %d",
running_trap);
> #endif
> }
> else
> old_sigint_handler = temp_sigint_handler;
2685c2775
< if (job == NO_JOB) /* XXX -- && pid != ANY_PID ? */
---
> if (job == NO_JOB && pid != ANY_PID) /* XXX -- && pid !=
ANY_PID ? */
2731c2821,2822
< /* XXX - restore sigint handler here? */
---
> /* XXX - restore sigint handler here */
> restore_sigint_handler ();
2775,2777c2866,2871
< /* XXX - could set child but we don't have a handle on what
waitchld
< reaps. Leave termination_state alone. */
< goto wait_for_return;
---
> {
> /* XXX - could set child but we don't have a handle on what
waitchld
> reaps. Leave termination_state alone. */
> restore_sigint_handler ();
> goto wait_for_return;
> }
2883a2978,2981
> /* If an interactive shell with job control enabled is sourcing
> a file, allow the interrupt to terminate the file sourcing. */
> else if (interactive_shell && signal_is_trapped (SIGINT) ==
0 && sourcelevel)
> ADDINTERRUPT;
2908,2909c3006,3019
< else if (interactive_shell == 0 && IS_FOREGROUND (job) &&
check_window_size)
< get_new_window_size (0, (int *)0, (int *)0);
---
> else if (interactive_shell == 0 && subshell_environment == 0 &&
IS_FOREGROUND (job))
> {
> s = job_signal_status (job);
>
> /* If we are non-interactive, but job control is enabled, and
the job
> died due to SIGINT, pretend we got the SIGINT */
> if (job_control && IS_JOBCONTROL (job) && WIFSIGNALED (s) &&
WTERMSIG (s) == SIGINT)
> {
> ADDINTERRUPT; /* For now */
> }
>
> if (check_window_size)
> get_new_window_size (0, (int *)0, (int *)0);
> }
2933c3043,3045
< are no unwaited-for child processes or an error occurs. */
---
> are no unwaited-for child processes or an error occurs. If FLAGS
> includes JWAIT_FORCE, we wait for the job to terminate, no just change
> state */
2935,2936c3047,3048
< wait_for_job (job)
< int job;
---
> wait_for_job (job, flags)
> int job, flags;
2939c3051
< int r;
---
> int r, state;
2943c3055,3056
< if (JOBSTATE (job) == JSTOPPED)
---
> state = JOBSTATE (job);
> if (state == JSTOPPED)
2948c3061,3075
< r = wait_for (pid);
---
>
> do
> {
> r = wait_for (pid);
> if (r == -1 && errno == ECHILD)
> mark_all_jobs_as_dead ();
>
> if ((flags & JWAIT_FORCE) == 0)
> break;
>
> BLOCK_CHILD (set, oset);
> state = (job != NO_JOB && jobs[job]) ? JOBSTATE (job) : JDEAD;
> UNBLOCK_CHILD (oset);
> }
> while (state != JDEAD);
2965c3092,3093
< wait_for_any_job ()
---
> wait_for_any_job (flags)
> int flags;
2968c3096
< int i, r, waited_for;
---
> int i, r;
2995c3123
< for (waited_for = 0;;)
---
> for (;;)
3445a3574
> int ind;
3551a3681,3688
> #if defined (PROCESS_SUBSTITUTION)
> /* Only manipulate the list of process substitutions while SIGCHLD
> is blocked. */
> if ((ind = find_procsub_child (pid)) >= 0)
> set_procsub_status (ind, pid, WSTATUS (status));
> /* XXX - save in bgpids list? */
> #endif
>
3597c3734
< if (job_control && children_exited &&
---
> if (children_exited &&
3943,3949d4079
< #if 0
< /* If job control is disabled, don't print the status messages.
< Mark dead jobs as notified so that they get cleaned up. If
< startup_state == 2, we were started to run `-c command', so
< don't print anything. */
< if ((job_control == 0 && interactive_shell) || startup_state == 2)
< #else
3954c4084,4087
< substitution, so don't print anything. */
---
> substitution, so don't print anything.
> Otherwise, if the shell is not interactive, POSIX says that
`jobs'
> is the only way to notify of job status. */
> #if 1
3956a4090,4093
> #else /* TAG:bash-5.1 */
> if ((job_control == 0 && interactive_shell) ||
> (startup_state == 2 && (subshell_environment &
SUBSHELL_COMSUB)) ||
> (startup_state == 2 && posixly_correct &&
(subshell_environment & SUBSHELL_COMSUB) == 0))
4049c4186
< int t_errno;
---
> int t_errno, tty_sigs;
4098a4236
> tty_sigs = 0;
4104a4243
> CHECK_TERMSIG;
4107a4247,4253
> if (tty_sigs++ > 16)
> {
> sys_error (_("initialize_job_control: no job control in
background"));
> job_control = 0;
> original_pgrp = terminal_pgrp; /* for eventual
give_terminal_to */
> goto just_bail;
> }
4166a4313
> just_bail:
4634a4782,4788
> void
> set_jobs_list_frozen (s)
> int s;
> {
> jobs_list_frozen = s;
> }
>
4689c4843
< if (interactive_shell || job_control) /* XXX - should it be
just job_control? */
---
> if (job_control)
BSDIFF40�^G^@^@^@^@^@^@�^@^@^@^@^@^@^@�^G^B^@^@^@^@^@BZh91AY&SY͌�8^@^Hu��������^?�������{�����������������P^EtU�K<^@m�^T^QMOI�5M�F�i^G��&�M^OQ�i�z�SF�F#@
4^F
i�^^��54�mG�^Z^Z=!�OS@=OSC�bd��^[PƠ^F��z�^A��^H���z*^?���LL���Q��M�h��?P��h^^��^OSF�d^Z^L�
4^Z^OP^F��^@^Z^@^Z^F�^@a^@�^@�d4�^@US�B�M2M^LJ{T�5#^XQ��^@^@^@^@^@�^@^@^@^CA�^@^@4^@^@^@^@^@^@^@^@^@^@^P^F�^F�
^@^@^@4d^@^A�^@^@^@^F@�i�^F�^@^@^@^@^@^A�@^@^@^@
^@^@�"MDjzS�^OQ�^Z^L�H4���i�^C
dѦ�^Z^OP^^�A�^A�F�^@���^A���^@i��^^P4^A��^X�d�=L�^D^@^Ad[������
�sU^D��㽆��������K�|^X2���&^]Y�m�G�7���l^L�uB�^Nu��ȧ#it{��:-,���<e^Wb���m2��띾�ờy��y��/����w^G����b�^Bg�Wpg�^N^O�ЗMR�!^V^E
^p\^\�#�j�0ā}Ǟ=�oL�R�[ �RƂ�<^O��� U^\@���OH>TxLڰP��D���Q�\(^S*l
���\�w^K"ޞ$
^Z<�]5�^?Y����"p�+L��7E����\�u^T��6���67^G�^D����`�ꀶr��^U���id2^Cd�H�o�&�0�K]r؈�7o�
� � x����Ld/^Zp5^C[�^Y��q�
��j^X<^Q\�,��Hp�`AN��(@���X�b@���U���DS�v�
0�4^\����Q@7�ceb�j^A��)�j���L�T�#H�֘9�]~�^\$�ۓB�r^X^XZ�X�RbX��q�'�j,C�C��S�^C^X^Y�ȗ�$LL�KɌw���aBB��^FW}(C���^G]T�ԭ2�^D��^DI^@R�������^]d`$
*^N�s^Q�^Q^S��^PM�^*'>�^VL��#�uf^F$q^Xe�2[�blDZ)�p`R��4��Jz�^]���(bj�L��^T�ȄOx%։AE��q�^H5�
^[�f�slX� �^^����^Q�^[�ĭ^N��R��n=^Tk4Z{�Fb]��^TxM%��^N��^Y�S
HCqi^U^O�^@^E^T^@^@PC[������-S����s%_^G�=>��^Wu
X��^T^F^_��k^SB��P�z�^WȗY[����$^OҢ���:^���9�8�[^H
^@��>}8�^RlÐ^Xb�f^@^N_Y���Z�e�AZ�^[�/^G���p3^U�^F^L,?�
�^@K^W��VVV3^F`&^K^Ff%��
^^�E^?:�6
}��En�^K���6$t�^H���c��N^@j^Uw^F18�lU��[
��T ��*�^E�E��s^Q&^_����$^B�^Zۇ��^B*�
i^@CGɄ��h
@^D^V"�^T^H^D�-�s� ^F�$^B$
X`�]����'�Ap^H��/`H���T�no9
b�3(&^]S�^B?
�c�PT^]�q XU�$�I �7҆�$RH^GA�#
����eI�^U)��Y���0K"^Q#ड़�Ĉ'^C1^�^RFa"!�!�p�r`^QAp^Vi�B�y^XrŒF^SAO^N��E8�����^O@G
�XcU^R"^K�k^\<^Yz^P�^]^\�>+yp ^D^@��
]M�I�Ր�\i��i���vѱ͝I��^A����),��^B���F��^P ^B�qH^O�^XA�`2�b��^F�
G��ѧ@^FW�^_�#ː��yk���
�溺T�Ƕ竨��^^hR��^K^NE�^��i�hiv^^?^H�
�!��n{�'���ˏ㻭6�+:�^_^Zw����^Q�E5���e^T6ili�c�������`_'OC��vG�-#�^UMc$�&�S=�����wu�
c�^G>�KHl�kW�B�Q�^Z��T���^K]G
8^O;^K��iD^B^P^@�bD�,H^D^PHd@E�^PA,^A^D3^R��B,I,^R@^D
,Q �E�,�^C2^S^P^K +2�Y))`���a��
H��s�b[^N�u��k��g�raF����Dg��^C�*����)X�^K:��"H�#?���t7^Y7�º
M�vQ^L��dw�?^]�^A"�dD
^D^GCȹ8�^K�@^O�5P�2Y�^T����
���ǜb�>�^O�_�w�ZbMo~�Ъf:^X�����c-��#:�^\�^K$�^N5��^P^G͋�J5�&^tE^?j��N�*(����/Gfq�Z��^OKަ�^[EE8
^?��H�
^R^Y���^@BZh91AY&SY��n�^@^@^F^?��D ^DA�^H^@^@
^D(^@^@�@^@^P^@^Q^B��^@� �
^@r#SP^F�^@4�z��^H�M4��^CF^Dh�i^F�i^A,��^O��\u�W^P^G�[
�DAn�*e^E^^��^D^G�ݨ�^Z\�,��k^T|�6��tg!q*^P^@^@?��"�(Hz`�l^@BZh91AY&SY���^O^@^BH߀p0{��߯�������P^CZW��Um�
4���MO5=5O�=^T��&�&j^_�������$��i�Hz���4h
^Zb241^L �LA��a^@^F
^A&�2!O�����S&�^@^@^F�^Y^Z
^C��4h
^Zb241^L �LA��a^@^F B��f��MCҏS�
^@i�^@^@�^C�
^]���+`����r^H>H����^[�^G^\�RdO�^F\�Y��5��'^D-2�^C=�h^R
,�!�9^Gn�rx^^]�$��?^x��ib(tP����V,`�^?O3�^F^Hyn=� ��]�<�I
ۦ0��@W?^\-qv�Z�^@��Nx[Y��G���^U�s^?T\��`�^UD
Y�_^U�"Չ�3��_��^[�>+^Ps�n^�^^!���QtPL^O\��^X,�s��Ivq^H��^U֨�^O^]�N��a4œ�,�ŝ��9��^YjG�^X��0�^]$s^Y^K���fQo�'^^�^?M\��^V�^_^G��7��9M$g^Ai]m^A�^A{2����x*�!���:�^?^]�]��]�#֎���1B+hO^CPt.����-e1b��K$Q��A?K���'I#^^m��$
�/h���*"=�^X�t^Wf�C^T�[�Am$~;��I��'�9�c�-�X��0߯U����cl~v?�����i&E^O�3%�B)`ʣ8j�-Kzp(��rR��d��o�3��^D��S^U���^D�-�^U^LU^S���nzB&��^Wu^X�K��)]lL^KC8y^C3�^W��)7!�o�M�^V��!#(^E�+�^N�WU���NUHp�^\{Y0�
6i�)t^Z ^WS���^?�w$S� ^N�L`�
Reply to: