commit bcf5d929e608a3c61a79f5c021478760db54d271 from: Omar Polo date: Mon Feb 01 11:07:57 2021 UTC ensure absolute paths in config-less mode commit - 6ff23c673989f92a42da0029728fe80ca3dde40f commit + bcf5d929e608a3c61a79f5c021478760db54d271 blob - d3ff036f395941aa34c2ac06ea29b110c5e34b34 blob + 4fbcbbb4c3303d603f6c34d0d35cc256b7a4ba4e --- gmid.c +++ gmid.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -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()); blob - a87c92793c83126a039f7a2d51925e11cd9cd0b4 blob + c32ecb8af4fe2267ab399151dff9bedf9ef4c50c --- utils.c +++ 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; +}