mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 05:16:47 +08:00
driverts/net/telnet.c: Refine Ctrl+C handling in telnet driver
Refine Ctrl-C handling in telnet driver to avoid issue the kill more than once Change-Id: I9fcec5d861ea85258170f379d741d2bb8e4d9b9e Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
+20
-31
@@ -309,7 +309,7 @@ static inline void telnet_dumpbuffer(FAR const char *msg,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: telnet_check_ctrl_char
|
* Name: telnet_check_ctrlchar
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Check if an incoming control character should generate a signal.
|
* Check if an incoming control character should generate a signal.
|
||||||
@@ -317,34 +317,31 @@ static inline void telnet_dumpbuffer(FAR const char *msg,
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef HAVE_SIGNALS
|
#ifdef HAVE_SIGNALS
|
||||||
static void telnet_check_ctrl_char (FAR struct telnet_dev_s *priv,
|
static void telnet_check_ctrlchar(FAR struct telnet_dev_s *priv,
|
||||||
uint8_t ch)
|
FAR char *buffer, size_t len)
|
||||||
{
|
{
|
||||||
int signo = 0;
|
int signo = 0;
|
||||||
|
|
||||||
#ifdef CONFIG_TTY_SIGINT
|
for (; priv->pid >= 0 && len > 0; buffer++, len--)
|
||||||
/* Is this the special character that will generate the SIGINT signal? */
|
|
||||||
|
|
||||||
if (priv->pid >= 0 && ch == CONFIG_TTY_SIGINT_CHAR)
|
|
||||||
{
|
{
|
||||||
/* Yes.. note that the kill is needed and do not put the character
|
#ifdef CONFIG_TTY_SIGINT
|
||||||
* into the Rx buffer. It should not be read as normal data.
|
/* Is this the special character that will generate the SIGINT signal? */
|
||||||
*/
|
|
||||||
|
|
||||||
signo = SIGINT;
|
if (*buffer == CONFIG_TTY_SIGINT_CHAR)
|
||||||
}
|
{
|
||||||
else
|
/* Yes.. note that the kill is needed and do not put the character
|
||||||
|
* into the Rx buffer. It should not be read as normal data.
|
||||||
|
*/
|
||||||
|
|
||||||
|
signo = SIGINT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_TTY_SIGSTP
|
#ifdef CONFIG_TTY_SIGSTP
|
||||||
/* Is this the special character that will generate the SIGSTP signal? */
|
/* Is this the special character that will generate the SIGSTP signal? */
|
||||||
|
|
||||||
if (priv->pid >= 0 && ch == CONFIG_TTY_SIGSTP_CHAR)
|
if (*buffer == CONFIG_TTY_SIGSTP_CHAR)
|
||||||
{
|
|
||||||
#ifdef CONFIG_TTY_SIGINT
|
|
||||||
/* Give precedence to SIGINT */
|
|
||||||
|
|
||||||
if (signo == 0)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
/* Note that the kill is needed and do not put the character
|
/* Note that the kill is needed and do not put the character
|
||||||
* into the Rx buffer. It should not be read as normal data.
|
* into the Rx buffer. It should not be read as normal data.
|
||||||
@@ -352,17 +349,15 @@ static void telnet_check_ctrl_char (FAR struct telnet_dev_s *priv,
|
|||||||
|
|
||||||
signo = SIGSTP;
|
signo = SIGSTP;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGSTP)
|
|
||||||
/* Send the signal if necessary */
|
/* Send the signal if necessary */
|
||||||
|
|
||||||
if (signo != 0)
|
if (signo != 0)
|
||||||
{
|
{
|
||||||
kill(priv->pid, signo);
|
kill(priv->pid, signo);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1326,9 +1321,6 @@ static int telnet_io_main(int argc, FAR char** argv)
|
|||||||
FAR struct telnet_dev_s *priv;
|
FAR struct telnet_dev_s *priv;
|
||||||
FAR char *buffer;
|
FAR char *buffer;
|
||||||
int i;
|
int i;
|
||||||
#ifdef HAVE_SIGNALS
|
|
||||||
int c;
|
|
||||||
#endif
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
@@ -1396,10 +1388,7 @@ static int telnet_io_main(int argc, FAR char** argv)
|
|||||||
* control that should generate a signal.
|
* control that should generate a signal.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (c = 0; c < ret; c++)
|
telnet_check_ctrlchar(priv, buffer, ret);
|
||||||
{
|
|
||||||
telnet_check_ctrl_char(priv, buffer[c]);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user