Changeset b2712e3 in rtems for cpukit/libmisc/shell/cmds.c


Ignore:
Timestamp:
May 24, 2001, 9:58:39 PM (20 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
87fb080d
Parents:
e565720a
Message:

2000-05-24 Fernando Ruiz Casas <fernando.ruiz@…>

  • monitor/mon-prmisc.c: Correct print line.
  • shell/Makefile.am: Added new file telnetd.c.
  • shell/telnetd.c, shell/telnetd.h, shell/pty.c: New files.
  • shell/shell.c, shell/cmds.c, shell/shell.h: Numerous improvments:
    • The shell_init has a new parameter 'forever' because in /dev/console you need that this process runs forever but in tcp/ip not. (respawn?)
    • A new task for every session opened trought tcp/ip telnet client. (the chargen,daytime and more are possible of implementation but I ask me if they are necesary)
    • Exit from the session delete the task and when the client fails too.
    • More cmds have been implemented. (very reduced version of these) umask, chmod, id, whoami, rm, cat, ...
    • A reduced line edit has been implemented.

Ctrl-C abort the input,
Ctrl-d in the first position gives EOF (logout).
'\b' and DEL makes the rubout operation.
I think that readline() for every session spents a lot of resources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libmisc/shell/cmds.c

    re565720a rb2712e3  
    1414 *
    1515 * TODO: A lot of improvements of course.
    16  *      cat, cp, rm, mv, ...
     16 *      cp, mv, ...
    1717 *      hexdump,
    1818 *     
     
    3535#include <fcntl.h>
    3636#include <unistd.h>
     37#include <pwd.h>
     38#include <grp.h>
    3739#include <errno.h>
    3840#include <sys/types.h>
     
    258260   struct dirent       *dp;
    259261   struct stat         stat_buf;
     262   struct passwd     * pwd;
     263   struct group      * grp;
     264   char * user;
     265   char * group;
    260266   char   sbuf[256];
    261267   char   nbuf[1024];
     
    280286      { /* AWFUL buts works...*/
    281287         strftime(sbuf,sizeof(sbuf)-1,"%b %d %H:%M",gmtime(&stat_buf.st_atime));     
    282          printf("%c%c%c%c%c%c%c%c%c%c %3d rtems  rtems  %11d %s %s%c\n",
     288         pwd=getpwuid(stat_buf.st_uid);
     289         user=pwd?pwd->pw_name:"nouser";
     290         grp=getgrgid(stat_buf.st_gid);
     291         group=grp?grp->gr_name:"nogrp";
     292         printf("%c%c%c%c%c%c%c%c%c%c %3d %6.6s %6.6s %11d %s %s%c\n",
    283293                 (S_ISLNK(stat_buf.st_mode)?('l'):
    284294                    (S_ISDIR(stat_buf.st_mode)?('d'):('-'))),
     
    293303                 (stat_buf.st_mode & S_IXOTH)?('x'):('-'),
    294304                 (int)stat_buf.st_nlink,
     305                 user,group,
    295306                 (int)stat_buf.st_size,
    296307                 sbuf,
     
    351362 };
    352363 return 0;
     364}
     365/*-----------------------------------------------------------*/         
     366int main_cat   (int argc, char *argv[])
     367{
     368   int n;
     369   n=1;
     370   while (n<argc) cat_file(stdout,argv[n++]);
     371   return 0;
     372}
     373/*-----------------------------------------------------------*/         
     374int main_rm    (int argc, char *argv[])
     375{
     376   int n;
     377   n=1;
     378   while (n<argc) {
     379    if (unlink(argv[n])) {
     380     printf("error %s:rm %s\n",strerror(errno),argv[n]);
     381     return -1;
     382    };
     383    n++;
     384   };
     385   return 0;
    353386}
    354387/*-----------------------------------------------------------*/         
     
    425458  return 0;
    426459}
     460/*-----------------------------------------------------------*/
     461int main_logoff(int argc,char *argv[])
     462{
     463  printf("logoff from the system..."); 
     464  current_shell_env->exit_shell=TRUE;   
     465  return 0;
     466}
     467/*-----------------------------------------------------------*/
     468int main_tty   (int argc,char *argv[])
     469{
     470  printf("%s\n",ttyname(fileno(stdin)));
     471  return 0;
     472}
     473/*-----------------------------------------------------------*/
     474int main_whoami(int argc,char *argv[])
     475{
     476   struct passwd     * pwd;
     477   pwd=getpwuid(getuid());
     478   printf("%s\n",pwd?pwd->pw_name:"nobody");
     479   return 0;
     480}
     481/*-----------------------------------------------------------*/
     482int main_id    (int argc,char *argv[])
     483{
     484   struct passwd     * pwd;
     485   struct group      * grp;
     486   pwd=getpwuid(getuid());
     487   grp=getgrgid(getgid());
     488   printf("uid=%d(%s),gid=%d(%s),",
     489                   getuid(),pwd?pwd->pw_name:"",
     490                   getgid(),grp?grp->gr_name:"");
     491   pwd=getpwuid(geteuid());
     492   grp=getgrgid(getegid());
     493   printf("euid=%d(%s),egid=%d(%s)\n",
     494                   geteuid(),pwd?pwd->pw_name:"",
     495                   getegid(),grp?grp->gr_name:"");
     496   return 0;
     497}
     498/*-----------------------------------------------------------*/
     499int main_umask(int argc,char *argv[])
     500{
     501   mode_t msk=umask(0);
     502   if (argc == 2) msk=str2int(argv[1]);
     503   umask(msk);
     504   msk=umask(0);
     505   printf("0%o\n",msk);
     506   umask(msk);
     507   return 0;
     508}
     509/*-----------------------------------------------------------*/
     510int main_chmod(int argc,char *argv[])
     511{
     512   int n;
     513   mode_t mode;
     514   if (argc > 2){
     515    mode=str2int(argv[1])&0777;
     516    n=2;
     517    while (n<argc) chmod(argv[n++],mode);
     518   };
     519   return 0;
     520}
    427521/*-----------------------------------------------------------*         
    428522 * with this you can call at all the rtems monitor commands.
     
    443537  rtems_monitor_command_entry_t *command;
    444538  extern rtems_monitor_command_entry_t rtems_monitor_commands[];
     539  /* monitor topic */
     540  command=rtems_monitor_commands;
     541  while (command) {
     542   if (strcmp("exit",command->command)) /*Exclude EXIT (alias quit)*/
     543    shell_add_cmd(command->command,"monitor",
     544                  command->usage  ,main_monitor);
     545   command=command->next;
     546  };
    445547  /* dir[ectories] topic */
    446548  shell_add_cmd  ("ls"    ,"dir","ls [dir]     # list files in the directory" ,main_ls   );
     
    450552  shell_add_cmd  ("pwd"   ,"dir","pwd          # print work directory"        ,main_pwd  );
    451553  shell_add_cmd  ("chroot","dir","chroot [dir] # change the root directory"   ,main_chroot);
     554  shell_add_cmd  ("cat"   ,"dir","cat n1 [n2 [n3...]]# show the ascii contents",main_cat );
     555  shell_add_cmd  ("rm"    ,"dir","rm n1 [n2 [n3...]]# remove files"           ,main_rm   );
     556  shell_add_cmd  ("chmod" ,"dir","chmod 0777 n1 n2... #change filemode"       ,main_chmod);
    452557
    453558  shell_alias_cmd("ls"    ,"dir");
     
    455560
    456561  /* misc. topic */
     562  shell_add_cmd  ("logoff","misc","logoff from the system"                    ,main_logoff);
     563  shell_alias_cmd("logoff","exit");
    457564  shell_add_cmd  ("date" ,"misc","date [[MMDDYY]hhmm[ss]]"                    ,main_date);
    458565  shell_add_cmd  ("reset","misc","reset the BSP"                              ,main_reset);
    459566  shell_add_cmd  ("alias","misc","alias old new"                              ,main_alias);
     567  shell_add_cmd  ("tty"  ,"misc","show ttyname"                               ,main_tty  );
     568  shell_add_cmd  ("whoami","misc","show current user"                         ,main_whoami);
     569  shell_add_cmd  ("id"    ,"misc","show uid,gid,euid,egid"                    ,main_id    );
     570  shell_add_cmd  ("umask" ,"misc","umask [new_umask]"                         ,main_umask );
     571
    460572
    461573  /* memory topic */
     
    468580  shell_add_cmd  ("malloc","mem","mem  show memory malloc'ed"                 ,main_mem);
    469581#endif 
    470   /* monitor topic */
    471   command=rtems_monitor_commands;
    472   while (command) {
    473    shell_add_cmd(command->command,"monitor",
    474                  command->usage  ,main_monitor);
    475    command=command->next;
    476   };
    477 }
    478 /*-----------------------------------------------------------*/         
     582}
     583/*-----------------------------------------------------------*/         
Note: See TracChangeset for help on using the changeset viewer.