version 1.186, 2018/01/12 10:22:02 |
version 1.187, 2018/11/22 10:36:40 |
|
|
} |
} |
|
|
const char * |
const char * |
|
find_cwd(void) |
|
{ |
|
char resolved1[PATH_MAX], resolved2[PATH_MAX]; |
|
static char cwd[PATH_MAX]; |
|
const char *pwd; |
|
|
|
if (getcwd(cwd, sizeof cwd) == NULL) |
|
return (NULL); |
|
if ((pwd = getenv("PWD")) == NULL || *pwd == '\0') |
|
return (cwd); |
|
|
|
/* |
|
* We want to use PWD so that symbolic links are maintained, |
|
* but only if it matches the actual working directory. |
|
*/ |
|
if (realpath(pwd, resolved1) == NULL) |
|
return (cwd); |
|
if (realpath(cwd, resolved2) == NULL) |
|
return (cwd); |
|
if (strcmp(resolved1, resolved2) != 0) |
|
return (cwd); |
|
return (pwd); |
|
} |
|
|
|
const char * |
find_home(void) |
find_home(void) |
{ |
{ |
struct passwd *pw; |
struct passwd *pw; |
|
|
main(int argc, char **argv) |
main(int argc, char **argv) |
{ |
{ |
char *path, *label, *cause, **var; |
char *path, *label, *cause, **var; |
char tmp[PATH_MAX]; |
|
const char *s, *shell, *cwd; |
const char *s, *shell, *cwd; |
int opt, flags, keys; |
int opt, flags, keys; |
const struct options_table_entry *oe; |
const struct options_table_entry *oe; |
|
|
global_environ = environ_create(); |
global_environ = environ_create(); |
for (var = environ; *var != NULL; var++) |
for (var = environ; *var != NULL; var++) |
environ_put(global_environ, *var); |
environ_put(global_environ, *var); |
if ((cwd = getenv("PWD")) == NULL && |
if ((cwd = find_cwd()) != NULL) |
(cwd = getcwd(tmp, sizeof tmp)) != NULL) |
|
environ_set(global_environ, "PWD", "%s", cwd); |
environ_set(global_environ, "PWD", "%s", cwd); |
|
|
global_options = options_create(NULL); |
global_options = options_create(NULL); |