Skip to content

apps/system: replace CONFIG_NSH_LINELEN to LINE_MAX #2918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/lp503x/lp503x_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ static int lp503x_cmd_help(FAR char *parg)
int main(int argc, FAR char *argv[])
{
bool running;
char buffer[CONFIG_NSH_LINELEN];
char buffer[LINE_MAX];
int len;
int x;
char *cmd;
Expand Down
2 changes: 1 addition & 1 deletion netutils/rexec/rexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ static int do_rexec(FAR struct rexec_arg_s *arg)

int main(int argc, FAR char **argv)
{
char cmd[CONFIG_NSH_LINELEN];
char cmd[LINE_MAX];
struct rexec_arg_s arg;
int option;
int i;
Expand Down
2 changes: 1 addition & 1 deletion nshlib/nsh.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
/* Maximum size of one command line (telnet or serial) */

#ifndef CONFIG_NSH_LINELEN
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove CONFIG_NSH_LINELEN directly

# define CONFIG_NSH_LINELEN 80
# define CONFIG_NSH_LINELEN LINE_MAX
#endif

/* The maximum number of nested if-then[-else]-fi sequences that
Expand Down
14 changes: 14 additions & 0 deletions nshlib/nsh_console.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@ struct nsh_vtbl_s

bool isctty;

/* Trace line buffer */

#ifdef CONFIG_SCHED_INSTRUMENTATION_DUMP
char traceline[CONFIG_NSH_LINELEN];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but traceline is used only when launching program, isn't good to keep the buffer in the whole nsh life cycle

#endif

/* Temporary line buffer */

#if (!defined(CONFIG_NSH_DISABLE_MEMDUMP) && defined(NSH_HAVE_WRITEFILE)) || \
!defined(CONFIG_NSH_DISABLEBG) || defined(CONFIG_NSH_PIPELINE) || \
!defined(CONFIG_NSH_DISABLE_WATCH)
char templine[CONFIG_NSH_LINELEN];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but this will increase the heap consumption for the temp use case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compared with irregular heap access, shared template and will make it more deterministic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you split the rename from moving buffer to nsh_vtbl?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the temp buffer is only used in few command, why move it to nsh_vtbl to extend the life to the whole session?

#endif

/* Current working directory */

#ifdef CONFIG_DISABLE_ENVIRON
Expand Down
4 changes: 2 additions & 2 deletions nshlib/nsh_login.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ int nsh_login(FAR struct console_stdio_s *pstate)

/* readline() returns EOF on failure */

ret = readline_fd(pstate->cn_line, CONFIG_NSH_LINELEN,
ret = readline_fd(pstate->cn_line, sizeof(pstate->cn_line),
INFD(pstate), OUTFD(pstate));
if (ret != EOF)
{
Expand Down Expand Up @@ -207,7 +207,7 @@ int nsh_login(FAR struct console_stdio_s *pstate)
}

password[0] = '\0';
ret = readline_fd(pstate->cn_line, CONFIG_NSH_LINELEN,
ret = readline_fd(pstate->cn_line, sizeof(pstate->cn_line),
INFD(pstate), -1);

/* Enable echo again after password */
Expand Down
10 changes: 5 additions & 5 deletions nshlib/nsh_mmcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ int cmd_free(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)

int cmd_memdump(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
{
char arg[CONFIG_NSH_LINELEN] = "";
int i;

if (argc == 1)
{
strlcpy(arg, "used", CONFIG_NSH_LINELEN);
strlcpy(vtbl->templine, "used", sizeof(vtbl->templine));
}
else if (argc >= 2 && (strcmp(argv[1], "-h") == 0 ||
strcmp(argv[1], "help") == 0))
Expand All @@ -73,15 +72,16 @@ int cmd_memdump(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
{
for (i = 1; i < argc; i++)
{
strlcat(arg, argv[i], CONFIG_NSH_LINELEN);
strlcat(vtbl->templine, argv[i], sizeof(vtbl->templine));
if (i < argc - 1)
{
strlcat(arg, " ", CONFIG_NSH_LINELEN);
strlcat(vtbl->templine, " ", sizeof(vtbl->templine));
}
}
}

return nsh_writefile(vtbl, argv[0], arg, strlen(arg),
return nsh_writefile(vtbl, argv[0], vtbl->templine,
strlen(vtbl->templine),
CONFIG_NSH_PROC_MOUNTPOINT "/memdump");
}

Expand Down
29 changes: 13 additions & 16 deletions nshlib/nsh_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,25 +605,24 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl,
{
FAR char *sh_argv[4];
FAR char *sh_cmd = "sh";
char sh_arg2[CONFIG_NSH_LINELEN];

DEBUGASSERT(strncmp(argv[0], sh_cmd, 3) != 0);

sh_arg2[0] = '\0';
vtbl->templine[0] = '\0';

for (ret = 0; ret < argc; ret++)
{
strlcat(sh_arg2, argv[ret], sizeof(sh_arg2));
strlcat(vtbl->templine, argv[ret], sizeof(vtbl->templine));

if (ret < argc - 1)
{
strcat(sh_arg2, " ");
strcat(vtbl->templine, " ");
}
}

sh_argv[0] = sh_cmd;
sh_argv[1] = "-c";
sh_argv[2] = sh_arg2;
sh_argv[2] = vtbl->templine;
sh_argv[3] = NULL;

/* np.np_bg still there, try use nsh_builtin or nsh_fileapp to
Expand Down Expand Up @@ -2460,15 +2459,13 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline)
#endif

#ifdef CONFIG_SCHED_INSTRUMENTATION_DUMP
char tracebuf[CONFIG_NSH_LINELEN + 1];

strlcpy(tracebuf, cmdline, sizeof(tracebuf));
sched_note_beginex(NOTE_TAG_APP, tracebuf);
strlcpy(vtbl->traceline, cmdline, sizeof(vtbl->traceline));
sched_note_beginex(NOTE_TAG_APP, vtbl->traceline);
#endif

/* Initialize parser state */

memset(argv, 0, MAX_ARGV_ENTRIES*sizeof(FAR char *));
memset(argv, 0, MAX_ARGV_ENTRIES * sizeof(FAR char *));
NSH_MEMLIST_INIT(memlist);
NSH_ALIASLIST_INIT(alist);

Expand Down Expand Up @@ -2683,7 +2680,6 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline)
{
FAR char *arg;
FAR char *sh_argv[4];
char sh_arg2[CONFIG_NSH_LINELEN];

if (argv[argc][g_pipeline1_len])
{
Expand All @@ -2701,21 +2697,22 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline)
goto dynlist_free;
}

sh_arg2[0] = '\0';
vtbl->templine[0] = '\0';

for (ret = 0; ret < argc; ret++)
{
strlcat(sh_arg2, argv[ret], sizeof(sh_arg2));
strlcat(vtbl->templine, argv[ret],
sizeof(vtbl->templine));

if (ret < argc - 1)
{
strcat(sh_arg2, " ");
strcat(vtbl->templine, " ");
}
}

sh_argv[0] = "sh";
sh_argv[1] = "-c";
sh_argv[2] = sh_arg2;
sh_argv[2] = vtbl->templine;
sh_argv[3] = NULL;

ret = pipe2(pipefd, 0);
Expand Down Expand Up @@ -2827,7 +2824,7 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline)
NSH_ALIASLIST_FREE(vtbl, &alist);
NSH_MEMLIST_FREE(&memlist);
#ifdef CONFIG_SCHED_INSTRUMENTATION_DUMP
sched_note_endex(NOTE_TAG_APP, tracebuf);
sched_note_endex(NOTE_TAG_APP, vtbl->traceline);
#endif
return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions nshlib/nsh_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ int nsh_session(FAR struct console_stdio_s *pstate,
* occurs. Either will cause the session to terminate.
*/

ret = cle_fd(pstate->cn_line, nsh_prompt(), CONFIG_NSH_LINELEN,
ret = cle_fd(pstate->cn_line, nsh_prompt(), sizeof(pstate->cn_line),
INFD(pstate), OUTFD(pstate));
if (ret < 0)
{
Expand All @@ -225,7 +225,7 @@ int nsh_session(FAR struct console_stdio_s *pstate,
* will cause the session to terminate.
*/

ret = readline_fd(pstate->cn_line, CONFIG_NSH_LINELEN,
ret = readline_fd(pstate->cn_line, sizeof(pstate->cn_line),
INFD(pstate), OUTFD(pstate));
if (ret == EOF)
{
Expand Down
6 changes: 3 additions & 3 deletions nshlib/nsh_telnetlogin.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ int nsh_telnetlogin(FAR struct console_stdio_s *pstate)
write(OUTFD(pstate), g_userprompt, strlen(g_userprompt));

username[0] = '\0';
if (readline_fd(pstate->cn_line, CONFIG_NSH_LINELEN,
if (readline_fd(pstate->cn_line, sizeof(pstate->cn_line),
INFD(pstate), OUTFD(pstate)) >= 0)

{
Expand Down Expand Up @@ -212,8 +212,8 @@ int nsh_telnetlogin(FAR struct console_stdio_s *pstate)
}

password[0] = '\0';
ret = readline_fd(pstate->cn_line, CONFIG_NSH_LINELEN,
INFD(pstate), OUTFD(pstate));
ret = readline_fd(pstate->cn_line, sizeof(pstate->cn_line),
INFD(pstate), OUTFD(pstate));

/* Enable echo again after password */

Expand Down
5 changes: 2 additions & 3 deletions nshlib/nsh_timcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ int cmd_timedatectl(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
#ifndef CONFIG_NSH_DISABLE_WATCH
int cmd_watch(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
{
char buffer[CONFIG_NSH_LINELEN];
int interval = 2;
int count = -1;
FAR char *cmd;
Expand Down Expand Up @@ -593,8 +592,8 @@ int cmd_watch(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)

for (i = 0; i < count; i++)
{
strlcpy(buffer, cmd, CONFIG_NSH_LINELEN);
ret = nsh_parse(vtbl, buffer);
strlcpy(vtbl->templine, cmd, sizeof(vtbl->templine));
ret = nsh_parse(vtbl, vtbl->templine);
if (ret < 0)
{
nsh_error(vtbl, g_fmtcmdfailed, argv[0], cmd, NSH_ERRNO);
Expand Down
2 changes: 1 addition & 1 deletion system/nxcamera/nxcamera_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ static int nxcamera_cmd_help(FAR struct nxcamera_s *pcam, FAR char *parg)

int main(int argc, FAR char *argv[])
{
char buffer[CONFIG_NSH_LINELEN];
char buffer[LINE_MAX];
int len;
int x;
bool running = true;
Expand Down
2 changes: 1 addition & 1 deletion system/nxlooper/nxlooper_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ static int nxlooper_cmd_help(FAR struct nxlooper_s *plooper, char *parg)

int main(int argc, FAR char *argv[])
{
char buffer[CONFIG_NSH_LINELEN];
char buffer[LINE_MAX];
int len;
int x;
int running;
Expand Down
2 changes: 1 addition & 1 deletion system/nxplayer/nxplayer_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ static int nxplayer_cmd_help(FAR struct nxplayer_s *pplayer, char *parg)

int main(int argc, FAR char *argv[])
{
char buffer[CONFIG_NSH_LINELEN];
char buffer[LINE_MAX];
int len;
int x;
int running;
Expand Down
2 changes: 1 addition & 1 deletion system/nxrecorder/nxrecorder_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ static int nxrecorder_cmd_help(FAR struct nxrecorder_s *precorder,

int main(int argc, FAR char *argv[])
{
char buffer[CONFIG_NSH_LINELEN];
char buffer[LINE_MAX];
int len;
int x;
int running;
Expand Down
14 changes: 2 additions & 12 deletions system/readline/readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@

#include "system/readline.h"

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

/* Maximum size of one command line (telnet or serial) */

#ifndef CONFIG_NSH_LINELEN
# define CONFIG_NSH_LINELEN 80
#endif

/****************************************************************************
* Public Functions
****************************************************************************/
Expand All @@ -57,14 +47,14 @@

FAR char *readline(FAR const char *prompt)
{
FAR char *line = malloc(CONFIG_NSH_LINELEN);
FAR char *line = malloc(LINE_MAX);

if (line != NULL)
{
#ifdef CONFIG_READLINE_TABCOMPLETION
FAR const char *orig = readline_prompt(prompt);
#endif
if (readline_fd(line, CONFIG_NSH_LINELEN,
if (readline_fd(line, LINE_MAX,
STDIN_FILENO, STDOUT_FILENO) == 0)
{
free(line);
Expand Down
4 changes: 2 additions & 2 deletions system/taskset/taskset.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static bool get_cpuset(const char *arg, cpu_set_t *cpu_set)

int main(int argc, FAR char *argv[])
{
char command[CONFIG_NSH_LINELEN];
char command[LINE_MAX];
int exitcode;
int option;
int pid = -1;
Expand Down Expand Up @@ -151,7 +151,7 @@ int main(int argc, FAR char *argv[])
}

/* Construct actual command with args
* NOTE: total length does not exceed CONFIG_NSH_LINELEN
* NOTE: total length does not exceed LINE_MAX
*/

for (i = 0; i < argc - 2; i++)
Expand Down
2 changes: 1 addition & 1 deletion system/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ static int trace_cmd_dump(FAR const char *name, int index, int argc,
static int trace_cmd_cmd(FAR const char *name, int index, int argc,
FAR char **argv, int notectlfd)
{
char command[CONFIG_NSH_LINELEN];
char command[LINE_MAX];
bool changed;
bool cont = false;

Expand Down
Loading