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:
parent
7154fc09ff
commit
9e25d89223
@ -45,6 +45,7 @@
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/signal.h>
|
||||
#include <nuttx/fs/fs.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)
|
||||
{
|
||||
DEBUGASSERT(dev != NULL);
|
||||
(void)kill(dev->gp_pid, dev->gp_signo);
|
||||
(void)nxsig_kill(dev->gp_pid, dev->gp_signo);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <semaphore.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
|
||||
@ -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;
|
||||
|
@ -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 <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -45,6 +45,7 @@
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/sched.h>
|
||||
#include <nuttx/page.h>
|
||||
#include <nuttx/signal.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -52,6 +52,7 @@
|
||||
#include <nuttx/signal.h>
|
||||
#include <nuttx/page.h>
|
||||
#include <nuttx/clock.h>
|
||||
#include <nuttx/signal.h>
|
||||
|
||||
#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
|
||||
|
||||
|
@ -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 <gnutt@nuttx.org>
|
||||
*
|
||||
* 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
|
||||
}
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -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 <gnutt@nuttx.org>
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
|
@ -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 <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -43,6 +43,7 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/wqueue.h>
|
||||
#include <nuttx/signal.h>
|
||||
|
||||
#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 */
|
||||
|
Loading…
Reference in New Issue
Block a user