Add option to disable background commands

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@865 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2008-09-02 12:35:30 +00:00
parent 51ca48986f
commit aa598de791
5 changed files with 45 additions and 23 deletions

View File

@ -117,6 +117,13 @@ examples/nsh
if-then[-else]-fi construct. This would only be set on systems if-then[-else]-fi construct. This would only be set on systems
where a minimal footprint is a necessity and scripting is not. where a minimal footprint is a necessity and scripting is not.
* CONFIG_EXAMPLES_NSH_DISABLEBG
This can be set to 'y' to suppress support for background
commands. This setting disables the 'nice' command prefix and
the '&' command suffix. This would only be set on systems
where a minimal footprint is a necessity and background command
execution is not.
* CONFIG_EXAMPLES_NSH_CONSOLE * CONFIG_EXAMPLES_NSH_CONSOLE
If CONFIG_EXAMPLES_NSH_CONSOLE is set to 'y', then a serial If CONFIG_EXAMPLES_NSH_CONSOLE is set to 'y', then a serial
console front-end is selected. console front-end is selected.

View File

@ -49,10 +49,13 @@
* Definitions * Definitions
****************************************************************************/ ****************************************************************************/
/* The telnetd interface requires pthread support */ /* The telnetd interface and background commands require pthread support */
#ifdef CONFIG_DISABLE_PTHREAD #ifdef CONFIG_DISABLE_PTHREAD
# undef CONFIG_EXAMPLES_NSH_TELNET # undef CONFIG_EXAMPLES_NSH_TELNET
# ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
# define CONFIG_EXAMPLES_NSH_DISABLEBG 1
# endif
#endif #endif
/* One front end must be defined */ /* One front end must be defined */
@ -114,6 +117,8 @@
# define CONFIG_LIB_HOMEDIR "/" # define CONFIG_LIB_HOMEDIR "/"
#endif #endif
/* Method access macros */
#define nsh_clone(v) (v)->clone(v) #define nsh_clone(v) (v)->clone(v)
#define nsh_release(v) (v)->release(v) #define nsh_release(v) (v)->release(v)
#define nsh_linebuffer(v) (v)->linebuffer(v) #define nsh_linebuffer(v) (v)->linebuffer(v)
@ -127,6 +132,8 @@
# define nsh_output vtbl->output # define nsh_output vtbl->output
#endif #endif
/* Size of info to be saved in call to nsh_redirect */
#define SAVE_SIZE (sizeof(int) + sizeof(FILE*) + sizeof(boolean)) #define SAVE_SIZE (sizeof(int) + sizeof(FILE*) + sizeof(boolean))
/* Stubs used when working directory is not supported */ /* Stubs used when working directory is not supported */
@ -158,7 +165,7 @@ struct nsh_state_s
struct nsh_parser_s struct nsh_parser_s
{ {
#ifndef CONFIG_DISABLE_PTHREAD #ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
boolean np_bg; /* TRUE: The last command executed in background */ boolean np_bg; /* TRUE: The last command executed in background */
#endif #endif
boolean np_redirect; /* TRUE: Output from the last command was re-directed */ boolean np_redirect; /* TRUE: Output from the last command was re-directed */
@ -166,7 +173,7 @@ struct nsh_parser_s
#ifndef CONFIG_EXAMPLES_NSH_DISABLESCRIPT #ifndef CONFIG_EXAMPLES_NSH_DISABLESCRIPT
ubyte np_ndx; /* Current index into np_st[] */ ubyte np_ndx; /* Current index into np_st[] */
#endif #endif
#ifndef CONFIG_DISABLE_PTHREAD #ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
int np_nice; /* "nice" value applied to last background cmd */ int np_nice; /* "nice" value applied to last background cmd */
#endif #endif
@ -187,7 +194,7 @@ struct nsh_vtbl_s
* of the front end. * of the front end.
*/ */
#ifndef CONFIG_DISABLE_PTHREAD #ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
FAR struct nsh_vtbl_s *(*clone)(FAR struct nsh_vtbl_s *vtbl); FAR struct nsh_vtbl_s *(*clone)(FAR struct nsh_vtbl_s *vtbl);
void (*addref)(FAR struct nsh_vtbl_s *vtbl); void (*addref)(FAR struct nsh_vtbl_s *vtbl);
void (*release)(FAR struct nsh_vtbl_s *vtbl); void (*release)(FAR struct nsh_vtbl_s *vtbl);

View File

@ -50,7 +50,7 @@
#include <errno.h> #include <errno.h>
#include <debug.h> #include <debug.h>
#ifndef CONFIG_DISABLE_PTHREAD #ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
# include <pthread.h> # include <pthread.h>
#endif #endif
@ -72,7 +72,7 @@
* Maximum size is NSH_MAX_ARGUMENTS+5 * Maximum size is NSH_MAX_ARGUMENTS+5
*/ */
#ifndef CONFIG_DISABLE_PTHREAD #ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
# define MAX_ARGV_ENTRIES (NSH_MAX_ARGUMENTS+5) # define MAX_ARGV_ENTRIES (NSH_MAX_ARGUMENTS+5)
#else #else
# define MAX_ARGV_ENTRIES (NSH_MAX_ARGUMENTS+4) # define MAX_ARGV_ENTRIES (NSH_MAX_ARGUMENTS+4)
@ -97,7 +97,7 @@ struct cmdmap_s
const char *usage; /* Usage instructions for 'help' command */ const char *usage; /* Usage instructions for 'help' command */
}; };
#ifndef CONFIG_DISABLE_PTHREAD #ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
struct cmdarg_s struct cmdarg_s
{ {
FAR struct nsh_vtbl_s *vtbl; /* For front-end interaction */ FAR struct nsh_vtbl_s *vtbl; /* For front-end interaction */
@ -238,7 +238,7 @@ static int cmd_help(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
const struct cmdmap_s *ptr; const struct cmdmap_s *ptr;
nsh_output(vtbl, "NSH command forms:\n"); nsh_output(vtbl, "NSH command forms:\n");
#ifndef CONFIG_DISABLE_PTHREAD #ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
nsh_output(vtbl, " [nice [-d <niceness>>]] <cmd> [> <file>|>> <file>] [&]\n"); nsh_output(vtbl, " [nice [-d <niceness>>]] <cmd> [> <file>|>> <file>] [&]\n");
#else #else
nsh_output(vtbl, " <cmd> [> <file>|>> <file>]\n"); nsh_output(vtbl, " <cmd> [> <file>|>> <file>]\n");
@ -353,7 +353,7 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl, int argc, char *argv[])
* Name: nsh_releaseargs * Name: nsh_releaseargs
****************************************************************************/ ****************************************************************************/
#ifndef CONFIG_DISABLE_PTHREAD #ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
static void nsh_releaseargs(struct cmdarg_s *arg) static void nsh_releaseargs(struct cmdarg_s *arg)
{ {
FAR struct nsh_vtbl_s *vtbl = arg->vtbl; FAR struct nsh_vtbl_s *vtbl = arg->vtbl;
@ -387,7 +387,7 @@ static void nsh_releaseargs(struct cmdarg_s *arg)
* Name: nsh_child * Name: nsh_child
****************************************************************************/ ****************************************************************************/
#ifndef CONFIG_DISABLE_PTHREAD #ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
static pthread_addr_t nsh_child(pthread_addr_t arg) static pthread_addr_t nsh_child(pthread_addr_t arg)
{ {
struct cmdarg_s *carg = (struct cmdarg_s *)arg; struct cmdarg_s *carg = (struct cmdarg_s *)arg;
@ -411,7 +411,7 @@ static pthread_addr_t nsh_child(pthread_addr_t arg)
* Name: nsh_cloneargs * Name: nsh_cloneargs
****************************************************************************/ ****************************************************************************/
#ifndef CONFIG_DISABLE_PTHREAD #ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
static inline struct cmdarg_s *nsh_cloneargs(FAR struct nsh_vtbl_s *vtbl, static inline struct cmdarg_s *nsh_cloneargs(FAR struct nsh_vtbl_s *vtbl,
int fd, int argc, char *argv[]) int fd, int argc, char *argv[])
{ {
@ -770,7 +770,7 @@ static inline int nsh_saveresult(FAR struct nsh_vtbl_s *vtbl, boolean result)
* Name: nsh_nice * Name: nsh_nice
****************************************************************************/ ****************************************************************************/
#ifndef CONFIG_DISABLE_PTHREAD #ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
static inline int nsh_nice(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd, FAR char **saveptr) static inline int nsh_nice(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd, FAR char **saveptr)
{ {
FAR char *cmd = *ppcmd; FAR char *cmd = *ppcmd;
@ -900,7 +900,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
/* Initialize parser state */ /* Initialize parser state */
memset(argv, 0, MAX_ARGV_ENTRIES*sizeof(FAR char *)); memset(argv, 0, MAX_ARGV_ENTRIES*sizeof(FAR char *));
#ifndef CONFIG_DISABLE_PTHREAD #ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
vtbl->np.np_bg = FALSE; vtbl->np.np_bg = FALSE;
#endif #endif
vtbl->np.np_redirect = FALSE; vtbl->np.np_redirect = FALSE;
@ -921,7 +921,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
/* Handle nice */ /* Handle nice */
#ifndef CONFIG_DISABLE_PTHREAD #ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
if (nsh_nice(vtbl, &cmd, &saveptr) != 0) if (nsh_nice(vtbl, &cmd, &saveptr) != 0)
{ {
goto errout; goto errout;
@ -972,7 +972,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
/* Check if the command should run in background */ /* Check if the command should run in background */
#ifndef CONFIG_DISABLE_PTHREAD #ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
if (argc > 1 && strcmp(argv[argc-1], "&") == 0) if (argc > 1 && strcmp(argv[argc-1], "&") == 0)
{ {
vtbl->np.np_bg = TRUE; vtbl->np.np_bg = TRUE;
@ -1036,7 +1036,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
/* Handle the case where the command is executed in background */ /* Handle the case where the command is executed in background */
#ifndef CONFIG_DISABLE_PTHREAD #ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
if (vtbl->np.np_bg) if (vtbl->np.np_bg)
{ {
struct sched_param param; struct sched_param param;
@ -1164,7 +1164,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
return nsh_saveresult(vtbl, FALSE); return nsh_saveresult(vtbl, FALSE);
#ifndef CONFIG_DISABLE_PTHREAD #ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
errout_with_redirect: errout_with_redirect:
if (vtbl->np.np_redirect) if (vtbl->np.np_redirect)
{ {

View File

@ -74,7 +74,7 @@ struct serialsave_s
* Private Function Prototypes * Private Function Prototypes
****************************************************************************/ ****************************************************************************/
#ifndef CONFIG_DISABLE_PTHREAD #ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
static FAR struct nsh_vtbl_s *nsh_consoleclone(FAR struct nsh_vtbl_s *vtbl); static FAR struct nsh_vtbl_s *nsh_consoleclone(FAR struct nsh_vtbl_s *vtbl);
static void nsh_consolerelease(FAR struct nsh_vtbl_s *vtbl); static void nsh_consolerelease(FAR struct nsh_vtbl_s *vtbl);
#endif #endif
@ -105,7 +105,7 @@ static inline FAR struct serial_s *nsh_allocstruct(void)
struct serial_s *pstate = (struct serial_s *)zalloc(sizeof(struct serial_s)); struct serial_s *pstate = (struct serial_s *)zalloc(sizeof(struct serial_s));
if (pstate) if (pstate)
{ {
#ifndef CONFIG_DISABLE_PTHREAD #ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
pstate->ss_vtbl.clone = nsh_consoleclone; pstate->ss_vtbl.clone = nsh_consoleclone;
pstate->ss_vtbl.release = nsh_consolerelease; pstate->ss_vtbl.release = nsh_consolerelease;
#endif #endif
@ -223,7 +223,7 @@ static FAR char *nsh_consolelinebuffer(FAR struct nsh_vtbl_s *vtbl)
* *
****************************************************************************/ ****************************************************************************/
#ifndef CONFIG_DISABLE_PTHREAD #ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
static FAR struct nsh_vtbl_s *nsh_consoleclone(FAR struct nsh_vtbl_s *vtbl) static FAR struct nsh_vtbl_s *nsh_consoleclone(FAR struct nsh_vtbl_s *vtbl)
{ {
FAR struct serial_s *pstate = (FAR struct serial_s *)vtbl; FAR struct serial_s *pstate = (FAR struct serial_s *)vtbl;
@ -251,7 +251,7 @@ static FAR struct nsh_vtbl_s *nsh_consoleclone(FAR struct nsh_vtbl_s *vtbl)
* *
****************************************************************************/ ****************************************************************************/
#ifndef CONFIG_DISABLE_PTHREAD #ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
static void nsh_consolerelease(FAR struct nsh_vtbl_s *vtbl) static void nsh_consolerelease(FAR struct nsh_vtbl_s *vtbl)
{ {
FAR struct serial_s *pstate = (FAR struct serial_s *)vtbl; FAR struct serial_s *pstate = (FAR struct serial_s *)vtbl;
@ -291,7 +291,7 @@ static void nsh_consoleredirect(FAR struct nsh_vtbl_s *vtbl, int fd, FAR ubyte *
} }
/**************************************************************************** /****************************************************************************
* Name: nsh_consoleredirect * Name: nsh_consoleundirect
* *
* Description: * Description:
* Set up for redirected output * Set up for redirected output

View File

@ -131,8 +131,10 @@ struct telnetd_s
* Private Function Prototypes * Private Function Prototypes
****************************************************************************/ ****************************************************************************/
#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
static void tio_semtake(struct telnetio_s *tio); static void tio_semtake(struct telnetio_s *tio);
static FAR struct nsh_vtbl_s *nsh_telnetclone(FAR struct nsh_vtbl_s *vtbl); static FAR struct nsh_vtbl_s *nsh_telnetclone(FAR struct nsh_vtbl_s *vtbl);
#endif
static void nsh_telnetrelease(FAR struct nsh_vtbl_s *vtbl); static void nsh_telnetrelease(FAR struct nsh_vtbl_s *vtbl);
static int nsh_telnetoutput(FAR struct nsh_vtbl_s *vtbl, const char *fmt, ...); static int nsh_telnetoutput(FAR struct nsh_vtbl_s *vtbl, const char *fmt, ...);
static int nsh_redirectoutput(FAR struct nsh_vtbl_s *vtbl, const char *fmt, ...); static int nsh_redirectoutput(FAR struct nsh_vtbl_s *vtbl, const char *fmt, ...);
@ -228,8 +230,10 @@ static FAR struct telnetd_s *nsh_allocstruct(void)
struct telnetd_s *pstate = (struct telnetd_s *)zalloc(sizeof(struct telnetd_s)); struct telnetd_s *pstate = (struct telnetd_s *)zalloc(sizeof(struct telnetd_s));
if (pstate) if (pstate)
{ {
#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
pstate->tn_vtbl.clone = nsh_telnetclone; pstate->tn_vtbl.clone = nsh_telnetclone;
pstate->tn_vtbl.release = nsh_telnetrelease; pstate->tn_vtbl.release = nsh_telnetrelease;
#endif
pstate->tn_vtbl.output = nsh_telnetoutput; pstate->tn_vtbl.output = nsh_telnetoutput;
pstate->tn_vtbl.linebuffer = nsh_telnetlinebuffer; pstate->tn_vtbl.linebuffer = nsh_telnetlinebuffer;
pstate->tn_vtbl.redirect = nsh_telnetredirect; pstate->tn_vtbl.redirect = nsh_telnetredirect;
@ -673,6 +677,7 @@ static FAR char *nsh_telnetlinebuffer(FAR struct nsh_vtbl_s *vtbl)
* *
****************************************************************************/ ****************************************************************************/
#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
static FAR struct nsh_vtbl_s *nsh_telnetclone(FAR struct nsh_vtbl_s *vtbl) static FAR struct nsh_vtbl_s *nsh_telnetclone(FAR struct nsh_vtbl_s *vtbl)
{ {
FAR struct telnetd_s *pstate = (FAR struct telnetd_s *)vtbl; FAR struct telnetd_s *pstate = (FAR struct telnetd_s *)vtbl;
@ -696,6 +701,7 @@ static FAR struct nsh_vtbl_s *nsh_telnetclone(FAR struct nsh_vtbl_s *vtbl)
} }
return ret; return ret;
} }
#endif
/**************************************************************************** /****************************************************************************
* Name: nsh_telnetrelease * Name: nsh_telnetrelease
@ -705,6 +711,7 @@ static FAR struct nsh_vtbl_s *nsh_telnetclone(FAR struct nsh_vtbl_s *vtbl)
* *
****************************************************************************/ ****************************************************************************/
#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
static void nsh_telnetrelease(FAR struct nsh_vtbl_s *vtbl) static void nsh_telnetrelease(FAR struct nsh_vtbl_s *vtbl)
{ {
FAR struct telnetd_s *pstate = (FAR struct telnetd_s *)vtbl; FAR struct telnetd_s *pstate = (FAR struct telnetd_s *)vtbl;
@ -719,6 +726,7 @@ static void nsh_telnetrelease(FAR struct nsh_vtbl_s *vtbl)
} }
free(pstate); free(pstate);
} }
#endif
/**************************************************************************** /****************************************************************************
* Name: nsh_telnetredirect * Name: nsh_telnetredirect
@ -755,7 +763,7 @@ static void nsh_telnetredirect(FAR struct nsh_vtbl_s *vtbl, int fd, FAR ubyte *s
} }
/**************************************************************************** /****************************************************************************
* Name: nsh_telnetredirect * Name: nsh_telnetundirect
* *
* Description: * Description:
* Set up for redirected output * Set up for redirected output