@@ -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);
}
@@ -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);
}
@@ -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. */
@@ -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);
@@ -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;
}
@@ -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;
}
@@ -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);
@@ -127,6 +127,7 @@ __faccessat_common (int fd, const char *file, int type, int at_flags,
rcrdir = rcwdir = MACH_PORT_NULL;
+ retry:
HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_id.lock);
@@ -172,6 +173,9 @@ __faccessat_common (int fd, const char *file, int type, int at_flags,
__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 (rcrdir != MACH_PORT_NULL)
__mach_port_deallocate (__mach_task_self (), rcrdir);
@@ -70,6 +70,7 @@ __fork (void)
__run_fork_handlers (atfork_run_prepare, true);
ss = _hurd_self_sigstate ();
+retry:
__spin_lock (&ss->critical_section_lock);
#undef LOSE
@@ -718,6 +719,9 @@ __fork (void)
}
_hurd_critical_section_unlock (ss);
+ if (err == EINTR)
+ /* Got a signal while inside an RPC of the critical section, retry again */
+ goto retry;
if (!err)
{
@@ -27,6 +27,7 @@ __getegid (void)
error_t err;
gid_t egid;
+retry:
HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_id.lock);
@@ -49,6 +50,9 @@ __getegid (void)
__mutex_unlock (&_hurd_id.lock);
HURD_CRITICAL_END;
+ if (egid == -1 && errno == EINTR)
+ /* Got a signal while inside an RPC of the critical section, retry again */
+ goto retry;
return egid;
}
@@ -27,6 +27,7 @@ __geteuid (void)
error_t err;
uid_t euid;
+retry:
HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_id.lock);
@@ -49,6 +50,9 @@ __geteuid (void)
__mutex_unlock (&_hurd_id.lock);
HURD_CRITICAL_END;
+ if (euid == -1 && errno == EINTR)
+ /* Got a signal while inside an RPC of the critical section, retry again */
+ goto retry;
return euid;
}
@@ -27,6 +27,7 @@ __getgid (void)
error_t err;
gid_t gid;
+retry:
HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_id.lock);
@@ -46,6 +47,9 @@ __getgid (void)
__mutex_unlock (&_hurd_id.lock);
HURD_CRITICAL_END;
+ if (gid == -1 && errno == EINTR)
+ /* Got a signal while inside an RPC of the critical section, retry again */
+ goto retry;
return gid;
}
@@ -31,6 +31,7 @@ __getgroups (int n, gid_t *gidset)
if (n < 0)
return __hurd_fail (EINVAL);
+retry:
crit = _hurd_critical_section_lock ();
__mutex_lock (&_hurd_id.lock);
@@ -38,6 +39,9 @@ __getgroups (int n, gid_t *gidset)
{
__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);
}
@@ -28,6 +28,7 @@ __getresgid (gid_t *rgid, gid_t *egid, gid_t *sgid)
{
error_t err;
+retry:
HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_id.lock);
@@ -49,6 +50,9 @@ __getresgid (gid_t *rgid, gid_t *egid, gid_t *sgid)
__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;
return __hurd_fail (err);
}
@@ -28,6 +28,7 @@ __getresuid (uid_t *ruid, uid_t *euid, uid_t *suid)
{
error_t err;
+retry:
HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_id.lock);
@@ -49,6 +50,9 @@ __getresuid (uid_t *ruid, uid_t *euid, uid_t *suid)
__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;
return __hurd_fail (err);
}
@@ -27,6 +27,7 @@ __getuid (void)
error_t err;
uid_t uid;
+retry:
HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_id.lock);
@@ -46,6 +47,9 @@ __getuid (void)
__mutex_unlock (&_hurd_id.lock);
HURD_CRITICAL_END;
+ if (uid == -1 && errno == EINTR)
+ /* Got a signal while inside an RPC of the critical section, retry again */
+ goto retry;
return uid;
}
@@ -28,6 +28,7 @@ __group_member (gid_t gid)
error_t err;
void *crit;
+retry:
crit = _hurd_critical_section_lock ();
__mutex_lock (&_hurd_id.lock);
@@ -45,6 +46,9 @@ __group_member (gid_t gid)
__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;
if (err)
__hurd_fail (err);
@@ -29,6 +29,7 @@ setegid (gid_t gid)
auth_t newauth;
error_t err;
+retry:
HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_id.lock);
err = _hurd_check_ids ();
@@ -55,6 +56,9 @@ setegid (gid_t gid)
}
__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);
@@ -29,6 +29,7 @@ seteuid (uid_t uid)
auth_t newauth;
error_t err;
+retry:
HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_id.lock);
err = _hurd_check_ids ();
@@ -55,6 +56,9 @@ seteuid (uid_t uid)
}
__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);
@@ -32,6 +32,7 @@ __setgid (gid_t gid)
auth_t newauth;
error_t err;
+retry:
HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_id.lock);
err = _hurd_check_ids ();
@@ -81,6 +82,9 @@ __setgid (gid_t gid)
}
__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);
@@ -34,6 +34,7 @@ setgroups (size_t n, const gid_t *groups)
for (i = 0; i < n; ++i)
new[i] = groups[i];
+retry:
HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_id.lock);
err = _hurd_check_ids ();
@@ -50,6 +51,9 @@ setgroups (size_t n, const gid_t *groups)
}
__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);
@@ -339,6 +339,7 @@ __setitimer (enum __itimer_which which, const struct itimerval *new,
struct itimerval *old)
{
void *crit;
+ int ret;
switch (which)
{
@@ -353,9 +354,15 @@ __setitimer (enum __itimer_which which, const struct itimerval *new,
break;
}
+retry:
crit = _hurd_critical_section_lock ();
__spin_lock (&_hurd_itimer_lock);
- return setitimer_locked (new, old, crit, 0);
+ ret = setitimer_locked (new, old, crit, 0);
+ if (ret == -1 && errno == EINTR)
+ /* Got a signal while inside an RPC of the critical section, retry again */
+ goto retry;
+
+ return ret;
}
static void
@@ -28,6 +28,7 @@ __setregid (gid_t rgid, gid_t egid)
auth_t newauth;
error_t err;
+retry:
HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_id.lock);
err = _hurd_check_ids ();
@@ -82,6 +83,9 @@ __setregid (gid_t rgid, gid_t egid)
}
__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);
@@ -29,6 +29,7 @@ __setresgid (gid_t rgid, gid_t egid, gid_t sgid)
auth_t newauth;
error_t err;
+retry:
HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_id.lock);
err = _hurd_check_ids ();
@@ -110,6 +111,9 @@ __setresgid (gid_t rgid, gid_t egid, gid_t sgid)
}
__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);
@@ -29,6 +29,7 @@ __setresuid (uid_t ruid, uid_t euid, uid_t suid)
auth_t newauth;
error_t err;
+retry:
HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_id.lock);
err = _hurd_check_ids ();
@@ -111,6 +112,9 @@ __setresuid (uid_t ruid, uid_t euid, uid_t suid)
__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);
@@ -28,6 +28,7 @@ __setreuid (uid_t ruid, uid_t euid)
auth_t newauth;
error_t err;
+retry:
HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_id.lock);
err = _hurd_check_ids ();
@@ -82,6 +83,9 @@ __setreuid (uid_t ruid, uid_t euid)
}
__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);
@@ -32,6 +32,7 @@ __setsid (void)
error_t err;
unsigned int stamp;
+retry:
HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_dtable_lock);
@@ -60,6 +61,9 @@ __setsid (void)
}
HURD_CRITICAL_END;
+ if (err == EINTR)
+ /* Got a signal while inside an RPC of the critical section, retry again */
+ goto retry;
return err ? __hurd_fail (err) : _hurd_pgrp;
}
@@ -32,6 +32,7 @@ __setuid (uid_t uid)
auth_t newauth;
error_t err;
+retry:
HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_id.lock);
err = _hurd_check_ids ();
@@ -86,6 +87,9 @@ __setuid (uid_t uid)
}
__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);
@@ -333,6 +333,7 @@ __spawni (pid_t *pid, const char *file,
ss = _hurd_self_sigstate ();
+retry:
assert (! __spin_lock_locked (&ss->critical_section_lock));
__spin_lock (&ss->critical_section_lock);
@@ -437,7 +438,19 @@ __spawni (pid_t *pid, const char *file,
MACH_PORT_RIGHT_SEND, +1));
if (err)
- goto out;
+ {
+ _hurd_critical_section_unlock (ss);
+
+ if (err == EINTR)
+ {
+ /* Got a signal while inside an RPC of the critical section, retry again */
+ __mach_port_deallocate (__mach_task_self (), auth);
+ auth = MACH_PORT_NULL;
+ goto retry;
+ }
+
+ goto out;
+ }
/* Pack up the descriptor table to give the new program.
These descriptors will need to be reauthenticated below