1
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2
// vim: ts=8 sw=2 smarttab
4
* Ceph - scalable distributed file system
6
* Copyright (C) 2011 New Dream Network
8
* This is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public
10
* License version 2.1, as published by the Free Software
11
* Foundation. See file COPYING.
15
#include "common/config.h"
16
#include "common/debug.h"
17
#include "common/errno.h"
22
#include <sys/types.h>
27
#define dout_prefix *_dout
29
int run_cmd(const char *cmd, ...)
32
std::vector <const char *> arr;
38
c = va_arg(ap, const char*);
46
derr << "run_cmd(" << cmd << "): unable to fork(): " << cpp_strerror(err)
51
// execvp doesn't modify its arguments, so the const-cast here is safe.
52
execvp(cmd, (char * const*)&arr[0]);
56
while (waitpid(ret, &status, 0) == -1) {
60
derr << "run_cmd(" << cmd << "): waitpid error: "
61
<< cpp_strerror(err) << dendl;
64
if (WIFEXITED(status)) {
65
return WEXITSTATUS(status);
67
else if (WIFSIGNALED(status)) {
68
derr << "run_cmd(" << cmd << "): terminated by signal" << dendl;
71
derr << "run_cmd(" << cmd << "): terminated by unknown mechanism" << dendl;