mirror of https://github.com/omar-polo/gmid.git
ensure absolute paths in config-less mode
This commit is contained in:
parent
6ff23c6739
commit
bcf5d929e6
10
gmid.c
10
gmid.c
|
@ -19,6 +19,7 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <limits.h>
|
||||
#include <netdb.h>
|
||||
#include <pwd.h>
|
||||
#include <signal.h>
|
||||
|
@ -544,11 +545,14 @@ main(int argc, char **argv)
|
|||
hosts[0].locations[0].match = "*";
|
||||
|
||||
switch (argc) {
|
||||
case 0:
|
||||
hosts[0].dir = ".";
|
||||
case 0: {
|
||||
char path[PATH_MAX];
|
||||
|
||||
hosts[0].dir = getcwd(path, sizeof(path));
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
hosts[0].dir = argv[0];
|
||||
hosts[0].dir = absolutify_path(argv[0]);
|
||||
break;
|
||||
default:
|
||||
usage(getprogname());
|
||||
|
|
18
utils.c
18
utils.c
|
@ -62,3 +62,21 @@ filesize(int fd)
|
|||
return -1;
|
||||
return len;
|
||||
}
|
||||
|
||||
char *
|
||||
absolutify_path(const char *path)
|
||||
{
|
||||
char *wd, *r;
|
||||
|
||||
if (*path == '/') {
|
||||
if ((r = strdup(path)) == NULL)
|
||||
err(1, "strdup");
|
||||
return r;
|
||||
}
|
||||
|
||||
wd = getcwd(NULL, 0);
|
||||
if (asprintf(&r, "%s/%s", wd, path) == -1)
|
||||
err(1, "asprintf");
|
||||
free(wd);
|
||||
return r;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue