From 04cc92c36e9695088a441a6282c41558a30205834efc2ecd2cc5b8116c3b4b55 Mon Sep 17 00:00:00 2001 From: Olaf Hering Date: Fri, 22 Mar 2013 15:49:02 +0000 Subject: [PATCH] - update hv_kvp_daemon Use CLOEXEC when opening kvp_pool files Fix permissions of created directory and files Fix /var subdirectory (move state files from /var/opt to /var/lib) Fix string types OBS-URL: https://build.opensuse.org/package/show/Virtualization/hyper-v?expand=0&rev=53 --- hyper-v.changes | 9 +++++++++ hyper-v.spec | 22 +++++++++++++++++++++- hyper-v.tools.hv.hv_kvp_daemon.c | 30 +++++++++++++++--------------- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/hyper-v.changes b/hyper-v.changes index 884162e..3e66f33 100644 --- a/hyper-v.changes +++ b/hyper-v.changes @@ -1,3 +1,12 @@ +------------------------------------------------------------------- +Fri Mar 22 16:19:38 CET 2013 - ohering@suse.de + +- update hv_kvp_daemon + Use CLOEXEC when opening kvp_pool files + Fix permissions of created directory and files + Fix /var subdirectory (move state files from /var/opt to /var/lib) + Fix string types + ------------------------------------------------------------------- Tue Nov 27 11:19:32 CET 2012 - ohering@suse.de diff --git a/hyper-v.spec b/hyper-v.spec index d359cc8..f7ec428 100644 --- a/hyper-v.spec +++ b/hyper-v.spec @@ -1,7 +1,7 @@ # # spec file for package hyper-v # -# Copyright (c) 2012 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -21,6 +21,7 @@ Name: hyper-v ExclusiveArch: %ix86 x86_64 PreReq: %insserv_prereq +Requires(pre): coreutils Summary: Microsoft Hyper-V tools License: GPL-2.0 Group: System/Kernel @@ -81,6 +82,25 @@ ln -sfvbn ../../etc/init.d/%{hv_kvp_daemon} $RPM_BUILD_ROOT/usr/sbin/rc%{hv_kvp_ /usr/sbin/%{hv_kvp_daemon} /usr/lib/%{name} +%pre +# hv_kvp_daemon in SLES11 SP2 stored temporary state files in /var/opt +# move them to /var/lib and remove old directory, if possible. +if test -d /var/opt/hyperv +then + if mkdir -p -v -m 0755 /var/lib/hyperv && pushd /var/lib/hyperv > /dev/null + then + for oldfile in /var/opt/hyperv/ifcfg-* /var/opt/hyperv/.kvp_pool_* + do + if test -e "${oldfile}" + then + mv -vfb "${oldfile}" . || : + fi + done + popd > /dev/null + fi + rmdir -v /var/opt/hyperv || : +fi + %post board_vendor= product_name= diff --git a/hyper-v.tools.hv.hv_kvp_daemon.c b/hyper-v.tools.hv.hv_kvp_daemon.c index 7164441..272a3ea 100644 --- a/hyper-v.tools.hv.hv_kvp_daemon.c +++ b/hyper-v.tools.hv.hv_kvp_daemon.c @@ -97,7 +97,7 @@ static struct utsname uts_buf; * The location of the interface configuration file. */ -#define KVP_CONFIG_LOC "/var/opt/" +#define KVP_CONFIG_LOC "/var/lib/hyperv" #define MAX_FILE_NAME 100 #define ENTRIES_PER_BLOCK 50 @@ -151,7 +151,7 @@ static void kvp_update_file(int pool) */ kvp_acquire_lock(pool); - filep = fopen(kvp_file_info[pool].fname, "w"); + filep = fopen(kvp_file_info[pool].fname, "we"); if (!filep) { kvp_release_lock(pool); syslog(LOG_ERR, "Failed to open file, pool: %d", pool); @@ -182,7 +182,7 @@ static void kvp_update_mem_state(int pool) kvp_acquire_lock(pool); - filep = fopen(kvp_file_info[pool].fname, "r"); + filep = fopen(kvp_file_info[pool].fname, "re"); if (!filep) { kvp_release_lock(pool); syslog(LOG_ERR, "Failed to open file, pool: %d", pool); @@ -234,9 +234,9 @@ static int kvp_file_init(void) int i; int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK; - if (access("/var/opt/hyperv", F_OK)) { - if (mkdir("/var/opt/hyperv", S_IRUSR | S_IWUSR | S_IROTH)) { - syslog(LOG_ERR, " Failed to create /var/opt/hyperv"); + if (access(KVP_CONFIG_LOC, F_OK)) { + if (mkdir(KVP_CONFIG_LOC, 0755 /* rwxr-xr-x */)) { + syslog(LOG_ERR, " Failed to create %s", KVP_CONFIG_LOC); exit(EXIT_FAILURE); } } @@ -245,14 +245,14 @@ static int kvp_file_init(void) fname = kvp_file_info[i].fname; records_read = 0; num_blocks = 1; - sprintf(fname, "/var/opt/hyperv/.kvp_pool_%d", i); - fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH); + sprintf(fname, "%s/.kvp_pool_%d", KVP_CONFIG_LOC, i); + fd = open(fname, O_RDWR | O_CREAT | O_CLOEXEC, 0644 /* rw-r--r-- */); if (fd == -1) return 1; - filep = fopen(fname, "r"); + filep = fopen(fname, "re"); if (!filep) return 1; @@ -299,7 +299,7 @@ static int kvp_file_init(void) return 0; } -static int kvp_key_delete(int pool, __u8 *key, int key_size) +static int kvp_key_delete(int pool, const char *key, int key_size) { int i; int j, k; @@ -342,7 +342,7 @@ static int kvp_key_delete(int pool, __u8 *key, int key_size) return 1; } -static int kvp_key_add_or_modify(int pool, __u8 *key, int key_size, __u8 *value, +static int kvp_key_add_or_modify(int pool, const char *key, int key_size, const char *value, int value_size) { int i; @@ -396,7 +396,7 @@ static int kvp_key_add_or_modify(int pool, __u8 *key, int key_size, __u8 *value, return 0; } -static int kvp_get_value(int pool, __u8 *key, int key_size, __u8 *value, +static int kvp_get_value(int pool, const char *key, int key_size, char *value, int value_size) { int i; @@ -428,8 +428,8 @@ static int kvp_get_value(int pool, __u8 *key, int key_size, __u8 *value, return 1; } -static int kvp_pool_enumerate(int pool, int index, __u8 *key, int key_size, - __u8 *value, int value_size) +static int kvp_pool_enumerate(int pool, int index, char *key, int key_size, + char *value, int value_size) { struct kvp_record *record; @@ -1271,7 +1271,7 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val) */ snprintf(if_file, sizeof(if_file), "%s%s%s", KVP_CONFIG_LOC, - "hyperv/ifcfg-", if_name); + "/ifcfg-", if_name); file = fopen(if_file, "w");