summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-09-02 12:35:30 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-09-02 12:35:30 +0000
commite2ce5d030925d1dd181d873b9f8a96ba5661a177 (patch)
tree41be2c630836828804f1ae8fa7ea9cacee77e6c5
parent16fdd6a9d18d44d4915b5285718c7a127090cf86 (diff)
downloadnuttx-e2ce5d030925d1dd181d873b9f8a96ba5661a177.tar.gz
nuttx-e2ce5d030925d1dd181d873b9f8a96ba5661a177.tar.bz2
nuttx-e2ce5d030925d1dd181d873b9f8a96ba5661a177.zip
Add option to disable background commands
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@865 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--nuttx/examples/README.txt7
-rw-r--r--nuttx/examples/nsh/nsh.h15
-rw-r--r--nuttx/examples/nsh/nsh_main.c26
-rw-r--r--nuttx/examples/nsh/nsh_serial.c10
-rw-r--r--nuttx/examples/nsh/nsh_telnetd.c10
5 files changed, 45 insertions, 23 deletions
diff --git a/nuttx/examples/README.txt b/nuttx/examples/README.txt
index 4847d3d25..4cbec9515 100644
--- a/nuttx/examples/README.txt
+++ b/nuttx/examples/README.txt
@@ -117,6 +117,13 @@ examples/nsh
if-then[-else]-fi construct. This would only be set on systems
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
If CONFIG_EXAMPLES_NSH_CONSOLE is set to 'y', then a serial
console front-end is selected.
diff --git a/nuttx/examples/nsh/nsh.h b/nuttx/examples/nsh/nsh.h
index 7afade195..9203d7c0f 100644
--- a/nuttx/examples/nsh/nsh.h
+++ b/nuttx/examples/nsh/nsh.h
@@ -49,10 +49,13 @@
* Definitions
****************************************************************************/
-/* The telnetd interface requires pthread support */
+/* The telnetd interface and background commands require pthread support */
#ifdef CONFIG_DISABLE_PTHREAD
# undef CONFIG_EXAMPLES_NSH_TELNET
+# ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
+# define CONFIG_EXAMPLES_NSH_DISABLEBG 1
+# endif
#endif
/* One front end must be defined */
@@ -114,6 +117,8 @@
# define CONFIG_LIB_HOMEDIR "/"
#endif
+/* Method access macros */
+
#define nsh_clone(v) (v)->clone(v)
#define nsh_release(v) (v)->release(v)
#define nsh_linebuffer(v) (v)->linebuffer(v)
@@ -127,6 +132,8 @@
# define nsh_output vtbl->output
#endif
+/* Size of info to be saved in call to nsh_redirect */
+
#define SAVE_SIZE (sizeof(int) + sizeof(FILE*) + sizeof(boolean))
/* Stubs used when working directory is not supported */
@@ -158,7 +165,7 @@ struct nsh_state_s
struct nsh_parser_s
{
-#ifndef CONFIG_DISABLE_PTHREAD
+#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
boolean np_bg; /* TRUE: The last command executed in background */
#endif
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
ubyte np_ndx; /* Current index into np_st[] */
#endif
-#ifndef CONFIG_DISABLE_PTHREAD
+#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
int np_nice; /* "nice" value applied to last background cmd */
#endif
@@ -187,7 +194,7 @@ struct nsh_vtbl_s
* 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);
void (*addref)(FAR struct nsh_vtbl_s *vtbl);
void (*release)(FAR struct nsh_vtbl_s *vtbl);
diff --git a/nuttx/examples/nsh/nsh_main.c b/nuttx/examples/nsh/nsh_main.c
index 01f5ed690..a70d2176d 100644
--- a/nuttx/examples/nsh/nsh_main.c
+++ b/nuttx/examples/nsh/nsh_main.c
@@ -50,7 +50,7 @@
#include <errno.h>
#include <debug.h>
-#ifndef CONFIG_DISABLE_PTHREAD
+#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
# include <pthread.h>
#endif
@@ -72,7 +72,7 @@
* Maximum size is NSH_MAX_ARGUMENTS+5
*/
-#ifndef CONFIG_DISABLE_PTHREAD
+#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
# define MAX_ARGV_ENTRIES (NSH_MAX_ARGUMENTS+5)
#else
# define MAX_ARGV_ENTRIES (NSH_MAX_ARGUMENTS+4)
@@ -97,7 +97,7 @@ struct cmdmap_s
const char *usage; /* Usage instructions for 'help' command */
};
-#ifndef CONFIG_DISABLE_PTHREAD
+#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
struct cmdarg_s
{
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;
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");
#else
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
****************************************************************************/
-#ifndef CONFIG_DISABLE_PTHREAD
+#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
static void nsh_releaseargs(struct cmdarg_s *arg)
{
FAR struct nsh_vtbl_s *vtbl = arg->vtbl;
@@ -387,7 +387,7 @@ static void nsh_releaseargs(struct cmdarg_s *arg)
* Name: nsh_child
****************************************************************************/
-#ifndef CONFIG_DISABLE_PTHREAD
+#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
static pthread_addr_t nsh_child(pthread_addr_t 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
****************************************************************************/
-#ifndef CONFIG_DISABLE_PTHREAD
+#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
static inline struct cmdarg_s *nsh_cloneargs(FAR struct nsh_vtbl_s *vtbl,
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
****************************************************************************/
-#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)
{
FAR char *cmd = *ppcmd;
@@ -900,7 +900,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
/* Initialize parser state */
memset(argv, 0, MAX_ARGV_ENTRIES*sizeof(FAR char *));
-#ifndef CONFIG_DISABLE_PTHREAD
+#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
vtbl->np.np_bg = FALSE;
#endif
vtbl->np.np_redirect = FALSE;
@@ -921,7 +921,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
/* Handle nice */
-#ifndef CONFIG_DISABLE_PTHREAD
+#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
if (nsh_nice(vtbl, &cmd, &saveptr) != 0)
{
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 */
-#ifndef CONFIG_DISABLE_PTHREAD
+#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
if (argc > 1 && strcmp(argv[argc-1], "&") == 0)
{
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 */
-#ifndef CONFIG_DISABLE_PTHREAD
+#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
if (vtbl->np.np_bg)
{
struct sched_param param;
@@ -1164,7 +1164,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
return nsh_saveresult(vtbl, FALSE);
-#ifndef CONFIG_DISABLE_PTHREAD
+#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
errout_with_redirect:
if (vtbl->np.np_redirect)
{
diff --git a/nuttx/examples/nsh/nsh_serial.c b/nuttx/examples/nsh/nsh_serial.c
index 4ffcc84b2..94ebca267 100644
--- a/nuttx/examples/nsh/nsh_serial.c
+++ b/nuttx/examples/nsh/nsh_serial.c
@@ -74,7 +74,7 @@ struct serialsave_s
* 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 void nsh_consolerelease(FAR struct nsh_vtbl_s *vtbl);
#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));
if (pstate)
{
-#ifndef CONFIG_DISABLE_PTHREAD
+#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
pstate->ss_vtbl.clone = nsh_consoleclone;
pstate->ss_vtbl.release = nsh_consolerelease;
#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)
{
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)
{
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:
* Set up for redirected output
diff --git a/nuttx/examples/nsh/nsh_telnetd.c b/nuttx/examples/nsh/nsh_telnetd.c
index 052970877..d3cce9971 100644
--- a/nuttx/examples/nsh/nsh_telnetd.c
+++ b/nuttx/examples/nsh/nsh_telnetd.c
@@ -131,8 +131,10 @@ struct telnetd_s
* Private Function Prototypes
****************************************************************************/
+#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
static void tio_semtake(struct telnetio_s *tio);
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 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, ...);
@@ -228,8 +230,10 @@ static FAR struct telnetd_s *nsh_allocstruct(void)
struct telnetd_s *pstate = (struct telnetd_s *)zalloc(sizeof(struct telnetd_s));
if (pstate)
{
+#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG
pstate->tn_vtbl.clone = nsh_telnetclone;
pstate->tn_vtbl.release = nsh_telnetrelease;
+#endif
pstate->tn_vtbl.output = nsh_telnetoutput;
pstate->tn_vtbl.linebuffer = nsh_telnetlinebuffer;
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)
{
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;
}
+#endif
/****************************************************************************
* 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)
{
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);
}
+#endif
/****************************************************************************
* 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:
* Set up for redirected output