2000-02-17 20:38:33 +01:00
|
|
|
/* signal.cc
|
|
|
|
|
|
|
|
Written by Steve Chamberlain of Cygnus Support, sac@cygnus.com
|
|
|
|
Significant changes by Sergey Okhapkin <sos@prospect.com.ru>
|
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
#include "winsup.h"
|
2002-01-11 03:24:06 +01:00
|
|
|
#include <stdlib.h>
|
2000-09-08 04:56:55 +02:00
|
|
|
#include <sys/cygwin.h>
|
2019-01-13 23:13:33 +01:00
|
|
|
#include <sys/signalfd.h>
|
2000-08-22 07:10:20 +02:00
|
|
|
#include "pinfo.h"
|
2003-11-28 21:55:59 +01:00
|
|
|
#include "sigproc.h"
|
|
|
|
#include "cygtls.h"
|
2005-11-04 21:45:56 +01:00
|
|
|
#include "path.h"
|
|
|
|
#include "fhandler.h"
|
|
|
|
#include "dtable.h"
|
|
|
|
#include "cygheap.h"
|
2012-06-17 22:50:24 +02:00
|
|
|
#include "cygwait.h"
|
2019-01-22 15:23:05 +01:00
|
|
|
#include "posix_timer.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2006-03-23 16:55:59 +01:00
|
|
|
#define _SA_NORESTART 0x8000
|
|
|
|
|
2013-01-21 05:34:52 +01:00
|
|
|
static int __reg3 sigaction_worker (int, const struct sigaction *, struct sigaction *, bool);
|
2006-03-23 16:55:59 +01:00
|
|
|
|
2000-10-15 03:37:07 +02:00
|
|
|
#define sigtrapped(func) ((func) != SIG_IGN && (func) != SIG_DFL)
|
|
|
|
|
2000-10-02 21:19:21 +02:00
|
|
|
extern "C" _sig_func_ptr
|
2000-02-17 20:38:33 +01:00
|
|
|
signal (int sig, _sig_func_ptr func)
|
|
|
|
{
|
2003-08-19 06:10:42 +02:00
|
|
|
sig_dispatch_pending ();
|
2000-02-17 20:38:33 +01:00
|
|
|
_sig_func_ptr prev;
|
|
|
|
|
|
|
|
/* check that sig is in right range */
|
2016-11-24 14:10:41 +01:00
|
|
|
if (sig <= 0 || sig >= NSIG || sig == SIGKILL || sig == SIGSTOP)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
syscall_printf ("SIG_ERR = signal (%d, %p)", sig, func);
|
|
|
|
return (_sig_func_ptr) SIG_ERR;
|
|
|
|
}
|
|
|
|
|
2003-11-28 23:13:57 +01:00
|
|
|
prev = global_sigs[sig].sa_handler;
|
2006-03-23 16:55:59 +01:00
|
|
|
struct sigaction& gs = global_sigs[sig];
|
|
|
|
if (gs.sa_flags & _SA_NORESTART)
|
|
|
|
gs.sa_flags &= ~SA_RESTART;
|
|
|
|
else
|
|
|
|
gs.sa_flags |= SA_RESTART;
|
|
|
|
|
2006-07-05 01:57:43 +02:00
|
|
|
gs.sa_mask = SIGTOMASK (sig);
|
2006-03-23 16:55:59 +01:00
|
|
|
gs.sa_handler = func;
|
|
|
|
gs.sa_flags &= ~SA_SIGINFO;
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
syscall_printf ("%p = signal (%d, %p)", prev, sig, func);
|
|
|
|
return prev;
|
|
|
|
}
|
|
|
|
|
2003-01-22 11:43:39 +01:00
|
|
|
extern "C" int
|
2011-08-03 21:17:02 +02:00
|
|
|
clock_nanosleep (clockid_t clk_id, int flags, const struct timespec *rqtp,
|
|
|
|
struct timespec *rmtp)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2011-08-03 21:17:02 +02:00
|
|
|
const bool abstime = (flags & TIMER_ABSTIME) ? true : false;
|
2003-01-22 11:43:39 +01:00
|
|
|
int res = 0;
|
2003-08-19 06:10:42 +02:00
|
|
|
sig_dispatch_pending ();
|
2003-01-14 21:05:49 +01:00
|
|
|
pthread_testcancel ();
|
|
|
|
|
2019-01-11 15:15:32 +01:00
|
|
|
__try
|
|
|
|
{
|
2019-01-18 14:31:01 +01:00
|
|
|
if (!valid_timespec (*rqtp))
|
2019-01-11 15:15:32 +01:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
__except (NO_ERROR)
|
|
|
|
{
|
|
|
|
return EFAULT;
|
|
|
|
}
|
|
|
|
__endtry
|
2011-08-03 21:17:02 +02:00
|
|
|
|
|
|
|
/* Explicitly disallowed by POSIX. Needs to be checked first to avoid
|
|
|
|
being caught by the following test. */
|
|
|
|
if (clk_id == CLOCK_THREAD_CPUTIME_ID)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
/* support for CPU-time clocks is optional */
|
|
|
|
if (CLOCKID_IS_PROCESS (clk_id) || CLOCKID_IS_THREAD (clk_id))
|
|
|
|
return ENOTSUP;
|
2018-11-27 13:47:02 +01:00
|
|
|
/* All other valid clocks are valid */
|
|
|
|
if (clk_id >= MAX_CLOCKS)
|
|
|
|
return EINVAL;
|
2011-08-03 21:17:02 +02:00
|
|
|
|
2011-08-03 18:40:48 +02:00
|
|
|
LARGE_INTEGER timeout;
|
2009-12-17 15:04:04 +01:00
|
|
|
|
2018-02-07 13:07:44 +01:00
|
|
|
timeout.QuadPart = (LONGLONG) rqtp->tv_sec * NS100PERSEC
|
|
|
|
+ ((LONGLONG) rqtp->tv_nsec + (NSPERSEC/NS100PERSEC) - 1)
|
|
|
|
/ (NSPERSEC/NS100PERSEC);
|
2011-08-03 18:40:48 +02:00
|
|
|
|
2011-08-03 21:17:02 +02:00
|
|
|
if (abstime)
|
|
|
|
{
|
|
|
|
struct timespec tp;
|
|
|
|
|
|
|
|
clock_gettime (clk_id, &tp);
|
|
|
|
/* Check for immediate timeout */
|
|
|
|
if (tp.tv_sec > rqtp->tv_sec
|
2011-12-18 00:39:47 +01:00
|
|
|
|| (tp.tv_sec == rqtp->tv_sec && tp.tv_nsec > rqtp->tv_nsec))
|
2011-08-03 21:17:02 +02:00
|
|
|
return 0;
|
|
|
|
|
2018-11-27 13:47:02 +01:00
|
|
|
switch (clk_id)
|
2011-08-03 21:17:02 +02:00
|
|
|
{
|
2018-11-27 13:47:02 +01:00
|
|
|
case CLOCK_REALTIME_COARSE:
|
|
|
|
case CLOCK_REALTIME:
|
|
|
|
timeout.QuadPart += FACTOR;
|
|
|
|
break;
|
|
|
|
default:
|
2011-08-03 21:17:02 +02:00
|
|
|
/* other clocks need to be handled with a relative timeout */
|
2018-02-07 13:07:44 +01:00
|
|
|
timeout.QuadPart -= tp.tv_sec * NS100PERSEC
|
|
|
|
+ tp.tv_nsec / (NSPERSEC/NS100PERSEC);
|
2011-08-03 21:17:02 +02:00
|
|
|
timeout.QuadPart *= -1LL;
|
2018-11-27 13:47:02 +01:00
|
|
|
break;
|
2011-08-03 21:17:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* !abstime */
|
|
|
|
timeout.QuadPart *= -1LL;
|
|
|
|
|
|
|
|
syscall_printf ("clock_nanosleep (%ld.%09ld)", rqtp->tv_sec, rqtp->tv_nsec);
|
2011-08-03 18:40:48 +02:00
|
|
|
|
2012-08-15 21:07:42 +02:00
|
|
|
int rc = cygwait (NULL, &timeout, cw_sig_eintr | cw_cancel | cw_cancel_self);
|
2012-07-22 00:58:20 +02:00
|
|
|
if (rc == WAIT_SIGNALED)
|
|
|
|
res = EINTR;
|
2000-09-16 15:19:52 +02:00
|
|
|
|
2011-08-03 21:17:02 +02:00
|
|
|
/* according to POSIX, rmtp is used only if !abstime */
|
|
|
|
if (rmtp && !abstime)
|
2003-01-22 11:43:39 +01:00
|
|
|
{
|
2019-01-11 15:15:32 +01:00
|
|
|
__try
|
|
|
|
{
|
|
|
|
rmtp->tv_sec = (time_t) (timeout.QuadPart / NS100PERSEC);
|
|
|
|
rmtp->tv_nsec = (long) ((timeout.QuadPart % NS100PERSEC)
|
|
|
|
* (NSPERSEC/NS100PERSEC));
|
|
|
|
}
|
|
|
|
__except (NO_ERROR)
|
|
|
|
{
|
|
|
|
res = EFAULT;
|
|
|
|
}
|
|
|
|
__endtry
|
2003-01-22 11:43:39 +01:00
|
|
|
}
|
2000-09-16 15:19:52 +02:00
|
|
|
|
2011-12-03 22:43:27 +01:00
|
|
|
syscall_printf ("%d = clock_nanosleep(%lu, %d, %ld.%09ld, %ld.%09.ld)",
|
2011-08-03 21:17:02 +02:00
|
|
|
res, clk_id, flags, rqtp->tv_sec, rqtp->tv_nsec,
|
|
|
|
rmtp ? rmtp->tv_sec : 0, rmtp ? rmtp->tv_nsec : 0);
|
2000-09-16 15:19:52 +02:00
|
|
|
return res;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2011-08-03 21:17:02 +02:00
|
|
|
extern "C" int
|
|
|
|
nanosleep (const struct timespec *rqtp, struct timespec *rmtp)
|
|
|
|
{
|
|
|
|
int res = clock_nanosleep (CLOCK_REALTIME, 0, rqtp, rmtp);
|
|
|
|
if (res != 0)
|
|
|
|
{
|
|
|
|
set_errno (res);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-10-02 21:19:21 +02:00
|
|
|
extern "C" unsigned int
|
2003-01-22 11:43:39 +01:00
|
|
|
sleep (unsigned int seconds)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2003-01-22 11:43:39 +01:00
|
|
|
struct timespec req, rem;
|
|
|
|
req.tv_sec = seconds;
|
|
|
|
req.tv_nsec = 0;
|
2011-08-03 21:17:02 +02:00
|
|
|
if (clock_nanosleep (CLOCK_REALTIME, 0, &req, &rem))
|
2009-12-17 15:04:04 +01:00
|
|
|
return rem.tv_sec + (rem.tv_nsec > 0);
|
|
|
|
return 0;
|
2003-01-22 11:43:39 +01:00
|
|
|
}
|
2003-01-14 21:05:49 +01:00
|
|
|
|
2003-01-22 11:43:39 +01:00
|
|
|
extern "C" unsigned int
|
2007-06-12 22:49:48 +02:00
|
|
|
usleep (useconds_t useconds)
|
2003-01-22 11:43:39 +01:00
|
|
|
{
|
|
|
|
struct timespec req;
|
2018-02-07 13:07:44 +01:00
|
|
|
req.tv_sec = useconds / USPERSEC;
|
|
|
|
req.tv_nsec = (useconds % USPERSEC) * (NSPERSEC/USPERSEC);
|
2011-08-03 21:17:02 +02:00
|
|
|
int res = clock_nanosleep (CLOCK_REALTIME, 0, &req, NULL);
|
|
|
|
if (res != 0)
|
|
|
|
{
|
|
|
|
set_errno (res);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2000-10-02 21:19:21 +02:00
|
|
|
extern "C" int
|
2005-03-09 22:07:56 +01:00
|
|
|
sigprocmask (int how, const sigset_t *set, sigset_t *oldset)
|
2003-11-28 21:55:59 +01:00
|
|
|
{
|
2011-07-10 02:01:33 +02:00
|
|
|
int res = handle_sigprocmask (how, set, oldset, _my_tls.sigmask);
|
|
|
|
if (res)
|
2011-12-13 21:06:31 +01:00
|
|
|
{
|
|
|
|
set_errno (res);
|
|
|
|
res = -1;
|
|
|
|
}
|
2014-05-09 16:28:48 +02:00
|
|
|
syscall_printf ("%R = sigprocmask (%d, %p, %p)", res, how, set, oldset);
|
2011-12-13 21:06:31 +01:00
|
|
|
return res;
|
2003-11-28 21:55:59 +01:00
|
|
|
}
|
|
|
|
|
2013-05-01 03:20:37 +02:00
|
|
|
int __reg3
|
2005-03-09 22:07:56 +01:00
|
|
|
handle_sigprocmask (int how, const sigset_t *set, sigset_t *oldset, sigset_t& opmask)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2005-03-09 22:07:56 +01:00
|
|
|
/* check that how is in right range */
|
|
|
|
if (how != SIG_BLOCK && how != SIG_UNBLOCK && how != SIG_SETMASK)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2005-03-09 22:07:56 +01:00
|
|
|
syscall_printf ("Invalid how value %d", how);
|
2011-07-10 02:01:33 +02:00
|
|
|
return EINVAL;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2014-08-22 11:21:33 +02:00
|
|
|
__try
|
|
|
|
{
|
|
|
|
if (oldset)
|
|
|
|
*oldset = opmask;
|
2003-11-28 21:55:59 +01:00
|
|
|
|
2014-08-22 11:21:33 +02:00
|
|
|
if (set)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2014-08-22 11:21:33 +02:00
|
|
|
sigset_t newmask = opmask;
|
|
|
|
switch (how)
|
|
|
|
{
|
|
|
|
case SIG_BLOCK:
|
|
|
|
/* add set to current mask */
|
|
|
|
newmask |= *set;
|
|
|
|
break;
|
|
|
|
case SIG_UNBLOCK:
|
|
|
|
/* remove set from current mask */
|
|
|
|
newmask &= ~*set;
|
|
|
|
break;
|
|
|
|
case SIG_SETMASK:
|
|
|
|
/* just set it */
|
|
|
|
newmask = *set;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
set_signal_mask (opmask, newmask);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
}
|
2014-08-22 11:21:33 +02:00
|
|
|
__except (EFAULT)
|
|
|
|
{
|
|
|
|
return EFAULT;
|
|
|
|
}
|
|
|
|
__endtry
|
2000-02-17 20:38:33 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-01 03:20:37 +02:00
|
|
|
int __reg2
|
2005-02-26 21:50:25 +01:00
|
|
|
_pinfo::kill (siginfo_t& si)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2011-04-17 23:45:28 +02:00
|
|
|
int res;
|
|
|
|
DWORD this_process_state;
|
2011-05-03 04:03:04 +02:00
|
|
|
pid_t this_pid;
|
2002-11-22 21:51:13 +01:00
|
|
|
|
2011-04-17 23:45:28 +02:00
|
|
|
sig_dispatch_pending ();
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2011-04-17 23:45:28 +02:00
|
|
|
if (exists ())
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2011-04-17 23:45:28 +02:00
|
|
|
bool sendSIGCONT;
|
2011-04-18 03:46:57 +02:00
|
|
|
this_process_state = process_state;
|
2011-04-17 23:45:28 +02:00
|
|
|
if ((sendSIGCONT = (si.si_signo < 0)))
|
|
|
|
si.si_signo = -si.si_signo;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2011-04-17 23:45:28 +02:00
|
|
|
if (si.si_signo == 0)
|
|
|
|
res = 0;
|
2019-07-12 16:32:45 +02:00
|
|
|
else if ((res = (int) sig_send (this, si)))
|
2011-04-17 23:45:28 +02:00
|
|
|
{
|
|
|
|
sigproc_printf ("%d = sig_send, %E ", res);
|
|
|
|
res = -1;
|
|
|
|
}
|
|
|
|
else if (sendSIGCONT)
|
|
|
|
{
|
|
|
|
siginfo_t si2 = {0};
|
|
|
|
si2.si_signo = SIGCONT;
|
|
|
|
si2.si_code = SI_KERNEL;
|
|
|
|
sig_send (this, si2);
|
|
|
|
}
|
2011-05-03 04:03:04 +02:00
|
|
|
this_pid = pid;
|
2011-04-17 23:45:28 +02:00
|
|
|
}
|
2017-09-17 04:04:18 +02:00
|
|
|
else if (process_state == PID_EXITED)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2011-04-17 23:45:28 +02:00
|
|
|
this_process_state = process_state;
|
2011-05-03 04:03:04 +02:00
|
|
|
this_pid = pid;
|
2011-04-17 23:45:28 +02:00
|
|
|
res = 0;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2011-04-17 23:45:28 +02:00
|
|
|
else
|
2004-01-19 06:46:54 +01:00
|
|
|
{
|
2011-04-17 23:45:28 +02:00
|
|
|
set_errno (ESRCH);
|
|
|
|
this_process_state = 0;
|
2011-05-05 02:31:22 +02:00
|
|
|
this_pid = 0;
|
2011-04-17 23:45:28 +02:00
|
|
|
res = -1;
|
2004-01-19 06:46:54 +01:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
syscall_printf ("%d = _pinfo::kill (%d), pid %d, process_state %y", res,
|
2011-05-05 02:31:22 +02:00
|
|
|
si.si_signo, this_pid, this_process_state);
|
2000-02-17 20:38:33 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2016-11-24 14:02:11 +01:00
|
|
|
extern "C" int
|
2002-10-20 06:15:50 +02:00
|
|
|
raise (int sig)
|
2000-08-29 04:06:49 +02:00
|
|
|
{
|
2019-01-30 11:36:45 +01:00
|
|
|
pthread *thread = _my_tls.tid;
|
|
|
|
if (!thread)
|
|
|
|
return kill (myself->pid, sig);
|
|
|
|
return pthread_kill (thread, sig);
|
2000-08-29 04:06:49 +02:00
|
|
|
}
|
|
|
|
|
2004-01-19 06:46:54 +01:00
|
|
|
static int
|
|
|
|
kill0 (pid_t pid, siginfo_t& si)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2004-01-19 06:46:54 +01:00
|
|
|
syscall_printf ("kill (%d, %d)", pid, si.si_signo);
|
2000-02-17 20:38:33 +01:00
|
|
|
/* check that sig is in right range */
|
2004-01-19 06:46:54 +01:00
|
|
|
if (si.si_signo < 0 || si.si_signo >= NSIG)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
2004-01-19 06:46:54 +01:00
|
|
|
syscall_printf ("signal %d out of range", si.si_signo);
|
2000-02-17 20:38:33 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2017-09-17 04:04:18 +02:00
|
|
|
if (pid > 0)
|
|
|
|
{
|
|
|
|
pinfo p (pid);
|
|
|
|
if (!p)
|
|
|
|
{
|
|
|
|
set_errno (ESRCH);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return p->kill (si);
|
|
|
|
}
|
|
|
|
return kill_pgrp (-pid, si);
|
2004-01-19 06:46:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
kill (pid_t pid, int sig)
|
|
|
|
{
|
2006-02-06 19:24:11 +01:00
|
|
|
siginfo_t si = {0};
|
2004-01-19 06:46:54 +01:00
|
|
|
si.si_signo = sig;
|
|
|
|
si.si_code = SI_USER;
|
|
|
|
return kill0 (pid, si);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-01-19 06:46:54 +01:00
|
|
|
kill_pgrp (pid_t pid, siginfo_t& si)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
int found = 0;
|
|
|
|
int killself = 0;
|
|
|
|
|
2004-01-19 06:46:54 +01:00
|
|
|
sigproc_printf ("pid %d, signal %d", pid, si.si_signo);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2003-09-17 03:15:56 +02:00
|
|
|
winpids pids ((DWORD) PID_MAP_RW);
|
2000-07-29 18:24:59 +02:00
|
|
|
for (unsigned i = 0; i < pids.npids; i++)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-11-05 07:42:23 +01:00
|
|
|
_pinfo *p = pids[i];
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2017-09-17 04:04:19 +02:00
|
|
|
if (!p || !p->exists ())
|
2000-02-17 20:38:33 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Is it a process we want to kill? */
|
2001-01-17 15:57:09 +01:00
|
|
|
if ((pid == 0 && (p->pgid != myself->pgid || p->ctty != myself->ctty)) ||
|
2001-09-07 23:32:07 +02:00
|
|
|
(pid > 1 && p->pgid != pid) ||
|
2004-01-19 06:46:54 +01:00
|
|
|
(si.si_signo < 0 && NOTSTATE (p, PID_STOPPED)))
|
2000-10-31 00:19:45 +01:00
|
|
|
continue;
|
2005-11-14 05:28:45 +01:00
|
|
|
sigproc_printf ("killing pid %d, pgrp %d, p->%s, %s", p->pid, p->pgid,
|
|
|
|
p->__ctty (), myctty ());
|
2000-02-17 20:38:33 +01:00
|
|
|
if (p == myself)
|
|
|
|
killself++;
|
2005-02-26 21:50:25 +01:00
|
|
|
else if (p->kill (si))
|
2000-02-17 20:38:33 +01:00
|
|
|
res = -1;
|
|
|
|
found++;
|
|
|
|
}
|
|
|
|
|
2005-02-26 21:50:25 +01:00
|
|
|
if (killself && !exit_state && myself->kill (si))
|
2000-02-17 20:38:33 +01:00
|
|
|
res = -1;
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
set_errno (ESRCH);
|
|
|
|
res = -1;
|
|
|
|
}
|
2011-12-03 22:43:27 +01:00
|
|
|
syscall_printf ("%R = kill(%d, %d)", res, pid, si.si_signo);
|
2000-02-17 20:38:33 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-10-02 21:19:21 +02:00
|
|
|
extern "C" int
|
2001-02-08 00:48:09 +01:00
|
|
|
killpg (pid_t pgrp, int sig)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-10-20 06:15:50 +02:00
|
|
|
return kill (-pgrp, sig);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2002-01-11 03:24:06 +01:00
|
|
|
extern "C" void
|
|
|
|
abort (void)
|
|
|
|
{
|
2006-04-23 01:13:18 +02:00
|
|
|
_my_tls.incyg++;
|
2003-08-19 06:10:42 +02:00
|
|
|
sig_dispatch_pending ();
|
2002-01-11 03:24:06 +01:00
|
|
|
/* Ensure that SIGABRT can be caught regardless of blockage. */
|
|
|
|
sigset_t sig_mask;
|
|
|
|
sigfillset (&sig_mask);
|
|
|
|
sigdelset (&sig_mask, SIGABRT);
|
2012-07-22 00:58:20 +02:00
|
|
|
set_signal_mask (_my_tls.sigmask, sig_mask);
|
2002-01-11 03:24:06 +01:00
|
|
|
|
2002-10-20 06:15:50 +02:00
|
|
|
raise (SIGABRT);
|
2005-07-06 22:05:03 +02:00
|
|
|
_my_tls.call_signal_handler (); /* Call any signal handler */
|
2008-06-09 15:45:59 +02:00
|
|
|
|
|
|
|
/* Flush all streams as per SUSv2. */
|
|
|
|
if (_GLOBAL_REENT->__cleanup)
|
|
|
|
_GLOBAL_REENT->__cleanup (_GLOBAL_REENT);
|
2004-11-26 05:15:10 +01:00
|
|
|
do_exit (SIGABRT); /* signal handler didn't exit. Goodbye. */
|
2002-01-11 03:24:06 +01:00
|
|
|
}
|
|
|
|
|
2013-01-21 05:34:52 +01:00
|
|
|
static int __reg3
|
2011-12-04 00:55:21 +01:00
|
|
|
sigaction_worker (int sig, const struct sigaction *newact,
|
2012-07-02 04:24:25 +02:00
|
|
|
struct sigaction *oldact, bool isinternal)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2011-12-04 00:55:21 +01:00
|
|
|
int res = -1;
|
2014-08-22 11:21:33 +02:00
|
|
|
__try
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2011-12-04 00:55:21 +01:00
|
|
|
sig_dispatch_pending ();
|
|
|
|
/* check that sig is in right range */
|
2016-11-24 14:10:41 +01:00
|
|
|
if (sig <= 0 || sig >= NSIG)
|
2011-12-04 00:55:21 +01:00
|
|
|
set_errno (EINVAL);
|
|
|
|
else
|
2003-09-01 04:05:32 +02:00
|
|
|
{
|
2011-12-04 00:55:21 +01:00
|
|
|
struct sigaction oa = global_sigs[sig];
|
|
|
|
|
|
|
|
if (!newact)
|
2014-08-22 11:21:33 +02:00
|
|
|
sigproc_printf ("signal %d, newact %p, oa %p",
|
|
|
|
sig, newact, oa, oa.sa_handler);
|
2011-12-04 00:55:21 +01:00
|
|
|
else
|
|
|
|
{
|
2014-08-22 11:21:33 +02:00
|
|
|
sigproc_printf ("signal %d, newact %p (handler %p), oa %p",
|
|
|
|
sig, newact, newact->sa_handler, oa,
|
|
|
|
oa.sa_handler);
|
2011-12-04 00:55:21 +01:00
|
|
|
if (sig == SIGKILL || sig == SIGSTOP)
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
2014-08-22 11:21:33 +02:00
|
|
|
__leave;
|
2011-12-04 00:55:21 +01:00
|
|
|
}
|
|
|
|
struct sigaction na = *newact;
|
|
|
|
struct sigaction& gs = global_sigs[sig];
|
|
|
|
if (!isinternal)
|
|
|
|
na.sa_flags &= ~_SA_INTERNAL_MASK;
|
|
|
|
gs = na;
|
|
|
|
if (!(gs.sa_flags & SA_NODEFER))
|
|
|
|
gs.sa_mask |= SIGTOMASK(sig);
|
|
|
|
if (gs.sa_handler == SIG_IGN)
|
|
|
|
sig_clear (sig);
|
|
|
|
if (gs.sa_handler == SIG_DFL && sig == SIGCHLD)
|
|
|
|
sig_clear (sig);
|
|
|
|
if (sig == SIGCHLD)
|
|
|
|
{
|
|
|
|
myself->process_state &= ~PID_NOCLDSTOP;
|
|
|
|
if (gs.sa_flags & SA_NOCLDSTOP)
|
|
|
|
myself->process_state |= PID_NOCLDSTOP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldact)
|
|
|
|
{
|
|
|
|
*oldact = oa;
|
|
|
|
oa.sa_flags &= ~_SA_INTERNAL_MASK;
|
|
|
|
}
|
|
|
|
res = 0;
|
2003-09-01 04:05:32 +02:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2014-08-22 11:21:33 +02:00
|
|
|
__except (EFAULT) {}
|
|
|
|
__endtry
|
2011-12-04 00:55:21 +01:00
|
|
|
return res;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2006-03-23 16:55:59 +01:00
|
|
|
extern "C" int
|
|
|
|
sigaction (int sig, const struct sigaction *newact, struct sigaction *oldact)
|
|
|
|
{
|
2012-07-02 04:24:25 +02:00
|
|
|
int res = sigaction_worker (sig, newact, oldact, false);
|
|
|
|
syscall_printf ("%R = sigaction(%d, %p, %p)", res, sig, newact, oldact);
|
|
|
|
return res;
|
2006-03-23 16:55:59 +01:00
|
|
|
}
|
|
|
|
|
2000-10-02 21:19:21 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
sigaddset (sigset_t *set, const int sig)
|
|
|
|
{
|
|
|
|
/* check that sig is in right range */
|
|
|
|
if (sig <= 0 || sig >= NSIG)
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
2001-04-01 02:06:17 +02:00
|
|
|
syscall_printf ("SIG_ERR = sigaddset signal %d out of range", sig);
|
2000-02-17 20:38:33 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*set |= SIGTOMASK (sig);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-10-02 21:19:21 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
sigdelset (sigset_t *set, const int sig)
|
|
|
|
{
|
|
|
|
/* check that sig is in right range */
|
|
|
|
if (sig <= 0 || sig >= NSIG)
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
2001-04-01 02:06:17 +02:00
|
|
|
syscall_printf ("SIG_ERR = sigdelset signal %d out of range", sig);
|
2000-02-17 20:38:33 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*set &= ~SIGTOMASK (sig);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-10-02 21:19:21 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
sigismember (const sigset_t *set, int sig)
|
|
|
|
{
|
|
|
|
/* check that sig is in right range */
|
|
|
|
if (sig <= 0 || sig >= NSIG)
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
2001-04-01 02:06:17 +02:00
|
|
|
syscall_printf ("SIG_ERR = sigdelset signal %d out of range", sig);
|
2000-02-17 20:38:33 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*set & SIGTOMASK (sig))
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-10-02 21:19:21 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
sigemptyset (sigset_t *set)
|
|
|
|
{
|
|
|
|
*set = (sigset_t) 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-10-02 21:19:21 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
sigfillset (sigset_t *set)
|
|
|
|
{
|
|
|
|
*set = ~((sigset_t) 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-10-02 21:19:21 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
sigsuspend (const sigset_t *set)
|
|
|
|
{
|
2012-07-30 05:44:40 +02:00
|
|
|
int res = handle_sigsuspend (*set);
|
|
|
|
syscall_printf ("%R = sigsuspend(%p)", res, set);
|
|
|
|
return res;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2000-10-02 21:19:21 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
sigpause (int signal_mask)
|
|
|
|
{
|
2012-07-30 05:44:40 +02:00
|
|
|
int res = handle_sigsuspend ((sigset_t) signal_mask);
|
2013-04-23 11:44:36 +02:00
|
|
|
syscall_printf ("%R = sigpause(%y)", res, signal_mask);
|
2012-07-30 05:44:40 +02:00
|
|
|
return res;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2017-06-14 17:20:05 +02:00
|
|
|
extern "C" int
|
|
|
|
__xpg_sigpause (int sig)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
sigset_t signal_mask;
|
|
|
|
sigprocmask (0, NULL, &signal_mask);
|
|
|
|
sigdelset (&signal_mask, sig);
|
|
|
|
res = handle_sigsuspend (signal_mask);
|
|
|
|
syscall_printf ("%R = __xpg_sigpause(%y)", res, sig);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-10-02 21:19:21 +02:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
pause (void)
|
|
|
|
{
|
2012-07-30 05:44:40 +02:00
|
|
|
int res = handle_sigsuspend (_my_tls.sigmask);
|
|
|
|
syscall_printf ("%R = pause()", res);
|
|
|
|
return res;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2002-11-15 20:04:36 +01:00
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
siginterrupt (int sig, int flag)
|
|
|
|
{
|
|
|
|
struct sigaction act;
|
2016-11-24 14:10:41 +01:00
|
|
|
int res = sigaction_worker (sig, NULL, &act, false);
|
|
|
|
if (res == 0)
|
2006-03-23 16:55:59 +01:00
|
|
|
{
|
2016-11-24 14:10:41 +01:00
|
|
|
if (flag)
|
|
|
|
{
|
|
|
|
act.sa_flags &= ~SA_RESTART;
|
|
|
|
act.sa_flags |= _SA_NORESTART;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
act.sa_flags &= ~_SA_NORESTART;
|
|
|
|
act.sa_flags |= SA_RESTART;
|
|
|
|
}
|
|
|
|
res = sigaction_worker (sig, &act, NULL, true);
|
2006-03-23 16:55:59 +01:00
|
|
|
}
|
2013-04-23 11:44:36 +02:00
|
|
|
syscall_printf ("%R = siginterrupt(%d, %y)", sig, flag);
|
2012-07-02 04:24:25 +02:00
|
|
|
return res;
|
2002-11-15 20:04:36 +01:00
|
|
|
}
|
|
|
|
|
2019-01-13 23:13:33 +01:00
|
|
|
int
|
2017-12-15 02:05:55 +01:00
|
|
|
sigwait_common (const sigset_t *set, siginfo_t *info, PLARGE_INTEGER waittime)
|
2003-11-28 21:55:59 +01:00
|
|
|
{
|
2014-08-22 11:21:33 +02:00
|
|
|
int res = -1;
|
2012-07-22 00:58:20 +02:00
|
|
|
|
2014-08-22 11:21:33 +02:00
|
|
|
pthread_testcancel ();
|
2003-11-28 21:55:59 +01:00
|
|
|
|
2014-08-22 11:21:33 +02:00
|
|
|
__try
|
2003-11-28 21:55:59 +01:00
|
|
|
{
|
2014-08-22 11:21:33 +02:00
|
|
|
set_signal_mask (_my_tls.sigwait_mask, *set);
|
|
|
|
sig_dispatch_pending (true);
|
|
|
|
|
2019-01-14 17:19:37 +01:00
|
|
|
switch (cygwait (NULL, waittime,
|
|
|
|
cw_sig_eintr | cw_cancel | cw_cancel_self))
|
2004-02-26 06:10:49 +01:00
|
|
|
{
|
2014-08-22 11:21:33 +02:00
|
|
|
case WAIT_SIGNALED:
|
|
|
|
if (!sigismember (set, _my_tls.infodata.si_signo))
|
|
|
|
set_errno (EINTR);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_my_tls.lock ();
|
2019-01-12 21:19:52 +01:00
|
|
|
if (_my_tls.infodata.si_code == SI_TIMER)
|
|
|
|
{
|
|
|
|
timer_tracker *tt = (timer_tracker *)
|
|
|
|
_my_tls.infodata.si_tid;
|
2019-01-22 15:23:05 +01:00
|
|
|
_my_tls.infodata.si_overrun = tt->disarm_overrun_event ();
|
2019-01-12 21:19:52 +01:00
|
|
|
}
|
2014-08-22 11:21:33 +02:00
|
|
|
if (info)
|
|
|
|
*info = _my_tls.infodata;
|
|
|
|
res = _my_tls.infodata.si_signo;
|
|
|
|
_my_tls.sig = 0;
|
2015-06-19 15:58:23 +02:00
|
|
|
if (_my_tls.retaddr () == (__tlsstack_t) sigdelayed)
|
2014-08-22 11:21:33 +02:00
|
|
|
_my_tls.pop ();
|
|
|
|
_my_tls.unlock ();
|
|
|
|
}
|
|
|
|
break;
|
2017-12-15 02:05:55 +01:00
|
|
|
case WAIT_TIMEOUT:
|
|
|
|
set_errno (EAGAIN);
|
|
|
|
break;
|
2014-08-22 11:21:33 +02:00
|
|
|
default:
|
|
|
|
__seterrno ();
|
|
|
|
break;
|
2004-02-26 06:10:49 +01:00
|
|
|
}
|
2003-11-28 21:55:59 +01:00
|
|
|
}
|
2019-01-13 22:48:43 +01:00
|
|
|
__except (EFAULT)
|
|
|
|
{
|
|
|
|
res = -1;
|
|
|
|
}
|
2014-08-22 11:21:33 +02:00
|
|
|
__endtry
|
2011-11-14 02:29:49 +01:00
|
|
|
sigproc_printf ("returning signal %d", res);
|
2004-01-19 06:46:54 +01:00
|
|
|
return res;
|
2003-11-28 21:55:59 +01:00
|
|
|
}
|
2004-02-26 06:10:49 +01:00
|
|
|
|
2017-12-18 19:44:30 +01:00
|
|
|
extern "C" int
|
|
|
|
sigtimedwait (const sigset_t *set, siginfo_t *info, const timespec *timeout)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER waittime;
|
|
|
|
|
|
|
|
if (timeout)
|
|
|
|
{
|
2019-01-18 14:31:01 +01:00
|
|
|
if (!valid_timespec (*timeout))
|
2017-12-18 19:44:30 +01:00
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* convert timespec to 100ns units */
|
2018-02-07 13:07:44 +01:00
|
|
|
waittime.QuadPart = (LONGLONG) timeout->tv_sec * NS100PERSEC
|
|
|
|
+ ((LONGLONG) timeout->tv_nsec + (NSPERSEC/NS100PERSEC) - 1)
|
|
|
|
/ (NSPERSEC/NS100PERSEC);
|
2018-07-19 11:35:40 +02:00
|
|
|
/* negate waittime to code as duration for NtSetTimer() below cygwait() */
|
|
|
|
waittime.QuadPart = -waittime.QuadPart;
|
2017-12-18 19:44:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return sigwait_common (set, info, timeout ? &waittime : cw_infinite);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
sigwait (const sigset_t *set, int *sig_ptr)
|
|
|
|
{
|
|
|
|
int sig;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
sig = sigwait_common (set, NULL, cw_infinite);
|
|
|
|
}
|
|
|
|
while (sig == -1 && get_errno () == EINTR);
|
|
|
|
if (sig > 0)
|
|
|
|
*sig_ptr = sig;
|
|
|
|
return sig > 0 ? 0 : get_errno ();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
sigwaitinfo (const sigset_t *set, siginfo_t *info)
|
|
|
|
{
|
|
|
|
return sigwait_common (set, info, cw_infinite);
|
|
|
|
}
|
|
|
|
|
2017-08-03 14:55:21 +02:00
|
|
|
/* FIXME: SUSv3 says that this function should block until the signal has
|
|
|
|
actually been delivered. Currently, this will only happen when sending
|
|
|
|
signals to the current process. It will not happen when sending signals
|
|
|
|
to other processes. */
|
|
|
|
extern "C" int
|
|
|
|
sigqueue (pid_t pid, int sig, const union sigval value)
|
2004-02-26 06:10:49 +01:00
|
|
|
{
|
2017-08-03 14:55:21 +02:00
|
|
|
siginfo_t si = {0};
|
2004-02-26 06:10:49 +01:00
|
|
|
pinfo dest (pid);
|
|
|
|
if (!dest)
|
|
|
|
{
|
|
|
|
set_errno (ESRCH);
|
|
|
|
return -1;
|
|
|
|
}
|
2016-11-24 14:10:41 +01:00
|
|
|
if (sig == 0)
|
|
|
|
return 0;
|
2017-08-03 14:55:21 +02:00
|
|
|
if (sig < 0 || sig >= NSIG)
|
2016-11-24 14:10:41 +01:00
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
2004-02-26 06:10:49 +01:00
|
|
|
si.si_signo = sig;
|
2005-09-26 16:51:48 +02:00
|
|
|
si.si_code = SI_QUEUE;
|
2004-02-26 06:10:49 +01:00
|
|
|
si.si_value = value;
|
2019-07-12 16:32:45 +02:00
|
|
|
return (int) sig_send (dest, si);
|
2004-02-26 06:10:49 +01:00
|
|
|
}
|
2015-06-19 15:58:23 +02:00
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
sigaltstack (const stack_t *ss, stack_t *oss)
|
|
|
|
{
|
|
|
|
_cygtls& me = _my_tls;
|
|
|
|
|
2015-06-20 18:48:09 +02:00
|
|
|
__try
|
2015-06-19 15:58:23 +02:00
|
|
|
{
|
2015-06-20 18:48:09 +02:00
|
|
|
if (ss)
|
2015-06-19 15:58:23 +02:00
|
|
|
{
|
2015-06-20 18:48:09 +02:00
|
|
|
if (me.altstack.ss_flags == SS_ONSTACK)
|
2015-06-19 15:58:23 +02:00
|
|
|
{
|
2015-06-20 18:48:09 +02:00
|
|
|
/* An attempt was made to modify an active stack. */
|
|
|
|
set_errno (EPERM);
|
2015-06-19 15:58:23 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2015-06-20 18:48:09 +02:00
|
|
|
if (ss->ss_flags == SS_DISABLE)
|
2015-06-19 15:58:23 +02:00
|
|
|
{
|
2015-06-20 18:48:09 +02:00
|
|
|
me.altstack.ss_sp = NULL;
|
|
|
|
me.altstack.ss_flags = 0;
|
|
|
|
me.altstack.ss_size = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ss->ss_flags)
|
|
|
|
{
|
|
|
|
/* The ss argument is not a null pointer, and the ss_flags
|
|
|
|
member pointed to by ss contains flags other than
|
|
|
|
SS_DISABLE. */
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (ss->ss_size < MINSIGSTKSZ)
|
|
|
|
{
|
|
|
|
/* The size of the alternate stack area is less than
|
|
|
|
MINSIGSTKSZ. */
|
|
|
|
set_errno (ENOMEM);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
memcpy (&me.altstack, ss, sizeof *ss);
|
2015-06-19 15:58:23 +02:00
|
|
|
}
|
|
|
|
}
|
2015-06-20 18:48:09 +02:00
|
|
|
if (oss)
|
2015-06-27 12:08:07 +02:00
|
|
|
{
|
|
|
|
char stack_marker;
|
|
|
|
memcpy (oss, &me.altstack, sizeof *oss);
|
2015-06-30 20:43:50 +02:00
|
|
|
/* Check if the current stack is the alternate signal stack. If so,
|
|
|
|
set ss_flags accordingly. We do this here rather than setting
|
|
|
|
ss_flags in _cygtls::call_signal_handler since the signal handler
|
|
|
|
calls longjmp, so we never return to reset the flag. */
|
2015-06-27 12:08:07 +02:00
|
|
|
if (!me.altstack.ss_flags && me.altstack.ss_sp)
|
|
|
|
{
|
|
|
|
if (&stack_marker >= (char *) me.altstack.ss_sp
|
|
|
|
&& &stack_marker < (char *) me.altstack.ss_sp
|
|
|
|
+ me.altstack.ss_size)
|
|
|
|
oss->ss_flags = SS_ONSTACK;
|
|
|
|
}
|
|
|
|
}
|
2015-06-19 15:58:23 +02:00
|
|
|
}
|
2015-06-20 18:48:09 +02:00
|
|
|
__except (EFAULT)
|
|
|
|
{
|
|
|
|
return EFAULT;
|
|
|
|
}
|
|
|
|
__endtry
|
2015-06-19 15:58:23 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2019-01-13 23:13:33 +01:00
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
signalfd (int fd_in, const sigset_t *mask, int flags)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
fhandler_signalfd *fh;
|
|
|
|
|
|
|
|
debug_printf ("signalfd (%d, %p, %y)", fd_in, mask, flags);
|
|
|
|
|
|
|
|
if ((flags & ~(SFD_NONBLOCK | SFD_CLOEXEC)) != 0)
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fd_in != -1)
|
|
|
|
{
|
|
|
|
/* Change signal mask. */
|
|
|
|
cygheap_fdget fd (fd_in);
|
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
goto done;
|
|
|
|
fh = fd->is_signalfd ();
|
|
|
|
if (!fh)
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
__try
|
|
|
|
{
|
|
|
|
if (fh->signalfd (mask, flags) == 0)
|
|
|
|
ret = fd_in;
|
|
|
|
}
|
|
|
|
__except (EINVAL) {}
|
|
|
|
__endtry
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Create new signalfd descriptor. */
|
|
|
|
cygheap_fdnew fd;
|
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
goto done;
|
|
|
|
fh = (fhandler_signalfd *) build_fh_dev (*signalfd_dev);
|
|
|
|
if (fh && fh->signalfd (mask, flags) == 0)
|
|
|
|
{
|
|
|
|
fd = fh;
|
|
|
|
if (fd <= 2)
|
|
|
|
set_std_handle (fd);
|
|
|
|
ret = fd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
delete fh;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
syscall_printf ("%R = signalfd (%d, %p, %y)", ret, fd_in, mask, flags);
|
|
|
|
return ret;
|
|
|
|
}
|