Skip to content

Commit 07cc71b

Browse files
committed
ksh segfaults in job_chksave after receiving SIGCHLD
Upstreaming Debian patch: Prior to this update, the compiler optimization dropped parts from the ksh job locking mechanism from the binary code. As a consequence, ksh could terminate unexpectedly with a segmentation fault after it received the SIGCHLD signal. This update implements a fix to ensure the compiler does not drop parts of the ksh mechanism and the crash no longer occurs. Author: Michal Hlavinka [email protected] Origin: Red Hat fix, ksh-20120801-locking.patch Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1123467 Bug-Ubuntu: https://bugs.launchpad.net/bugs/1697501 Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=867181
1 parent 5498d9e commit 07cc71b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/cmd/ksh93/include/jobs.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,18 @@ extern struct jobs job;
149149
#define vmbusy() 0
150150
#endif
151151

152-
#define job_lock() (job.in_critical++)
152+
#define asoincint(p) __sync_fetch_and_add(p,1)
153+
#define asodecint(p) __sync_fetch_and_sub(p,1)
154+
155+
#define job_lock() asoincint(&job.in_critical)
153156
#define job_unlock() \
154157
do { \
155158
int sig; \
156-
if (!--job.in_critical && (sig = job.savesig)) \
159+
if (asodecint(&job.in_critical)==1 && (sig = job.savesig)) \
157160
{ \
158-
if (!job.in_critical++ && !vmbusy()) \
161+
if (!asoincint(&job.in_critical) && !vmbusy()) \
159162
job_reap(sig); \
160-
job.in_critical--; \
163+
asodecint(&job.in_critical); \
161164
} \
162165
} while(0)
163166

0 commit comments

Comments
 (0)