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>
|
||||
|
||||
* 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
|
||||
qemudEnsureConfigDir(struct qemud_server *server,
|
||||
const char *configDir) {
|
||||
struct stat sb;
|
||||
qemudEnsureDir(const char *path)
|
||||
{
|
||||
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) {
|
||||
if (errno == ENOENT) {
|
||||
if (mkdir(configDir, 0700) < 0) {
|
||||
qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
|
||||
"cannot create config directory %s: %s",
|
||||
configDir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
|
||||
"cannot stat config directory %s",
|
||||
configDir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
} else if (!S_ISDIR(sb.st_mode)) {
|
||||
qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
|
||||
"config directory %s is not a directory", configDir);
|
||||
return -1;
|
||||
}
|
||||
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;
|
||||
}
|
||||
@ -1138,12 +1139,16 @@ static int qemudSaveConfig(struct qemud_server *server,
|
||||
char *xml;
|
||||
int fd = -1, ret = -1;
|
||||
int towrite;
|
||||
int err;
|
||||
|
||||
if (!(xml = qemudGenerateXML(server, vm, 0))) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -1268,12 +1273,16 @@ static int qemudSaveNetworkConfig(struct qemud_server *server,
|
||||
char *xml;
|
||||
int fd, ret = -1;
|
||||
int towrite;
|
||||
int err;
|
||||
|
||||
if (!(xml = qemudGenerateNetworkXML(server, network, 0))) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -350,37 +350,6 @@ static int qemudListenUnix(struct qemud_server *server,
|
||||
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,
|
||||
char *configDir,
|
||||
char *networkConfigDir,
|
||||
@ -388,7 +357,6 @@ static int qemudInitPaths(int sys,
|
||||
char *roSockname,
|
||||
int maxlen) {
|
||||
uid_t uid;
|
||||
int err;
|
||||
|
||||
uid = geteuid();
|
||||
|
||||
@ -432,18 +400,6 @@ static int qemudInitPaths(int sys,
|
||||
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;
|
||||
|
||||
snprintf_error:
|
||||
|
Loading…
Reference in New Issue
Block a user