From 08cfcae91b588c8a2141de2af88adb2ec3dfe9d2 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Fri, 23 Feb 2007 09:10:28 +0000 Subject: [PATCH] Fri Feb 23 09:03:19 IST 2007 Mark McLoughlin * 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. --- ChangeLog | 10 +++++++++ qemud/internal.h | 18 ++++++++++++---- qemud/qemud.c | 55 ++++++++++++++++++++---------------------------- 3 files changed, 47 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index 449f04ae8a..4c7b81f8f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Fri Feb 23 09:03:19 IST 2007 Mark McLoughlin + + * 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 * qemud/driver.c: maintain the autostart flag on disk diff --git a/qemud/internal.h b/qemud/internal.h index e43222fff5..b18aed8fe3 100644 --- a/qemud/internal.h +++ b/qemud/internal.h @@ -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; diff --git a/qemud/qemud.c b/qemud/qemud.c index 3961c6415e..a66a0dd6c6 100644 --- a/qemud/qemud.c +++ b/qemud/qemud.c @@ -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; -- GitLab