mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-31 00:45:18 +00:00
commandhelper: Factor out printDaemonization
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
6fedbe37a2
commit
0e3911f02f
@ -163,6 +163,19 @@ static int printFds(FILE *log)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void printDaemonization(FILE *log, struct Arguments *args)
|
||||||
|
{
|
||||||
|
int retries = 3;
|
||||||
|
|
||||||
|
if (args->daemonize_check) {
|
||||||
|
while ((getpgrp() == getppid()) && (retries-- > 0)) {
|
||||||
|
usleep(100 * 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(log, "DAEMON:%s\n", getpgrp() != getppid() ? "yes" : "no");
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
struct Arguments *args = parseArguments(argc, argv);
|
struct Arguments *args = parseArguments(argc, argv);
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -172,7 +185,6 @@ int main(int argc, char **argv) {
|
|||||||
struct pollfd fds[3];
|
struct pollfd fds[3];
|
||||||
char *buffers[3] = {NULL, NULL, NULL};
|
char *buffers[3] = {NULL, NULL, NULL};
|
||||||
size_t buflen[3] = {0, 0, 0};
|
size_t buflen[3] = {0, 0, 0};
|
||||||
size_t daemonize_retries = 3;
|
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
ssize_t got;
|
ssize_t got;
|
||||||
|
|
||||||
@ -187,17 +199,7 @@ int main(int argc, char **argv) {
|
|||||||
if (printFds(log) != 0)
|
if (printFds(log) != 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
while (true) {
|
printDaemonization(log, args);
|
||||||
bool daemonized = getpgrp() != getppid();
|
|
||||||
|
|
||||||
if (args->daemonize_check && !daemonized && daemonize_retries-- > 0) {
|
|
||||||
usleep(100*1000);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(log, "DAEMON:%s\n", daemonized ? "yes" : "no");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(cwd = getcwd(NULL, 0)))
|
if (!(cwd = getcwd(NULL, 0)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user