diff --git a/drivers/ioexpander/gpio.c b/drivers/ioexpander/gpio.c index 072687f1f8..69ebd8d3b5 100644 --- a/drivers/ioexpander/gpio.c +++ b/drivers/ioexpander/gpio.c @@ -45,6 +45,7 @@ #include #include +#include #include #include @@ -99,7 +100,7 @@ static const struct file_operations g_gpio_drvrops = static int gpio_handler(FAR struct gpio_dev_s *dev) { DEBUGASSERT(dev != NULL); - (void)kill(dev->gp_pid, dev->gp_signo); + (void)nxsig_kill(dev->gp_pid, dev->gp_signo); return OK; } diff --git a/drivers/net/slip.c b/drivers/net/slip.c index db7ea97b6e..f9a30b64ea 100644 --- a/drivers/net/slip.c +++ b/drivers/net/slip.c @@ -739,7 +739,7 @@ static int slip_rxtask(int argc, FAR char *argv[]) if (priv->dev.d_len > 0) { slip_transmit(priv); - kill(priv->txpid, SIGALRM); + (void)nxsig_kill(priv->txpid, SIGALRM); } net_unlock(); @@ -840,7 +840,7 @@ static int slip_txavail(FAR struct net_driver_s *dev) /* Wake up the TX polling thread */ priv->txnodelay = true; - kill(priv->txpid, SIGALRM); + (void)nxsig_kill(priv->txpid, SIGALRM); } return OK; diff --git a/drivers/usbhost/usbhost_hidkbd.c b/drivers/usbhost/usbhost_hidkbd.c index 2987effce8..2148d47a0a 100644 --- a/drivers/usbhost/usbhost_hidkbd.c +++ b/drivers/usbhost/usbhost_hidkbd.c @@ -2028,7 +2028,7 @@ static int usbhost_disconnected(struct usbhost_class_s *usbclass) * perhaps, destroy the class instance. Then it will exit. */ - (void)kill(priv->pollpid, SIGALRM); + (void)nxsig_kill(priv->pollpid, SIGALRM); } else { @@ -2184,7 +2184,7 @@ static int usbhost_close(FAR struct file *filep) * signal that we use does not matter in this case. */ - (void)kill(priv->pollpid, SIGALRM); + (void)nxsig_kill(priv->pollpid, SIGALRM); } } } diff --git a/drivers/usbhost/usbhost_hidmouse.c b/drivers/usbhost/usbhost_hidmouse.c index 3c0afef7e1..32c00c302f 100644 --- a/drivers/usbhost/usbhost_hidmouse.c +++ b/drivers/usbhost/usbhost_hidmouse.c @@ -87,8 +87,8 @@ # warning "Worker thread support is required (CONFIG_SCHED_WORKQUEUE)" #endif -/* Signals must not be disabled as they are needed for kill. Need to have - * CONFIG_DISABLE_SIGNALS=n +/* Signals must not be disabled as they are needed for nxsig_kill. Need to + * have CONFIG_DISABLE_SIGNALS=n */ #ifdef CONFIG_DISABLE_SIGNALS @@ -2097,7 +2097,7 @@ static int usbhost_disconnected(struct usbhost_class_s *usbclass) * perhaps, destroy the class instance. Then it will exit. */ - (void)kill(priv->pollpid, SIGALRM); + (void)nxsig_kill(priv->pollpid, SIGALRM); } else { @@ -2273,7 +2273,7 @@ static int usbhost_close(FAR struct file *filep) * signal that we use does not matter in this case. */ - (void)kill(priv->pollpid, SIGALRM); + (void)nxsig_kill(priv->pollpid, SIGALRM); } } } diff --git a/drivers/usbhost/usbhost_xboxcontroller.c b/drivers/usbhost/usbhost_xboxcontroller.c index ff0132b6ef..ec8a2c48df 100644 --- a/drivers/usbhost/usbhost_xboxcontroller.c +++ b/drivers/usbhost/usbhost_xboxcontroller.c @@ -1730,7 +1730,7 @@ static int usbhost_disconnected(struct usbhost_class_s *usbclass) * perhaps, destroy the class instance. Then it will exit. */ - (void)kill(priv->pollpid, SIGALRM); + (void)nxsig_kill(priv->pollpid, SIGALRM); } else { @@ -1907,7 +1907,7 @@ static int usbhost_close(FAR struct file *filep) * signal that we use does not matter in this case. */ - (void)kill(priv->pollpid, SIGALRM); + (void)nxsig_kill(priv->pollpid, SIGALRM); } } } diff --git a/include/nuttx/signal.h b/include/nuttx/signal.h index 999bebbe17..c566c4b85f 100644 --- a/include/nuttx/signal.h +++ b/include/nuttx/signal.h @@ -51,6 +51,42 @@ struct timespec; /* Forward reference */ +/**************************************************************************** + * Name: nxsig_kill + * + * Description: + * The nxsig_kill() system call can be used to send any signal to any task. + * + * This is an internal OS interface. It is functionally equivalent to + * the POSIX standard kill() function but does not modify the appliation + * errno variable. + * + * Limitation: Sending of signals to 'process groups' is not + * supported in NuttX + * + * Parameters: + * pid - The id of the task to receive the signal. The POSIX nxsig_kill + * specification encodes process group information as zero and + * negative pid values. Only positive, non-zero values of pid are + * supported by this implementation. + * signo - The signal number to send. If signo is zero, no signal is + * sent, but all error checking is performed. + * + * Returned 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 An invalid signal was specified. + * EPERM The process does not have permission to send the + * signal to any of the target processes. + * ESRCH The pid or process group does not exist. + * ENOSYS Do not support sending signals to process groups. + * + ****************************************************************************/ + +int nxsig_kill(pid_t pid, int signo); + /**************************************************************************** * Name: nxsig_waitinfo * diff --git a/mm/mm_heap/mm_sem.c b/mm/mm_heap/mm_sem.c index 4d547299d3..99f519f134 100644 --- a/mm/mm_heap/mm_sem.c +++ b/mm/mm_heap/mm_sem.c @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -155,7 +156,7 @@ int mm_trysemaphore(FAR struct mm_heap_s *heap) return ret; } - /* We have it. Claim the stak and return */ + /* We have it. Claim the heap and return */ heap->mm_holder = my_pid; heap->mm_counts_held = 1; diff --git a/sched/paging/pg_miss.c b/sched/paging/pg_miss.c index c3eb14cb7c..6bec634e06 100644 --- a/sched/paging/pg_miss.c +++ b/sched/paging/pg_miss.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/paging/pg_miss.c * - * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Copyright (C) 2010, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -45,6 +45,7 @@ #include #include #include +#include #ifdef CONFIG_PAGING @@ -172,7 +173,7 @@ void pg_miss(void) if (!g_pftcb) { pginfo("Signaling worker. PID: %d\n", g_pgworker); - kill(g_pgworker, SIGWORK); + (void)nxsig_kill(g_pgworker, SIGWORK); } } diff --git a/sched/paging/pg_worker.c b/sched/paging/pg_worker.c index 4c52e549cf..1c8ee188a4 100644 --- a/sched/paging/pg_worker.c +++ b/sched/paging/pg_worker.c @@ -2,7 +2,7 @@ * sched/paging/pg_worker.c * Page fill worker thread implementation. * - * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2010-2011, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -52,6 +52,7 @@ #include #include #include +#include #include "sched/sched.h" #include "paging/paging.h" @@ -200,7 +201,7 @@ static void pg_callback(FAR struct tcb_s *tcb, int result) /* Signal the page fill worker thread (in any event) */ pginfo("Signaling worker. PID: %d\n", g_pgworker); - kill(g_pgworker, SIGWORK); + (void)nxsig_kill(g_pgworker, SIGWORK); } #endif diff --git a/sched/pthread/pthread_kill.c b/sched/pthread/pthread_kill.c index d6b5d14a8e..21b18f8a52 100644 --- a/sched/pthread/pthread_kill.c +++ b/sched/pthread/pthread_kill.c @@ -1,7 +1,8 @@ /**************************************************************************** * sched/pthread/pthread_kill.c * - * Copyright (C) 2007, 2009, 2011, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011, 2015, 2017 Gregory Nutt. All rights + * reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -59,8 +60,8 @@ * * Description: * The pthread_kill() system call can be used to send any signal to a - * thread. See kill() for further information as this is just a simple - * wrapper around the kill() function. + * thread. See nxsig_kill() for further information as this is just a + * simple wrapper around the nxsig_kill() function. * * Parameters: * thread - The id of the thread to receive the signal. Only positive, @@ -79,18 +80,16 @@ * specified by the given thread ID * ENOSYS Do not support sending signals to process groups. * - * Assumptions: - * ****************************************************************************/ int pthread_kill(pthread_t thread, int signo) { #ifdef HAVE_GROUP_MEMBERS - /* If group members are supported then pthread_kill() differs from kill(). - * kill(), in this case, must follow the POSIX rules for delivery of - * signals in the group environment. Otherwise, kill(), like - * pthread_kill() will just deliver the signal to the thread ID it is - * requested to use. + /* If group members are supported then pthread_kill() differs from + * nxsig_kill(). nxsig_kill(), in this case, must follow the POSIX rules + * for delivery of signals in the group environment. Otherwise, + * nxsig_kill(), like pthread_kill() will just deliver the signal to the + * thread ID it is requested to use. */ #ifdef CONFIG_SCHED_HAVE_PARENT @@ -153,18 +152,10 @@ errout: #else /* If group members are not supported then pthread_kill is basically the - * same as kill(). + * same as nxsig_kill() other than the sign of the returned value. */ - int ret; - - set_errno(EINVAL); - ret = kill((pid_t)thread, signo); - if (ret != OK) - { - ret = get_errno(); - } - - return ret; + int ret = nxsig_kill((pid_t)thread, signo); + return (ret < 0) ? -ret : OK; #endif } diff --git a/sched/sched/sched_waitid.c b/sched/sched/sched_waitid.c index 697178ec1e..15af9cc1cf 100644 --- a/sched/sched/sched_waitid.c +++ b/sched/sched/sched_waitid.c @@ -327,11 +327,11 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options) } else { - /* We can use kill() with signal number 0 to determine if that - * task is still alive. + /* We can use nxsig_kill() with signal number 0 to determine if + * that task is still alive. */ - ret = kill((pid_t)id, 0); + ret = nxsig_kill((pid_t)id, 0); if (ret < 0) { /* It is no longer running. We know that the child task @@ -353,9 +353,9 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options) */ if (rtcb->group->tg_nchildren == 0 || - (idtype == P_PID && (ret = kill((pid_t)id, 0)) < 0)) + (idtype == P_PID && (ret = nxsig_kill((pid_t)id, 0)) < 0)) { - /* We know that the child task was running okay we stared, + /* We know that the child task was running okay we started, * so we must have lost the signal. What can we do? * Let's return ECHILD.. that is at least informative. */ diff --git a/sched/sched/sched_waitpid.c b/sched/sched/sched_waitpid.c index b2b341eea9..1763ee966f 100644 --- a/sched/sched/sched_waitpid.c +++ b/sched/sched/sched_waitpid.c @@ -486,11 +486,11 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) } else { - /* We can use kill() with signal number 0 to determine if that - * task is still alive. + /* We can use nxsig_kill() with signal number 0 to determine if + * that task is still alive. */ - ret = kill(pid, 0); + ret = nxsig_kill(pid, 0); if (ret < 0) { /* It is no longer running. We know that the child task @@ -514,9 +514,9 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) */ if (rtcb->group->tg_nchildren == 0 || - (pid != (pid_t)-1 && (ret = kill(pid, 0)) < 0)) + (pid != (pid_t)-1 && (ret = nxsig_kill(pid, 0)) < 0)) { - /* We know that the child task was running okay we stared, + /* We know that the child task was running okay we started, * so we must have lost the signal. What can we do? * Let's return ECHILD.. that is at least informative. */ diff --git a/sched/signal/sig_kill.c b/sched/signal/sig_kill.c index a357c5fbaa..fcf09ddd7a 100644 --- a/sched/signal/sig_kill.c +++ b/sched/signal/sig_kill.c @@ -1,7 +1,8 @@ /**************************************************************************** * sched/signal/sig_kill.c * - * Copyright (C) 2007, 2009, 2011, 2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011, 2013, 2015, 2017 Gregory Nutt. All + * rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -52,16 +53,20 @@ ****************************************************************************/ /**************************************************************************** - * Name: kill + * Name: nxsig_kill * * Description: - * The kill() system call can be used to send any signal to any task. + * The nxsig_kill() system call can be used to send any signal to any task. + * + * This is an internal OS interface. It is functionally equivalent to + * the POSIX standard kill() function but does not modify the appliation + * errno variable. * * Limitation: Sending of signals to 'process groups' is not * supported in NuttX * * Parameters: - * pid - The id of the task to receive the signal. The POSIX kill + * pid - The id of the task to receive the signal. The POSIX nxsig_kill * specification encodes process group information as zero and * negative pid values. Only positive, non-zero values of pid are * supported by this implementation. @@ -69,8 +74,9 @@ * sent, but all error checking is performed. * * Returned Value: - * On success (at least one signal was sent), zero is returned. On - * error, -1 is returned, and errno is set appropriately: + * 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 An invalid signal was specified. * EPERM The process does not have permission to send the @@ -78,11 +84,9 @@ * ESRCH The pid or process group does not exist. * ENOSYS Do not support sending signals to process groups. * - * Assumptions: - * ****************************************************************************/ -int kill(pid_t pid, int signo) +int nxsig_kill(pid_t pid, int signo) { #ifdef CONFIG_SCHED_HAVE_PARENT FAR struct tcb_s *rtcb = this_task(); @@ -94,16 +98,14 @@ int kill(pid_t pid, int signo) if (pid <= 0) { - ret = -ENOSYS; - goto errout; + return -ENOSYS; } /* Make sure that the signal is valid */ if (!GOOD_SIGNO(signo)) { - ret = -EINVAL; - goto errout; + return -EINVAL; } /* Keep things stationary through the following */ @@ -124,16 +126,53 @@ int kill(pid_t pid, int signo) /* Send the signal */ ret = nxsig_dispatch(pid, &info); - sched_unlock(); + sched_unlock(); + return ret; +} + +/**************************************************************************** + * Name: kill + * + * Description: + * The kill() system call can be used to send any signal to any task. + * + * Limitation: Sending of signals to 'process groups' is not + * supported in NuttX + * + * Parameters: + * pid - The id of the task to receive the signal. The POSIX kill + * specification encodes process group information as zero and + * negative pid values. Only positive, non-zero values of pid are + * supported by this implementation. + * signo - The signal number to send. If signo is zero, no signal is + * sent, but all error checking is performed. + * + * Returned Value: + * This is a standard POSIX application interface. On success (at least + * one signal was sent), zero (OK) is returned. On any failure , -1 + * (ERROR) is returned, and errno is set appropriately: + * + * EINVAL An invalid signal was specified. + * EPERM The process does not have permission to send the + * signal to any of the target processes. + * ESRCH The pid or process group does not exist. + * ENOSYS Do not support sending signals to process groups. + * + ****************************************************************************/ + +int kill(pid_t pid, int signo) +{ + int ret; + + /* Let nxsem_kill() do all of the work */ + + ret = nxsig_kill(pid, signo); if (ret < 0) { - goto errout; + set_errno(-ret); + ret = ERROR; } - return OK; - -errout: - set_errno(-ret); - return ERROR; + return ret; } diff --git a/sched/wqueue/kwork_signal.c b/sched/wqueue/kwork_signal.c index 9c5b9a8e97..2efec2ea45 100644 --- a/sched/wqueue/kwork_signal.c +++ b/sched/wqueue/kwork_signal.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/wqueue/work_signal.c * - * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -43,6 +43,7 @@ #include #include +#include #include "wqueue/wqueue.h" @@ -64,14 +65,13 @@ * qid - The work queue ID * * Returned Value: - * Zero on success, a negated errno on failure + * Zero (OK) on success, a negated errno value on failure * ****************************************************************************/ int work_signal(int qid) { pid_t pid; - int ret; /* Get the process ID of the worker thread */ @@ -120,14 +120,7 @@ int work_signal(int qid) /* Signal the worker thread */ - ret = kill(pid, SIGWORK); - if (ret < 0) - { - int errcode = errno; - return -errcode; - } - - return OK; + return nxsig_kill(pid, SIGWORK); } #endif /* CONFIG_SCHED_WORKQUEUE */