SHA256
1
0
forked from pool/schily
schily/schily-2018-05-25_star_lock.patch

49 lines
1.1 KiB
Diff
Raw Normal View History

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