summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc/shell/shell.c
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2014-05-29 15:05:56 +1000
committerChris Johns <chrisj@rtems.org>2014-06-04 22:32:55 +1000
commitbb581906a68a07074a5b0bc6cb6698fe983ca3ca (patch)
tree21cdfe7a360964039699f6d0a26414906d0f0af5 /cpukit/libmisc/shell/shell.c
parentscore: Rename _Scheduler_Update() (diff)
downloadrtems-bb581906a68a07074a5b0bc6cb6698fe983ca3ca.tar.bz2
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.
Diffstat (limited to 'cpukit/libmisc/shell/shell.c')
-rw-r--r--cpukit/libmisc/shell/shell.c49
1 files changed, 32 insertions, 17 deletions
diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c
index 0f31f2a5c2..a94724f95a 100644
--- a/cpukit/libmisc/shell/shell.c
+++ b/cpukit/libmisc/shell/shell.c
@@ -114,9 +114,25 @@ static void rtems_shell_current_env_make_key(void)
*/
rtems_shell_env_t *rtems_shell_get_current_env(void)
{
- void *ptr = pthread_getspecific(rtems_shell_current_env_key);
- assert (ptr != NULL);
- return (rtems_shell_env_t *) ptr;
+ return (rtems_shell_env_t *) pthread_getspecific(rtems_shell_current_env_key);
+}
+
+/*
+ * Duplication the current shell environment and if none is set
+ * clear it.
+ */
+void rtems_shell_dup_current_env(rtems_shell_env_t *copy)
+{
+ rtems_shell_env_t *env = rtems_shell_get_current_env();
+ if (env) {
+ *copy = *env;
+ }
+ else {
+ memset(copy, 0, sizeof(rtems_shell_env_t));
+ copy->magic = rtems_build_name('S', 'E', 'N', 'V');
+ copy->devname = CONSOLE_DEVICE_NAME;
+ copy->taskname = "RTSH";
+ }
}
/*
@@ -511,9 +527,13 @@ static void rtems_shell_init_issue(void)
}
static bool rtems_shell_login(FILE * in,FILE * out) {
- FILE *fd;
- int c;
- time_t t;
+ rtems_shell_env_t *env;
+ FILE *fd;
+ int c;
+ time_t t;
+
+ env = rtems_shell_get_current_env();
+ assert(env != NULL);
rtems_shell_init_issue();
setuid(0);
@@ -522,16 +542,16 @@ static bool rtems_shell_login(FILE * in,FILE * out) {
rtems_current_user_env->egid =0;
if (out) {
- if ((rtems_current_shell_env->devname[5]!='p')||
- (rtems_current_shell_env->devname[6]!='t')||
- (rtems_current_shell_env->devname[7]!='y')) {
+ if ((env->devname[5]!='p')||
+ (env->devname[6]!='t')||
+ (env->devname[7]!='y')) {
fd = fopen("/etc/issue","r");
if (fd) {
while ((c=fgetc(fd))!=EOF) {
if (c=='@') {
switch(c=fgetc(fd)) {
case 'L':
- fprintf(out,"%s",rtems_current_shell_env->devname);
+ fprintf(out,"%s", env->devname);
break;
case 'B':
fprintf(out,"0");
@@ -578,7 +598,7 @@ static bool rtems_shell_login(FILE * in,FILE * out) {
if (c=='%') {
switch(c=fgetc(fd)) {
case 't':
- fprintf(out,"%s",rtems_current_shell_env->devname);
+ fprintf(out,"%s", env->devname);
break;
case 'h':
fprintf(out,"0");
@@ -617,12 +637,7 @@ static bool rtems_shell_login(FILE * in,FILE * out) {
}
}
- return rtems_shell_login_prompt(
- in,
- out,
- rtems_current_shell_env->devname,
- rtems_current_shell_env->login_check
- );
+ return rtems_shell_login_prompt(in, out, env->devname, env->login_check);
}
#if defined(SHELL_DEBUG)