#include <sys/wait.h>
#include <unistd.h>
#include <getopt.h>
+#include "busybox.h"
+#include "cmdedit.h"
#ifdef BB_LOCALE_SUPPORT
#include <locale.h>
#include <glob.h>
#define expand_t glob_t
#endif
-#include "busybox.h"
-#include "cmdedit.h"
static const int MAX_READ = 128; /* size of input buffer for `read' builtin */
/* Globals that are static to this file */
-static char *cwd;
+static const char *cwd;
static char *local_pending_command = NULL;
static struct jobset job_list = { NULL, NULL };
static int argc;
printf("cd: %s: %m\n", newdir);
return EXIT_FAILURE;
}
- cwd = xgetcwd(cwd);
-
+ cwd = xgetcwd((char *)cwd);
+ if (!cwd)
+ cwd = unknown;
return EXIT_SUCCESS;
}
/* built-in 'pwd' handler */
static int builtin_pwd(struct child_prog *dummy)
{
+ cwd = xgetcwd((char *)cwd);
+ if (!cwd)
+ cwd = unknown;
printf( "%s\n", cwd);
return EXIT_SUCCESS;
}
(tmpcmd = strsep_space(cmd, &ix)) != NULL; cmd += ix, ix=0) {
if (*tmpcmd == '\0')
break;
+ /* we need to trim() the result for glob! */
+ trim(tmpcmd);
retval = glob(tmpcmd, flags, NULL, &expand_result);
free(tmpcmd); /* Free mem allocated by strsep_space */
if (retval == GLOB_NOSPACE) {
error_msg(out_of_space);
return FALSE;
}
- if (i>0) {
- strcat(command+total_length, " ");
- total_length+=1;
- }
+ strcat(command+total_length, " ");
+ total_length+=1;
strcat(command+total_length, expand_result.gl_pathv[i]);
total_length+=length;
}
if (!job_list.fg) {
/* move the shell to the foreground */
/* suppress messages when run from /linuxrc mag@sysgo.de */
- if (tcsetpgrp(0, getpid()) && errno != ENOTTY)
+ if (tcsetpgrp(0, getpgrp()) && errno != ENOTTY)
perror_msg("tcsetpgrp");
}
}
{
if (cwd) {
free(cwd);
- cwd = NULL;
}
if (local_pending_command)
free(local_pending_command);
/* initialize the cwd -- this is never freed...*/
cwd = xgetcwd(0);
+ if (!cwd)
+ cwd = unknown;
#ifdef BB_FEATURE_CLEAN_UP
atexit(free_memory);