mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-26 18:41:17 +00:00
Fri Feb 20 16:49:53 IST 2007 Mark McLoughlin <markmc@redhat.com>
* qemud/conf.c, qemud/qemud.c: only create config dirs when actually trying to write out config.
This commit is contained in:
parent
5ed716484e
commit
c5b3181ad9
@ -1,3 +1,8 @@
|
|||||||
|
Fri Feb 20 16:49:53 IST 2007 Mark McLoughlin <markmc@redhat.com>
|
||||||
|
|
||||||
|
* qemud/conf.c, qemud/qemud.c: only create config dirs
|
||||||
|
when actually trying to write out config.
|
||||||
|
|
||||||
Fri Feb 20 09:56:35 IST 2007 Mark McLoughlin <markmc@redhat.com>
|
Fri Feb 20 09:56:35 IST 2007 Mark McLoughlin <markmc@redhat.com>
|
||||||
|
|
||||||
* qemud/bridge.c: change the fix for the alignment warning
|
* qemud/bridge.c: change the fix for the alignment warning
|
||||||
|
59
qemud/conf.c
59
qemud/conf.c
@ -138,31 +138,32 @@ qemudMakeConfigPath(const char *configDir,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemudEnsureConfigDir(struct qemud_server *server,
|
qemudEnsureDir(const char *path)
|
||||||
const char *configDir) {
|
{
|
||||||
struct stat sb;
|
struct stat st;
|
||||||
|
char parent[PATH_MAX];
|
||||||
|
char *p;
|
||||||
|
int err;
|
||||||
|
|
||||||
/* XXX: needs to be recursive */
|
if (stat(path, &st) >= 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (stat(configDir, &sb) < 0) {
|
strncpy(parent, path, PATH_MAX);
|
||||||
if (errno == ENOENT) {
|
parent[PATH_MAX - 1] = '\0';
|
||||||
if (mkdir(configDir, 0700) < 0) {
|
|
||||||
qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
|
if (!(p = strrchr(parent, '/')))
|
||||||
"cannot create config directory %s: %s",
|
return EINVAL;
|
||||||
configDir, strerror(errno));
|
|
||||||
return -1;
|
if (p == parent)
|
||||||
}
|
return EPERM;
|
||||||
} else {
|
|
||||||
qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
|
*p = '\0';
|
||||||
"cannot stat config directory %s",
|
|
||||||
configDir, strerror(errno));
|
if ((err = qemudEnsureDir(parent)))
|
||||||
return -1;
|
return err;
|
||||||
}
|
|
||||||
} else if (!S_ISDIR(sb.st_mode)) {
|
if (mkdir(path, 0777) < 0 && errno != EEXIST)
|
||||||
qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
|
return errno;
|
||||||
"config directory %s is not a directory", configDir);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1138,12 +1139,16 @@ static int qemudSaveConfig(struct qemud_server *server,
|
|||||||
char *xml;
|
char *xml;
|
||||||
int fd = -1, ret = -1;
|
int fd = -1, ret = -1;
|
||||||
int towrite;
|
int towrite;
|
||||||
|
int err;
|
||||||
|
|
||||||
if (!(xml = qemudGenerateXML(server, vm, 0))) {
|
if (!(xml = qemudGenerateXML(server, vm, 0))) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemudEnsureConfigDir(server, server->configDir) < 0) {
|
if ((err = qemudEnsureDir(server->configDir))) {
|
||||||
|
qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"cannot create config directory %s: %s",
|
||||||
|
server->configDir, strerror(err));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1268,12 +1273,16 @@ static int qemudSaveNetworkConfig(struct qemud_server *server,
|
|||||||
char *xml;
|
char *xml;
|
||||||
int fd, ret = -1;
|
int fd, ret = -1;
|
||||||
int towrite;
|
int towrite;
|
||||||
|
int err;
|
||||||
|
|
||||||
if (!(xml = qemudGenerateNetworkXML(server, network, 0))) {
|
if (!(xml = qemudGenerateNetworkXML(server, network, 0))) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemudEnsureConfigDir(server, server->networkConfigDir) < 0) {
|
if ((err = qemudEnsureDir(server->networkConfigDir))) {
|
||||||
|
qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"cannot create config directory %s: %s",
|
||||||
|
server->networkConfigDir, strerror(err));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,37 +350,6 @@ static int qemudListenUnix(struct qemud_server *server,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
qemudEnsureDir(const char *path)
|
|
||||||
{
|
|
||||||
struct stat st;
|
|
||||||
char parent[PATH_MAX];
|
|
||||||
char *p;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
if (stat(path, &st) >= 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
strncpy(parent, path, PATH_MAX);
|
|
||||||
parent[PATH_MAX - 1] = '\0';
|
|
||||||
|
|
||||||
if (!(p = strrchr(parent, '/')))
|
|
||||||
return EINVAL;
|
|
||||||
|
|
||||||
if (p == parent)
|
|
||||||
return EPERM;
|
|
||||||
|
|
||||||
*p = '\0';
|
|
||||||
|
|
||||||
if ((err = qemudEnsureDir(parent)))
|
|
||||||
return err;
|
|
||||||
|
|
||||||
if (mkdir(path, 0777) < 0 && errno != EEXIST)
|
|
||||||
return errno;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qemudInitPaths(int sys,
|
static int qemudInitPaths(int sys,
|
||||||
char *configDir,
|
char *configDir,
|
||||||
char *networkConfigDir,
|
char *networkConfigDir,
|
||||||
@ -388,7 +357,6 @@ static int qemudInitPaths(int sys,
|
|||||||
char *roSockname,
|
char *roSockname,
|
||||||
int maxlen) {
|
int maxlen) {
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
int err;
|
|
||||||
|
|
||||||
uid = geteuid();
|
uid = geteuid();
|
||||||
|
|
||||||
@ -432,18 +400,6 @@ static int qemudInitPaths(int sys,
|
|||||||
goto snprintf_error;
|
goto snprintf_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = qemudEnsureDir(configDir))) {
|
|
||||||
qemudLog(QEMUD_ERR, "Failed to create directory '%s': %s",
|
|
||||||
configDir, strerror(err));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((err = qemudEnsureDir(networkConfigDir))) {
|
|
||||||
qemudLog(QEMUD_ERR, "Failed to create directory '%s': %s",
|
|
||||||
networkConfigDir, strerror(err));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
snprintf_error:
|
snprintf_error:
|
||||||
|
Loading…
Reference in New Issue
Block a user