The exec() family of UNIX functions have broken const-ness in the argv[]
parameter. For inexplicable reasons, I followed this brokeness when
originally doing the virRun/virExec functions. So every caller is either
using wrong const-ness, or having to cast when calling them. This patch
fixes the virRun/virExec API const-ness, so we only need apply a cast
at the time we finally call exec()
src/iptables.c | 12 ++++++------
src/lxc_driver.c | 2 +-
src/openvz_driver.c | 34 +++++++++++++++++-----------------
src/qemu_conf.c | 4 ++--
src/qemu_conf.h | 2 +-
src/qemu_driver.c | 6 +++---
src/storage_backend.c | 4 ++--
src/storage_backend_disk.c | 4 ++--
src/storage_backend_fs.c | 8 ++++----
src/storage_backend_iscsi.c | 6 +++---
src/storage_backend_logical.c | 12 ++++++------
src/util.c | 16 ++++++++--------
src/util.h | 6 +++---
src/veth.c | 8 ++++----
tests/qemuxml2argvtest.c | 2 +-
15 files changed, 63 insertions(+), 63 deletions(-)
Daniel
diff -r cc63ab958867 src/iptables.c
--- a/src/iptables.c Thu Aug 07 15:00:21 2008 +0100
+++ b/src/iptables.c Thu Aug 07 22:59:08 2008 +0100
@@ -57,7 +57,7 @@
typedef struct
{
char *rule;
- char **argv;
+ const char **argv;
int command_idx;
} iptRule;
@@ -91,7 +91,7 @@
const char *path)
{
char arg[PATH_MAX];
- char *argv[4];
+ const char *argv[4];
snprintf(arg, sizeof(arg), "--custom-rules=ipv4:%s:%s", table, path);
@@ -278,7 +278,7 @@
static int
iptRulesAppend(iptRules *rules,
char *rule,
- char **argv,
+ const char **argv,
int command_idx)
{
if (VIR_REALLOC_N(rules->rules, rules->nrules+1) < 0) {
@@ -385,7 +385,7 @@
}
static char *
-argvToString(char **argv)
+argvToString(const char *const *argv)
{
int len, i;
char *ret, *p;
@@ -415,7 +415,7 @@
{
va_list args;
int retval = ENOMEM;
- char **argv;
+ const char **argv;
char *rule = NULL;
const char *s;
int n, command_idx;
@@ -571,7 +571,7 @@
for (i = 0; i < rules->nrules; i++) {
iptRule *rule = &rules->rules[i];
- char *orig;
+ const char *orig;
orig = rule->argv[rule->command_idx];
rule->argv[rule->command_idx] = (char *) "--delete";
diff -r cc63ab958867 src/lxc_driver.c
--- a/src/lxc_driver.c Thu Aug 07 15:00:21 2008 +0100
+++ b/src/lxc_driver.c Thu Aug 07 22:59:08 2008 +0100
@@ -1288,7 +1288,7 @@
int user_netns = 0;
int kern_netns = 0;
- if (virRun(NULL, (char **)argv, &ip_rc) == 0)
+ if (virRun(NULL, argv, &ip_rc) == 0)
user_netns = WIFEXITED(ip_rc) && (WEXITSTATUS(ip_rc) != 255);
if (lxcCheckContainerSupport(CLONE_NEWNET) == 0)
diff -r cc63ab958867 src/openvz_driver.c
--- a/src/openvz_driver.c Thu Aug 07 15:00:21 2008 +0100
+++ b/src/openvz_driver.c Thu Aug 07 22:59:08 2008 +0100
@@ -91,13 +91,13 @@
unsigned int flags ATTRIBUTE_UNUSED);
static int openvzDomainUndefine(virDomainPtr dom);
-static void cmdExecFree(char *cmdExec[]);
+static void cmdExecFree(const char *cmdExec[]);
static int openvzGetProcessInfo(unsigned long long *cpuTime, int vpsid);
struct openvz_driver ovz_driver;
-static void cmdExecFree(char *cmdExec[])
+static void cmdExecFree(const char *cmdExec[])
{
int i=-1;
while(cmdExec[++i])
@@ -111,7 +111,7 @@
0 - OK
*/
static int openvzDomainDefineCmd(virConnectPtr conn,
- char *args[],
+ const char *args[],
int maxarg,
struct openvz_vm_def *vmdef)
{
@@ -287,7 +287,7 @@
return -1;
}
- if (virRun(dom->conn, (char **)prog, NULL) < 0) {
+ if (virRun(dom->conn, prog, NULL) < 0) {
openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
_("Could not exec %s"), VZCTL);
return -1;
@@ -319,7 +319,7 @@
return -1;
}
- if (virRun(dom->conn, (char **)prog, NULL) < 0) {
+ if (virRun(dom->conn, prog, NULL) < 0) {
openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
_("Could not exec %s"), VZCTL);
return -1;
@@ -333,7 +333,7 @@
virDomainNetDefPtr net)
{
int rc = 0, narg;
- char *prog[OPENVZ_MAX_ARG];
+ const char *prog[OPENVZ_MAX_ARG];
char *mac = NULL;
#define ADD_ARG_LIT(thisarg) \
@@ -391,7 +391,7 @@
if (prog[0] != NULL){
ADD_ARG_LIT("--save");
- if (virRun(conn, (char **)prog, NULL) < 0) {
+ if (virRun(conn, prog, NULL) < 0) {
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
_("Could not exec %s"), VZCTL);
rc = -1;
@@ -427,7 +427,7 @@
struct openvz_vm_def *vmdef = NULL;
struct openvz_vm *vm = NULL;
virDomainPtr dom = NULL;
- char *prog[OPENVZ_MAX_ARG];
+ const char *prog[OPENVZ_MAX_ARG];
prog[0] = NULL;
if ((vmdef = openvzParseVMDef(conn, xml, NULL)) == NULL)
@@ -453,7 +453,7 @@
//TODO: set number virtual CPUs
//TODO: set quota
- if (virRun(conn, (char **)prog, NULL) < 0) {
+ if (virRun(conn, prog, NULL) < 0) {
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
_("Could not exec %s"), VZCTL);
goto exit;
@@ -489,7 +489,7 @@
virDomainPtr dom = NULL;
struct openvz_driver *driver = (struct openvz_driver *) conn->privateData;
const char *progstart[] = {VZCTL, "--quiet", "start", NULL,
NULL};
- char *progcreate[OPENVZ_MAX_ARG];
+ const char *progcreate[OPENVZ_MAX_ARG];
progcreate[0] = NULL;
if (!(vmdef = openvzParseVMDef(conn, xml, NULL)))
@@ -514,7 +514,7 @@
goto exit;
}
- if (virRun(conn, (char **)progcreate, NULL) < 0) {
+ if (virRun(conn, progcreate, NULL) < 0) {
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
_("Could not exec %s"), VZCTL);
goto exit;
@@ -534,7 +534,7 @@
progstart[3] = vmdef->name;
- if (virRun(conn, (char **)progstart, NULL) < 0) {
+ if (virRun(conn, progstart, NULL) < 0) {
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
_("Could not exec %s"), VZCTL);
goto exit;
@@ -572,7 +572,7 @@
return -1;
}
- if (virRun(dom->conn, (char **)prog, NULL) < 0) {
+ if (virRun(dom->conn, prog, NULL) < 0) {
openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
_("Could not exec %s"), VZCTL);
return -1;
@@ -604,7 +604,7 @@
return -1;
}
- if (virRun(conn, (char **)prog, NULL) < 0) {
+ if (virRun(conn, prog, NULL) < 0) {
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
_("Could not exec %s"), VZCTL);
return -1;
@@ -629,7 +629,7 @@
return -1;
}
- if (virRun(conn, (char **)prog, NULL) < 0) {
+ if (virRun(conn, prog, NULL) < 0) {
openvzError(conn, VIR_ERR_INTERNAL_ERROR, _("Could not exec %s"),
VZCTL);
return -1;
}
@@ -742,7 +742,7 @@
char *endptr;
const char *cmd[] = {VZLIST, "-ovpsid", "-H" , NULL};
- ret = virExec(conn, (char **)cmd, &pid, -1, &outfd, &errfd);
+ ret = virExec(conn, cmd, &pid, -1, &outfd, &errfd);
if(ret == -1) {
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
_("Could not exec %s"), VZLIST);
@@ -779,7 +779,7 @@
const char *cmd[] = {VZLIST, "-ovpsid", "-H", "-S",
NULL};
/* the -S options lists only stopped domains */
- ret = virExec(conn, (char **)cmd, &pid, -1, &outfd, &errfd);
+ ret = virExec(conn, cmd, &pid, -1, &outfd, &errfd);
if(ret == -1) {
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
_("Could not exec %s"), VZLIST);
diff -r cc63ab958867 src/qemu_conf.c
--- a/src/qemu_conf.c Thu Aug 07 15:00:21 2008 +0100
+++ b/src/qemu_conf.c Thu Aug 07 22:59:08 2008 +0100
@@ -711,7 +711,7 @@
struct qemud_driver *driver,
virDomainObjPtr vm,
int qemuCmdFlags,
- char ***retargv,
+ const char ***retargv,
int **tapfds,
int *ntapfds,
const char *migrateFrom) {
@@ -728,7 +728,7 @@
struct utsname ut;
int disableKQEMU = 0;
int qargc = 0, qarga = 0;
- char **qargv = NULL;
+ const char **qargv = NULL;
uname(&ut);
diff -r cc63ab958867 src/qemu_conf.h
--- a/src/qemu_conf.h Thu Aug 07 15:00:21 2008 +0100
+++ b/src/qemu_conf.h Thu Aug 07 22:59:08 2008 +0100
@@ -95,7 +95,7 @@
struct qemud_driver *driver,
virDomainObjPtr dom,
int qemuCmdFlags,
- char ***argv,
+ const char ***argv,
int **tapfds,
int *ntapfds,
const char *migrateFrom);
diff -r cc63ab958867 src/qemu_driver.c
--- a/src/qemu_driver.c Thu Aug 07 15:00:21 2008 +0100
+++ b/src/qemu_driver.c Thu Aug 07 22:59:08 2008 +0100
@@ -842,7 +842,7 @@
struct qemud_driver *driver,
virDomainObjPtr vm,
const char *migrateFrom) {
- char **argv = NULL, **tmp;
+ const char **argv = NULL, **tmp;
int i, ret;
char logfile[PATH_MAX];
struct stat sb;
@@ -1087,7 +1087,7 @@
static int
qemudBuildDnsmasqArgv(virConnectPtr conn,
virNetworkObjPtr network,
- char ***argv) {
+ const char ***argv) {
int i, len, r;
char buf[PATH_MAX];
@@ -1184,7 +1184,7 @@
dhcpStartDhcpDaemon(virConnectPtr conn,
virNetworkObjPtr network)
{
- char **argv;
+ const char **argv;
int ret, i;
if (network->def->ipAddress == NULL) {
diff -r cc63ab958867 src/storage_backend.c
--- a/src/storage_backend.c Thu Aug 07 15:00:21 2008 +0100
+++ b/src/storage_backend.c Thu Aug 07 22:59:08 2008 +0100
@@ -403,7 +403,7 @@
/* Run the program and capture its output */
- if (virExec(conn, (char**)prog, &child, -1, &fd, NULL) < 0) {
+ if (virExec(conn, prog, &child, -1, &fd, NULL) < 0) {
goto cleanup;
}
@@ -537,7 +537,7 @@
v[i] = NULL;
/* Run the program and capture its output */
- if (virExec(conn, (char**)prog, &child, -1, &fd, NULL) < 0) {
+ if (virExec(conn, prog, &child, -1, &fd, NULL) < 0) {
goto cleanup;
}
diff -r cc63ab958867 src/storage_backend_disk.c
--- a/src/storage_backend_disk.c Thu Aug 07 15:00:21 2008 +0100
+++ b/src/storage_backend_disk.c Thu Aug 07 22:59:08 2008 +0100
@@ -410,7 +410,7 @@
NULL,
};
- if (virRun(conn, (char**)prog, NULL) < 0)
+ if (virRun(conn, prog, NULL) < 0)
return -1;
return 0;
@@ -469,7 +469,7 @@
snprintf(end, sizeof(end)-1, "%lluB", endOffset);
end[sizeof(end)-1] = '\0';
- if (virRun(conn, (char**)cmdargv, NULL) < 0)
+ if (virRun(conn, cmdargv, NULL) < 0)
return -1;
/* Blow away free extent info, as we're about to re-populate it */
diff -r cc63ab958867 src/storage_backend_fs.c
--- a/src/storage_backend_fs.c Thu Aug 07 15:00:21 2008 +0100
+++ b/src/storage_backend_fs.c Thu Aug 07 22:59:08 2008 +0100
@@ -571,7 +571,7 @@
}
mntargv[source_index] = src;
- if (virRun(conn, (char**)mntargv, NULL) < 0) {
+ if (virRun(conn, mntargv, NULL) < 0) {
VIR_FREE(src);
return -1;
}
@@ -625,7 +625,7 @@
mntargv[1] = pool->def->target.path;
mntargv[2] = NULL;
- if (virRun(conn, (char**)mntargv, NULL) < 0) {
+ if (virRun(conn, mntargv, NULL) < 0) {
return -1;
}
return 0;
@@ -940,7 +940,7 @@
imgargv[5] = size;
imgargv[6] = NULL;
- if (virRun(conn, (char **)imgargv, NULL) < 0) {
+ if (virRun(conn, imgargv, NULL) < 0) {
unlink(vol->target.path);
return -1;
}
@@ -975,7 +975,7 @@
imgargv[2] = vol->target.path;
imgargv[3] = NULL;
- if (virRun(conn, (char **)imgargv, NULL) < 0) {
+ if (virRun(conn, imgargv, NULL) < 0) {
unlink(vol->target.path);
return -1;
}
diff -r cc63ab958867 src/storage_backend_iscsi.c
--- a/src/storage_backend_iscsi.c Thu Aug 07 15:00:21 2008 +0100
+++ b/src/storage_backend_iscsi.c Thu Aug 07 22:59:08 2008 +0100
@@ -158,7 +158,7 @@
"--targetname", pool->def->source.devices[0].path, action, NULL
};
- if (virRun(conn, (char **)cmdargv, NULL) < 0)
+ if (virRun(conn, cmdargv, NULL) < 0)
return -1;
return 0;
@@ -507,7 +507,7 @@
ISCSIADM, "--mode", "session", "-r", session,
"-R", NULL,
};
- if (virRun(conn, (char **)cmdargv, NULL) < 0)
+ if (virRun(conn, cmdargv, NULL) < 0)
return -1;
return 0;
@@ -524,7 +524,7 @@
"--portal", portal, NULL
};
- if (virRun(conn, (char **)cmdsendtarget, NULL) < 0)
+ if (virRun(conn, cmdsendtarget, NULL) < 0)
return -1;
return virStorageBackendISCSIConnection(conn, pool, portal, "--login");
diff -r cc63ab958867 src/storage_backend_logical.c
--- a/src/storage_backend_logical.c Thu Aug 07 15:00:21 2008 +0100
+++ b/src/storage_backend_logical.c Thu Aug 07 22:59:08 2008 +0100
@@ -83,7 +83,7 @@
cmdargv[2] = pool->def->name;
cmdargv[3] = NULL;
- if (virRun(conn, (char**)cmdargv, NULL) < 0)
+ if (virRun(conn, cmdargv, NULL) < 0)
return -1;
return 0;
@@ -324,14 +324,14 @@
*/
vgargv[n++] = pool->def->source.devices[i].path;
pvargv[1] = pool->def->source.devices[i].path;
- if (virRun(conn, (char**)pvargv, NULL) < 0)
+ if (virRun(conn, pvargv, NULL) < 0)
goto cleanup;
}
vgargv[n++] = NULL;
/* Now create the volume group itself */
- if (virRun(conn, (char**)vgargv, NULL) < 0)
+ if (virRun(conn, vgargv, NULL) < 0)
goto cleanup;
VIR_FREE(vgargv);
@@ -422,7 +422,7 @@
VGREMOVE, "-f", pool->def->name, NULL
};
- if (virRun(conn, (char**)cmdargv, NULL) < 0)
+ if (virRun(conn, cmdargv, NULL) < 0)
return -1;
/* XXX clear the PVs too ? ie pvremove ? probably ought to */
@@ -453,7 +453,7 @@
snprintf(size, sizeof(size)-1, "%lluK", vol->capacity/1024);
size[sizeof(size)-1] = '\0';
- if (virRun(conn, (char**)cmdargv, NULL) < 0)
+ if (virRun(conn, cmdargv, NULL) < 0)
return -1;
if ((fd = open(vol->target.path, O_RDONLY)) < 0) {
@@ -514,7 +514,7 @@
LVREMOVE, "-f", vol->target.path, NULL
};
- if (virRun(conn, (char**)cmdargv, NULL) < 0)
+ if (virRun(conn, cmdargv, NULL) < 0)
return -1;
return 0;
diff -r cc63ab958867 src/util.c
--- a/src/util.c Thu Aug 07 15:00:21 2008 +0100
+++ b/src/util.c Thu Aug 07 22:59:08 2008 +0100
@@ -102,8 +102,8 @@
static int
_virExec(virConnectPtr conn,
- char **argv,
- int *retpid, int infd, int *outfd, int *errfd, int non_block) {
+ const char *const*argv,
+ int *retpid, int infd, int *outfd, int *errfd, int non_block) {
int pid, null;
int pipeout[2] = {-1,-1};
int pipeerr[2] = {-1,-1};
@@ -185,7 +185,7 @@
if (pipeerr[1] > 0)
close(pipeerr[1]);
- execvp(argv[0], argv);
+ execvp(argv[0], (char **) argv);
_exit(1);
@@ -207,16 +207,16 @@
int
virExec(virConnectPtr conn,
- char **argv,
- int *retpid, int infd, int *outfd, int *errfd) {
+ const char *const*argv,
+ int *retpid, int infd, int *outfd, int *errfd) {
return(_virExec(conn, argv, retpid, infd, outfd, errfd, 0));
}
int
virExecNonBlock(virConnectPtr conn,
- char **argv,
- int *retpid, int infd, int *outfd, int *errfd) {
+ const char *const*argv,
+ int *retpid, int infd, int *outfd, int *errfd) {
return(_virExec(conn, argv, retpid, infd, outfd, errfd, 1));
}
@@ -238,7 +238,7 @@
*/
int
virRun(virConnectPtr conn,
- char **argv,
+ const char *const*argv,
int *status) {
int childpid, exitstatus, ret;
diff -r cc63ab958867 src/util.h
--- a/src/util.h Thu Aug 07 15:00:21 2008 +0100
+++ b/src/util.h Thu Aug 07 22:59:08 2008 +0100
@@ -27,11 +27,11 @@
#include "util-lib.h"
#include "verify.h"
-int virExec(virConnectPtr conn, char **argv, int *retpid,
+int virExec(virConnectPtr conn, const char *const*argv, int *retpid,
int infd, int *outfd, int *errfd);
-int virExecNonBlock(virConnectPtr conn, char **argv, int *retpid,
+int virExecNonBlock(virConnectPtr conn, const char *const*argv, int *retpid,
int infd, int *outfd, int *errfd);
-int virRun(virConnectPtr conn, char **argv, int *status);
+int virRun(virConnectPtr conn, const char *const*argv, int *status);
int __virFileReadAll(const char *path,
int maxlen,
diff -r cc63ab958867 src/veth.c
--- a/src/veth.c Thu Aug 07 15:00:21 2008 +0100
+++ b/src/veth.c Thu Aug 07 22:59:08 2008 +0100
@@ -104,7 +104,7 @@
}
DEBUG("veth1: %s veth2: %s", veth1, veth2);
- rc = virRun(NULL, (char**)argv, &cmdResult);
+ rc = virRun(NULL, argv, &cmdResult);
if (0 == rc) {
rc = cmdResult;
@@ -137,7 +137,7 @@
DEBUG("veth: %s", veth);
- rc = virRun(NULL, (char**)argv, &cmdResult);
+ rc = virRun(NULL, argv, &cmdResult);
if (0 == rc) {
rc = cmdResult;
@@ -172,7 +172,7 @@
else
argv[2] = "up";
- rc = virRun(NULL, (char**)argv, &cmdResult);
+ rc = virRun(NULL, argv, &cmdResult);
if (0 == rc) {
rc = cmdResult;
@@ -210,7 +210,7 @@
goto error_out;
argv[5] = pid;
- rc = virRun(NULL, (char**)argv, &cmdResult);
+ rc = virRun(NULL, argv, &cmdResult);
if (0 == rc)
rc = cmdResult;
diff -r cc63ab958867 tests/qemuxml2argvtest.c
--- a/tests/qemuxml2argvtest.c Thu Aug 07 15:00:21 2008 +0100
+++ b/tests/qemuxml2argvtest.c Thu Aug 07 22:59:08 2008 +0100
@@ -26,7 +26,7 @@
char argvData[MAX_FILE];
char *expectargv = &(argvData[0]);
char *actualargv = NULL;
- char **argv = NULL;
+ const char **argv = NULL;
char **tmp = NULL;
int ret = -1, len, flags;
virDomainDefPtr vmdef = NULL;
--
|: Red Hat, Engineering, London -o-
http://people.redhat.com/berrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org -o-
http://ovirt.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|