aboutsummaryrefslogtreecommitdiff
path: root/seatd-launch/seatd-launch.c
diff options
context:
space:
mode:
authorKenny Levinsen <kl@kl.wtf>2021-08-06 23:00:05 +0200
committerKenny Levinsen <kl@kl.wtf>2021-08-06 23:00:05 +0200
commit48727a0b6bc2f7127f2115470be27aa09be7a4a7 (patch)
tree849f3a8f6c1f1e4c953c997f4d6e27e80560aafa /seatd-launch/seatd-launch.c
parent369af8f9e4797be55c4b95facd50dd7cc20565d1 (diff)
seatd-launch: Command line argument support
Diffstat (limited to 'seatd-launch/seatd-launch.c')
-rw-r--r--seatd-launch/seatd-launch.c44
1 files changed, 38 insertions, 6 deletions
diff --git a/seatd-launch/seatd-launch.c b/seatd-launch/seatd-launch.c
index acec145..9fd3f23 100644
--- a/seatd-launch/seatd-launch.c
+++ b/seatd-launch/seatd-launch.c
@@ -13,10 +13,42 @@
int main(int argc, char *argv[]) {
(void)argc;
+
+ const char *usage = "Usage: seatd-launch [options] [--] command\n"
+ "\n"
+ " -h Show this help message\n"
+ " -s <path> Where to create the seatd socket\n"
+ " -v Show the version number\n"
+ "\n";
+
+ int c;
+ char *sockpath = NULL;
+ while ((c = getopt(argc, argv, "vhs:")) != -1) {
+ switch (c) {
+ case 's':
+ sockpath = optarg;
+ break;
+ case 'v':
+ printf("seatd-launch version %s\n", SEATD_VERSION);
+ return 0;
+ case 'h':
+ printf("%s", usage);
+ return 0;
+ case '?':
+ fprintf(stderr, "Try '%s -h' for more information.\n", argv[0]);
+ return 1;
+ default:
+ abort();
+ }
+ }
+
char sockbuf[256];
+ if (sockpath == NULL) {
+ sprintf(sockbuf, "/tmp/seatd.%d.sock", getpid());
+ sockpath = sockbuf;
+ }
- sprintf(sockbuf, "/tmp/seatd.%d.sock", getpid());
- unlink(sockbuf);
+ unlink(sockpath);
int fds[2];
if (pipe(fds) == -1) {
@@ -41,7 +73,7 @@ int main(int argc, char *argv[]) {
}
// TODO: Make seatd accept the numeric UID
- execlp("seatd", "seatd", "-n", pipebuf, "-u", user->pw_name, "-s", sockbuf, NULL);
+ execlp("seatd", "seatd", "-n", pipebuf, "-u", user->pw_name, "-s", sockpath, NULL);
perror("Could not start seatd");
_exit(1);
}
@@ -100,7 +132,7 @@ int main(int argc, char *argv[]) {
perror("Could not fork target process");
goto error_seatd;
} else if (child == 0) {
- setenv("SEATD_SOCK", sockbuf, 1);
+ setenv("SEATD_SOCK", sockpath, 1);
execv(argv[1], &argv[1]);
perror("Could not start target");
_exit(1);
@@ -117,7 +149,7 @@ int main(int argc, char *argv[]) {
}
}
- unlink(sockbuf);
+ unlink(sockpath);
kill(seatd_child, SIGTERM);
if (WIFEXITED(status)) {
@@ -127,7 +159,7 @@ int main(int argc, char *argv[]) {
}
error_seatd:
- unlink(sockbuf);
+ unlink(sockpath);
kill(seatd_child, SIGTERM);
error:
return 1;