seatd-launch: Use optind to find the command

The command indexing had not been updated afer the introduction of
getopt, so combining a command with flags would fail.

Add error handling for if no command was specified while we're at it.
This commit is contained in:
Kenny Levinsen 2021-09-12 11:44:07 +02:00
parent d5c1a7811b
commit 483dbf76fa

View file

@ -41,6 +41,12 @@ int main(int argc, char *argv[]) {
} }
} }
if (optind >= argc) {
fprintf(stderr, "A command must be specified\n\n%s", usage);
return 1;
}
char **command = &argv[optind];
char sockbuf[256]; char sockbuf[256];
if (sockpath == NULL) { if (sockpath == NULL) {
sprintf(sockbuf, "/tmp/seatd.%d.sock", getpid()); sprintf(sockbuf, "/tmp/seatd.%d.sock", getpid());
@ -139,7 +145,7 @@ int main(int argc, char *argv[]) {
goto error_seatd; goto error_seatd;
} else if (child == 0) { } else if (child == 0) {
setenv("SEATD_SOCK", sockpath, 1); setenv("SEATD_SOCK", sockpath, 1);
execvp(argv[1], &argv[1]); execvp(command[0], command);
perror("Could not start target"); perror("Could not start target");
_exit(1); _exit(1);
} }