From 483dbf76faf9f23117454aa8fc6d22abee3edc89 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Sun, 12 Sep 2021 11:44:07 +0200 Subject: 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. --- seatd-launch/seatd-launch.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/seatd-launch/seatd-launch.c b/seatd-launch/seatd-launch.c index c362a15..1877c98 100644 --- a/seatd-launch/seatd-launch.c +++ b/seatd-launch/seatd-launch.c @@ -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]; if (sockpath == NULL) { sprintf(sockbuf, "/tmp/seatd.%d.sock", getpid()); @@ -139,7 +145,7 @@ int main(int argc, char *argv[]) { goto error_seatd; } else if (child == 0) { setenv("SEATD_SOCK", sockpath, 1); - execvp(argv[1], &argv[1]); + execvp(command[0], command); perror("Could not start target"); _exit(1); } -- cgit v1.2.3