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.

This commit is contained in:
Gregory Nutt 2017-11-13 13:35:04 -06:00
parent 0cda4cec15
commit e37f4b7004
2 changed files with 10 additions and 102 deletions

View File

@ -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

View File

@ -39,64 +39,9 @@
#include <nuttx/config.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#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 */