nshlib: Split shell functionality from nsh to sh
1.Improve the compatiblity as other OS 2.Avoid call nsh_initialize more than once Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
3f9302561c
commit
de8a56d149
@ -42,6 +42,8 @@
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
@ -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)
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
53
system/nsh/sh_main.c
Normal file
53
system/nsh/sh_main.c
Normal file
@ -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 <nuttx/config.h>
|
||||
|
||||
#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);
|
||||
}
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user