Skip to content

Commit c50bad1

Browse files
system/init: Add NSH builtin support for action
Enable CONFIG_SYSTEM_SYSTEM to support nsh builtins, which depends on nsh. Signed-off-by: wangjianyu3 <[email protected]>
1 parent 024910b commit c50bad1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

system/init/builtin.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
****************************************************************************/
2626

2727
#include <errno.h>
28+
#include <stdlib.h>
2829
#include <string.h>
2930
#include <spawn.h>
3031
#include <sys/param.h>
32+
#include <sys/wait.h>
3133

3234
#include "builtin.h"
3335
#include "init.h"
@@ -192,6 +194,27 @@ int init_builtin_run(FAR struct action_manager_s *am,
192194
ret = posix_spawnp(&pid, argv[0], NULL, NULL, argv, NULL);
193195
if (ret != 0)
194196
{
197+
#ifdef CONFIG_SYSTEM_SYSTEM
198+
char cmd[CONFIG_SYSTEM_INIT_RC_LINE_MAX];
199+
200+
for (i = 0, cmd[i] = '\0'; i < argc; i++)
201+
{
202+
strlcat(cmd, argv[i], sizeof(cmd));
203+
if (i < argc - 1)
204+
{
205+
strcat(cmd, " ");
206+
}
207+
}
208+
209+
init_debug("executing NSH command '%s'", cmd);
210+
ret = system(cmd);
211+
if (WIFEXITED(ret))
212+
{
213+
init_debug("NSH command '%s' exited %d", cmd, WEXITSTATUS(ret));
214+
return -WEXITSTATUS(ret);
215+
}
216+
#endif
217+
195218
init_err("executing command '%s': %d", argv[0], ret);
196219
init_dump_args(argc, argv);
197220
return -ret;

0 commit comments

Comments
 (0)