Squashed commit of the following:

Replace all usage kill() in the OS proper with nxsig_kill().

    sched/signal:  Add nxsig_kill() which is functionally equivalent to kill() except that it does not modify the errno variable.
This commit is contained in:
Gregory Nutt 2017-10-07 08:22:18 -06:00
parent 7154fc09ff
commit 9e25d89223
14 changed files with 141 additions and 78 deletions

View File

@ -45,6 +45,7 @@
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <nuttx/signal.h>
#include <nuttx/fs/fs.h> #include <nuttx/fs/fs.h>
#include <nuttx/ioexpander/gpio.h> #include <nuttx/ioexpander/gpio.h>
@ -99,7 +100,7 @@ static const struct file_operations g_gpio_drvrops =
static int gpio_handler(FAR struct gpio_dev_s *dev) static int gpio_handler(FAR struct gpio_dev_s *dev)
{ {
DEBUGASSERT(dev != NULL); DEBUGASSERT(dev != NULL);
(void)kill(dev->gp_pid, dev->gp_signo); (void)nxsig_kill(dev->gp_pid, dev->gp_signo);
return OK; return OK;
} }

View File

@ -739,7 +739,7 @@ static int slip_rxtask(int argc, FAR char *argv[])
if (priv->dev.d_len > 0) if (priv->dev.d_len > 0)
{ {
slip_transmit(priv); slip_transmit(priv);
kill(priv->txpid, SIGALRM); (void)nxsig_kill(priv->txpid, SIGALRM);
} }
net_unlock(); net_unlock();
@ -840,7 +840,7 @@ static int slip_txavail(FAR struct net_driver_s *dev)
/* Wake up the TX polling thread */ /* Wake up the TX polling thread */
priv->txnodelay = true; priv->txnodelay = true;
kill(priv->txpid, SIGALRM); (void)nxsig_kill(priv->txpid, SIGALRM);
} }
return OK; return OK;

View File

@ -2028,7 +2028,7 @@ static int usbhost_disconnected(struct usbhost_class_s *usbclass)
* perhaps, destroy the class instance. Then it will exit. * perhaps, destroy the class instance. Then it will exit.
*/ */
(void)kill(priv->pollpid, SIGALRM); (void)nxsig_kill(priv->pollpid, SIGALRM);
} }
else else
{ {
@ -2184,7 +2184,7 @@ static int usbhost_close(FAR struct file *filep)
* signal that we use does not matter in this case. * signal that we use does not matter in this case.
*/ */
(void)kill(priv->pollpid, SIGALRM); (void)nxsig_kill(priv->pollpid, SIGALRM);
} }
} }
} }

View File

@ -87,8 +87,8 @@
# warning "Worker thread support is required (CONFIG_SCHED_WORKQUEUE)" # warning "Worker thread support is required (CONFIG_SCHED_WORKQUEUE)"
#endif #endif
/* Signals must not be disabled as they are needed for kill. Need to have /* Signals must not be disabled as they are needed for nxsig_kill. Need to
* CONFIG_DISABLE_SIGNALS=n * have CONFIG_DISABLE_SIGNALS=n
*/ */
#ifdef CONFIG_DISABLE_SIGNALS #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. * perhaps, destroy the class instance. Then it will exit.
*/ */
(void)kill(priv->pollpid, SIGALRM); (void)nxsig_kill(priv->pollpid, SIGALRM);
} }
else else
{ {
@ -2273,7 +2273,7 @@ static int usbhost_close(FAR struct file *filep)
* signal that we use does not matter in this case. * signal that we use does not matter in this case.
*/ */
(void)kill(priv->pollpid, SIGALRM); (void)nxsig_kill(priv->pollpid, SIGALRM);
} }
} }
} }

View File

@ -1730,7 +1730,7 @@ static int usbhost_disconnected(struct usbhost_class_s *usbclass)
* perhaps, destroy the class instance. Then it will exit. * perhaps, destroy the class instance. Then it will exit.
*/ */
(void)kill(priv->pollpid, SIGALRM); (void)nxsig_kill(priv->pollpid, SIGALRM);
} }
else else
{ {
@ -1907,7 +1907,7 @@ static int usbhost_close(FAR struct file *filep)
* signal that we use does not matter in this case. * signal that we use does not matter in this case.
*/ */
(void)kill(priv->pollpid, SIGALRM); (void)nxsig_kill(priv->pollpid, SIGALRM);
} }
} }
} }

