Skip to content
Merged
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
11 changes: 8 additions & 3 deletions nshlib/nsh_syscmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <nuttx/config.h>

#include <nuttx/rptun/rptun.h>
#include <nuttx/streams.h>
#include <sys/boardctl.h>
#include <sys/ioctl.h>
#include <sys/utsname.h>
Expand Down Expand Up @@ -488,6 +489,7 @@ int cmd_rptun(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
int cmd_uname(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
{
FAR const char *str;
struct lib_memoutstream_s stream;
struct utsname info;
unsigned int set;
int option;
Expand Down Expand Up @@ -579,6 +581,8 @@ int cmd_uname(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
/* Process each option */

first = true;
lib_memoutstream(&stream, alloca(sizeof(struct utsname)),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is it enough to allocate struct utsname in the extreme case? since we add more ' ' and '\n'.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is adequate, an extra 7 characters are added when using “uname -a”
But utsname->sysname is 21 (SYS_NAMELEN) bytes, only 6 bytes ("NuttX") are actually used

sizeof(struct utsname));
for (i = 0; set != 0; i++)
{
unsigned int mask = (1 << i);
Expand Down Expand Up @@ -623,15 +627,16 @@ int cmd_uname(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)

if (!first)
{
nsh_output(vtbl, " ");
lib_stream_putc(&stream, ' ');
}

nsh_output(vtbl, "%s", str);
lib_stream_puts(&stream, str, strlen(str));
first = false;
}
}

nsh_output(vtbl, "\n");
lib_stream_putc(&stream, '\n');
nsh_write(vtbl, stream.buffer, stream.public.nput);
return OK;
}
#endif