2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
5 * This file is part of LVM2.
7 * This copyrighted material is made available to anyone wishing to use,
8 * modify, copy, or redistribute it subject to the terms and conditions
9 * of the GNU Lesser General Public License v.2.1.
11 * You should have received a copy of the GNU Lesser General Public License
12 * along with this program; if not, write to the Free Software Foundation,
13 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "toolcontext.h"
26 * Create verbose string with list of parameters
28 static char *_verbose_args(const char *const argv[], char *buf, size_t sz)
35 for (i = 0; argv[i]; i++) {
36 if ((len = dm_snprintf(buf + pos, sz - pos,
47 * Execute and wait for external command
49 int exec_cmd(struct cmd_context *cmd, const char *const argv[], int *rstatus)
53 char buf[PATH_MAX * 2];
55 log_verbose("Executing: %s", _verbose_args(argv, buf, sizeof(buf)));
57 if ((pid = fork()) == -1) {
58 log_error("fork failed: %s", strerror(errno));
66 /* FIXME Fix effect of reset_locking on cache then include this */
67 /* destroy_toolcontext(cmd); */
68 /* FIXME Use execve directly */
69 execvp(argv[0], (char **const) argv);
70 log_sys_error("execvp", argv[0]);
78 if (wait4(pid, &status, 0, NULL) != pid) {
79 log_error("wait4 child process %u failed: %s", pid,
84 if (!WIFEXITED(status)) {
85 log_error("Child %u exited abnormally", pid);
89 if (WEXITSTATUS(status)) {
91 *rstatus = WEXITSTATUS(status);
92 log_verbose("%s failed: %u", argv[0], *rstatus);
94 log_error("%s failed: %u", argv[0], WEXITSTATUS(status));