diff options
| author | Kenny Levinsen <kl@kl.wtf> | 2021-09-12 11:44:07 +0200 | 
|---|---|---|
| committer | Kenny Levinsen <kl@kl.wtf> | 2021-09-12 12:06:05 +0200 | 
| commit | 483dbf76faf9f23117454aa8fc6d22abee3edc89 (patch) | |
| tree | 2fbe7a40be0dedc27b5876e332191cf92bb08322 | |
| parent | d5c1a7811bf76abf22045f8f2f5c24fc0d1f6747 (diff) | |
| download | seatd-483dbf76faf9f23117454aa8fc6d22abee3edc89.tar.xz | |
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.
| -rw-r--r-- | seatd-launch/seatd-launch.c | 8 | 
1 files changed, 7 insertions, 1 deletions
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);  	}  | 
