Skip to content

Commit 7937627

Browse files
wangchdoextinguish
andcommitted
sched/signal: Add support to disable partial signals
Fix dependency issue when signals are only partially enabled Co-authored-by: guoshichao <guoshichao@xiaomi.com> Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
1 parent 0045d8b commit 7937627

File tree

10 files changed

+80
-28
lines changed

10 files changed

+80
-28
lines changed

examples/buttons/buttons_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,11 @@ static int button_daemon(int argc, char *argv[])
219219
goto errout_with_fd;
220220
}
221221

222+
#ifdef CONFIG_ENABLE_ALL_SIGNALS
222223
/* Ignore the default signal action */
223224

224225
signal(CONFIG_EXAMPLES_BUTTONS_SIGNO, SIG_IGN);
226+
#endif
225227
#endif
226228

227229
/* Now loop forever, waiting BUTTONs events */

examples/chrono/chrono_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,11 @@ static int chrono_daemon(int argc, char *argv[])
165165
goto errout_with_fd;
166166
}
167167

168+
#ifdef CONFIG_ENABLE_ALL_SIGNALS
168169
/* Ignore the default signal action */
169170

170171
signal(BUTTON_SIGNO, SIG_IGN);
172+
#endif
171173

172174
/* Now loop forever, waiting BUTTONs events */
173175

examples/timer/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
config EXAMPLES_TIMER
77
tristate "Timer example"
88
default n
9-
depends on TIMER
9+
depends on TIMER && ENABLE_ALL_SIGNALS
1010
---help---
1111
Enable the timer example
1212

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_ALL_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_ALL_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+
#ifdef CONFIG_ENABLE_ALL_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_ALL_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+
#ifdef CONFIG_ENABLE_ALL_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+
#ifdef CONFIG_ENABLE_ALL_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+
#ifdef CONFIG_ENABLE_ALL_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_ENABLE_ALL_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_ENABLE_ALL_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_ENABLE_ALL_SIGNALS */
117117

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

nshlib/nsh_builtin.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,14 @@ int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
7474
FAR char **argv,
7575
FAR const struct nsh_param_s *param)
7676
{
77-
#if !defined(CONFIG_NSH_DISABLEBG) && defined(CONFIG_SCHED_CHILD_STATUS)
77+
#if !defined(CONFIG_NSH_DISABLEBG) && defined(CONFIG_SCHED_CHILD_STATUS) && \
78+
defined(CONFIG_ENABLE_ALL_SIGNALS)
7879
struct sigaction act;
7980
struct sigaction old;
80-
#endif
81+
#endif /* !CONFIG_NSH_DISABLEBG && CONFIG_SCHED_CHILD_STATUS &&
82+
* CONFIG_ENABLE_ALL_SIGNALS
83+
*/
84+
8185
int ret = OK;
8286

8387
/* Lock the scheduler in an attempt to prevent the application from
@@ -86,7 +90,8 @@ int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
8690

8791
sched_lock();
8892

89-
#if !defined(CONFIG_NSH_DISABLEBG) && defined(CONFIG_SCHED_CHILD_STATUS)
93+
#if !defined(CONFIG_NSH_DISABLEBG) && \
94+
defined(CONFIG_SCHED_CHILD_STATUS) && defined(CONFIG_ENABLE_ALL_SIGNALS)
9095
/* Ignore the child status if run the application on background. */
9196

9297
if (vtbl->np.np_bg == true)
@@ -98,7 +103,9 @@ int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
98103
sigaction(SIGCHLD, &act, &old);
99104
}
100105

101-
#endif /* CONFIG_NSH_DISABLEBG */
106+
#endif /* !CONFIG_NSH_DISABLEBG && !CONFIG_SCHED_CHILD_STATUS &&
107+
* CONFIG_ENABLE_ALL_SIGNALS
108+
*/
102109

