Changeset bb58190 in rtems


Ignore:
Timestamp:
May 29, 2014, 5:05:56 AM (5 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.11, master
Children:
a20c114
Parents:
4d1f500
git-author:
Chris Johns <chrisj@…> (05/29/14 05:05:56)
git-committer:
Chris Johns <chrisj@…> (06/04/14 12:32:55)
Message:

shell: Add rtems_shell_dup_current_env to get a default env.

Remove rtems_current_shell_env as this is dangerous because
the env can be NULL if used outside of a valid shell with the
POSIX key to an env set up.

Clean up the usage of rtems_current_shell_env.

Location:
cpukit/libmisc/shell
Files:
4 edited

Legend:

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

    r4d1f500 rbb58190  
    4444  /* Valid user? */
    4545  if (pw != NULL && strcmp( pw->pw_passwd, "!") != 0) {
     46    rtems_shell_env_t *env = rtems_shell_get_current_env();
    4647    setuid( pw->pw_uid);
    4748    setgid( pw->pw_gid);
    4849    rtems_current_user_env->euid = 0;
    4950    rtems_current_user_env->egid = 0;
    50     chown( rtems_current_shell_env->devname, pw->pw_uid, 0);
     51    if (env)
     52      chown( env->devname, pw->pw_uid, 0);
    5153    rtems_current_user_env->euid = pw->pw_uid;
    5254    rtems_current_user_env->egid = pw->pw_gid;
  • cpukit/libmisc/shell/main_logoff.c

    r4d1f500 rbb58190  
    2626)
    2727{
     28  rtems_shell_env_t *env = rtems_shell_get_current_env();
     29
    2830  printf("logoff from the system...");
    2931
    30   rtems_current_shell_env->exit_shell = true;
     32  if (env)
     33    env->exit_shell = true;
    3134
    3235  return 0;
  • cpukit/libmisc/shell/shell.c

    r4d1f500 rbb58190  
    115115rtems_shell_env_t *rtems_shell_get_current_env(void)
    116116{
    117   void *ptr = pthread_getspecific(rtems_shell_current_env_key);
    118   assert (ptr != NULL);
    119   return (rtems_shell_env_t *) ptr;
     117  return (rtems_shell_env_t *) pthread_getspecific(rtems_shell_current_env_key);
     118}
     119
     120/*
     121 *  Duplication the current shell environment and if none is set
     122 *  clear it.
     123 */
     124void rtems_shell_dup_current_env(rtems_shell_env_t *copy)
     125{
     126  rtems_shell_env_t *env = rtems_shell_get_current_env();
     127  if (env) {
     128    *copy = *env;
     129  }
     130  else {
     131    memset(copy, 0, sizeof(rtems_shell_env_t));
     132    copy->magic    = rtems_build_name('S', 'E', 'N', 'V');
     133    copy->devname  = CONSOLE_DEVICE_NAME;
     134    copy->taskname = "RTSH";
     135  }
    120136}
    121137
     
    512528
    513529static bool rtems_shell_login(FILE * in,FILE * out) {
    514   FILE          *fd;
    515   int            c;
    516   time_t         t;
     530  rtems_shell_env_t *env;
     531  FILE              *fd;
     532  int               c;
     533  time_t            t;
     534
     535  env = rtems_shell_get_current_env();
     536  assert(env != NULL);
    517537
    518538  rtems_shell_init_issue();
     
    523543
    524544  if (out) {
    525     if ((rtems_current_shell_env->devname[5]!='p')||
    526         (rtems_current_shell_env->devname[6]!='t')||
    527         (rtems_current_shell_env->devname[7]!='y')) {
     545    if ((env->devname[5]!='p')||
     546        (env->devname[6]!='t')||
     547        (env->devname[7]!='y')) {
    528548      fd = fopen("/etc/issue","r");
    529549      if (fd) {
     
    532552            switch(c=fgetc(fd)) {
    533553              case 'L':
    534                 fprintf(out,"%s",rtems_current_shell_env->devname);
     554                fprintf(out,"%s", env->devname);
    535555                break;
    536556              case 'B':
     
    579599            switch(c=fgetc(fd)) {
    580600              case 't':
    581                 fprintf(out,"%s",rtems_current_shell_env->devname);
     601                fprintf(out,"%s", env->devname);
    582602                break;
    583603              case 'h':
     
    618638  }
    619639
    620   return rtems_shell_login_prompt(
    621     in,
    622     out,
    623     rtems_current_shell_env->devname,
    624     rtems_current_shell_env->login_check
    625   );
     640  return rtems_shell_login_prompt(in, out, env->devname, env->login_check);
    626641}
    627642
  • cpukit/libmisc/shell/shell.h

    r4d1f500 rbb58190  
    209209
    210210rtems_shell_env_t *rtems_shell_get_current_env(void);
    211 #define rtems_current_shell_env rtems_shell_get_current_env()
     211void rtems_shell_dup_current_env(rtems_shell_env_t *);
    212212
    213213/*
Note: See TracChangeset for help on using the changeset viewer.