mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 02:51:16 +00:00
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.
This commit is contained in:
parent
56d2857f95
commit
08cfcae91b
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
||||
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,30 +389,23 @@ 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)
|
||||
goto snprintf_error;
|
||||
|
||||
if (snprintf(networkAutostartDir, maxlen, "%s/.libvirt/qemu/networks/autostart", pw->pw_dir) >= maxlen)
|
||||
goto snprintf_error;
|
||||
|
||||
if (snprintf(sockname, maxlen, "@%s/.libvirt/qemud-sock", pw->pw_dir) >= maxlen)
|
||||
goto snprintf_error;
|
||||
|
||||
if (snprintf(base, PATH_MAX, "%s/.", pw->pw_dir) >= PATH_MAX)
|
||||
goto snprintf_error;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
snprintf_error:
|
||||
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user