mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
commandhelper: Factor out printCwd
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
0e3911f02f
commit
c73f0343bb
@ -176,10 +176,34 @@ static void printDaemonization(FILE *log, struct Arguments *args)
|
|||||||
fprintf(log, "DAEMON:%s\n", getpgrp() != getppid() ? "yes" : "no");
|
fprintf(log, "DAEMON:%s\n", getpgrp() != getppid() ? "yes" : "no");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int printCwd(FILE *log)
|
||||||
|
{
|
||||||
|
char *cwd = NULL;
|
||||||
|
char *display;
|
||||||
|
|
||||||
|
if (!(cwd = getcwd(NULL, 0)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if ((strlen(cwd) > strlen(".../commanddata")) &&
|
||||||
|
(STREQ(cwd + strlen(cwd) - strlen("/commanddata"), "/commanddata"))) {
|
||||||
|
strcpy(cwd, ".../commanddata");
|
||||||
|
}
|
||||||
|
|
||||||
|
display = cwd;
|
||||||
|
|
||||||
|
# ifdef __APPLE__
|
||||||
|
if (strstr(cwd, "/private"))
|
||||||
|
display = cwd + strlen("/private");
|
||||||
|
# endif
|
||||||
|
|
||||||
|
fprintf(log, "CWD:%s\n", display);
|
||||||
|
free(cwd);
|
||||||
|
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;
|
||||||
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;
|
||||||
struct pollfd fds[3];
|
struct pollfd fds[3];
|
||||||
@ -201,22 +225,8 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
printDaemonization(log, args);
|
printDaemonization(log, args);
|
||||||
|
|
||||||
if (!(cwd = getcwd(NULL, 0)))
|
if (printCwd(log) != 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (strlen(cwd) > strlen(".../commanddata") &&
|
|
||||||
STREQ(cwd + strlen(cwd) - strlen("/commanddata"), "/commanddata"))
|
|
||||||
strcpy(cwd, ".../commanddata");
|
|
||||||
# ifdef __APPLE__
|
|
||||||
char *noprivateprefix = NULL;
|
|
||||||
if (strstr(cwd, "/private"))
|
|
||||||
noprivateprefix = cwd + strlen("/private");
|
|
||||||
else
|
|
||||||
noprivateprefix = cwd;
|
|
||||||
fprintf(log, "CWD:%s\n", noprivateprefix);
|
|
||||||
# else
|
|
||||||
fprintf(log, "CWD:%s\n", cwd);
|
|
||||||
# endif
|
|
||||||
free(cwd);
|
|
||||||
|
|
||||||
fprintf(log, "UMASK:%04o\n", umask(0));
|
fprintf(log, "UMASK:%04o\n", umask(0));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user