Fix const-correctness of virRUn and virExec

This commit is contained in:
Daniel P. Berrange 2008-08-08 15:43:38 +00:00
parent 5ba372306a
commit b3728d7d72
16 changed files with 76 additions and 66 deletions

View File

@ -1,3 +1,13 @@
Fri Aug 8 16:41:24 BST 2008 Daniel Berrange <berrange@redhat.com>
* src/iptables.c, src/lxc_driver.c, src/openvz_driver.c,
src/qemu_conf.c, src/qemu_conf.h, src/qemu_driver.c,
src/storage_backend.c, src/storage_backend_disk.c,
src/storage_backend_fs.c, src/storage_backend_iscsi.c,
src/storage_backend_logical.c, src/util.c, src/util.h,
src/veth.c, tests/qemuxml2argvtest.c: Fix const-correctness
of virRun and virExec, and remove unneccessary casts in callers
Fri Aug 8 16:53:24 CEST 2008 Daniel Veillard <veillard@redhat.com>
* src/domain_conf.c src/domain_conf.h src/qemu_conf.c

View File

@ -57,7 +57,7 @@ enum {
typedef struct
{
char *rule;
char **argv;
const char **argv;
int command_idx;
} iptRule;
@ -91,7 +91,7 @@ notifyRulesUpdated(const char *table,
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 @@ iptRuleFree(iptRule *rule)
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 @@ iptRulesNew(const char *table,
}
static char *
argvToString(char **argv)
argvToString(const char *const *argv)
{
int len, i;
char *ret, *p;
@ -415,7 +415,7 @@ iptablesAddRemoveRule(iptRules *rules, int action, const char *arg, ...)
{
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 @@ iptRulesReload(iptRules *rules)
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";

View File

@ -1288,7 +1288,7 @@ static int lxcCheckNetNsSupport(void)
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)

View File

@ -91,13 +91,13 @@ static virDomainPtr openvzDomainCreateLinux(virConnectPtr conn, const char *xml,
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 @@ static void cmdExecFree(char *cmdExec[])
0 - OK
*/
static int openvzDomainDefineCmd(virConnectPtr conn,
char *args[],
const char *args[],
int maxarg,
struct openvz_vm_def *vmdef)
{
@ -287,7 +287,7 @@ static int openvzDomainShutdown(virDomainPtr dom) {
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 @@ static int openvzDomainReboot(virDomainPtr dom,
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 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
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 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
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 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml)
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 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml)
//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 @@ openvzDomainCreateLinux(virConnectPtr conn, const char *xml,
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 @@ openvzDomainCreateLinux(virConnectPtr conn, const char *xml,
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 @@ openvzDomainCreateLinux(virConnectPtr conn, const char *xml,
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 @@ openvzDomainCreate(virDomainPtr dom)
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 @@ openvzDomainUndefine(virDomainPtr dom)
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 @@ openvzDomainSetAutostart(virDomainPtr dom, int autostart)
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 @@ static int openvzListDomains(virConnectPtr conn, int *ids, int nids) {
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 @@ static int openvzListDefinedDomains(virConnectPtr conn,
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);

View File

@ -712,7 +712,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
struct qemud_driver *driver,
virDomainObjPtr vm,
int qemuCmdFlags,
char ***retargv,
const char ***retargv,
int **tapfds,
int *ntapfds,
const char *migrateFrom) {
@ -730,7 +730,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
struct utsname ut;
int disableKQEMU = 0;
int qargc = 0, qarga = 0;
char **qargv = NULL;
const char **qargv = NULL;
uname(&ut);
@ -777,7 +777,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
do { \
ADD_ARG_LIT("-usbdevice"); \
ADD_ARG_SPACE; \
if ((asprintf(&qargv[qargc++], "disk:%s", thisarg)) == -1) { \
if ((asprintf((char **)&(qargv[qargc++]), "disk:%s", thisarg)) == -1) { \
qargv[qargc-1] = NULL; \
goto no_memory; \
} \

View File

@ -95,7 +95,7 @@ int qemudBuildCommandLine (virConnectPtr conn,
struct qemud_driver *driver,
virDomainObjPtr dom,
int qemuCmdFlags,
char ***argv,
const char ***argv,
int **tapfds,
int *ntapfds,
const char *migrateFrom);

View File

@ -842,7 +842,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
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 qemudDispatchVMFailure(struct qemud_driver *driver, virDomainObjPtr v
static int
qemudBuildDnsmasqArgv(virConnectPtr conn,
virNetworkObjPtr network,
char ***argv) {
const char ***argv) {
int i, len, r;
char buf[PATH_MAX];
@ -1184,7 +1184,7 @@ static int
dhcpStartDhcpDaemon(virConnectPtr conn,
virNetworkObjPtr network)
{
char **argv;
const char **argv;
int ret, i;
if (network->def->ipAddress == NULL) {

View File

@ -403,7 +403,7 @@ virStorageBackendRunProgRegex(virConnectPtr conn,
/* 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 @@ virStorageBackendRunProgNul(virConnectPtr conn,
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;
}

View File

@ -410,7 +410,7 @@ virStorageBackendDiskBuildPool(virConnectPtr conn,
NULL,
};
if (virRun(conn, (char**)prog, NULL) < 0)
if (virRun(conn, prog, NULL) < 0)
return -1;
return 0;
@ -469,7 +469,7 @@ virStorageBackendDiskCreateVol(virConnectPtr conn,
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 */

View File

@ -571,7 +571,7 @@ virStorageBackendFileSystemMount(virConnectPtr conn,
}
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 @@ virStorageBackendFileSystemUnmount(virConnectPtr conn,
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 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
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 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
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;
}

View File

@ -158,7 +158,7 @@ virStorageBackendISCSIConnection(virConnectPtr conn,
"--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 @@ virStorageBackendISCSIRescanLUNs(virConnectPtr conn,
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 @@ virStorageBackendISCSILogin(virConnectPtr conn,
"--portal", portal, NULL
};
if (virRun(conn, (char **)cmdsendtarget, NULL) < 0)
if (virRun(conn, cmdsendtarget, NULL) < 0)
return -1;
return virStorageBackendISCSIConnection(conn, pool, portal, "--login");

View File

@ -83,7 +83,7 @@ virStorageBackendLogicalSetActive(virConnectPtr conn,
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 @@ virStorageBackendLogicalBuildPool(virConnectPtr conn,
*/
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 @@ virStorageBackendLogicalDeletePool(virConnectPtr conn,
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 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
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 @@ virStorageBackendLogicalDeleteVol(virConnectPtr conn,
LVREMOVE, "-f", vol->target.path, NULL
};
if (virRun(conn, (char**)cmdargv, NULL) < 0)
if (virRun(conn, cmdargv, NULL) < 0)
return -1;
return 0;

View File

@ -102,8 +102,8 @@ static int virSetNonBlock(int fd) {
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 @@ _virExec(virConnectPtr conn,
if (pipeerr[1] > 0)
close(pipeerr[1]);
execvp(argv[0], argv);
execvp(argv[0], (char **) argv);
_exit(1);
@ -207,16 +207,16 @@ _virExec(virConnectPtr conn,
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 @@ virExecNonBlock(virConnectPtr conn,
*/
int
virRun(virConnectPtr conn,
char **argv,
const char *const*argv,
int *status) {
int childpid, exitstatus, ret;

View File

@ -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,

View File

@ -104,7 +104,7 @@ int vethCreate(char* veth1, int veth1MaxLen,
}
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 @@ int vethDelete(const char *veth)
DEBUG("veth: %s", veth);
rc = virRun(NULL, (char**)argv, &cmdResult);
rc = virRun(NULL, argv, &cmdResult);
if (0 == rc) {
rc = cmdResult;
@ -172,7 +172,7 @@ int vethInterfaceUpOrDown(const char* veth, int upOrDown)
else
argv[2] = "up";
rc = virRun(NULL, (char**)argv, &cmdResult);
rc = virRun(NULL, argv, &cmdResult);
if (0 == rc) {
rc = cmdResult;
@ -210,7 +210,7 @@ int moveInterfaceToNetNs(const char* interface, int pidInNs)
goto error_out;
argv[5] = pid;
rc = virRun(NULL, (char**)argv, &cmdResult);
rc = virRun(NULL, argv, &cmdResult);
if (0 == rc)
rc = cmdResult;

View File

@ -26,8 +26,8 @@ static int testCompareXMLToArgvFiles(const char *xml, const char *cmd, int extra
char argvData[MAX_FILE];
char *expectargv = &(argvData[0]);
char *actualargv = NULL;
char **argv = NULL;
char **tmp = NULL;
const char **argv = NULL;
const char **tmp = NULL;
int ret = -1, len, flags;
virDomainDefPtr vmdef = NULL;
virDomainObj vm;
@ -81,7 +81,7 @@ static int testCompareXMLToArgvFiles(const char *xml, const char *cmd, int extra
if (argv) {
tmp = argv;
while (*tmp) {
free(*tmp);
free(*(char**)tmp);
tmp++;
}
free(argv);