Changes to rtems_shell_script() working directory?

Peter Dufault dufault at hda.com
Sun Jun 28 14:38:32 UTC 2015


> On Jun 28, 2015, at 07:20 , Peter Dufault <dufault at hda.com> wrote:
> 
> Does anyone know of changes in how the shell starts up that would affect the current working directory?  My 
> "rc_file()" function no longer works, I see the output "shell: open input init.rc failed: No such file or directory” on the console.
> 
> Note that the rc_file() function verified the file existed with stat() before calling rtems_shell_script().
> 
> This is RTEMS 4.11 on the Phytec MPC5554 updated this AM and previously updated last September.  I can’t attach the debugger at the moment because this is at a remote site.
> 
> void rc_file(const char *name)
> {
>  struct stat st;
>  if (stat(name, &st) == 0) {
>    if (rtems_shell_script(
>      "RUN_RC",
>      rc_file.stacksize,
>      rc_file.priority,
>      name,
>      "/dev/console",
>      1,  /* Output append. */
>      1,  /* Wait. */
>      0   /* Echo. */
>    )) {
>      fprintf(stderr, "Error running \"%s\".\n", name);
>    } 
>  }
> }         
> 
> 

Now I’m confused.  When an RTEMS classic task is started does it inherit the current working directory of the creating task?  It fails at line 772 of shell.c at the following test, which would only work if the new task was still in the current working directory of the task that created it:

  if (shell_env->input && strcmp(shell_env_arg->input, "stdin") != 0) {
    FILE *input = fopen(shell_env_arg->input, "r");
    if (!input) {                                          // XXX Line 772, fails here.
      fprintf(stderr, "shell: open input %s failed: %s\n",
              shell_env_arg->input, strerror(errno));
      return false;
    }
    stdin = input;
    stdinToClose = input;
    shell_env->forever = false;
    input_file =true;
  }

However, further down in the file at line 861 it checks to see if an input_file is open and if so changes to the current working directory of the creating task, which is only needed if the new task isn’t in the current working directory of the task that created it:

        if (input_file)
          chdir(shell_env->cwd);				// XXX Line 861, why the chdir()?
        else
          chdir("/"); /* XXX: chdir to getpwent homedir */

This appears to be the same as from last September, so it shouldn’t have been working before if it doesn’t work now.

I’m going to change it to do the chdir() before the fopen() and see if that then works.

Peter
-----------------
Peter Dufault
HD Associates, Inc.      Software and System Engineering




More information about the users mailing list