aboutsummaryrefslogtreecommitdiff
path: root/hurd
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2021-03-23 22:38:54 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2021-03-23 22:40:10 +0000
commitc3b287be74e12bdb15ed36e98d24fd42f8ee9122 (patch)
tree82a9f85685a35bf5b12e480ee6ed1abc24103dc8 /hurd
parenta4ea18ec6cc3f1370efab09bc18c1badbf74aa13 (diff)
downloadglibc-c3b287be74e12bdb15ed36e98d24fd42f8ee9122.zip
glibc-c3b287be74e12bdb15ed36e98d24fd42f8ee9122.tar.gz
glibc-c3b287be74e12bdb15ed36e98d24fd42f8ee9122.tar.bz2
hurd: handle EINTR during critical sections
During critical sections, signal handling is deferred and thus RPCs return EINTR, even if SA_RESTART is set. We thus have to restart the whole critical section in that case. This also adds HURD_CRITICAL_UNLOCK in the cases where one wants to break the section in the middle.
Diffstat (limited to 'hurd')
-rw-r--r--hurd/dtable.c15
-rw-r--r--hurd/geteuids.c4
-rw-r--r--hurd/hurd/signal.h4
-rw-r--r--hurd/hurdexec.c4
-rw-r--r--hurd/hurdfchdir.c4
-rw-r--r--hurd/hurdsock.c4
-rw-r--r--hurd/seteuids.c4
7 files changed, 37 insertions, 2 deletions
diff --git a/hurd/dtable.c b/hurd/dtable.c
index 9437f8c..bbd3bfc 100644
--- a/hurd/dtable.c
+++ b/hurd/dtable.c
@@ -189,6 +189,7 @@ ctty_new_pgrp (void)
{
int i;
+retry:
HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_dtable_lock);
@@ -224,8 +225,18 @@ ctty_new_pgrp (void)
/* This fd has a ctty-special port. We need a new one, to tell
the io server of our different process group. */
io_t new;
- if (__term_open_ctty (port, _hurd_pid, _hurd_pgrp, &new))
- new = MACH_PORT_NULL;
+ error_t err;
+ if ((err = __term_open_ctty (port, _hurd_pid, _hurd_pgrp, &new)))
+ {
+ if (err == EINTR)
+ {
+ /* Got a signal while inside an RPC of the critical section, retry again */
+ __mutex_unlock (&_hurd_dtable_lock);
+ HURD_CRITICAL_UNLOCK;
+ goto retry;
+ }
+ new = MACH_PORT_NULL;
+ }
_hurd_port_set (&d->ctty, new);
}
diff --git a/hurd/geteuids.c b/hurd/geteuids.c
index 840d80a..7fb8b0e 100644
--- a/hurd/geteuids.c
+++ b/hurd/geteuids.c
@@ -26,6 +26,7 @@ geteuids (int n, uid_t *uidset)
int nuids;
void *crit;
+retry:
crit = _hurd_critical_section_lock ();
__mutex_lock (&_hurd_id.lock);
@@ -33,6 +34,9 @@ geteuids (int n, uid_t *uidset)
{
__mutex_unlock (&_hurd_id.lock);
_hurd_critical_section_unlock (crit);
+ if (err == EINTR)
+ /* Got a signal while inside an RPC of the critical section, retry again */
+ goto retry;
return __hurd_fail (err);
}
diff --git a/hurd/hurd/signal.h b/hurd/hurd/signal.h
index 37b7dec..db9a02f 100644
--- a/hurd/hurd/signal.h
+++ b/hurd/hurd/signal.h
@@ -277,6 +277,10 @@ _hurd_critical_section_unlock (void *our_lock)
{ void *__hurd_critical__ = _hurd_critical_section_lock ()
#define HURD_CRITICAL_END \
_hurd_critical_section_unlock (__hurd_critical__); } while (0)
+
+/* This one can be used inside the C scoping level, for early exits. */
+#define HURD_CRITICAL_UNLOCK \
+ _hurd_critical_section_unlock (__hurd_critical__);
/* Initialize the signal code, and start the signal thread.
Arguments give the "init ints" from exec_startup. */
diff --git a/hurd/hurdexec.c b/hurd/hurdexec.c
index db8989e..7dca090 100644
--- a/hurd/hurdexec.c
+++ b/hurd/hurdexec.c
@@ -123,6 +123,7 @@ _hurd_exec_paths (task_t task, file_t file,
ss = _hurd_self_sigstate ();
+retry:
assert (! __spin_lock_locked (&ss->critical_section_lock));
__spin_lock (&ss->critical_section_lock);
@@ -429,6 +430,9 @@ _hurd_exec_paths (task_t task, file_t file,
/* Safe to let signals happen now. */
_hurd_critical_section_unlock (ss);
+ if (err == EINTR)
+ /* Got a signal while inside an RPC of the critical section, retry again */
+ goto retry;
outargs:
free (args);
diff --git a/hurd/hurdfchdir.c b/hurd/hurdfchdir.c
index 62a6ed1..84dc292 100644
--- a/hurd/hurdfchdir.c
+++ b/hurd/hurdfchdir.c
@@ -32,6 +32,7 @@ _hurd_change_directory_port_from_fd (struct hurd_port *portcell, int fd)
if (!d)
return __hurd_fail (EBADF);
+retry:
HURD_CRITICAL_BEGIN;
ret = HURD_PORT_USE (&d->port,
@@ -53,6 +54,9 @@ _hurd_change_directory_port_from_fd (struct hurd_port *portcell, int fd)
}));
HURD_CRITICAL_END;
+ if (ret == -1 && errno == EINTR)
+ /* Got a signal while inside an RPC of the critical section, retry again */
+ goto retry;
return ret;
}
diff --git a/hurd/hurdsock.c b/hurd/hurdsock.c
index 79395d9..04e86b4 100644
--- a/hurd/hurdsock.c
+++ b/hurd/hurdsock.c
@@ -52,6 +52,7 @@ _hurd_socket_server (int domain, int dead)
return MACH_PORT_NULL;
}
+retry:
HURD_CRITICAL_BEGIN;
__mutex_lock (&lock);
@@ -101,6 +102,9 @@ _hurd_socket_server (int domain, int dead)
__mutex_unlock (&lock);
HURD_CRITICAL_END;
+ if (server == MACH_PORT_NULL && errno == EINTR)
+ /* Got a signal while inside an RPC of the critical section, retry again */
+ goto retry;
return server;
}
diff --git a/hurd/seteuids.c b/hurd/seteuids.c
index 19db47f..df0922f 100644
--- a/hurd/seteuids.c
+++ b/hurd/seteuids.c
@@ -31,6 +31,7 @@ seteuids (int n, const uid_t *uids)
for (i = 0; i < n; ++i)
new[i] = uids[i];
+retry:
HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_id.lock);
err = _hurd_check_ids ();
@@ -47,6 +48,9 @@ seteuids (int n, const uid_t *uids)
}
__mutex_unlock (&_hurd_id.lock);
HURD_CRITICAL_END;
+ if (err == EINTR)
+ /* Got a signal while inside an RPC of the critical section, retry again */
+ goto retry;
if (err)
return __hurd_fail (err);