|
char buf[MAXPATHLEN];
|
|
if (aux_info[AT_EXECPATH] != 0) {
|
|
char *kexecpath;
|
|
|
|
kexecpath = aux_info[AT_EXECPATH]->a_un.a_ptr;
|
|
dbg("AT_EXECPATH %p %s", kexecpath, kexecpath);
|
|
if (kexecpath[0] == '/')
|
|
obj_main->path = kexecpath;
|
|
else if (getcwd(buf, sizeof(buf)) == NULL ||
|
|
strlcat(buf, "/", sizeof(buf)) >= sizeof(buf) ||
|
|
strlcat(buf, kexecpath, sizeof(buf)) >= sizeof(buf))
|
|
obj_main->path = xstrdup(argv0);
|
|
else
|
|
obj_main->path = xstrdup(buf);
|
|
} else {
|
|
char resolved[MAXPATHLEN];
|
|
dbg("No AT_EXECPATH");
|
|
if (argv0[0] == '/') {
|
|
if (realpath(argv0, resolved) != NULL)
|
|
obj_main->path = xstrdup(resolved);
|
|
else
|
|
obj_main->path = xstrdup(argv0);
|
|
} else {
|
|
if (getcwd(buf, sizeof(buf)) != NULL
|
|
&& strlcat(buf, "/", sizeof(buf)) < sizeof(buf)
|
|
&& strlcat(buf, argv0, sizeof (buf)) < sizeof(buf)
|
|
&& access(buf, R_OK) == 0
|
|
&& realpath(buf, resolved) != NULL)
|
|
obj_main->path = xstrdup(resolved);
|
|
else
|
|
obj_main->path = xstrdup(argv0);
|
|
}
|
|
}
|
|
dbg("obj_main path %s", obj_main->path);
|
|
obj_main->mainprog = true;
|