diff options
author | Zdenek Kabelac <zkabelac@redhat.com> | 2009-02-24 15:48:00 +0000 |
---|---|---|
committer | Zdenek Kabelac <zkabelac@redhat.com> | 2009-02-24 15:48:00 +0000 |
commit | c8669f6b13df4e87fa42916972c0b7f540ea5172 (patch) | |
tree | 07977a53cf3c552a484fec30525ede9052ac18b6 /lib/misc/lvm-exec.c | |
parent | 049cbb75b8228c34c35a6aa51f6520828cc4234b (diff) | |
download | lvm2-c8669f6b13df4e87fa42916972c0b7f540ea5172.tar.gz lvm2-c8669f6b13df4e87fa42916972c0b7f540ea5172.tar.xz lvm2-c8669f6b13df4e87fa42916972c0b7f540ea5172.zip |
Fixed bug where lvresize option -t was not properly passed to fsadm.
Using argv[] list in exec_cmd() to allow more params for external commands.
Fsadm does not allow checking mounted filesystem.
Fsadm no longer accepts 'any other key' as 'no' answer to y/n.
Fsadm improved handling of command line options.
Diffstat (limited to 'lib/misc/lvm-exec.c')
-rw-r--r-- | lib/misc/lvm-exec.c | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/lib/misc/lvm-exec.c b/lib/misc/lvm-exec.c index 9ff7214f..30a455cb 100644 --- a/lib/misc/lvm-exec.c +++ b/lib/misc/lvm-exec.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. - * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved. * * This file is part of LVM2. * @@ -19,16 +19,45 @@ #include <unistd.h> #include <sys/wait.h> + +/* + * Create verbose string with list of parameters + */ +static char *verbose_args(const char *const argv[]) +{ + char *buf = 0; + int pos = 0; + size_t sz = 0; + size_t len; + int i; + + for (i = 0; argv[i] != NULL; i++) { + len = strlen(argv[i]); + if (pos + len >= sz) { + sz = 64 + (sz + len) * 2; + if (!(buf = realloc(buf, sz))) + break; + } + if (pos) + buf[pos++] = ' '; + memcpy(buf + pos, argv[i], len + 1); /* copy with '\0' */ + pos += len; + } + + return buf; +} + /* * Execute and wait for external command */ -int exec_cmd(const char *command, const char *fscmd, const char *lv_path, - const char *size) +int exec_cmd(const char *const argv[]) { pid_t pid; int status; + char *buf = 0; - log_verbose("Executing: %s %s %s %s", command, fscmd, lv_path, size); + log_verbose("Executing: %s", buf = verbose_args(argv)); + free(buf); if ((pid = fork()) == -1) { log_error("fork failed: %s", strerror(errno)); @@ -38,8 +67,8 @@ int exec_cmd(const char *command, const char *fscmd, const char *lv_path, if (!pid) { /* Child */ /* FIXME Use execve directly */ - execlp(command, command, fscmd, lv_path, size, NULL); - log_sys_error("execlp", command); + execvp(argv[0], (char **const) argv); /* cast to match execvp prototype */ + log_sys_error("execvp", argv[0]); exit(errno); } @@ -56,7 +85,7 @@ int exec_cmd(const char *command, const char *fscmd, const char *lv_path, } if (WEXITSTATUS(status)) { - log_error("%s failed: %u", command, WEXITSTATUS(status)); + log_error("%s failed: %u", argv[0], WEXITSTATUS(status)); return 0; } |