mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-07-06 09:55:46 +00:00
commandhelper: Use automatic memory management in main
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
f00a6c2a5c
commit
7471dc5b86
@ -67,6 +67,12 @@ static void cleanupStringList(char ***ptr)
|
|||||||
free(strings);
|
free(strings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void cleanupFile(FILE **ptr)
|
||||||
|
{
|
||||||
|
FILE *file = *ptr;
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
|
||||||
static void cleanupGeneric(void *ptr)
|
static void cleanupGeneric(void *ptr)
|
||||||
{
|
{
|
||||||
void **ptrptr = ptr;
|
void **ptrptr = ptr;
|
||||||
@ -330,42 +336,34 @@ static int printInput(struct Arguments *args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
struct Arguments *args = parseArguments(argc, argv);
|
cleanup(struct Arguments *, cleanupArguments) args = NULL;
|
||||||
FILE *log = fopen(abs_builddir "/commandhelper.log", "w");
|
cleanup(FILE *, cleanupFile) log = NULL;
|
||||||
int ret = EXIT_FAILURE;
|
|
||||||
|
|
||||||
if (!log || !args)
|
if (!(log = fopen(abs_builddir "/commandhelper.log", "w")))
|
||||||
goto cleanup;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
|
if (!(args = parseArguments(argc, argv)))
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
printArguments(log, argc, argv);
|
printArguments(log, argc, argv);
|
||||||
|
|
||||||
if (printEnvironment(log) != 0)
|
if (printEnvironment(log) != 0)
|
||||||
goto cleanup;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
if (printFds(log) != 0)
|
if (printFds(log) != 0)
|
||||||
goto cleanup;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
printDaemonization(log, args);
|
printDaemonization(log, args);
|
||||||
|
|
||||||
if (printCwd(log) != 0)
|
if (printCwd(log) != 0)
|
||||||
goto cleanup;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
fprintf(log, "UMASK:%04o\n", umask(0));
|
fprintf(log, "UMASK:%04o\n", umask(0));
|
||||||
|
|
||||||
if (printInput(args) != 0)
|
if (printInput(args) != 0)
|
||||||
goto cleanup;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
ret = EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
if (args) {
|
|
||||||
if (args->readfds)
|
|
||||||
free(args->readfds);
|
|
||||||
free(args);
|
|
||||||
}
|
|
||||||
if (log)
|
|
||||||
fclose(log);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user