View File

@ -51,6 +51,42 @@
struct timespec; /* Forward reference */ 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 * Name: nxsig_waitinfo
* *

View File

@ -40,6 +40,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <unistd.h> #include <unistd.h>
#include <semaphore.h>
#include <errno.h> #include <errno.h>
#include <assert.h> #include <assert.h>
@ -155,7 +156,7 @@ int mm_trysemaphore(FAR struct mm_heap_s *heap)
return ret; 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_holder = my_pid;
heap->mm_counts_held = 1; heap->mm_counts_held = 1;

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* sched/paging/pg_miss.c * 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 <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -45,6 +45,7 @@
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/sched.h> #include <nuttx/sched.h>
#include <nuttx/page.h> #include <nuttx/page.h>
#include <nuttx/signal.h>
#ifdef CONFIG_PAGING #ifdef CONFIG_PAGING
@ -172,7 +173,7 @@ void pg_miss(void)
if (!g_pftcb) if (!g_pftcb)
{ {
pginfo("Signaling worker. PID: %d\n", g_pgworker); pginfo("Signaling worker. PID: %d\n", g_pgworker);
kill(g_pgworker, SIGWORK); (void)nxsig_kill(g_pgworker, SIGWORK);
} }
} }

View File

@ -2,7 +2,7 @@
* sched/paging/pg_worker.c * sched/paging/pg_worker.c
* Page fill worker thread implementation. * 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 <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -52,6 +52,7 @@
#include <nuttx/signal.h> #include <nuttx/signal.h>
#include <nuttx/page.h> #include <nuttx/page.h>
#include <nuttx/clock.h> #include <nuttx/clock.h>
#include <nuttx/signal.h>
#include "sched/sched.h" #include "sched/sched.h"
#include "paging/paging.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) */ /* Signal the page fill worker thread (in any event) */
pginfo("Signaling worker. PID: %d\n", g_pgworker); pginfo("Signaling worker. PID: %d\n", g_pgworker);
kill(g_pgworker, SIGWORK); (void)nxsig_kill(g_pgworker, SIGWORK);
} }
#endif #endif

View File

