mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-29 17:33:09 +00:00
cleanup OpenVZ config file accesses
* src/openvz_conf.c: cleanup OpenVZ config file accesses, patch from Evgeniy Sokolov Daniel
This commit is contained in:
parent
fc2076033b
commit
915b86d29b
@ -1,3 +1,8 @@
|
|||||||
|
Fri Jul 11 10:53:59 CEST 2008 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
|
* src/openvz_conf.c: cleanup OpenVZ config file accesses, patch
|
||||||
|
from Evgeniy Sokolov
|
||||||
|
|
||||||
Thu Jul 10 17:28:19 CEST 2008 Daniel Veillard <veillard@redhat.com>
|
Thu Jul 10 17:28:19 CEST 2008 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
* src/libvirt.c: Evgeniy Sokolov found a driver open bug
|
* src/libvirt.c: Evgeniy Sokolov found a driver open bug
|
||||||
|
@ -60,6 +60,7 @@ static char *openvzLocateConfDir(void);
|
|||||||
static struct openvz_vm_def *openvzParseXML(virConnectPtr conn, xmlDocPtr xml);
|
static struct openvz_vm_def *openvzParseXML(virConnectPtr conn, xmlDocPtr xml);
|
||||||
static int openvzGetVPSUUID(int vpsid, char *uuidstr);
|
static int openvzGetVPSUUID(int vpsid, char *uuidstr);
|
||||||
static int openvzSetUUID(int vpsid);
|
static int openvzSetUUID(int vpsid);
|
||||||
|
static int openvzLocateConfFile(int vpsid, char *conffile, int maxlen);
|
||||||
|
|
||||||
void
|
void
|
||||||
openvzError (virConnectPtr conn, virErrorNumber code, const char *fmt, ...)
|
openvzError (virConnectPtr conn, virErrorNumber code, const char *fmt, ...)
|
||||||
@ -595,20 +596,13 @@ openvzReadConfigParam(int vpsid ,const char * param, char *value, int maxlen)
|
|||||||
char conf_file[PATH_MAX] ;
|
char conf_file[PATH_MAX] ;
|
||||||
char line[PATH_MAX] ;
|
char line[PATH_MAX] ;
|
||||||
int ret, found = 0;
|
int ret, found = 0;
|
||||||
char * conf_dir;
|
|
||||||
int fd ;
|
int fd ;
|
||||||
char * sf, * token;
|
char * sf, * token;
|
||||||
char *saveptr = NULL;
|
char *saveptr = NULL;
|
||||||
|
|
||||||
conf_dir = openvzLocateConfDir();
|
if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX)<0)
|
||||||
if (conf_dir == NULL)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (snprintf(conf_file, PATH_MAX, "%s/%d.conf", conf_dir,vpsid) >= PATH_MAX)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
VIR_FREE(conf_dir);
|
|
||||||
|
|
||||||
value[0] = 0;
|
value[0] = 0;
|
||||||
|
|
||||||
fd = open(conf_file, O_RDONLY);
|
fd = open(conf_file, O_RDONLY);
|
||||||
@ -638,6 +632,27 @@ openvzReadConfigParam(int vpsid ,const char * param, char *value, int maxlen)
|
|||||||
return ret ;
|
return ret ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Locate config file of container
|
||||||
|
* return -1 - error
|
||||||
|
* 0 - OK
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
openvzLocateConfFile(int vpsid, char *conffile, int maxlen)
|
||||||
|
{
|
||||||
|
char * confdir;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
confdir = openvzLocateConfDir();
|
||||||
|
if (confdir == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (snprintf(conffile, maxlen, "%s/%d.conf", confdir, vpsid) >= maxlen)
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
|
VIR_FREE(confdir);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static char
|
static char
|
||||||
*openvzLocateConfDir(void)
|
*openvzLocateConfDir(void)
|
||||||
{
|
{
|
||||||
@ -686,16 +701,12 @@ openvzGetVPSUUID(int vpsid, char *uuidstr)
|
|||||||
char line[1024];
|
char line[1024];
|
||||||
char uuidbuf[1024];
|
char uuidbuf[1024];
|
||||||
char iden[1024];
|
char iden[1024];
|
||||||
char *conf_dir;
|
|
||||||
int fd, ret;
|
int fd, ret;
|
||||||
|
|
||||||
conf_dir = openvzLocateConfDir();
|
if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX)<0)
|
||||||
if (conf_dir == NULL)
|
|
||||||
return -1;
|
return -1;
|
||||||
sprintf(conf_file, "%s/%d.conf", conf_dir, vpsid);
|
|
||||||
VIR_FREE(conf_dir);
|
|
||||||
|
|
||||||
fd = open(conf_file, O_RDWR);
|
fd = open(conf_file, O_RDONLY);
|
||||||
if(fd == -1)
|
if(fd == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -730,13 +741,9 @@ openvzSetUUID(int vpsid)
|
|||||||
char conf_file[PATH_MAX];
|
char conf_file[PATH_MAX];
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
unsigned char uuid[VIR_UUID_BUFLEN];
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
||||||
char *conf_dir;
|
|
||||||
|
|
||||||
conf_dir = openvzLocateConfDir();
|
if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX)<0)
|
||||||
if (conf_dir == NULL)
|
|
||||||
return -1;
|
return -1;
|
||||||
sprintf(conf_file, "%s/%d.conf", conf_dir, vpsid);
|
|
||||||
VIR_FREE(conf_dir);
|
|
||||||
|
|
||||||
if (openvzGetVPSUUID(vpsid, uuidstr))
|
if (openvzGetVPSUUID(vpsid, uuidstr))
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user