mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
command: Add virCommandEnvAddFormat
Similar to virCommandArgAddFormat. We will use this shortly. v2: Convert virCommandEnvAddPair to use the new function
This commit is contained in:
parent
fc0ab50abd
commit
35c1b35e25
@ -100,6 +100,7 @@ virCommandAddArgList;
|
||||
virCommandAddArgPair;
|
||||
virCommandAddArgSet;
|
||||
virCommandAddEnvBuffer;
|
||||
virCommandAddEnvFormat;
|
||||
virCommandAddEnvPair;
|
||||
virCommandAddEnvPass;
|
||||
virCommandAddEnvPassCommon;
|
||||
|
@ -259,23 +259,26 @@ virCommandNonblockingFDs(virCommandPtr cmd)
|
||||
}
|
||||
|
||||
/*
|
||||
* Add an environment variable to the child
|
||||
* using separate name & value strings
|
||||
* Add an environment variable to the child created by a printf-style format
|
||||
*/
|
||||
void
|
||||
virCommandAddEnvPair(virCommandPtr cmd, const char *name, const char *value)
|
||||
virCommandAddEnvFormat(virCommandPtr cmd, const char *format, ...)
|
||||
{
|
||||
char *env;
|
||||
va_list list;
|
||||
|
||||
if (!cmd || cmd->has_error)
|
||||
return;
|
||||
|
||||
if (virAsprintf(&env, "%s=%s", name, value ? value : "") < 0) {
|
||||
va_start(list, format);
|
||||
if (virVasprintf(&env, format, list) < 0) {
|
||||
cmd->has_error = ENOMEM;
|
||||
va_end(list);
|
||||
return;
|
||||
}
|
||||
va_end(list);
|
||||
|
||||
/* env plus trailing NULL */
|
||||
/* Arg plus trailing NULL. */
|
||||
if (VIR_RESIZE_N(cmd->env, cmd->maxenv, cmd->nenv, 1 + 1) < 0) {
|
||||
VIR_FREE(env);
|
||||
cmd->has_error = ENOMEM;
|
||||
@ -285,6 +288,16 @@ virCommandAddEnvPair(virCommandPtr cmd, const char *name, const char *value)
|
||||
cmd->env[cmd->nenv++] = env;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add an environment variable to the child
|
||||
* using separate name & value strings
|
||||
*/
|
||||
void
|
||||
virCommandAddEnvPair(virCommandPtr cmd, const char *name, const char *value)
|
||||
{
|
||||
virCommandAddEnvFormat(cmd, "%s=%s", name, value);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Add an environment variable to the child
|
||||
|
@ -97,6 +97,13 @@ void virCommandDaemonize(virCommandPtr cmd);
|
||||
*/
|
||||
void virCommandNonblockingFDs(virCommandPtr cmd);
|
||||
|
||||
/*
|
||||
* Add an environment variable to the child created by a printf-style format
|
||||
*/
|
||||
void
|
||||
virCommandAddEnvFormat(virCommandPtr cmd, const char *format, ...)
|
||||
ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 3);
|
||||
|
||||
/*
|
||||
* Add an environment variable to the child
|
||||
* using separate name & value strings
|
||||
|
Loading…
Reference in New Issue
Block a user