forked from pool/schily
Jan Engelhardt
2588b7d48a
OBS-URL: https://build.opensuse.org/package/show/utilities/schily?expand=0&rev=28
56 lines
1.3 KiB
Diff
56 lines
1.3 KiB
Diff
From: Kristyna Streitova <kstreitova@suse.com>
|
|
Date: Wed, 06 Jun 2018 14:51:57 +0000
|
|
References: http://bugzilla.opensuse.org/414251
|
|
X-Upstream: PATCH-FIX-SUSE
|
|
|
|
Set read lock before using the semaphore wait on a pipe fd to avoid deadlock
|
|
|
|
Index: schily-2018-05-25/star/fifo.c
|
|
===================================================================
|
|
--- schily-2018-05-25.orig/star/fifo.c
|
|
+++ schily-2018-05-25/star/fifo.c
|
|
@@ -487,13 +487,42 @@ LOCAL int
|
|
swait(f)
|
|
int f;
|
|
{
|
|
- int ret;
|
|
+ int ret, err;
|
|
unsigned char c;
|
|
+ struct flock lock;
|
|
+ useconds_t wait;
|
|
+
|
|
+ wait = 500000;
|
|
+ lock.l_type = F_RDLCK;
|
|
+ lock.l_whence = SEEK_CUR;
|
|
+ lock.l_start = 0;
|
|
+ lock.l_len = 0;
|
|
+ do {
|
|
+ err = fcntl(f, F_SETLK, &lock);
|
|
+ if (err < 0) {
|
|
+ err = geterrno();
|
|
+ if (err == EINTR)
|
|
+ continue;
|
|
+ if ((err == EACCES || err == EAGAIN) && (wait > 0)) {
|
|
+ usleep(10000);
|
|
+ wait -= 10000;
|
|
+ continue;
|
|
+ }
|
|
+ errmsg("Can not get lock on semaphore wait for file descriptor\n");
|
|
+ exprstats(-1);
|
|
+ }
|
|
+ } while (0);
|
|
|
|
seterrno(0);
|
|
do {
|
|
ret = read(f, &c, 1);
|
|
} while (ret < 0 && geterrno() == EINTR);
|
|
+
|
|
+ lock.l_type = F_UNLCK;
|
|
+ do {
|
|
+ err = fcntl(f, F_SETLK, &lock);
|
|
+ } while (err < 0 && geterrno() == EINTR);
|
|
+
|
|
if (ret < 0 || (ret == 0 && pid)) {
|
|
/*
|
|
* If pid != 0, this is the foreground process
|