int val;
if (virStrToLong_i(str, NULL, 10, &val) < 0)
- return 0 ;
+ return 0;
return val;
}
from_len = strlen(from);
to_len = strlen(to);
- while((offset = strstr(str_start, from)))
+ while ((offset = strstr(str_start, from)))
{
virBufferAdd(&buf, str_start, offset-str_start);
virBufferAdd(&buf, to, to_len);
return -1;
}
- while(!feof(fp)) {
+ while (!feof(fp)) {
if (fscanf(fp, "%d %s\n", &veid, status) != 2) {
if (feof(fp))
break;
{
char * temp_file = NULL;
int fd = -1, temp_fd = -1;
- char line[PATH_MAX] ;
+ char line[PATH_MAX];
if (virAsprintf(&temp_file, "%s.tmp", conf_file)<0) {
virReportOOMError();
goto error;
}
- while(1) {
+ while (1) {
if (openvz_readline(fd, line, sizeof(line)) <= 0)
break;
close(fd);
if (temp_fd != -1)
close(temp_fd);
- if(temp_file)
+ if (temp_file)
unlink(temp_file);
VIR_FREE(temp_file);
return -1;
static int
openvzReadConfigParam(const char * conf_file ,const char * param, char *value, int maxlen)
{
- char line[PATH_MAX] ;
+ char line[PATH_MAX];
int ret, found = 0;
- int fd ;
+ int fd;
char * sf, * token;
char *saveptr = NULL;
if (fd == -1)
return -1;
- while(1) {
+ while (1) {
ret = openvz_readline(fd, line, sizeof(line));
- if(ret <= 0)
+ if (ret <= 0)
break;
saveptr = NULL;
if (STREQLEN(line, param, strlen(param))) {
sf = line;
sf += strlen(param);
if (sf[0] == '=' && sf[1] != '\0' ) {
- sf ++;
+ sf++;
if ((token = strtok_r(sf,"\"\t\n", &saveptr)) != NULL) {
if (virStrcpy(value, token, maxlen) == NULL) {
ret = -1;
if (ret == 0 && found)
ret = 1;
- return ret ;
+ return ret;
}
/*
int
openvzReadVPSConfigParam(int vpsid ,const char * param, char *value, int maxlen)
{
- char conf_file[PATH_MAX] ;
+ char conf_file[PATH_MAX];
if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX, "conf")<0)
return -1;
return -1;
}
- while(1) {
+ while (1) {
if (openvz_readline(fd, line, sizeof(line)) <= 0)
break;
char conf_file[PATH_MAX];
int ret = -1;
- if(openvzReadConfigParam(VZ_CONF_FILE, "CONFIGFILE", configfile_value, PATH_MAX) < 0)
+ if (openvzReadConfigParam(VZ_CONF_FILE, "CONFIGFILE", configfile_value,
+ PATH_MAX) < 0)
goto cleanup;
confdir = openvzLocateConfDir();
const char *conf_dir_list[] = {"/etc/vz/conf", "/usr/local/etc/conf", NULL};
int i=0;
- while(conf_dir_list[i]) {
- if(!access(conf_dir_list[i], F_OK))
+ while (conf_dir_list[i]) {
+ if (!access(conf_dir_list[i], F_OK))
return strdup(conf_dir_list[i]);
- i ++;
+ i++;
}
return NULL;
int n, rc;
char c;
- for(n = 1; n < maxlen; n ++) {
- if( (rc = read(fd, &c, 1)) == 1) {
+ for (n = 1; n < maxlen; n++) {
+ if ( (rc = read(fd, &c, 1)) == 1) {
*ptr++ = c;
- if(c == '\n')
+ if (c == '\n')
break;
- }
- else if(rc == 0) {
- if(n == 1)
+ } else if (rc == 0) {
+ if (n == 1)
return 0; /* EOF condition */
else
break;
int retval = 0;
if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX, "conf")<0)
- return -1;
+ return -1;
fd = open(conf_file, O_RDONLY);
- if(fd == -1)
+ if (fd == -1)
return -1;
- while(1) {
+ while (1) {
ret = openvz_readline(fd, line, sizeof(line));
- if(ret == -1) {
+ if (ret == -1) {
close(fd);
return -1;
}
- if(ret == 0) { /* EoF, UUID was not found */
+ if (ret == 0) { /* EoF, UUID was not found */
uuidstr[0] = 0;
break;
}
return -1;
if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX, "conf")<0)
- return -1;
+ return -1;
if (openvzGetVPSUUID(vpsid, uuidstr, sizeof(uuidstr)))
return -1;
if (uuidstr[0] == 0) {
FILE *fp = fopen(conf_file, "a"); /* append */
if (fp == NULL)
- return -1;
+ return -1;
virUUIDFormat(uuid, uuidstr);
return -1;
dp = opendir(conf_dir);
- if(dp == NULL) {
+ if (dp == NULL) {
VIR_FREE(conf_dir);
return 0;
}
- while((dent = readdir(dp))) {
+ while ((dent = readdir(dp))) {
res = sscanf(dent->d_name, "%d.%5s", &vpsid, ext);
- if(!(res == 2 && STREQ(ext, "conf")))
+ if (!(res == 2 && STREQ(ext, "conf")))
continue;
- if(vpsid > 0) /* '0.conf' belongs to the host, ignore it */
+ if (vpsid > 0) /* '0.conf' belongs to the host, ignore it */
openvzSetUUID(vpsid);
}
closedir(dp);
static void cmdExecFree(const char *cmdExec[])
{
int i=-1;
- while(cmdExec[++i])
- {
+ while (cmdExec[++i]) {
VIR_FREE(cmdExec[i]);
}
}
vmdef->fss[0]->type == VIR_DOMAIN_FS_TYPE_MOUNT)
{
- if(virStrToLong_i(vmdef->name, NULL, 10, &vpsid) < 0) {
+ if (virStrToLong_i(vmdef->name, NULL, 10, &vpsid) < 0) {
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not convert domain name to VEID"));
goto cleanup;
//TODO: processing NAT and physical device
- if (prog[0] != NULL){
+ if (prog[0] != NULL) {
ADD_ARG_LIT("--save");
if (virRun(prog, NULL) < 0) {
openvzError(VIR_ERR_INTERNAL_ERROR,
ret = virExec(cmd, NULL, NULL,
&pid, -1, &outfd, &errfd, VIR_EXEC_NONE);
- if(ret == -1) {
+ if (ret == -1) {
openvzError(VIR_ERR_INTERNAL_ERROR,
_("Could not exec %s"), VZLIST);
return -1;
}
- while(got < nids){
+ while (got < nids) {
ret = openvz_readline(outfd, buf, 32);
- if(!ret) break;
+ if (!ret)
+ break;
if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) {
openvzError(VIR_ERR_INTERNAL_ERROR,
_("Could not parse VPS ID %s"), buf);
/* the -S options lists only stopped domains */
ret = virExec(cmd, NULL, NULL,
&pid, -1, &outfd, &errfd, VIR_EXEC_NONE);
- if(ret == -1) {
+ if (ret == -1) {
openvzError(VIR_ERR_INTERNAL_ERROR,
_("Could not exec %s"), VZLIST);
return -1;
}
- while(got < nnames){
+ while (got < nnames) {
ret = openvz_readline(outfd, buf, 32);
- if(!ret) break;
+ if (!ret)
+ break;
if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) {
openvzError(VIR_ERR_INTERNAL_ERROR,
_("Could not parse VPS ID %s"), buf);
return -1;
/*search line with VEID=vpsid*/
- while(1) {
+ while (1) {
ret = openvz_readline(fd, line, sizeof(line));
if (ret <= 0)
break;