103110
/* Try to find and execute the command within the list of builtin
104111
* applications.
@@ -230,7 +237,8 @@ int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
230237

231238
#if !defined(CONFIG_SCHED_WAITPID) || !defined(CONFIG_NSH_DISABLEBG)
232239
{
233-
#if !defined(CONFIG_NSH_DISABLEBG) && defined(CONFIG_SCHED_CHILD_STATUS)
240+
#if !defined(CONFIG_NSH_DISABLEBG) && defined(CONFIG_SCHED_CHILD_STATUS) && \
241+
defined(CONFIG_ENABLE_ALL_SIGNALS)
234242

235243
/* Restore the old actions */
236244

@@ -241,7 +249,10 @@ int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
241249
sigaction(SIGCHLD, &old, NULL);
242250
}
243251

244-
# endif
252+
# endif /* !CONFIG_NSH_DISABLEBG && CONFIG_SCHED_CHILD_STATUS && \
253+
* CONFIG_ENABLE_ALL_SIGNALS
254+
*/
255+
245256
struct sched_param sched;
246257
sched_getparam(ret, &sched);
247258
nsh_output(vtbl, "%s [%d:%d]\n", cmd, ret, sched.sched_priority);

nshlib/nsh_proccmds.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,7 @@ static int top_cmpcpuload(FAR const void *item1, FAR const void *item2)
873873
}
874874
}
875875

876+
#ifdef CONFIG_ENABLE_FULL_SIGNALS
876877
/****************************************************************************
877878
* Name: top_exit
878879
****************************************************************************/
@@ -882,6 +883,8 @@ static void top_exit(int signo, FAR siginfo_t *siginfo, FAR void *context)
882883
*(FAR bool *)siginfo->si_user = true;
883884
}
884885

886+
#endif /* CONFIG_ENABLE_FULL_SIGNALS */
887+
885888
#endif
886889

887890
/****************************************************************************
@@ -1357,7 +1360,9 @@ int cmd_top(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
13571360
FAR char *pidlist = NULL;
13581361
size_t num = SIZE_MAX;
13591362
size_t i;
1363+
#ifdef CONFIG_ENABLE_FULL_SIGNALS
13601364
struct sigaction act;
1365+
#endif
13611366
bool quit = false;
13621367
int delay = 3;
13631368
int ret = 0;
@@ -1393,6 +1398,7 @@ int cmd_top(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
13931398
}
13941399
}
13951400

1401+
#ifdef CONFIG_ENABLE_FULL_SIGNALS
13961402
act.sa_user = &quit;
13971403
act.sa_sigaction = top_exit;
13981404
sigemptyset(&act.sa_mask);
@@ -1402,6 +1408,7 @@ int cmd_top(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
14021408
nsh_error(vtbl, g_fmtcmdfailed, "top", "sigaction", NSH_ERRNO);
14031409
return ERROR;
14041410
}
1411+
#endif
14051412

14061413
if (vtbl->isctty)
14071414
{

system/cu/cu_main.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,12 @@ static FAR void *cu_listener(FAR void *parameter)
124124
return NULL;
125125
}
126126

127+
#ifdef CONFIG_ENABLE_ALL_SIGNALS
127128
static void sigint(int sig)
128129
{
129130
g_cu.force_exit = true;
130131
}
132+
#endif
131133

132134
#ifdef CONFIG_SERIAL_TERMIOS
133135
static int set_termios(FAR struct cu_globals_s *cu, int rate,
@@ -275,7 +277,9 @@ static int cu_cmd(FAR struct cu_globals_s *cu, char bcmd)
275277
int main(int argc, FAR char *argv[])
276278
{
277279
pthread_attr_t attr;
280+
#ifdef CONFIG_ENABLE_ALL_SIGNALS
278281
struct sigaction sa;
282+
#endif
279283
FAR const char *devname = CONFIG_SYSTEM_CUTERM_DEFAULT_DEVICE;
280284
FAR struct cu_globals_s *cu = &g_cu;
281285
#ifdef CONFIG_SERIAL_TERMIOS
@@ -295,13 +299,13 @@ int main(int argc, FAR char *argv[])
295299

296300
memset(cu, 0, sizeof(*cu));
297301
cu->escape = '~';
298-
302+
#ifdef CONFIG_ENABLE_ALL_SIGNALS
299303
/* Install signal handlers */
300304

