提交 08cfcae9 编写于 作者: M Mark McLoughlin

Fri Feb 23 09:03:19 IST 2007 Mark McLoughlin <markmc@redhat.com>

        * qemud/internal.h: put the config directory paths in
        an array in order to make them easier to initialize,
        but still expose pointers to each of them as members
        in the server struct.

        * qemud/qemud.c: cleanup the config directory path
        initialization.
上级 56d2857f
Fri Feb 23 09:03:19 IST 2007 Mark McLoughlin <markmc@redhat.com>
* qemud/internal.h: put the config directory paths in
an array in order to make them easier to initialize,
but still expose pointers to each of them as members
in the server struct.
* qemud/qemud.c: cleanup the config directory path
initialization.
Fri Feb 23 09:03:19 IST 2007 Mark McLoughlin <markmc@redhat.com>
* qemud/driver.c: maintain the autostart flag on disk
......
......@@ -54,6 +54,15 @@ typedef enum {
#endif
} qemudLogPriority;
typedef enum {
QEMUD_DIR_CONFIG = 0,
QEMUD_DIR_AUTOSTART,
QEMUD_DIR_NETWORK_CONFIG,
QEMUD_DIR_NETWORK_AUTOSTART,
QEMUD_N_CONFIG_DIRS
} qemudConfigDirType;
/* Different types of QEMU acceleration possible */
enum qemud_vm_virt_type {
QEMUD_VIRT_QEMU,
......@@ -293,10 +302,11 @@ struct qemud_server {
struct qemud_network *networks;
brControl *brctl;
iptablesContext *iptables;
char configDir[PATH_MAX];
char networkConfigDir[PATH_MAX];
char autostartDir[PATH_MAX];
char networkAutostartDir[PATH_MAX];
char configDirs[QEMUD_N_CONFIG_DIRS][PATH_MAX];
char *configDir;
char *autostartDir;
char *networkConfigDir;
char *networkAutostartDir;
char errorMessage[QEMUD_MAX_ERROR_LEN];
int errorCode;
unsigned int shutdown : 1;
......
......@@ -354,15 +354,22 @@ static int qemudListenUnix(struct qemud_server *server,
return 0;
}
static int qemudInitPaths(int sys,
char *configDir,
char *networkConfigDir,
char *autostartDir,
char *networkAutostartDir,
static int qemudInitPaths(struct qemud_server *server,
int sys,
char *sockname,
char *roSockname,
int maxlen) {
const char *paths[] = {
"libvirt/qemu", /* QEMUD_DIR_DOMAINS */
"libvirt/qemu/autostart", /* QEMUD_DIR_AUTO_DOMAINS */
"libvirt/qemu/networks", /* QEMUD_DIR_NETWORKS */
"libvirt/qemu/networks/autostart", /* QEMUD_DIR_AUTO_NETWORKS */
};
uid_t uid;
struct passwd *pw;
char base[PATH_MAX] = SYSCONF_DIR "/";
int i;
uid = geteuid();
......@@ -372,18 +379,6 @@ static int qemudInitPaths(int sys,
return -1;
}
if (snprintf(configDir, maxlen, "%s/libvirt/qemu", SYSCONF_DIR) >= maxlen)
goto snprintf_error;
if (snprintf(networkConfigDir, maxlen, "%s/libvirt/qemu/networks", SYSCONF_DIR) >= maxlen)
goto snprintf_error;
if (snprintf(autostartDir, maxlen, "%s/libvirt/qemu/autostart", SYSCONF_DIR) >= maxlen)
goto snprintf_error;
if (snprintf(networkAutostartDir, maxlen, "%s/libvirt/qemu/networks/autostart", SYSCONF_DIR) >= maxlen)
goto snprintf_error;
if (snprintf(sockname, maxlen, "%s/run/libvirt/qemud-sock", LOCAL_STATE_DIR) >= maxlen)
goto snprintf_error;
......@@ -394,29 +389,22 @@ static int qemudInitPaths(int sys,
unlink(sockname);
} else {
struct passwd *pw;
if (!(pw = getpwuid(uid))) {
qemudLog(QEMUD_ERR, "Failed to find user record for uid '%d': %s",
uid, strerror(errno));
return -1;
}
if (snprintf(configDir, maxlen, "%s/.libvirt/qemu", pw->pw_dir) >= maxlen)
goto snprintf_error;
if (snprintf(networkConfigDir, maxlen, "%s/.libvirt/qemu/networks", pw->pw_dir) >= maxlen)
goto snprintf_error;
if (snprintf(autostartDir, maxlen, "%s/.libvirt/qemu/autostart", pw->pw_dir) >= maxlen)
if (snprintf(sockname, maxlen, "@%s/.libvirt/qemud-sock", pw->pw_dir) >= maxlen)
goto snprintf_error;
if (snprintf(networkAutostartDir, maxlen, "%s/.libvirt/qemu/networks/autostart", pw->pw_dir) >= maxlen)
if (snprintf(base, PATH_MAX, "%s/.", pw->pw_dir) >= PATH_MAX)
goto snprintf_error;
}
if (snprintf(sockname, maxlen, "@%s/.libvirt/qemud-sock", pw->pw_dir) >= maxlen)
for (i = 0; i < QEMUD_N_CONFIG_DIRS; i++)
if (snprintf(server->configDirs[i], PATH_MAX, "%s%s", base, paths[i]) >= PATH_MAX)
goto snprintf_error;
}
return 0;
......@@ -443,11 +431,14 @@ static struct qemud_server *qemudInitialize(int sys, int sigread) {
roSockname[0] = '\0';
if (qemudInitPaths(sys, server->configDir, server->networkConfigDir,
server->autostartDir, server->networkAutostartDir,
sockname, roSockname, PATH_MAX) < 0)
if (qemudInitPaths(server, sys, sockname, roSockname, PATH_MAX) < 0)
goto cleanup;
server->configDir = server->configDirs[QEMUD_DIR_CONFIG];
server->autostartDir = server->configDirs[QEMUD_DIR_AUTOSTART];
server->networkConfigDir = server->configDirs[QEMUD_DIR_NETWORK_CONFIG];
server->networkAutostartDir = server->configDirs[QEMUD_DIR_NETWORK_AUTOSTART];
if (qemudListenUnix(server, sockname, 0) < 0)
goto cleanup;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册