mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-01 17:35:17 +00:00
commandhelper: Factor out printEnvironment
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
99ceaffd15
commit
7aa36ccacc
@ -106,11 +106,44 @@ static int envsort(const void *a, const void *b)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int printEnvironment(FILE *log)
|
||||||
|
{
|
||||||
|
char **newenv;
|
||||||
|
size_t length;
|
||||||
|
size_t i;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
for (length = 0; environ[length]; length++) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(newenv = malloc(sizeof(*newenv) * length)))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
for (i = 0; i < length; i++) {
|
||||||
|
newenv[i] = environ[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
qsort(newenv, length, sizeof(newenv[0]), envsort);
|
||||||
|
|
||||||
|
for (i = 0; i < length; i++) {
|
||||||
|
/* Ignore the variables used to instruct the loader into
|
||||||
|
* behaving differently, as they could throw the tests off. */
|
||||||
|
if (!STRPREFIX(newenv[i], "LD_"))
|
||||||
|
fprintf(log, "ENV:%s\n", newenv[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
if (newenv)
|
||||||
|
free(newenv);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
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, n;
|
size_t i;
|
||||||
int open_max;
|
int open_max;
|
||||||
char **newenv = NULL;
|
|
||||||
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;
|
||||||
@ -126,25 +159,9 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
printArguments(log, argc, argv);
|
printArguments(log, argc, argv);
|
||||||
|
|
||||||
for (n = 0; environ[n]; n++) {
|
if (printEnvironment(log) != 0)
|
||||||
}
|
|
||||||
|
|
||||||
if (!(newenv = malloc(sizeof(*newenv) * n)))
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
newenv[i] = environ[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
qsort(newenv, n, sizeof(newenv[0]), envsort);
|
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
/* Ignore the variables used to instruct the loader into
|
|
||||||
* behaving differently, as they could throw the tests off. */
|
|
||||||
if (!STRPREFIX(newenv[i], "LD_"))
|
|
||||||
fprintf(log, "ENV:%s\n", newenv[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
open_max = sysconf(_SC_OPEN_MAX);
|
open_max = sysconf(_SC_OPEN_MAX);
|
||||||
if (open_max < 0)
|
if (open_max < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -275,8 +292,6 @@ int main(int argc, char **argv) {
|
|||||||
free(buffers[i]);
|
free(buffers[i]);
|
||||||
if (args)
|
if (args)
|
||||||
free(args);
|
free(args);
|
||||||
if (newenv)
|
|
||||||
free(newenv);
|
|
||||||
if (log)
|
if (log)
|
||||||
fclose(log);
|
fclose(log);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user