Skip to content

Commit d76ab4f

Browse files
committed
netutils: make the net tools can work with signal disabled
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
1 parent 3dcdb38 commit d76ab4f

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

netutils/dhcpc/dhcpc.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,16 @@ static void *dhcpc_run(void *args)
533533
struct dhcpc_state result;
534534
int ret;
535535

536+
#ifdef CONFIG_DISABLE_SIGNALS
537+
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
538+
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
539+
#endif
540+
536541
while (1)
537542
{
543+
#ifdef CONFIG_DISABLE_SIGNALS
544+
pthread_testcancel();
545+
#endif
538546
ret = dhcpc_request(pdhcpc, &result);
539547
if (ret == OK)
540548
{
@@ -701,7 +709,9 @@ void dhcpc_close(FAR void *handle)
701709
void dhcpc_cancel(FAR void *handle)
702710
{
703711
struct dhcpc_state_s *pdhcpc = (struct dhcpc_state_s *)handle;
712+
#ifndef CONFIG_DISABLE_SIGNALS
704713
sighandler_t old;
714+
#endif
705715
int ret;
706716

707717
if (pdhcpc)
@@ -710,6 +720,9 @@ void dhcpc_cancel(FAR void *handle)
710720

711721
if (pdhcpc->thread)
712722
{
723+
#ifdef CONFIG_DISABLE_SIGNALS
724+
pthread_cancel(pdhcpc->thread);
725+
#else
713726
old = signal(SIGQUIT, SIG_IGN);
714727

715728
/* Signal the dhcpc_run */
@@ -719,6 +732,7 @@ void dhcpc_cancel(FAR void *handle)
719732
{
720733
nerr("ERROR: pthread_kill DHCPC thread\n");
721734
}
735+
#endif
722736

723737
/* Wait for the end of dhcpc_run */
724738

@@ -729,7 +743,9 @@ void dhcpc_cancel(FAR void *handle)
729743
}
730744

731745
pdhcpc->thread = 0;
746+
#ifndef CONFIG_DISABLE_SIGNALS
732747
signal(SIGQUIT, old);
748+
#endif
733749
}
734750
}
735751
}

netutils/ping/icmp_ping.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ static volatile bool g_exiting;
9191
* Private Functions
9292
****************************************************************************/
9393

94+
#ifndef CONFIG_DISABLE_SIGNALS
9495
/****************************************************************************
9596
* Name: sigexit
9697
****************************************************************************/
@@ -99,6 +100,7 @@ static void sigexit(int signo)
99100
{
100101
g_exiting = true;
101102
}
103+
#endif
102104

103105
/****************************************************************************
104106
* Name: ping_newid
@@ -199,7 +201,9 @@ void icmp_ping(FAR const struct ping_info_s *info)
199201
int i;
200202

201203
g_exiting = false;
204+
#ifndef CONFIG_DISABLE_SIGNALS
202205
signal(SIGINT, sigexit);
206+
#endif
203207

204208
/* Initialize result structure */
205209

netutils/telnetd/telnetd_daemon.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ int telnetd_daemon(FAR const struct telnetd_config_s *config)
7474
#endif
7575
} addr;
7676

77-
#ifdef CONFIG_SCHED_HAVE_PARENT
77+
#if defined(CONFIG_SCHED_HAVE_PARENT) && !defined(CONFIG_DISABLE_SIGNALS)
7878
struct sigaction sa;
7979
sigset_t blockset;
8080
#endif
@@ -85,7 +85,7 @@ int telnetd_daemon(FAR const struct telnetd_config_s *config)
8585
int optval;
8686
#endif
8787

88-
#ifdef CONFIG_SCHED_HAVE_PARENT
88+
#if defined(CONFIG_SCHED_HAVE_PARENT) && !defined(CONFIG_DISABLE_SIGNALS)
8989
/* Call sigaction with the SA_NOCLDWAIT flag so that we do not transform
9090
* children into "zombies" when they terminate: Child exit status will
9191
* not be retained.
@@ -113,7 +113,7 @@ int telnetd_daemon(FAR const struct telnetd_config_s *config)
113113
nerr("ERROR: sigprocmask failed: %d\n", errno);
114114
goto errout;
115115
}
116-
#endif /* CONFIG_SCHED_HAVE_PARENT */
116+
#endif /* CONFIG_SCHED_HAVE_PARENT && !CONFIG_DISABLE_SIGNALS */
117117

118118
/* Create a new TCP socket to use to listen for connections */
119119

0 commit comments

Comments
 (0)