301305
memset(&sa, 0, sizeof(sa));
302306
sa.sa_handler = sigint;
303307
sigaction(SIGINT, &sa, NULL);
304-
308+
#endif
305309
optind = 0; /* Global that needs to be reset in FLAT mode */
306310
while ((option = getopt(argc, argv, "l:s:ceE:fho?")) != ERROR)
307311
{
@@ -474,7 +478,7 @@ int main(int argc, FAR char *argv[])
474478
}
475479

476480
if (start_of_line == 1 && ch == cu->escape)
477-
{
481+
{
478482
/* Normal character */
479483

480484
if (i > nwrite)
@@ -484,27 +488,27 @@ int main(int argc, FAR char *argv[])
484488

485489
nwrite = i + 1;
486490

487-
/* We've seen and escape (~) character, echo it to local
488-
* terminal and read the next char from serial
489-
*/
491+
/* We've seen and escape (~) character, echo it to local
492+
* terminal and read the next char from serial
493+
*/
490494

491-
write(STDOUT_FILENO, &ch, 1);
495+
write(STDOUT_FILENO, &ch, 1);
492496
start_of_line = 0;
493497
escaping = true;
494498
continue;
495499
}
496500

497-
/* Determine if we are now at the start of a new line or not */
501+
/* Determine if we are now at the start of a new line or not */
498502

499-
if (ch == '\n' || ch == '\r')
500-
{
501-
start_of_line = 1;
502-
}
503-
else
504-
{
505-
start_of_line = 0;
506-
}
503+
if (ch == '\n' || ch == '\r')
504+
{
505+
start_of_line = 1;
506+
}
507+
else
508+
{
509+
start_of_line = 0;
507510
}
511+
}
508512

509513
/* Normal character */
510514

testing/ostest/ostest_main.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ static int user_main(int argc, char *argv[])
278278
* verify that status is retained correctly.
279279
*/
280280

281-
#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS)
281+
#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) && \
282+
defined(CONFIG_ENABLE_ALL_SIGNALS)
282283
{
283284
struct sigaction sa;
284285
int ret;
@@ -511,6 +512,7 @@ static int user_main(int argc, char *argv[])
511512
check_test_memory_usage();
512513
#endif
513514

515+
#ifdef CONFIG_ENABLE_ALL_SIGNALS
514516
/* Verify that we can modify the signal mask */
515517

516518
printf("\nuser_main: sigprocmask test\n");
@@ -534,18 +536,22 @@ static int user_main(int argc, char *argv[])
534536
check_test_memory_usage();
535537
#endif
536538

539+
#endif /* CONFIG_DISABLE_ALL_SIGNALS */
540+
537541
#ifdef CONFIG_BUILD_FLAT
538542
printf("\nuser_main: wdog test\n");
539543
wdog_test();
540544
check_test_memory_usage();
541545
#endif
542546

543547
#ifndef CONFIG_DISABLE_POSIX_TIMERS
548+
#ifdef CONFIG_ENABLE_ALL_SIGNALS
544549
/* Verify posix timers (with SIGEV_SIGNAL) */
545550

546551
printf("\nuser_main: POSIX timer test\n");
547552
timer_test();
548553
check_test_memory_usage();
554+
#endif
549555

550556
#ifdef CONFIG_SIG_EVTHREAD
551557
/* Verify posix timers (with SIGEV_THREAD) */
@@ -705,7 +711,7 @@ int main(int argc, FAR char **argv)
705711
stdio_test();
706712

707713
#ifdef SDCC
708-
/* I am not yet certain why SDCC does not like the following initilizers.
714+
/* I am not yet certain why SDCC does not like the following initializers.
709715
* It involves some issues with 2- vs 3-byte pointer types.
710716
*/
711717

0 commit comments

Comments
 (0)