diff --git a/ChangeLog b/ChangeLog index 740b98ccf8..50702e81e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Fri Aug 8 16:41:24 BST 2008 Daniel Berrange + + * 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 * src/domain_conf.c src/domain_conf.h src/qemu_conf.c diff --git a/src/iptables.c b/src/iptables.c index 3e3a1a2261..726141a88f 100644 --- a/src/iptables.c +++ b/src/iptables.c @@ -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"; diff --git a/src/lxc_driver.c b/src/lxc_driver.c index f58cf58b7d..2c2ae4396d 100644 --- a/src/lxc_driver.c +++ b/src/lxc_driver.c @@ -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) diff --git a/src/openvz_driver.c b/src/openvz_driver.c index e09b093ee1..110a9d5df5 100644 --- a/src/openvz_driver.c +++ b/src/openvz_driver.c @@ -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); diff --git a/src/qemu_conf.c b/src/qemu_conf.c index 3ffabcce14..15ccb27a6f 100644 --- a/src/qemu_conf.c +++ b/src/qemu_conf.c @@ -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; \ } \ diff --git a/src/qemu_conf.h b/src/qemu_conf.h index fcd896fd40..c03ad59a18 100644 --- a/src/qemu_conf.h +++ b/src/qemu_conf.h @@ -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); diff --git a/src/qemu_driver.c b/src/qemu_driver.c index a432e79a2d..42322ad980 100644 --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -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) { diff --git a/src/storage_backend.c b/src/storage_backend.c index a164a08e56..23b846c63e 100644 --- a/src/storage_backend.c +++ b/src/storage_backend.c @@ -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; } diff --git a/src/storage_backend_disk.c b/src/storage_backend_disk.c index d6548eb343..dac827b15c 100644 --- a/src/storage_backend_disk.c +++ b/src/storage_backend_disk.c @@ -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 */ diff --git a/src/storage_backend_fs.c b/src/storage_backend_fs.c index f1950342f9..36bfac49b5 100644 --- a/src/storage_backend_fs.c +++ b/src/storage_backend_fs.c @@ -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; } diff --git a/src/storage_backend_iscsi.c b/src/storage_backend_iscsi.c index cd6a251334..4f1906a051 100644 --- a/src/storage_backend_iscsi.c +++ b/src/storage_backend_iscsi.c @@ -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"); diff --git a/src/storage_backend_logical.c b/src/storage_backend_logical.c index db9768c0e8..0c4f6a5702 100644 --- a/src/storage_backend_logical.c +++ b/src/storage_backend_logical.c @@ -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; diff --git a/src/util.c b/src/util.c index 3980d1ba5b..d1b7ae16d4 100644 --- a/src/util.c +++ b/src/util.c @@ -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; diff --git a/src/util.h b/src/util.h index 4a567c97a5..16f79c26e4 100644 --- a/src/util.h +++ b/src/util.h @@ -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 --git a/src/veth.c b/src/veth.c index bb29b7cd03..ca0efbf206 100644 --- a/src/veth.c +++ b/src/veth.c @@ -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; diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 757d80440d..8f8906f92e 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -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);