mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 03:25:20 +00:00
commandhelper: Factor out printFds
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
7aa36ccacc
commit
6fedbe37a2
@ -140,10 +140,32 @@ static int printEnvironment(FILE *log)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int printFds(FILE *log)
|
||||||
|
{
|
||||||
|
long int open_max = sysconf(_SC_OPEN_MAX);
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (open_max < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
for (i = 0; i < open_max; i++) {
|
||||||
|
int ignore;
|
||||||
|
|
||||||
|
if (i == fileno(log))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (fcntl(i, F_GETFD, &ignore) == -1 && errno == EBADF)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
fprintf(log, "FD:%zu\n", i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
int open_max;
|
|
||||||
char *cwd;
|
char *cwd;
|
||||||
FILE *log = fopen(abs_builddir "/commandhelper.log", "w");
|
FILE *log = fopen(abs_builddir "/commandhelper.log", "w");
|
||||||
int ret = EXIT_FAILURE;
|
int ret = EXIT_FAILURE;
|
||||||
@ -162,19 +184,8 @@ int main(int argc, char **argv) {
|
|||||||
if (printEnvironment(log) != 0)
|
if (printEnvironment(log) != 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
open_max = sysconf(_SC_OPEN_MAX);
|
if (printFds(log) != 0)
|
||||||
if (open_max < 0)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
for (i = 0; i < open_max; i++) {
|
|
||||||
int f;
|
|
||||||
int closed;
|
|
||||||
if (i == fileno(log))
|
|
||||||
continue;
|
|
||||||
closed = fcntl(i, F_GETFD, &f) == -1 &&
|
|
||||||
errno == EBADF;
|
|
||||||
if (!closed)
|
|
||||||
fprintf(log, "FD:%zu\n", i);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
bool daemonized = getpgrp() != getppid();
|
bool daemonized = getpgrp() != getppid();
|
||||||
|
Loading…
Reference in New Issue
Block a user