diff --git a/include/nshlib/nshlib.h b/include/nshlib/nshlib.h index 1e7084d96..1e0db818f 100644 --- a/include/nshlib/nshlib.h +++ b/include/nshlib/nshlib.h @@ -42,6 +42,8 @@ #include +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ diff --git a/system/nsh/Makefile b/system/nsh/Makefile index 232404b91..166ca6a81 100644 --- a/system/nsh/Makefile +++ b/system/nsh/Makefile @@ -37,9 +37,9 @@ # NuttShell (NSH) Example -MAINSRC = nsh_main.c +MAINSRC = nsh_main.c sh_main.c -PROGNAME = $(CONFIG_SYSTEM_NSH_PROGNAME) +PROGNAME = $(CONFIG_SYSTEM_NSH_PROGNAME) sh PRIORITY = $(CONFIG_SYSTEM_NSH_PRIORITY) STACKSIZE = $(CONFIG_SYSTEM_NSH_STACKSIZE) MODULE = $(CONFIG_SYSTEM_NSH) diff --git a/system/nsh/nsh_main.c b/system/nsh/nsh_main.c index 7ebcf8078..5c20be036 100644 --- a/system/nsh/nsh_main.c +++ b/system/nsh/nsh_main.c @@ -80,17 +80,6 @@ # undef CONFIG_SYSTEM_NSH_SYMTAB #endif -/* Check if we need to build in support for the system() and/or popen() - * functions. In the KERNEL build mode (only), NSH is build as a ELF - * program and must be capable of executing a single command provided - * on the command line. - */ - -#undef HAVE_NSH_COMMAND -#if defined(CONFIG_SYSTEM_SYSTEM) || defined(CONFIG_SYSTEM_POPEN) -# define HAVE_NSH_COMMAND 1 -#endif - /* C++ initialization requires CXX initializer support */ #if !defined(CONFIG_HAVE_CXX) || !defined(CONFIG_HAVE_CXXINITIALIZE) @@ -115,11 +104,11 @@ extern const int CONFIG_SYSTEM_NSH_SYMTAB_COUNTNAME; #endif /**************************************************************************** - * Private Functions + * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: nsh_task + * Name: nsh_main * * Description: * This is the main logic for the case of the NSH task. It will perform @@ -128,14 +117,26 @@ extern const int CONFIG_SYSTEM_NSH_SYMTAB_COUNTNAME; * ****************************************************************************/ -static int nsh_task(void) +int main(int argc, FAR char *argv[]) { #if defined (CONFIG_SYSTEM_NSH_SYMTAB) struct boardioc_symtab_s symdesc; #endif + struct sched_param param; int exitval = 0; int ret; + /* Check the task priority that we were started with */ + + sched_getparam(0, ¶m); + if (param.sched_priority != CONFIG_SYSTEM_NSH_PRIORITY) + { + /* If not then set the priority to the configured priority */ + + param.sched_priority = CONFIG_SYSTEM_NSH_PRIORITY; + sched_setparam(0, ¶m); + } + #if defined(CONFIG_SYSTEM_NSH_CXXINITIALIZE) /* Call all C++ static constructors */ @@ -190,51 +191,3 @@ static int nsh_task(void) return exitval; } - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_main - ****************************************************************************/ - -int main(int argc, FAR char *argv[]) -{ - struct sched_param param; - - /* Check the task priority that we were started with */ - - sched_getparam(0, ¶m); - if (param.sched_priority != CONFIG_SYSTEM_NSH_PRIORITY) - { - /* If not then set the priority to the configured priority */ - - param.sched_priority = CONFIG_SYSTEM_NSH_PRIORITY; - sched_setparam(0, ¶m); - } - - /* There are two modes that NSH can be executed in: - * - * 1) As a normal, interactive shell. In this case, no arguments are - * expected on the command line. OR - * 2) As a single command processor. In this case, the single command is - * is provided in argv[1]. - * - * NOTE: The latter mode is only available if CONFIG_SYSTEM_NSH=m. - * In that case, this main() function will be built as a process. The - * process will be started with a command by the implementations of the - * system() and popen() interfaces. - */ - -#ifdef HAVE_NSH_COMMAND - if (argc > 1) - { - return nsh_system(argc, argv); - } - else -#endif - { - return nsh_task(); - } -} diff --git a/system/nsh/sh_main.c b/system/nsh/sh_main.c new file mode 100644 index 000000000..345097d47 --- /dev/null +++ b/system/nsh/sh_main.c @@ -0,0 +1,53 @@ +/**************************************************************************** + * system/nsh/sh_main.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include "nshlib/nshlib.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sh_main + ****************************************************************************/ + +int main(int argc, FAR char *argv[]) +{ + /* There are two modes that NSH can be executed in: + * + * 1) As a normal, interactive shell. In this case, no arguments are + * expected on the command line. OR + * 2) As a single command processor. In this case, the single command is + * is provided in argv[1]. + * + * NOTE: The latter mode is only available if CONFIG_SYSTEM_NSH=m. + * In that case, this main() function will be built as a process. The + * process will be started with a command by the implementations of the + * system() and popen() interfaces. + */ + + return nsh_system(argc, argv); +} diff --git a/system/popen/Kconfig b/system/popen/Kconfig index 9c7527baa..14a245fb0 100644 --- a/system/popen/Kconfig +++ b/system/popen/Kconfig @@ -17,7 +17,7 @@ if SYSTEM_POPEN config SYSTEM_POPEN_SHPATH string "Path to shell command" - default "/bin/nsh" + default "/bin/sh" depends on SYSTEM_NSH=m ---help--- This is the full path to the program in a mounted file system that diff --git a/system/system/Kconfig b/system/system/Kconfig index 36be798e4..60af65449 100644 --- a/system/system/Kconfig +++ b/system/system/Kconfig @@ -16,7 +16,7 @@ if SYSTEM_SYSTEM config SYSTEM_SYSTEM_SHPATH string "Path to shell command" - default "/bin/nsh" + default "/bin/sh" depends on SYSTEM_NSH=m ---help--- This is the full path to the program in a mounted file system that