seatd-launch: Minor readability improvements
This commit is contained in:
parent
ed90ed62cd
commit
3eb0db57bb
1 changed files with 9 additions and 10 deletions
|
@ -11,8 +11,6 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
(void)argc;
|
|
||||||
|
|
||||||
const char *usage = "Usage: seatd-launch [options] [--] command\n"
|
const char *usage = "Usage: seatd-launch [options] [--] command\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -h Show this help message\n"
|
" -h Show this help message\n"
|
||||||
|
@ -45,21 +43,22 @@ int main(int argc, char *argv[]) {
|
||||||
char sockpath[32];
|
char sockpath[32];
|
||||||
snprintf(sockpath, sizeof sockpath, "/tmp/seatd.%d.sock", getpid());
|
snprintf(sockpath, sizeof sockpath, "/tmp/seatd.%d.sock", getpid());
|
||||||
|
|
||||||
int fds[2];
|
int readiness_pipe[2];
|
||||||
if (pipe(fds) == -1) {
|
if (pipe(readiness_pipe) == -1) {
|
||||||
perror("Could not create pipe");
|
perror("Could not create pipe");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start seatd
|
||||||
pid_t seatd_child = fork();
|
pid_t seatd_child = fork();
|
||||||
if (seatd_child == -1) {
|
if (seatd_child == -1) {
|
||||||
perror("Could not fork seatd process");
|
perror("Could not fork seatd process");
|
||||||
goto error;
|
goto error;
|
||||||
} else if (seatd_child == 0) {
|
} else if (seatd_child == 0) {
|
||||||
close(fds[0]);
|
close(readiness_pipe[0]);
|
||||||
|
|
||||||
char pipebuf[16] = {0};
|
char pipebuf[16] = {0};
|
||||||
snprintf(pipebuf, sizeof pipebuf, "%d", fds[1]);
|
snprintf(pipebuf, sizeof pipebuf, "%d", readiness_pipe[1]);
|
||||||
|
|
||||||
char *env[2] = {NULL, NULL};
|
char *env[2] = {NULL, NULL};
|
||||||
char loglevelbuf[32] = {0};
|
char loglevelbuf[32] = {0};
|
||||||
|
@ -74,7 +73,7 @@ int main(int argc, char *argv[]) {
|
||||||
perror("Could not start seatd");
|
perror("Could not start seatd");
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
close(fds[1]);
|
close(readiness_pipe[1]);
|
||||||
|
|
||||||
// Wait for seatd to be ready
|
// Wait for seatd to be ready
|
||||||
char buf[1] = {0};
|
char buf[1] = {0};
|
||||||
|
@ -89,7 +88,7 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pollfd fd = {
|
struct pollfd fd = {
|
||||||
.fd = fds[0],
|
.fd = readiness_pipe[0],
|
||||||
.events = POLLIN,
|
.events = POLLIN,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -104,7 +103,7 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fd.revents & POLLIN) {
|
if (fd.revents & POLLIN) {
|
||||||
ssize_t n = read(fds[0], buf, 1);
|
ssize_t n = read(readiness_pipe[0], buf, 1);
|
||||||
if (n == -1 && errno != EINTR) {
|
if (n == -1 && errno != EINTR) {
|
||||||
perror("Could not read from pipe");
|
perror("Could not read from pipe");
|
||||||
goto error_seatd;
|
goto error_seatd;
|
||||||
|
@ -113,7 +112,7 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close(fds[0]);
|
close(readiness_pipe[0]);
|
||||||
|
|
||||||
uid_t uid = getuid();
|
uid_t uid = getuid();
|
||||||
gid_t gid = getgid();
|
gid_t gid = getgid();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue