diff --git a/binfmt/binfmt_schedunload.c b/binfmt/binfmt_schedunload.c index 3c4ace497c8..f742b493962 100644 --- a/binfmt/binfmt_schedunload.c +++ b/binfmt/binfmt_schedunload.c @@ -45,6 +45,7 @@ #include #include +#include #include #include "binfmt.h" @@ -100,10 +101,10 @@ static void unload_list_add(pid_t pid, FAR struct binary_s *bin) bin->pid = pid; - /* Disable deliver of any signals while we muck with the list. The graceful - * way to do this would be block delivery of SIGCHLD would be with - * sigprocmask. Here we do it the quick'n'dirty way by just disabling - * interrupts. + /* Disable deliver of any signals while we muck with the list. The + * graceful way to do this would be block delivery of SIGCHLD would be + * with nxsig_procmask. Here we do it the quick'n'dirty way by just + * disabling interrupts. */ flags = enter_critical_section(); @@ -277,13 +278,10 @@ int schedule_unload(pid_t pid, FAR struct binary_s *bin) (void)sigemptyset(&set); (void)sigaddset(&set, SIGCHLD); - ret = sigprocmask(SIG_UNBLOCK, &set, NULL); - if (ret != OK) + ret = nxsig_procmask(SIG_UNBLOCK, &set, NULL); + if (ret < 0) { - /* The errno value will get trashed by the following debug output */ - - ret = -get_errno(); - berr("ERROR: sigprocmask failed: %d\n", ret); + berr("ERROR: nxsig_procmask failed: %d\n", ret); return ret; } diff --git a/include/nuttx/signal.h b/include/nuttx/signal.h index 3e6bd5e1d11..cf3bc0d48dc 100644 --- a/include/nuttx/signal.h +++ b/include/nuttx/signal.h @@ -51,6 +51,48 @@ struct timespec; /* Forward reference */ +/**************************************************************************** + * Name: nxsig_procmask + * + * Description: + * This function allows the calling process to examine and/or change its + * signal mask. If the 'set' is not NULL, then it points to a set of + * signals to be used to change the currently blocked set. The value of + * 'how' indicates the manner in which the set is changed. + * + * If there any pending unblocked signals after the call to + * nxsig_procmask(), those signals will be delivered before + * nxsig_procmask() returns. + * + * If nxsig_procmask() fails, the signal mask of the process is not changed + * by this function call. + * + * This is an internal OS interface. It is functionally equivalent to + * sigprocmask() except that it does not modify the errno value. + * + * Parameters: + * how - How the signal mast will be changed: + * SIG_BLOCK - The resulting set is the union of the current set + * and the signal set pointed to by 'set'. + * SIG_UNBLOCK - The resulting set is the intersection of the current + * set and the complement of the signal set pointed to + * by 'set'. + * SIG_SETMASK - The resulting set is the signal set pointed to by + * 'set'. + * set - Location of the new signal mask + * oset - Location to store the old signal mask + * + * Return Value: + * This is an internal OS interface and should not be used by applications. + * It follows the NuttX internal error return policy: Zero (OK) is + * returned on success. A negated errno value is returned on failure. + * + * EINVAL - The 'how' argument is invalid. + * + ****************************************************************************/ + +int nxsig_procmask(int how, FAR const sigset_t *set, FAR sigset_t *oset); + /**************************************************************************** * Name: nxsig_queue * diff --git a/sched/pthread/pthread_exit.c b/sched/pthread/pthread_exit.c index 1eb07233118..ae183374ad8 100644 --- a/sched/pthread/pthread_exit.c +++ b/sched/pthread/pthread_exit.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/pthread/pthread_exit.c * - * Copyright (C) 2007, 2009, 2011-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011-2013, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -48,6 +48,7 @@ #include #include +#include #include "sched/sched.h" #include "task/task.h" @@ -90,7 +91,7 @@ void pthread_exit(FAR void *exit_value) #ifndef CONFIG_DISABLE_SIGNALS { sigset_t set = ALL_SIGNAL_SET; - (void)sigprocmask(SIG_SETMASK, &set, NULL); + (void)nxsig_procmask(SIG_SETMASK, &set, NULL); } #endif diff --git a/sched/pthread/pthread_sigmask.c b/sched/pthread/pthread_sigmask.c index 012024b71db..0a9fb16d2de 100644 --- a/sched/pthread/pthread_sigmask.c +++ b/sched/pthread/pthread_sigmask.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/pthread/pthread_sigmask.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -52,8 +52,8 @@ * Name: pthread_sigmask * * Description: - * This function is a simple wrapper around sigprocmask(). - * See the sigprocmask() function description for further + * This function is a simple wrapper around nxsig_procmask(). + * See the nxsig_procmask() function description for further * information. * * Parameters: @@ -70,19 +70,13 @@ * oset - Location to store the old signal mask * * Return Value: - * 0 (OK) or EINVAL if how is invalid. - * - * Assumptions: + * On success, this function will return 0 (OK). It will return EINVAL if + * how is invalid. * ****************************************************************************/ int pthread_sigmask(int how, FAR const sigset_t *set, FAR sigset_t *oset) { - int ret = sigprocmask(how, set, oset); - if (ret != OK) - { - ret = EINVAL; - } - - return ret; + int ret = nxsig_procmask(how, set, oset); + return ret < 0 ? -ret : OK; } diff --git a/sched/signal/sig_mqnotempty.c b/sched/signal/sig_mqnotempty.c index d585fdcc0ed..c7db80b8de3 100644 --- a/sched/signal/sig_mqnotempty.c +++ b/sched/signal/sig_mqnotempty.c @@ -1,7 +1,8 @@ /**************************************************************************** * sched/signal/sig_mqnotempty.c * - * Copyright (C) 2007-2009, 2013, 2015, 2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2013, 2015, 2017 Gregory Nutt. All rights + * reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/sched/signal/sig_procmask.c b/sched/signal/sig_procmask.c index d037340a3de..19bf70316e6 100644 --- a/sched/signal/sig_procmask.c +++ b/sched/signal/sig_procmask.c @@ -1,7 +1,8 @@ /**************************************************************************** * sched/signal/sig_procmask.c * - * Copyright (C) 2007-2009, 2014, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2014, 2016-2017 Gregory Nutt. All rights + * reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -42,14 +43,16 @@ #include #include #include -#include -#include #include +#include +#include +#include #include #include #include #include +#include #include "sched/sched.h" #include "signal/signal.h" @@ -59,7 +62,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: sigprocmask + * Name: nxsig_procmask * * Description: * This function allows the calling process to examine and/or change its @@ -67,12 +70,16 @@ * signals to be used to change the currently blocked set. The value of * 'how' indicates the manner in which the set is changed. * - * If there any pending unblocked signals after the call to sigprocmask(), - * those signals will be delivered before sigprocmask() returns. + * If there any pending unblocked signals after the call to + * nxsig_procmask(), those signals will be delivered before + * nxsig_procmask() returns. * - * If sigprocmask() fails, the signal mask of the process is not changed + * If nxsig_procmask() fails, the signal mask of the process is not changed * by this function call. * + * This is an internal OS interface. It is functionally equivalent to + * sigprocmask() except that it does not modify the errno value. + * * Parameters: * how - How the signal mast will be changed: * SIG_BLOCK - The resulting set is the union of the current set @@ -86,13 +93,15 @@ * oset - Location to store the old signal mask * * Return Value: - * 0 (OK), or -1 (ERROR) if how is invalid. + * This is an internal OS interface and should not be used by applications. + * It follows the NuttX internal error return policy: Zero (OK) is + * returned on success. A negated errno value is returned on failure. * - * Assumptions: + * EINVAL - The 'how' argument is invalid. * ****************************************************************************/ -int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset) +int nxsig_procmask(int how, FAR const sigset_t *set, FAR sigset_t *oset) { FAR struct tcb_s *rtcb = this_task(); sigset_t oldsigprocmask; @@ -111,7 +120,7 @@ int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset) /* Modify the current signal mask if so requested */ - if (set) + if (set != NULL) { /* Some of these operations are non-atomic. We need to protect * ourselves from attempts to process signals from interrupts @@ -146,7 +155,7 @@ int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset) break; default: - ret = ERROR; + ret = -EINVAL; break; } @@ -160,3 +169,52 @@ int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset) sched_unlock(); return ret; } + +/**************************************************************************** + * Name: sigprocmask + * + * Description: + * This function allows the calling process to examine and/or change its + * signal mask. If the 'set' is not NULL, then it points to a set of + * signals to be used to change the currently blocked set. The value of + * 'how' indicates the manner in which the set is changed. + * + * If there any pending unblocked signals after the call to sigprocmask(), + * those signals will be delivered before sigprocmask() returns. + * + * If sigprocmask() fails, the signal mask of the process is not changed + * by this function call. + * + * Parameters: + * how - How the signal mast will be changed: + * SIG_BLOCK - The resulting set is the union of the current set + * and the signal set pointed to by 'set'. + * SIG_UNBLOCK - The resulting set is the intersection of the current + * set and the complement of the signal set pointed to + * by 'set'. + * SIG_SETMASK - The resulting set is the signal set pointed to by + * 'set'. + * set - Location of the new signal mask + * oset - Location to store the old signal mask + * + * Return Value: + * This function will return 0 (OK) on success or -1 (ERROR) if how is + * invalid. In the latter case, the errno variable will be set to EINVAL. + * + ****************************************************************************/ + +int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset) +{ + int ret; + + /* Let nxsig_procmask do all of the work */ + + ret = nxsig_procmask(how, set, oset); + if (ret < 0) + { + set_errno(-ret); + ret = ERROR; + } + + return ret; +} diff --git a/sched/task/task_setup.c b/sched/task/task_setup.c index 2716db6aae7..b0511170907 100644 --- a/sched/task/task_setup.c +++ b/sched/task/task_setup.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/task/task_setup.c * - * Copyright (C) 2007-2014, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2014, 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -47,6 +47,7 @@ #include #include +#include #include "sched/sched.h" #include "pthread/pthread.h" @@ -406,7 +407,7 @@ static int thread_schedsetup(FAR struct tcb_s *tcb, int priority, * inherit the signal mask of the parent thread. */ - (void)sigprocmask(SIG_SETMASK, NULL, &tcb->sigprocmask); + (void)nxsig_procmask(SIG_SETMASK, NULL, &tcb->sigprocmask); #endif /* Initialize the task state. It does not get a valid state diff --git a/sched/task/task_spawnparms.c b/sched/task/task_spawnparms.c index d93e80a1245..1a9e5f79fcd 100644 --- a/sched/task/task_spawnparms.c +++ b/sched/task/task_spawnparms.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/task/task_spawnparms.c * - * Copyright (C) 2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,6 +44,7 @@ #include #include +#include #include #include "task/spawn.h" @@ -317,7 +318,7 @@ int spawn_proxyattrs(FAR const posix_spawnattr_t *attr, #ifndef CONFIG_DISABLE_SIGNALS if (attr && (attr->flags & POSIX_SPAWN_SETSIGMASK) != 0) { - (void)sigprocmask(SIG_SETMASK, &attr->sigmask, NULL); + (void)nxsig_procmask(SIG_SETMASK, &attr->sigmask, NULL); } /* Were we also requested to perform file actions? */