From e37f4b70048efe4d6a93489b710551956c375074 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 13 Nov 2017 13:35:04 -0600 Subject: [PATCH] apps/nshlib: Big simplification of last change. /proc/kmm, umm, and progmem have been replaced with a single procfs file called /proc/meminfo. The NSH free command now degenerates to a simple dump of /proc/meminfo. --- nshlib/nsh.h | 30 +++++------------ nshlib/nsh_mmcmds.c | 82 ++------------------------------------------- 2 files changed, 10 insertions(+), 102 deletions(-) diff --git a/nshlib/nsh.h b/nshlib/nsh.h index 40625b2bb..3573f67a8 100644 --- a/nshlib/nsh.h +++ b/nshlib/nsh.h @@ -664,24 +664,9 @@ # define HAVE_MOUNT_LIST 1 #endif -#undef HAVE_PROC_KMEM -#undef HAVE_PROC_UMEM -#undef HAVE_PROC_PROGMEM - -#ifdef CONFIG_FS_PROCFS -# if defined(CONFIG_MM_KERNEL_HEAP) && !defined(CONFIG_FS_PROCFS_EXCLUDE_KMM) -# define HAVE_PROC_KMEM 1 -# endif -# if !defined(CONFIG_FS_PROCFS_EXCLUDE_UMM) && !defined(CONFIG_BUILD_KERNEL) -# define HAVE_PROC_UMEM 1 -# endif -# if defined(CONFIG_ARCH_HAVE_PROGMEM) && !defined(CONFIG_FS_PROCFS_EXCLUDE_PROGMEM) -# define HAVE_PROC_PROGMEM 1 -# endif -# if !defined(HAVE_PROC_KMEM) && !defined(HAVE_PROC_UMEM) && !defined(HAVE_PROC_PROGMEM) -# undef CONFIG_NSH_DISABLE_FREE -# define CONFIG_NSH_DISABLE_FREE 1 -# endif +#if !defined(CONFIG_FS_PROCFS) || defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO) +# undef CONFIG_NSH_DISABLE_FREE +# define CONFIG_NSH_DISABLE_FREE 1 #endif /* Suppress unused file utilities */ @@ -699,11 +684,12 @@ # undef NSH_HAVE_TRIMDIR #endif -/* nsh_catfile used by cat, ifconfig, ifup/down, df, and mount */ +/* nsh_catfile used by cat, ifconfig, ifup/down, df, free, and mount */ -#if defined(CONFIG_NSH_DISABLE_CAT) && defined(CONFIG_NSH_DISABLE_IFCONFIG) && \ - defined(CONFIG_NSH_DISABLE_IFUPDOWN) && defined(CONFIG_NSH_DISABLE_DF) && \ - (defined(CONFIG_NSH_DISABLE_MOUNT) || !defined(HAVE_MOUNT_LIST)) +#if !defined(CONFIG_NSH_DISABLE_CAT) && !defined(CONFIG_NSH_DISABLE_IFCONFIG) && \ + !defined(CONFIG_NSH_DISABLE_IFUPDOWN) && !defined(CONFIG_NSH_DISABLE_DF) && \ + !defined(CONFIG_NSH_DISABLE_FREE) && \ + (!defined(CONFIG_NSH_DISABLE_MOUNT) || !defined(HAVE_MOUNT_LIST)) # undef NSH_HAVE_CATFILE #endif diff --git a/nshlib/nsh_mmcmds.c b/nshlib/nsh_mmcmds.c index e025787fc..75bdde8cf 100644 --- a/nshlib/nsh_mmcmds.c +++ b/nshlib/nsh_mmcmds.c @@ -39,64 +39,9 @@ #include -#include -#include -#include -#include - #include "nsh.h" #include "nsh_console.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#undef NEED_CATLINE2 -#ifndef CONFIG_NSH_DISABLE_FREE -# if defined(HAVE_PROC_KMEM) && (defined(HAVE_PROC_UMEM) || \ - defined(HAVE_PROC_PROGMEM)) -# define NEED_CATLINE2 1 -# elif defined(HAVE_PROC_UMEM) && defined(HAVE_PROC_PROGMEM) -# define NEED_CATLINE2 1 -# endif -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: cat_free - ****************************************************************************/ - -#ifdef NEED_CATLINE2 -static void nsh_catline2(FAR struct nsh_vtbl_s *vtbl, FAR const char *filepath) -{ - int fd; - - /* Open the file for reading */ - - fd = open(filepath, O_RDONLY); - if (fd >= 0) - { - /* Skip the first line which contains the header */ - - if (fgets(vtbl->iobuffer, IOBUFFERSIZE, INSTREAM(pstate)) != NULL) - { - /* The second line contains the info to send to stdout */ - - if (fgets(vtbl->iobuffer, IOBUFFERSIZE, INSTREAM(pstate)) != NULL) - { - size_t linesize = strnlen(vtbl->iobuffer, IOBUFFERSIZE); - (void)nsh_write(vtbl, vtbl->iobuffer, linesize); - } - } - - (void)close(fd); - } -} -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -105,32 +50,9 @@ static void nsh_catline2(FAR struct nsh_vtbl_s *vtbl, FAR const char *filepath) * Name: cmd_free ****************************************************************************/ -#ifndef CONFIG_NSH_DISABLE_FREE +#if !defined(CONFIG_NSH_DISABLE_FREE) && defined(NSH_HAVE_CATFILE) int cmd_free(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { -#if defined(HAVE_PROC_KMEM) - (void)nsh_catfile(vtbl, argv[0], CONFIG_NSH_PROC_MOUNTPOINT "/kmm"); -# ifdef HAVE_PROC_UMEM - nsh_catline2(vtbl, CONFIG_NSH_PROC_MOUNTPOINT "/umm"); -# endif -# ifdef HAVE_PROC_PROGMEM - nsh_catline2(vtbl, CONFIG_NSH_PROC_MOUNTPOINT "/progmem"); -# endif - return OK; - -#elif defined(HAVE_PROC_UMEM) - (void)nsh_catfile(vtbl, argv[0], CONFIG_NSH_PROC_MOUNTPOINT "/umm"); -# ifdef HAVE_PROC_PROGMEM - nsh_catline2(vtbl, CONFIG_NSH_PROC_MOUNTPOINT "/progmem"); -# endif - return OK; - -#else -# ifdef HAVE_PROC_PROGMEM - return nsh_catfile(vtbl, argv[0], CONFIG_NSH_PROC_MOUNTPOINT "/progmem"); -# else - return ERROR; -# endif -#endif + return nsh_catfile(vtbl, argv[0], CONFIG_NSH_PROC_MOUNTPOINT "/meminfo"); } #endif /* !CONFIG_NSH_DISABLE_FREE */