2010-05-25 11:14:06 +00:00
|
|
|
/*
|
|
|
|
* command.h: Child command execution
|
|
|
|
*
|
2011-03-22 17:55:45 +00:00
|
|
|
* Copyright (C) 2010-2011 Red Hat, Inc.
|
2010-05-25 11:14:06 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __VIR_COMMAND_H__
|
|
|
|
# define __VIR_COMMAND_H__
|
|
|
|
|
|
|
|
# include "internal.h"
|
|
|
|
# include "util.h"
|
2010-12-10 18:33:53 +00:00
|
|
|
# include "buf.h"
|
2010-05-25 11:14:06 +00:00
|
|
|
|
|
|
|
typedef struct _virCommand virCommand;
|
|
|
|
typedef virCommand *virCommandPtr;
|
|
|
|
|
2011-05-10 18:42:59 +00:00
|
|
|
/* This will execute in the context of the first child
|
2011-07-14 19:47:25 +00:00
|
|
|
* after fork() but before execve(). As such, it is unsafe to
|
|
|
|
* call any function that is not async-signal-safe. */
|
2011-05-10 18:42:59 +00:00
|
|
|
typedef int (*virExecHook)(void *data);
|
|
|
|
|
|
|
|
int virFork(pid_t *pid) ATTRIBUTE_RETURN_CHECK;
|
|
|
|
|
|
|
|
int virRun(const char *const*argv, int *status) ATTRIBUTE_RETURN_CHECK;
|
|
|
|
|
2010-05-25 11:14:06 +00:00
|
|
|
virCommandPtr virCommandNew(const char *binary) ATTRIBUTE_NONNULL(1);
|
|
|
|
|
|
|
|
virCommandPtr virCommandNewArgs(const char *const*args) ATTRIBUTE_NONNULL(1);
|
|
|
|
|
|
|
|
virCommandPtr virCommandNewArgList(const char *binary, ...)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_SENTINEL;
|
|
|
|
|
|
|
|
/* All error report from these setup APIs is
|
|
|
|
* delayed until the Run/RunAsync methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
void virCommandPreserveFD(virCommandPtr cmd,
|
|
|
|
int fd);
|
|
|
|
|
|
|
|
void virCommandTransferFD(virCommandPtr cmd,
|
|
|
|
int fd);
|
|
|
|
|
|
|
|
void virCommandSetPidFile(virCommandPtr cmd,
|
|
|
|
const char *pidfile) ATTRIBUTE_NONNULL(2);
|
|
|
|
|
|
|
|
void virCommandClearCaps(virCommandPtr cmd);
|
|
|
|
|
|
|
|
void virCommandAllowCap(virCommandPtr cmd,
|
|
|
|
int capability);
|
|
|
|
|
|
|
|
void virCommandDaemonize(virCommandPtr cmd);
|
|
|
|
|
|
|
|
void virCommandNonblockingFDs(virCommandPtr cmd);
|
|
|
|
|
2011-07-14 19:47:25 +00:00
|
|
|
void virCommandAddEnvFormat(virCommandPtr cmd, const char *format, ...)
|
|
|
|
ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 3);
|
2011-05-05 20:32:52 +00:00
|
|
|
|
2010-05-25 11:14:06 +00:00
|
|
|
void virCommandAddEnvPair(virCommandPtr cmd,
|
|
|
|
const char *name,
|
|
|
|
const char *value) ATTRIBUTE_NONNULL(2);
|
|
|
|
|
|
|
|
void virCommandAddEnvString(virCommandPtr cmd,
|
|
|
|
const char *str) ATTRIBUTE_NONNULL(2);
|
2010-12-10 18:33:53 +00:00
|
|
|
|
|
|
|
void virCommandAddEnvBuffer(virCommandPtr cmd,
|
|
|
|
virBufferPtr buf);
|
|
|
|
|
2010-05-25 11:14:06 +00:00
|
|
|
void virCommandAddEnvPass(virCommandPtr cmd,
|
|
|
|
const char *name) ATTRIBUTE_NONNULL(2);
|
2011-07-14 19:47:25 +00:00
|
|
|
|
2010-05-25 11:14:06 +00:00
|
|
|
void virCommandAddEnvPassCommon(virCommandPtr cmd);
|
|
|
|
|
|
|
|
void virCommandAddArg(virCommandPtr cmd,
|
|
|
|
const char *val) ATTRIBUTE_NONNULL(2);
|
|
|
|
|
2010-12-10 18:33:53 +00:00
|
|
|
void virCommandAddArgBuffer(virCommandPtr cmd,
|
|
|
|
virBufferPtr buf);
|
|
|
|
|
2010-05-25 11:14:06 +00:00
|
|
|
void virCommandAddArgFormat(virCommandPtr cmd,
|
|
|
|
const char *format, ...)
|
|
|
|
ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 3);
|
|
|
|
|
|
|
|
void virCommandAddArgPair(virCommandPtr cmd,
|
|
|
|
const char *name,
|
|
|
|
const char *val)
|
|
|
|
ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
|
2011-07-14 19:47:25 +00:00
|
|
|
|
2010-05-25 11:14:06 +00:00
|
|
|
void virCommandAddArgSet(virCommandPtr cmd,
|
|
|
|
const char *const*vals) ATTRIBUTE_NONNULL(2);
|
2011-07-14 19:47:25 +00:00
|
|
|
|
2010-05-25 11:14:06 +00:00
|
|
|
void virCommandAddArgList(virCommandPtr cmd,
|
|
|
|
... /* const char *arg, ..., NULL */)
|
|
|
|
ATTRIBUTE_SENTINEL;
|
|
|
|
|
|
|
|
void virCommandSetWorkingDirectory(virCommandPtr cmd,
|
|
|
|
const char *pwd) ATTRIBUTE_NONNULL(2);
|
|
|
|
|
|
|
|
void virCommandSetInputBuffer(virCommandPtr cmd,
|
|
|
|
const char *inbuf) ATTRIBUTE_NONNULL(2);
|
2011-07-14 19:47:25 +00:00
|
|
|
|
2010-05-25 11:14:06 +00:00
|
|
|
void virCommandSetOutputBuffer(virCommandPtr cmd,
|
|
|
|
char **outbuf) ATTRIBUTE_NONNULL(2);
|
2011-07-14 19:47:25 +00:00
|
|
|
|
2010-05-25 11:14:06 +00:00
|
|
|
void virCommandSetErrorBuffer(virCommandPtr cmd,
|
|
|
|
char **errbuf) ATTRIBUTE_NONNULL(2);
|
|
|
|
|
|
|
|
void virCommandSetInputFD(virCommandPtr cmd,
|
|
|
|
int infd);
|
2011-07-14 19:47:25 +00:00
|
|
|
|
2010-05-25 11:14:06 +00:00
|
|
|
void virCommandSetOutputFD(virCommandPtr cmd,
|
|
|
|
int *outfd) ATTRIBUTE_NONNULL(2);
|
2011-07-14 19:47:25 +00:00
|
|
|
|
2010-05-25 11:14:06 +00:00
|
|
|
void virCommandSetErrorFD(virCommandPtr cmd,
|
|
|
|
int *errfd) ATTRIBUTE_NONNULL(2);
|
|
|
|
|
|
|
|
void virCommandSetPreExecHook(virCommandPtr cmd,
|
|
|
|
virExecHook hook,
|
|
|
|
void *opaque) ATTRIBUTE_NONNULL(2);
|
|
|
|
|
|
|
|
void virCommandWriteArgLog(virCommandPtr cmd,
|
|
|
|
int logfd);
|
|
|
|
|
|
|
|
char *virCommandToString(virCommandPtr cmd) ATTRIBUTE_RETURN_CHECK;
|
|
|
|
|
2011-03-22 17:55:45 +00:00
|
|
|
|
|
|
|
char *virCommandTranslateStatus(int exitstatus) ATTRIBUTE_RETURN_CHECK;
|
|
|
|
|
2011-05-06 14:37:36 +00:00
|
|
|
int virCommandExec(virCommandPtr cmd) ATTRIBUTE_RETURN_CHECK;
|
|
|
|
|
2010-05-25 11:14:06 +00:00
|
|
|
int virCommandRun(virCommandPtr cmd,
|
|
|
|
int *exitstatus) ATTRIBUTE_RETURN_CHECK;
|
|
|
|
|
|
|
|
int virCommandRunAsync(virCommandPtr cmd,
|
|
|
|
pid_t *pid) ATTRIBUTE_RETURN_CHECK;
|
|
|
|
|
2011-07-12 16:42:41 +00:00
|
|
|
int virPidWait(pid_t pid,
|
|
|
|
int *exitstatus) ATTRIBUTE_RETURN_CHECK;
|
|
|
|
|
2010-05-25 11:14:06 +00:00
|
|
|
int virCommandWait(virCommandPtr cmd,
|
|
|
|
int *exitstatus) ATTRIBUTE_RETURN_CHECK;
|
|
|
|
|
2010-11-22 13:31:35 +00:00
|
|
|
void virCommandRequireHandshake(virCommandPtr cmd);
|
|
|
|
|
|
|
|
int virCommandHandshakeWait(virCommandPtr cmd)
|
|
|
|
ATTRIBUTE_RETURN_CHECK;
|
|
|
|
|
|
|
|
int virCommandHandshakeNotify(virCommandPtr cmd)
|
|
|
|
ATTRIBUTE_RETURN_CHECK;
|
|
|
|
|
2011-07-12 16:42:41 +00:00
|
|
|
void virPidAbort(pid_t pid);
|
|
|
|
|
2011-03-22 22:22:37 +00:00
|
|
|
void virCommandAbort(virCommandPtr cmd);
|
|
|
|
|
2010-05-25 11:14:06 +00:00
|
|
|
void virCommandFree(virCommandPtr cmd);
|
|
|
|
|
|
|
|
#endif /* __VIR_COMMAND_H__ */
|