diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2008-02-27 21:52:16 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2008-02-27 21:52:16 +0000 |
commit | dfe0e5833a279b70e077a1b0b36e9903f1dc6d13 (patch) | |
tree | dbb2538052be1d504e42ab4e99438f09bd6f7765 /cpukit/libmisc/shell | |
parent | 2008-02-27 Joel Sherrill <joel.sherrill@oarcorp.com> (diff) | |
download | rtems-dfe0e5833a279b70e077a1b0b36e9903f1dc6d13.tar.bz2 |
2008-02-27 Joel Sherrill <joel.sherrill@oarcorp.com>
* libmisc/shell/cat_file.c, libmisc/shell/main_alias.c,
libmisc/shell/main_blksync.c, libmisc/shell/main_cat.c,
libmisc/shell/main_chdir.c, libmisc/shell/main_chmod.c,
libmisc/shell/main_chroot.c, libmisc/shell/main_cpuuse.c,
libmisc/shell/main_date.c, libmisc/shell/main_help.c,
libmisc/shell/main_id.c, libmisc/shell/main_logoff.c,
libmisc/shell/main_ls.c, libmisc/shell/main_mallocinfo.c,
libmisc/shell/main_mdump.c, libmisc/shell/main_medit.c,
libmisc/shell/main_mfill.c, libmisc/shell/main_mkdir.c,
libmisc/shell/main_mmove.c, libmisc/shell/main_mount.c,
libmisc/shell/main_mount_nfs.c, libmisc/shell/main_msdosfmt.c,
libmisc/shell/main_mwdump.c, libmisc/shell/main_perioduse.c,
libmisc/shell/main_pwd.c, libmisc/shell/main_rm.c,
libmisc/shell/main_rmdir.c, libmisc/shell/main_stackuse.c,
libmisc/shell/main_tty.c, libmisc/shell/main_umask.c,
libmisc/shell/main_unmount.c, libmisc/shell/main_whoami.c,
libmisc/shell/shell.h: Clean up done while writing documentation.
Some command improvements such as date now allows setting of the
current TOD. Often commands did not use stdout/stderr per
expectations and did not return -1 on an error.
Diffstat (limited to '')
33 files changed, 388 insertions, 284 deletions
diff --git a/cpukit/libmisc/shell/cat_file.c b/cpukit/libmisc/shell/cat_file.c index 9fe683021e..91e719aec0 100644 --- a/cpukit/libmisc/shell/cat_file.c +++ b/cpukit/libmisc/shell/cat_file.c @@ -18,17 +18,20 @@ #include <stdio.h> -void rtems_shell_cat_file(FILE * out,char * name) { +int rtems_shell_cat_file(FILE * out,char * name) { FILE * fd; int c; if (out) { fd = fopen(name,"r"); - if (fd) { - while ((c=fgetc(fd))!=EOF) fputc(c,out); - fclose(fd); + if (!fd) { + return -1; } + while ((c=fgetc(fd))!=EOF) + fputc(c,out); + fclose(fd); } + return 0; } diff --git a/cpukit/libmisc/shell/main_alias.c b/cpukit/libmisc/shell/main_alias.c index cb07475a71..9f1b094eaa 100644 --- a/cpukit/libmisc/shell/main_alias.c +++ b/cpukit/libmisc/shell/main_alias.c @@ -25,12 +25,12 @@ int rtems_shell_rtems_main_alias(int argc, char **argv) { if (argc<3) { - fprintf(stdout,"too few arguments\n"); + fprintf(stderr,"too few arguments\n"); return 1; } if (!rtems_shell_alias_cmd(argv[1],argv[2])) { - fprintf(stdout,"unable to make an alias(%s,%s)\n",argv[1],argv[2]); + fprintf(stderr,"unable to make an alias(%s,%s)\n",argv[1],argv[2]); } return 0; } diff --git a/cpukit/libmisc/shell/main_blksync.c b/cpukit/libmisc/shell/main_blksync.c index c59760c2b6..0089a75adf 100644 --- a/cpukit/libmisc/shell/main_blksync.c +++ b/cpukit/libmisc/shell/main_blksync.c @@ -28,45 +28,42 @@ #include <rtems/blkdev.h> #include "internal.h" -int rtems_shell_main_blksync(int argc, char *argv[]) +int rtems_shell_main_blksync( + int argc, + char *argv[] +) { const char* driver = NULL; int arg; + int fd; - for (arg = 1; arg < argc; arg++) - { - if (argv[arg][0] == '-') - { - printf ("error: invalid option: %s\n", argv[arg]); + for (arg = 1; arg < argc; arg++) { + if (argv[arg][0] == '-') { + fprintf( stderr, "%s: invalid option: %s\n", argv[0], argv[arg]); return 1; - } - else - { + } else { if (!driver) driver = argv[arg]; - else - { - printf ("error: only one driver name allowed: %s\n", argv[arg]); + else { + fprintf( stderr, "%s: only one driver name allowed: %s\n", + argv[0], argv[arg]); return 1; } } } - int fd = open (driver, O_WRONLY, 0); - if (fd < 0) - { - printf ("error: driver open failed: %s\n", strerror (errno)); + fd = open (driver, O_WRONLY, 0); + if (fd < 0) { + fprintf( stderr, "%s: driver open failed: %s\n", argv[0], strerror (errno)); return 1; } - if (ioctl (fd, BLKIO_SYNCDEV) < 0) - { - printf ("error: driver sync failed: %s\n", strerror (errno)); + if (ioctl (fd, BLKIO_SYNCDEV) < 0) { + fprintf( stderr, "%s: driver sync failed: %s\n", argv[0], strerror (errno)); return 1; } close (fd); - return 0; } diff --git a/cpukit/libmisc/shell/main_cat.c b/cpukit/libmisc/shell/main_cat.c index 9fe322d408..6efd7a09c8 100644 --- a/cpukit/libmisc/shell/main_cat.c +++ b/cpukit/libmisc/shell/main_cat.c @@ -37,12 +37,17 @@ int rtems_shell_main_cat(int argc, char *argv[]) { - int n; - n=1; + int n; + int sc; - while (n<argc) - rtems_shell_cat_file(stdout,argv[n++]); - return 0; + for ( n=1; n < argc ; n++) { + sc = rtems_shell_cat_file(stdout, argv[n]); + if ( sc == -1 ) { + fprintf(stderr, "%s: %s: %s\n", argv[0], argv[n], strerror(errno)); + return -1; + } + } + return 0; } rtems_shell_cmd_t rtems_shell_CAT_Command = { diff --git a/cpukit/libmisc/shell/main_chdir.c b/cpukit/libmisc/shell/main_chdir.c index a1299ed553..2273f5c956 100644 --- a/cpukit/libmisc/shell/main_chdir.c +++ b/cpukit/libmisc/shell/main_chdir.c @@ -25,16 +25,20 @@ #include <rtems/shell.h> #include "internal.h" -int rtems_shell_main_chdir (int argc, char *argv[]) { +int rtems_shell_main_chdir( + int argc, + char *argv[] +) +{ char *dir; dir = "/"; - if (argc>1) + if (argc > 1) dir = argv[1]; if (chdir(dir)) { - fprintf(stdout, "chdir to '%s' failed:%s\n", dir,strerror(errno)); + fprintf(stderr, "chdir to '%s' failed:%s\n", dir,strerror(errno)); return errno; } return 0; diff --git a/cpukit/libmisc/shell/main_chmod.c b/cpukit/libmisc/shell/main_chmod.c index 044e48389a..053da1d5a3 100644 --- a/cpukit/libmisc/shell/main_chmod.c +++ b/cpukit/libmisc/shell/main_chmod.c @@ -28,15 +28,18 @@ #include <rtems/shell.h> #include "internal.h" -int rtems_shell_main_chmod(int argc,char *argv[]) +int rtems_shell_main_chmod( + int argc, + char *argv[] +) { int n; mode_t mode; - if (argc > 2){ - mode = rtems_shell_str2int(argv[1])&0777; + if (argc > 2) { + mode = rtems_shell_str2int(argv[1]) & 0777; n = 2; - while (n<argc) + while (n < argc) chmod(argv[n++], mode); } return 0; diff --git a/cpukit/libmisc/shell/main_chroot.c b/cpukit/libmisc/shell/main_chroot.c index e3740393b5..ffdfb9ca3b 100644 --- a/cpukit/libmisc/shell/main_chroot.c +++ b/cpukit/libmisc/shell/main_chroot.c @@ -25,14 +25,18 @@ #include <rtems/shell.h> #include "internal.h" -int rtems_shell_main_chroot(int argc,char * argv[]) { - char *new_root="/"; - - if (argc==2) - new_root=argv[1]; - - if (chroot(new_root)<0) { - fprintf(stdout,"error %s:chroot(%s);\n",strerror(errno),new_root); +int rtems_shell_main_chroot( + int argc, + char * argv[] +) +{ + char *new_root = "/"; + + if (argc == 2) + new_root = argv[1]; + + if ( chroot(new_root) < 0 ) { + fprintf(stderr,"chroot %s (%s)\n", new_root, strerror(errno)); return -1; } diff --git a/cpukit/libmisc/shell/main_cpuuse.c b/cpukit/libmisc/shell/main_cpuuse.c index 2ca92812c7..492997cd8f 100644 --- a/cpukit/libmisc/shell/main_cpuuse.c +++ b/cpukit/libmisc/shell/main_cpuuse.c @@ -22,14 +22,33 @@ #include <rtems/shell.h> #include "internal.h" -int rtems_shell_main_cpuuse(int argc,char *argv[]) +int rtems_shell_main_cpuuse( + int argc, + char *argv[] +) { - if ( argc >= 1 && !strcmp( argv[1], "-r" ) ) { + /* + * When invoked with no arguments, print the report. + */ + if ( argc == 1 ) { + rtems_cpu_usage_report_with_plugin(stdout, (rtems_printk_plugin_t)fprintf); + return 0; + } + + /* + * When invoked with the single argument -r, reset the statistics. + */ + if ( argc == 2 && !strcmp( argv[1], "-r" ) ) { printf( "Resetting CPU Usage information\n" ); rtems_cpu_usage_reset(); - } else - rtems_cpu_usage_report_with_plugin(stdout, (rtems_printk_plugin_t)fprintf); - return 0; + return 0; + } + + /* + * OK. The user did something wrong. + */ + fprintf( stderr, "%s: [-r]\n", argv[0] ); + return -1; } rtems_shell_cmd_t rtems_shell_CPUUSE_Command = { diff --git a/cpukit/libmisc/shell/main_date.c b/cpukit/libmisc/shell/main_date.c index b3180eecd8..4d3f4fa94f 100644 --- a/cpukit/libmisc/shell/main_date.c +++ b/cpukit/libmisc/shell/main_date.c @@ -25,18 +25,52 @@ #include <rtems/shell.h> #include "internal.h" -int rtems_shell_main_date(int argc,char *argv[]) +int rtems_shell_main_date( + int argc, + char *argv[] +) { - time_t t; + /* + * Print the current date and time in default format. + */ + if ( argc == 1 ) { + time_t t; - time(&t); - fprintf(stdout,"%s", ctime(&t)); - return 0; + time(&t); + printf("%s", ctime(&t)); + return 0; + } + + /* + * Set the current date and time + */ + if ( argc == 3 ) { + char buf[128]; + struct tm TOD; + struct timespec timesp; + char *result; + + sprintf( buf, "%s %s", argv[1], argv[2] ); + result = strptime( + buf, + "%Y-%m-%d %T", + &TOD + ); + if ( result && !*result ) { + timesp.tv_sec = mktime( &TOD ); + timesp.tv_nsec = 0; + clock_settime( CLOCK_REALTIME, ×p ); + return 0; + } + } + + fprintf( stderr, "%s: Usage: [YYYY-MM-DD HH:MM:SS]\n", argv[0] ); + return -1; } rtems_shell_cmd_t rtems_shell_DATE_Command = { "date", /* name */ - "date", /* usage */ + "date [YYYY-MM-DD HH:MM:SS]", /* usage */ "misc", /* topic */ rtems_shell_main_date, /* command */ NULL, /* alias */ diff --git a/cpukit/libmisc/shell/main_help.c b/cpukit/libmisc/shell/main_help.c index 6aba4c5fc3..01dd35020f 100644 --- a/cpukit/libmisc/shell/main_help.c +++ b/cpukit/libmisc/shell/main_help.c @@ -27,7 +27,10 @@ /* * show the help for one command. */ -int rtems_shell_help_cmd(rtems_shell_cmd_t * shell_cmd) { +int rtems_shell_help_cmd( + rtems_shell_cmd_t *shell_cmd +) +{ char * pc; int col,line; diff --git a/cpukit/libmisc/shell/main_id.c b/cpukit/libmisc/shell/main_id.c index 994c706d47..3f2ceefe31 100644 --- a/cpukit/libmisc/shell/main_id.c +++ b/cpukit/libmisc/shell/main_id.c @@ -28,7 +28,10 @@ #include <rtems/shell.h> #include "internal.h" -int rtems_shell_main_id(int argc,char *argv[]) +int rtems_shell_main_id( + int argc, + char *argv[] +) { struct passwd *pwd; struct group *grp; @@ -38,18 +41,18 @@ int rtems_shell_main_id(int argc,char *argv[]) printf( "uid=%d(%s),gid=%d(%s),", getuid(), - pwd?pwd->pw_name:"", + (pwd) ? pwd->pw_name : "", getgid(), - grp?grp->gr_name:"" + (grp) ? grp->gr_name : "" ); pwd = getpwuid(geteuid()); grp = getgrgid(getegid()); printf( "euid=%d(%s),egid=%d(%s)\n", geteuid(), - pwd?pwd->pw_name:"", + (pwd) ? pwd->pw_name : "", getegid(), - grp?grp->gr_name:"" + (grp) ? grp->gr_name : "" ); return 0; } diff --git a/cpukit/libmisc/shell/main_logoff.c b/cpukit/libmisc/shell/main_logoff.c index ea4681a160..f19df02725 100644 --- a/cpukit/libmisc/shell/main_logoff.c +++ b/cpukit/libmisc/shell/main_logoff.c @@ -22,12 +22,14 @@ #include <rtems/shell.h> #include "internal.h" -/*-----------------------------------------------------------*/ -int rtems_shell_main_logoff(int argc,char *argv[]) +int rtems_shell_main_logoff( + int argc, + char *argv[] +) { printf("logoff from the system..."); - rtems_current_shell_env->exit_shell=TRUE; + rtems_current_shell_env->exit_shell = TRUE; return 0; } diff --git a/cpukit/libmisc/shell/main_ls.c b/cpukit/libmisc/shell/main_ls.c index 51dfd160e7..c81e35efda 100644 --- a/cpukit/libmisc/shell/main_ls.c +++ b/cpukit/libmisc/shell/main_ls.c @@ -35,7 +35,10 @@ #include <rtems/shell.h> #include "internal.h" -int rtems_shell_main_ls(int argc, char *argv[]) +int rtems_shell_main_ls( + int argc, + char *argv[] +) { char *fname; DIR *dirp; @@ -55,7 +58,7 @@ int rtems_shell_main_ls(int argc, char *argv[]) fname = argv[1]; if ((dirp = opendir(fname)) == NULL) { - fprintf(stdout,"%s: No such file or directory.\n", fname); + fprintf(stderr,"%s: %s: No such file or directory.\n", argv[0], fname); return errno; } n = 0; @@ -65,13 +68,13 @@ int rtems_shell_main_ls(int argc, char *argv[]) if (nbuf[strlen(nbuf)-1]!='/') strcat(nbuf,"/"); strcat(nbuf,dp->d_name); /* always the fullpathname. Avoid ftpd problem.*/ - if (stat(nbuf, &stat_buf) == 0) { /* AWFUL buts works...*/ - strftime(sbuf,sizeof(sbuf)-1,"%b %d %H:%M",gmtime(&stat_buf.st_mtime)); + if (stat(nbuf, &stat_buf) == 0) { /* AWFUL but works...*/ + strftime(sbuf,sizeof(sbuf)-1,"%b %d %H:%M", gmtime(&stat_buf.st_mtime)); pwd = getpwuid(stat_buf.st_uid); user = pwd?pwd->pw_name:"nouser"; grp = getgrgid(stat_buf.st_gid); group = grp?grp->gr_name:"nogrp"; - fprintf(stdout,"%c%c%c%c%c%c%c%c%c%c %3d %6.6s %6.6s %11d %s %s%c\n", + printf("%c%c%c%c%c%c%c%c%c%c %3d %6.6s %6.6s %11d %s %s%c\n", (S_ISLNK(stat_buf.st_mode)?('l'): (S_ISDIR(stat_buf.st_mode)?('d'):('-'))), (stat_buf.st_mode & S_IRUSR)?('r'):('-'), @@ -93,7 +96,7 @@ int rtems_shell_main_ls(int argc, char *argv[]) size += stat_buf.st_size; } } - fprintf(stdout,"%d files %d bytes occupied\n",n,size); + printf("%d files %d bytes occupied\n",n,size); closedir(dirp); return 0; } diff --git a/cpukit/libmisc/shell/main_mallocinfo.c b/cpukit/libmisc/shell/main_mallocinfo.c index 001c3ea73b..1f459270ee 100644 --- a/cpukit/libmisc/shell/main_mallocinfo.c +++ b/cpukit/libmisc/shell/main_mallocinfo.c @@ -24,21 +24,6 @@ extern int malloc_info( region_information_block * ); -static void printit( - const char *c, - Heap_Information *h -) -{ - printf( - "Number of %s blocks: %" PRId32 "\n" - "Largest %s block: %" PRId32 "\n" - "Total bytes %s: %" PRId32 "\n", - c, h->number, - c, h->largest, - c, h->total - ); -} - int rtems_shell_main_malloc_info( int argc, char *argv[] @@ -60,7 +45,7 @@ int rtems_shell_main_malloc_info( return 0; } } - fprintf( stderr, "subcommands info or stats\n" ); + fprintf( stderr, "%s: [info|stats]\n", argv[0] ); return -1; } diff --git a/cpukit/libmisc/shell/main_mdump.c b/cpukit/libmisc/shell/main_mdump.c index 408dcfe26d..f245afb183 100644 --- a/cpukit/libmisc/shell/main_mdump.c +++ b/cpukit/libmisc/shell/main_mdump.c @@ -18,6 +18,7 @@ #include <ctype.h> #include <stdio.h> +#include <inttypes.h> #include <string.h> #include <rtems.h> @@ -28,40 +29,44 @@ * RAM MEMORY COMMANDS *----------------------------------------------------------------------------*/ -int rtems_shell_main_mdump(int argc,char * argv[]) { - unsigned char n,m,max=0; - uintptr_t addr; +int rtems_shell_main_mdump( + int argc, + char *argv[] +) +{ + unsigned char n, m, max=20; + uintptr_t addr = 0; unsigned char *pb; - addr = rtems_current_shell_env->mdump_addr; if (argc>1) addr = rtems_shell_str2int(argv[1]); - if (argc>2) + + if (argc>2) { max = rtems_shell_str2int(argv[2]); + max /= 16; + } - max /= 16; if (!max) - max = 20; + max = 1; - for (m=0;m<max;m++) { - fprintf(stdout,"0x%08lX ",addr); + for (m=0; m<max; m++) { + printf("0x%08" PRIXPTR " ", addr); pb = (unsigned char*) addr; for (n=0;n<16;n++) - fprintf(stdout,"%02X%c",pb[n],n==7?'-':' '); + printf("%02X%c", pb[n], (n == 7) ? '-' : ' '); for (n=0;n<16;n++) { - fprintf(stdout,"%c",isprint(pb[n])?pb[n]:'.'); + printf("%c", isprint(pb[n]) ? pb[n] : '.'); } - fprintf(stdout,"\n"); + printf("\n"); addr += 16; } - rtems_current_shell_env->mdump_addr = addr; return 0; } rtems_shell_cmd_t rtems_shell_MDUMP_Command = { "mdump", /* name */ - "mdump [addr [size]]", /* usage */ + "mdump [address [length]]", /* usage */ "mem", /* topic */ rtems_shell_main_mdump, /* command */ NULL, /* alias */ diff --git a/cpukit/libmisc/shell/main_medit.c b/cpukit/libmisc/shell/main_medit.c index b3c59f91bd..2e590d4982 100644 --- a/cpukit/libmisc/shell/main_medit.c +++ b/cpukit/libmisc/shell/main_medit.c @@ -26,29 +26,32 @@ extern int rtems_shell_main_mdump(int, char *); -int rtems_shell_main_medit(int argc,char * argv[]) { +int rtems_shell_main_medit( + int argc, + char *argv[] +) +{ unsigned char * pb; int n,i; if (argc<3) { - fprintf(stdout,"too few arguments\n"); - return 0; + fprintf(stderr,"%s: too few arguments\n", argv[0]); + return -1; } pb = (unsigned char*)rtems_shell_str2int(argv[1]); i = 2; n = 0; while (i<=argc) { - pb[n++] = rtems_shell_str2int(argv[i++])%0x100; + pb[n++] = rtems_shell_str2int(argv[i++]) % 0x100; } - rtems_current_shell_env->mdump_addr = (int)pb; - return rtems_shell_main_mdump(0,NULL); + return 0; } rtems_shell_cmd_t rtems_shell_MEDIT_Command = { "medit", /* name */ - "medit addr value [value ...]", /* usage */ + "medit address value1 [value2 ...]", /* usage */ "mem", /* topic */ rtems_shell_main_medit, /* command */ NULL, /* alias */ diff --git a/cpukit/libmisc/shell/main_mfill.c b/cpukit/libmisc/shell/main_mfill.c index 6dd5aa6396..605cd58580 100644 --- a/cpukit/libmisc/shell/main_mfill.c +++ b/cpukit/libmisc/shell/main_mfill.c @@ -24,30 +24,31 @@ #include <rtems/shell.h> #include "internal.h" -extern int rtems_shell_main_mdump(int, char *); - -int rtems_shell_main_mfill(int argc,char * argv[]) { - uintptr_t addr; - size_t size; +int rtems_shell_main_mfill( + int argc, + char *argv[] +) +{ + uintptr_t addr; + size_t size; unsigned char value; - if (argc<4) { - fprintf(stdout,"too few arguments\n"); - return 0; + if ( argc != 4 ) { + fprintf(stderr,"%s: too few arguments\n", argv[0]); + return -1; } - addr = rtems_shell_str2int(argv[1]); - size = rtems_shell_str2int(argv[2]); - value= rtems_shell_str2int(argv[3]) % 0x100; + addr = rtems_shell_str2int(argv[1]); + size = rtems_shell_str2int(argv[2]); + value = rtems_shell_str2int(argv[3]) % 0x100; memset((unsigned char*)addr,size,value); - rtems_current_shell_env->mdump_addr = addr; - return rtems_shell_main_mdump(0,NULL); + return 0; } rtems_shell_cmd_t rtems_shell_MFILL_Command = { "mfill", /* name */ - "mfill addr size value", /* usage */ + "mfill address size value", /* usage */ "mem", /* topic */ rtems_shell_main_mfill, /* command */ NULL, /* alias */ diff --git a/cpukit/libmisc/shell/main_mkdir.c b/cpukit/libmisc/shell/main_mkdir.c index 510ffe0e6b..e191818923 100644 --- a/cpukit/libmisc/shell/main_mkdir.c +++ b/cpukit/libmisc/shell/main_mkdir.c @@ -27,15 +27,19 @@ #include <rtems/shell.h> #include "internal.h" -int rtems_shell_main_mkdir(int argc, char *argv[]) { +int rtems_shell_main_mkdir( + int argc, + char *argv[] +) +{ char *dir; - int n; + n = 1; while (n<argc) { dir = argv[n++]; if (mkdir(dir,S_IRWXU|S_IRWXG|S_IRWXO)) { - fprintf(stdout, "mkdir '%s' failed:%s\n", dir, strerror(errno)); + fprintf(stderr, "mkdir '%s' failed:%s\n", dir, strerror(errno)); } } return errno; diff --git a/cpukit/libmisc/shell/main_mmove.c b/cpukit/libmisc/shell/main_mmove.c index 6c8e6574ea..a97f0ebfa5 100644 --- a/cpukit/libmisc/shell/main_mmove.c +++ b/cpukit/libmisc/shell/main_mmove.c @@ -26,28 +26,31 @@ extern int rtems_shell_main_mdump(int, char *); -int rtems_shell_main_mmove(int argc,char * argv[]) { +int rtems_shell_main_mmove( + int argc, + char *argv[] +) +{ uintptr_t src; uintptr_t dst; - size_t size; + size_t length; - if (argc<4) { - fprintf(stdout,"too few arguments\n"); - return 0; + if ( argc<4 ) { + fprintf(stderr,"%s: too few arguments\n", argv[0]); + return -1; } - dst = rtems_shell_str2int(argv[1]); - src = rtems_shell_str2int(argv[2]); - size = rtems_shell_str2int(argv[3]); - memcpy((unsigned char*)dst, (unsigned char*)src, size); - rtems_current_shell_env->mdump_addr = dst; + dst = rtems_shell_str2int(argv[1]); + src = rtems_shell_str2int(argv[2]); + length = rtems_shell_str2int(argv[3]); + memcpy((unsigned char*)dst, (unsigned char*)src, length); - return rtems_shell_main_mdump(0,NULL); + return 0; } rtems_shell_cmd_t rtems_shell_MMOVE_Command = { "mmove", /* name */ - "mmove dst src size", /* usage */ + "mmove dst src length", /* usage */ "mem", /* topic */ rtems_shell_main_mmove, /* command */ NULL, /* alias */ diff --git a/cpukit/libmisc/shell/main_mount.c b/cpukit/libmisc/shell/main_mount.c index b09b8ea5eb..c949715313 100644 --- a/cpukit/libmisc/shell/main_mount.c +++ b/cpukit/libmisc/shell/main_mount.c @@ -28,10 +28,11 @@ #include <rtems/fsmount.h> #include "internal.h" -int rtems_shell_libc_mounter(const char* driver, - const char* path, - rtems_shell_filesystems_t* fs, - rtems_filesystem_options_t options) +int rtems_shell_libc_mounter( + const char* driver, + const char* path, + rtems_shell_filesystems_t* fs, + rtems_filesystem_options_t options) { rtems_filesystem_mount_table_entry_t* mt_entry; /* @@ -40,7 +41,7 @@ int rtems_shell_libc_mounter(const char* driver, if (mount (&mt_entry, fs->fs_ops, options, (char*) driver, (char*) path) < 0) { - printf ("error: mount failed: %s\n", strerror (errno)); + fprintf (stderr, "mount: mount failed: %s\n", strerror (errno)); return 1; } @@ -49,7 +50,10 @@ int rtems_shell_libc_mounter(const char* driver, #define NUMOF(_i) (sizeof (_i) / sizeof (_i[0])) -int rtems_shell_main_mount(int argc, char *argv[]) +int rtems_shell_main_mount( + int argc, + char *argv[] +) { rtems_filesystem_options_t options = RTEMS_FILESYSTEM_READ_WRITE; rtems_shell_filesystems_t* fs = NULL; @@ -57,79 +61,66 @@ int rtems_shell_main_mount(int argc, char *argv[]) char* mount_point = NULL; int arg; - for (arg = 1; arg < argc; arg++) - { - if (argv[arg][0] == '-') - { - if (argv[arg][1] == 't') - { + for (arg = 1; arg < argc; arg++) { + if (argv[arg][0] == '-') { + if (argv[arg][1] == 't') { rtems_shell_filesystems_t** a; arg++; - if (arg == argc) - { - fprintf (stdout, "error: -t needs a type of file-system;; see -L.\n"); + if (arg == argc) { + fprintf( + stderr, + "%s: -t needs a type of file-system;; see -L.\n", + argv[0] + ); return 1; } - for (a = rtems_shell_Mount_filesystems; *a; a++) - { - if (strcmp (argv[arg], (*a)->name) == 0) - { + for (a = rtems_shell_Mount_filesystems; *a; a++) { + if (strcmp (argv[arg], (*a)->name) == 0) { fs = *a; break; } } - } - else if (argv[arg][1] == 'r') - { + } else if (argv[arg][1] == 'r') { options = RTEMS_FILESYSTEM_READ_ONLY; - } - else if (argv[arg][1] == 'L') - { + } else if (argv[arg][1] == 'L') { rtems_shell_filesystems_t** a; - fprintf (stdout, "File systems: "); + fprintf (stderr, "File systems: "); for (a = rtems_shell_Mount_filesystems; *a; a++) if (*a) - fprintf (stdout, "%s ", (*a)->name); - fprintf (stdout, "\n"); + fprintf (stderr, "%s ", (*a)->name); + fprintf (stderr, "\n"); return 1; - } - else - { - fprintf (stdout, "unknown option: %s\n", argv[arg]); + } else { + fprintf (stderr, "unknown option: %s\n", argv[arg]); return 1; } - } - else - { + } else { if (!driver) driver = argv[arg]; else if (!mount_point) mount_point = argv[arg]; - else - { - printf ("error: driver and mount only require: %s\n", argv[arg]); + else { + fprintf ( + stderr, "mount: driver and mount only require: %s\n", argv[arg]); return 1; } } } - if (fs == NULL) - { - fprintf (stdout, "error: no file-system; see the -L option\n"); + if (fs == NULL) { + fprintf (stderr, "mount: no file-system; see the -L option\n"); return 1; } - if (fs->driver_needed && !driver) - { - fprintf (stdout, "error: no driver\n"); + if (fs->driver_needed && !driver) { + fprintf (stderr, "mount: no driver\n"); return 1; } - if (!mount_point) - { - printf ("error: no mount point\n"); + if (!mount_point) { + fprintf (stderr, "mount: no mount point\n"); return 1; } diff --git a/cpukit/libmisc/shell/main_mount_nfs.c b/cpukit/libmisc/shell/main_mount_nfs.c index f09be8fa0f..bc11b54fb6 100644 --- a/cpukit/libmisc/shell/main_mount_nfs.c +++ b/cpukit/libmisc/shell/main_mount_nfs.c @@ -28,24 +28,23 @@ #include <librtemsNfs.h> static int -rtems_shell_nfs_mounter (const char* device, - const char* mntpoint, - rtems_shell_filesystems_t* fs, - rtems_filesystem_options_t options) +rtems_shell_nfs_mounter ( + const char* device, + const char* mntpoint, + rtems_shell_filesystems_t* fs, + rtems_filesystem_options_t options) { char* uidhost; char* path; int ret; - if (strchr (device, ':') == NULL) - { - fprintf (stdout, "error: nfs mount device is [uid.gid@]host:path\n"); + if (strchr (device, ':') == NULL) { + fprintf (stderr, "error: nfs mount device is [uid.gid@]host:path\n"); return -1; } - if (rpcUdpInit () < 0) - { - fprintf (stdout, "error: initialising RPC\n"); + if (rpcUdpInit () < 0) { + fprintf (stderr, "error: initialising RPC\n"); return -1; } diff --git a/cpukit/libmisc/shell/main_msdosfmt.c b/cpukit/libmisc/shell/main_msdosfmt.c index 24d978e07a..12ba79e8c8 100644 --- a/cpukit/libmisc/shell/main_msdosfmt.c +++ b/cpukit/libmisc/shell/main_msdosfmt.c @@ -28,7 +28,10 @@ #include <rtems/fsmount.h> #include "internal.h" -int rtems_shell_main_msdos_format(int argc, char *argv[]) +int rtems_shell_main_msdos_format( + int argc, + char *argv[] +) { msdos_format_request_param_t rqdata = { OEMName: "RTEMS", @@ -45,17 +48,13 @@ int rtems_shell_main_msdos_format(int argc, char *argv[]) const char* driver = NULL; int arg; - for (arg = 1; arg < argc; arg++) - { - if (argv[arg][0] == '-') - { - switch (argv[arg][1]) - { + for (arg = 1; arg < argc; arg++) { + if (argv[arg][0] == '-') { + switch (argv[arg][1]) { case 'v': arg++; - if (arg == argc) - { - printf ("error: no volume label.\n"); + if (arg == argc) { + fprintf (stderr, "error: no volume label.\n"); return 1; } rqdata.VolLabel = argv[arg]; @@ -63,9 +62,8 @@ int rtems_shell_main_msdos_format(int argc, char *argv[]) case 'r': arg++; - if (arg == argc) - { - printf ("error: no root directory size.\n"); + if (arg == argc) { + fprintf (stderr, "error: no root directory size.\n"); return 1; } rqdata.files_per_root_dir = rtems_shell_str2int(argv[arg]); @@ -73,9 +71,8 @@ int rtems_shell_main_msdos_format(int argc, char *argv[]) case 't': arg++; - if (arg == argc) - { - printf ("error: no FAT type.\n"); + if (arg == argc) { + fprintf (stderr, "error: no FAT type.\n"); return 1; } @@ -87,42 +84,36 @@ int rtems_shell_main_msdos_format(int argc, char *argv[]) rqdata.fattype = MSDOS_FMT_FAT16; else if (strcmp (argv[arg], "32") == 0) rqdata.fattype = MSDOS_FMT_FAT32; - else - { - printf ("error: invalid type, can any, 12, 16, or 32\n"); + else { + fprintf (stderr, "error: invalid type, can any, 12, 16, or 32\n"); return 1; } break; default: - printf ("error: invalid option: %s\n", argv[arg]); + fprintf (stderr, "error: invalid option: %s\n", argv[arg]); return 1; } - } - else - { + } else { if (!driver) driver = argv[arg]; - else - { - printf ("error: only one driver allowed: %s\n", argv[arg]); + else { + fprintf (stderr, "error: only one driver allowed: %s\n", argv[arg]); return 1; } } } - if (!driver) - { - printf ("error: no driver\n"); + if (!driver) { + fprintf (stderr, "error: no driver\n"); return 1; } printf ("msdos format: %s\n", driver); - if (msdos_format (driver, &rqdata) < 0) - { - printf ("error: format failed: %s\n", strerror (errno)); + if (msdos_format (driver, &rqdata) < 0) { + fprintf (stderr, "error: format failed: %s\n", strerror (errno)); return 1; } diff --git a/cpukit/libmisc/shell/main_mwdump.c b/cpukit/libmisc/shell/main_mwdump.c index 9cdc9cff76..fda0a780c7 100644 --- a/cpukit/libmisc/shell/main_mwdump.c +++ b/cpukit/libmisc/shell/main_mwdump.c @@ -19,45 +19,51 @@ #include <ctype.h> #include <stdio.h> #include <string.h> +#include <inttypes.h> #include <rtems.h> #include <rtems/shell.h> #include "internal.h" -int rtems_shell_main_mwdump(int argc,char * argv[]) { - unsigned char n,m,max=0; - int addr=rtems_current_shell_env->mdump_addr; - unsigned short * pw; +int rtems_shell_main_mwdump( + int argc, + char *argv[] +) +{ + unsigned char n, m, max=20; + uintptr_t addr=0; + unsigned short *pw; + unsigned char *p; if (argc>1) addr = rtems_shell_str2int(argv[1]); - if (argc>2) - max = rtems_shell_str2int(argv[2]); - max /= 16; + if (argc>2) { + max = rtems_shell_str2int(argv[2]); + max /= 16; + } if (!max) - max = 20; + max = 1; for (m=0;m<max;m++) { - fprintf(stdout,"0x%08X ",addr); + printf("0x%08" PRIXPTR " ",addr); + p = (unsigned char *) addr; pw = (unsigned short*) addr; for (n=0;n<8;n++) - fprintf(stdout,"%02X %02X%c",pw[n]/0x100,pw[n]%0x100,n==3?'-':' '); - for (n=0;n<8;n++) { - fprintf(stdout,"%c",isprint(pw[n]/0x100)?pw[n]/0x100:'.'); - fprintf(stdout,"%c",isprint(pw[n]%0x100)?pw[n]%0x100:'.'); + printf("%04X%c",pw[n],n==3?'-':' '); + for (n=0;n<16;n++) { + printf("%c",isprint(p[n])?p[n]:'.'); } - fprintf(stdout,"\n"); + printf("\n"); addr += 16; } - rtems_current_shell_env->mdump_addr = addr; return 0; } rtems_shell_cmd_t rtems_shell_WDUMP_Command = { "wdump", /* name */ - "wdump [addr [size]]", /* usage */ + "wdump [address [length]]", /* usage */ "mem", /* topic */ rtems_shell_main_mwdump, /* command */ NULL, /* alias */ diff --git a/cpukit/libmisc/shell/main_perioduse.c b/cpukit/libmisc/shell/main_perioduse.c index 349e168cd4..9ad18d76de 100644 --- a/cpukit/libmisc/shell/main_perioduse.c +++ b/cpukit/libmisc/shell/main_perioduse.c @@ -21,18 +21,36 @@ #include <rtems/shell.h> #include "internal.h" -int rtems_shell_main_perioduse(int argc,char *argv[]) +int rtems_shell_main_perioduse( + int argc, + char *argv[] +) { - if ( argc >= 1 && !strcmp( argv[1], "-r" ) ) { - printf( "Resetting Period Usage information\n" ); - rtems_rate_monotonic_reset_all_statistics(); - } else { + /* + * When invoked with no arguments, print the report. + */ + if ( argc == 1 ) { rtems_rate_monotonic_report_statistics_with_plugin( stdout, (rtems_printk_plugin_t)fprintf ); + return 0; } - return 0; + + /* + * When invoked with the single argument -r, reset the statistics. + */ + if ( argc == 2 && !strcmp( argv[1], "-r" ) ) { + printf( "Resetting Period Usage information\n" ); + rtems_rate_monotonic_reset_all_statistics(); + return 0; + } + + /* + * OK. The user did something wrong. + */ + fprintf( stderr, "%s: [-r]\n", argv[0] ); + return -1; } rtems_shell_cmd_t rtems_shell_PERIODUSE_Command = { diff --git a/cpukit/libmisc/shell/main_pwd.c b/cpukit/libmisc/shell/main_pwd.c index 6b9a743b2f..80b8004834 100644 --- a/cpukit/libmisc/shell/main_pwd.c +++ b/cpukit/libmisc/shell/main_pwd.c @@ -23,11 +23,15 @@ #include <rtems/shell.h> #include "internal.h" -int rtems_shell_main_pwd (int argc, char *argv[]) { +int rtems_shell_main_pwd( + int argc, + char *argv[] +) +{ char dir[1024]; getcwd(dir,1024); - fprintf(stdout,"%s\n",dir); + puts(dir); return 0; } diff --git a/cpukit/libmisc/shell/main_rm.c b/cpukit/libmisc/shell/main_rm.c index 19b3d0693c..9bf60b61cf 100644 --- a/cpukit/libmisc/shell/main_rm.c +++ b/cpukit/libmisc/shell/main_rm.c @@ -25,14 +25,16 @@ #include <rtems/shell.h> #include "internal.h" -int rtems_shell_main_rm(int argc, char *argv[]) +int rtems_shell_main_rm( + int argc, + char *argv[] +) { - int n; - n = 1; + int n = 1; - while (n<argc) { + while ( n<argc ) { if (unlink(argv[n])) { - fprintf(stdout,"error %s:rm %s\n",strerror(errno),argv[n]); + fprintf(stderr,"%s: %s: %s\n", argv[0], argv[n], strerror(errno)); return -1; } n++; diff --git a/cpukit/libmisc/shell/main_rmdir.c b/cpukit/libmisc/shell/main_rmdir.c index b7069df4cc..df94a7efbf 100644 --- a/cpukit/libmisc/shell/main_rmdir.c +++ b/cpukit/libmisc/shell/main_rmdir.c @@ -30,13 +30,15 @@ int rtems_shell_main_rmdir (int argc, char *argv[]) char *dir; int n; - n=1; - while (n<argc) { - dir=argv[n++]; - if (rmdir(dir)) - fprintf(stdout, "rmdir '%s' failed:%s\n", dir, strerror(errno)); + n = 1; + while (n < argc) { + dir = argv[n++]; + if (rmdir(dir)) { + fprintf(stderr,"%s: %s: %s\n", argv[0], dir, strerror(errno)); + return -1; + } } - return errno; + return 0; } rtems_shell_cmd_t rtems_shell_RMDIR_Command = { diff --git a/cpukit/libmisc/shell/main_stackuse.c b/cpukit/libmisc/shell/main_stackuse.c index 43d8fa74d7..6c6c9251ae 100644 --- a/cpukit/libmisc/shell/main_stackuse.c +++ b/cpukit/libmisc/shell/main_stackuse.c @@ -22,9 +22,12 @@ #include <rtems/shell.h> #include "internal.h" -int rtems_shell_main_stackuse(int argc,char *argv[]) +int rtems_shell_main_stackuse( + int argc, + char *argv[] +) { - rtems_stack_checker_report_usage_with_plugin( + rtems_stack_checker_report_usage_with_plugin( stdout, (rtems_printk_plugin_t)fprintf ); diff --git a/cpukit/libmisc/shell/main_tty.c b/cpukit/libmisc/shell/main_tty.c index 37e2509f01..185478bc28 100644 --- a/cpukit/libmisc/shell/main_tty.c +++ b/cpukit/libmisc/shell/main_tty.c @@ -26,9 +26,12 @@ #include <rtems/shell.h> #include "internal.h" -int rtems_shell_main_tty(int argc,char *argv[]) +int rtems_shell_main_tty( + int argc, + char *argv[] +) { - printf("%s\n",ttyname(fileno(stdin))); + printf("%s\n", ttyname(fileno(stdin))); return 0; } diff --git a/cpukit/libmisc/shell/main_umask.c b/cpukit/libmisc/shell/main_umask.c index 37c23605a3..4dd35f1af4 100644 --- a/cpukit/libmisc/shell/main_umask.c +++ b/cpukit/libmisc/shell/main_umask.c @@ -28,7 +28,10 @@ #include <rtems/shell.h> #include "internal.h" -int rtems_shell_main_umask(int argc,char *argv[]) +int rtems_shell_main_umask( + int argc, + char *argv[] +) { mode_t msk = umask(0); diff --git a/cpukit/libmisc/shell/main_unmount.c b/cpukit/libmisc/shell/main_unmount.c index f191610275..0a9de416fe 100644 --- a/cpukit/libmisc/shell/main_unmount.c +++ b/cpukit/libmisc/shell/main_unmount.c @@ -27,25 +27,25 @@ #include <rtems/fsmount.h> #include "internal.h" -int rtems_shell_main_unmount(int argc, char *argv[]) +int rtems_shell_main_unmount( + int argc, + char *argv[] +) { char* mount_point = NULL; int arg; - for (arg = 1; arg < argc; arg++) - { + for (arg = 1; arg < argc; arg++) { if (!mount_point) mount_point = argv[arg]; - else - { - printf ("error: only one mount path require: %s\n", argv[arg]); + else { + fprintf (stderr, "error: only one mount path require: %s\n", argv[arg]); return 1; } } - if (!mount_point) - { - printf ("error: no mount point\n"); + if (!mount_point) { + fprintf (stderr, "error: no mount point\n"); return 1; } @@ -53,9 +53,8 @@ int rtems_shell_main_unmount(int argc, char *argv[]) * Unmount the disk. */ - if (unmount (mount_point) < 0) - { - fprintf (stdout, "error: unmount failed: %s: %s\n", + if (unmount (mount_point) < 0) { + fprintf (stderr, "error: unmount failed: %s: %s\n", mount_point, strerror (errno)); return 1; } diff --git a/cpukit/libmisc/shell/main_whoami.c b/cpukit/libmisc/shell/main_whoami.c index 289cd15cc8..5a5c51e965 100644 --- a/cpukit/libmisc/shell/main_whoami.c +++ b/cpukit/libmisc/shell/main_whoami.c @@ -27,12 +27,15 @@ #include <rtems/shell.h> #include "internal.h" -int rtems_shell_main_whoami(int argc,char *argv[]) +int rtems_shell_main_whoami( + int argc, + char *argv[] +) { struct passwd *pwd; - pwd = getpwuid(getuid()); - printf("%s\n",pwd?pwd->pw_name:"nobody"); + pwd = getpwuid(geteuid()); + printf( "%s\n", (pwd) ? pwd->pw_name : "nobody"); return 0; } diff --git a/cpukit/libmisc/shell/shell.h b/cpukit/libmisc/shell/shell.h index d9312a4a6c..9415c5940f 100644 --- a/cpukit/libmisc/shell/shell.h +++ b/cpukit/libmisc/shell/shell.h @@ -74,7 +74,7 @@ int rtems_shell_make_args( ); int rtems_shell_scanline(char * line,int size,FILE * in,FILE * out) ; -void rtems_shell_cat_file(FILE * out,char *name); +int rtems_shell_cat_file(FILE * out,char *name); void rtems_shell_write_file(char *name,char * content); /** @@ -139,7 +139,6 @@ typedef struct { int exit_shell; /* logout */ int forever ; /* repeat login */ int errorlevel; - uintptr_t mdump_addr; const char* input; const char* output; int output_append; |