run tincd from the same directory as tincctl and pass all options to it

For tincctl start, run tincd from dirname($0) not SBINDIR -
this allows painless alternative directory installation and
running from build directory too.

Also while at it, pass the rest of command line to tincd, not
only options before "start" argument.  This way it's possible
to pass options to tincd like this:
  tincctl -n net start -- -d 1 -R -U tincuser ...

And also add missing newline at the end of error message there.

Signed-Off-By: Michael Tokarev <mjt@tls.msk.ru>
This commit is contained in:
Michael Tokarev 2011-08-07 12:05:07 +04:00 committed by Guus Sliepen
parent 2696ad2cca
commit a7556a9d2c

View file

@ -568,9 +568,26 @@ int main(int argc, char *argv[], char *envp[]) {
} }
if(!strcasecmp(argv[optind], "start")) { if(!strcasecmp(argv[optind], "start")) {
argv[optind] = NULL; int i, j;
execve(SBINDIR "/tincd", argv, envp); char *c;
fprintf(stderr, "Could not start tincd: %s", strerror(errno)); char *slash = strrchr(argv[0], '/');
#ifdef HAVE_MINGW
if ((c = strrchr(argv[0], '\\')) > slash)
slash = c;
#endif
if (slash++) {
c = xmalloc((slash - argv[0]) + sizeof("tincd"));
sprintf(c, "%.*stincd", slash - argv[0], argv[0]);
}
else
c = "tincd";
argv[0] = c;
for(i = j = 1; argv[i]; ++i)
if (i != optind && strcmp(argv[i], "--") != 0)
argv[j++] = argv[i];
argv[j] = NULL;
execve(c, argv, envp);
fprintf(stderr, "Could not start %s: %s\n", c, strerror(errno));
return 1; return 1;
} }