@ -1,7 +1,8 @@
/**************************************************************************** /****************************************************************************
* sched/pthread/pthread_kill.c * 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 <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -59,8 +60,8 @@
* *
* Description: * Description:
* The pthread_kill() system call can be used to send any signal to a * 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 * thread. See nxsig_kill() for further information as this is just a
* wrapper around the kill() function. * simple wrapper around the nxsig_kill() function.
* *
* Parameters: * Parameters:
* thread - The id of the thread to receive the signal. Only positive, * thread - The id of the thread to receive the signal. Only positive,
@ -79,18 +80,16 @@
* specified by the given thread ID * specified by the given thread ID
* ENOSYS Do not support sending signals to process groups. * ENOSYS Do not support sending signals to process groups.
* *
* Assumptions:
*
****************************************************************************/ ****************************************************************************/
int pthread_kill(pthread_t thread, int signo) int pthread_kill(pthread_t thread, int signo)
{ {
#ifdef HAVE_GROUP_MEMBERS #ifdef HAVE_GROUP_MEMBERS
/* If group members are supported then pthread_kill() differs from kill(). /* If group members are supported then pthread_kill() differs from
* kill(), in this case, must follow the POSIX rules for delivery of * nxsig_kill(). nxsig_kill(), in this case, must follow the POSIX rules
* signals in the group environment. Otherwise, kill(), like * for delivery of signals in the group environment. Otherwise,
* pthread_kill() will just deliver the signal to the thread ID it is * nxsig_kill(), like pthread_kill() will just deliver the signal to the
* requested to use. * thread ID it is requested to use.
*/ */
#ifdef CONFIG_SCHED_HAVE_PARENT #ifdef CONFIG_SCHED_HAVE_PARENT
@ -153,18 +152,10 @@ errout:
#else #else
/* If group members are not supported then pthread_kill is basically the /* 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; int ret = nxsig_kill((pid_t)thread, signo);
return (ret < 0) ? -ret : OK;
set_errno(EINVAL);
ret = kill((pid_t)thread, signo);
if (ret != OK)
{
ret = get_errno();
}
return ret;
#endif #endif
} }

View File

@ -327,11 +327,11 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
} }
else else
{ {
/* We can use kill() with signal number 0 to determine if that /* We can use nxsig_kill() with signal number 0 to determine if
* task is still alive. * that task is still alive.
*/ */
ret = kill((pid_t)id, 0); ret = nxsig_kill((pid_t)id, 0);
if (ret < 0) if (ret < 0)
{ {
/* It is no longer running. We know that the child task /* 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 || 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? * so we must have lost the signal. What can we do?
* Let's return ECHILD.. that is at least informative. * Let's return ECHILD.. that is at least informative.
*/ */

View File

@ -486,11 +486,11 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options)
} }
else else
{ {
/* We can use kill() with signal number 0 to determine if that /* We can use nxsig_kill() with signal number 0 to determine if
* task is still alive. * that task is still alive.
*/ */
ret = kill(pid, 0); ret = nxsig_kill(pid, 0);
if (ret < 0) if (ret < 0)
{ {
/* It is no longer running. We know that the child task /* 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 || 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? * so we must have lost the signal. What can we do?
* Let's return ECHILD.. that is at least informative. * Let's return ECHILD.. that is at least informative.
*/ */

View File

@ -1,7 +1,8 @@
/**************************************************************************** /****************************************************************************
* sched/signal/sig_kill.c * 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 <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -52,16 +53,20 @@
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: kill * Name: nxsig_kill
* *
* Description: * 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 * Limitation: Sending of signals to 'process groups' is not
* supported in NuttX * supported in NuttX
* *
* Parameters: * 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 * specification encodes process group information as zero and
* negative pid values. Only positive, non-zero values of pid are * negative pid values. Only positive, non-zero values of pid are
* supported by this implementation. * supported by this implementation.
@ -69,8 +74,9 @@
* sent, but all error checking is performed. * sent, but all error checking is performed.
* *
* Returned Value: * Returned Value:
* On success (at least one signal was sent), zero is returned. On * This is an internal OS interface and should not be used by applications.
* error, -1 is returned, and errno is set appropriately: * 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. * EINVAL An invalid signal was specified.
* EPERM The process does not have permission to send the * EPERM The process does not have permission to send the
@ -78,11 +84,9 @@
* ESRCH The pid or process group does not exist. * ESRCH The pid or process group does not exist.
* ENOSYS Do not support sending signals to process groups. * 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 #ifdef CONFIG_SCHED_HAVE_PARENT
FAR struct tcb_s *rtcb = this_task(); FAR struct tcb_s *rtcb = this_task();
@ -94,16 +98,14 @@ int kill(pid_t pid, int signo)
if (pid <= 0) if (pid <= 0)
{ {
ret = -ENOSYS; return -ENOSYS;
goto errout;
} }
/* Make sure that the signal is valid */ /* Make sure that the signal is valid */
if (!GOOD_SIGNO(signo)) if (!GOOD_SIGNO(signo))
{ {
ret = -EINVAL; return -EINVAL;
goto errout;
} }
/* Keep things stationary through the following */ /* Keep things stationary through the following */
@ -124,16 +126,53 @@ int kill(pid_t pid, int signo)
/* Send the signal */ /* Send the signal */
ret = nxsig_dispatch(pid, &info); 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) if (ret < 0)
{ {
goto errout; set_errno(-ret);
ret = ERROR;
} }
return OK; return ret;
errout:
set_errno(-ret);
return ERROR;
} }

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* sched/wqueue/work_signal.c * 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 <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -43,6 +43,7 @@
#include <errno.h> #include <errno.h>
#include <nuttx/wqueue.h> #include <nuttx/wqueue.h>
#include <nuttx/signal.h>
#include "wqueue/wqueue.h" #include "wqueue/wqueue.h"
@ -64,14 +65,13 @@
* qid - The work queue ID * qid - The work queue ID
* *
* Returned Value: * 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) int work_signal(int qid)
{ {
pid_t pid; pid_t pid;
int ret;
/* Get the process ID of the worker thread */ /* Get the process ID of the worker thread */
@ -120,14 +120,7 @@ int work_signal(int qid)
/* Signal the worker thread */ /* Signal the worker thread */
ret = kill(pid, SIGWORK); return nxsig_kill(pid, SIGWORK);
if (ret < 0)
{
int errcode = errno;
return -errcode;
}
return OK;
} }
#endif /* CONFIG_SCHED_WORKQUEUE */ #endif /* CONFIG_SCHED_WORKQUEUE */