Dash:
[t2.git] / package / shells / pdksh / pdksh-5.2.14-1.patch
blob46cdbce0b0395acb572bac2348f8e27d4c8b7b32
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
3 #
4 # T2 SDE: package/.../pdksh/pdksh-5.2.14-1.patch
5 # Copyright (C) 2004 - 2005 The T2 SDE Project
6 # Copyright (C) 1998 - 2003 ROCK Linux Project
7 #
8 # More information can be found in the files COPYING and README.
9 #
10 # This patch file is dual-licensed. It is available under the license the
11 # patched project is licensed under, as long as it is an OpenSource license
12 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
13 # of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
15 # version.
16 # --- T2-COPYRIGHT-NOTE-END ---
19 [ ftp://ftp.cs.mun.ca/pub/pdksh/pdksh-5.2.14-patches.1 ]
21 Here are patches for 3 significant bugs in pdksh-5.2.14:
22 - set -x dumps core (shf.c);
23 - output of "jobs" command is filled with ^A characters (jobs.c);
24 - "typeset -r foo=bar" fails saying foo is readonly (var.c).
26 --- ./shf.c
27 +++ ./shf.c
28 @@ -355,7 +355,6 @@
29 shf->rp = nbuf + (shf->rp - shf->buf);
30 shf->wp = nbuf + (shf->wp - shf->buf);
31 shf->rbsize += shf->wbsize;
32 - shf->wbsize += shf->wbsize;
33 shf->wnleft += shf->wbsize;
34 shf->wbsize *= 2;
35 shf->buf = nbuf;
38 --- ./var.c
39 +++ ./var.c
40 @@ -353,7 +353,9 @@
41 const char *s;
42 int error_ok;
44 - if (vq->flag & RDONLY) {
45 + int no_ro_check = error_ok & 0x4;
46 + error_ok &= ~0x4;
47 + if ((vq->flag & RDONLY) && !no_ro_check) {
48 warningf(TRUE, "%s: is read only", vq->name);
49 if (!error_ok)
50 errorf(null);
51 @@ -715,13 +717,13 @@
52 if (val != NULL) {
53 if (vp->flag&INTEGER) {
54 /* do not zero base before assignment */
55 - setstr(vp, val, KSH_UNWIND_ERROR);
56 + setstr(vp, val, KSH_UNWIND_ERROR | 0x4);
57 /* Done after assignment to override default */
58 if (base > 0)
59 vp->type = base;
60 } else
61 /* setstr can't fail (readonly check already done) */
62 - setstr(vp, val, KSH_RETURN_ERROR);
63 + setstr(vp, val, KSH_RETURN_ERROR | 0x4);
66 /* only x[0] is ever exported, so use vpbase */
69 --- ./jobs.c
70 +++ ./jobs.c
71 @@ -219,8 +219,7 @@
72 static void check_job ARGS((Job *j));
73 static void put_job ARGS((Job *j, int where));
74 static void remove_job ARGS((Job *j, const char *where));
75 -static void kill_job ARGS((Job *j));
76 -static void fill_command ARGS((char *c, int len, struct op *t));
77 +static int kill_job ARGS((Job *j, int sig));
79 /* initialize job control */
80 void
81 @@ -294,10 +293,17 @@
82 && procpid == kshpid)))))
84 killed = 1;
85 - killpg(j->pgrp, SIGHUP);
86 + if (j->pgrp == 0)
87 + kill_job(j, SIGHUP);
88 + else
89 + killpg(j->pgrp, SIGHUP);
90 #ifdef JOBS
91 - if (j->state == PSTOPPED)
92 - killpg(j->pgrp, SIGCONT);
93 + if (j->state == PSTOPPED) {
94 + if (j->pgrp == 0)
95 + kill_job(j, SIGCONT);
96 + else
97 + killpg(j->pgrp, SIGCONT);
98 + }
99 #endif /* JOBS */
102 @@ -497,7 +503,7 @@
103 put_job(j, PJ_PAST_STOPPED);
106 - fill_command(p->command, sizeof(p->command), t);
107 + snptreef(p->command, sizeof(p->command), "%T", t);
109 /* create child process */
110 forksleep = 1;
111 @@ -508,7 +514,7 @@
112 forksleep <<= 1;
114 if (i < 0) {
115 - kill_job(j);
116 + kill_job(j, SIGKILL);
117 remove_job(j, "fork failed");
118 #ifdef NEED_PGRP_SYNC
119 if (j_sync_open) {
120 @@ -823,11 +829,10 @@
123 if (j->pgrp == 0) { /* started when !Flag(FMONITOR) */
124 - for (p=j->proc_list; p != (Proc *) 0; p = p->next)
125 - if (kill(p->pid, sig) < 0) {
126 - bi_errorf("%s: %s", cp, strerror(errno));
127 - rv = 1;
129 + if (kill_job(j, sig) < 0) {
130 + bi_errorf("%s: %s", cp, strerror(errno));
131 + rv = 1;
133 } else {
134 #ifdef JOBS
135 if (j->state == PSTOPPED && (sig == SIGTERM || sig == SIGHUP))
136 @@ -1825,50 +1830,17 @@
138 * If jobs are compiled in then this routine expects sigchld to be blocked.
140 -static void
141 -kill_job(j)
142 +static int
143 +kill_job(j, sig)
144 Job *j;
145 + int sig;
147 Proc *p;
148 + int rval = 0;
150 for (p = j->proc_list; p != (Proc *) 0; p = p->next)
151 if (p->pid != 0)
152 - (void) kill(p->pid, SIGKILL);
155 -/* put a more useful name on a process than snptreef does (in certain cases) */
156 -static void
157 -fill_command(c, len, t)
158 - char *c;
159 - int len;
160 - struct op *t;
162 - int alen;
163 - char **ap;
165 - if (t->type == TEXEC || t->type == TCOM) {
166 - /* Causes problems when set -u is in effect, can also
167 - cause problems when array indices evaluated (may have
168 - side effects, eg, assignment, incr, etc.)
169 - if (t->type == TCOM)
170 - ap = eval(t->args, DOBLANK|DONTRUNCOMMAND);
171 - else
172 - */
173 - ap = t->args;
174 - --len; /* save room for the null */
175 - while (len > 0 && *ap != (char *) 0) {
176 - alen = strlen(*ap);
177 - if (alen > len)
178 - alen = len;
179 - memcpy(c, *ap, alen);
180 - c += alen;
181 - len -= alen;
182 - if (len > 0) {
183 - *c++ = ' '; len--;
185 - ap++;
187 - *c = '\0';
188 - } else
189 - snptreef(c, len, "%T", t);
190 + if (kill(p->pid, sig) < 0)
191 + rval = -1;
192 + return rval;