SHA256
1
0
forked from pool/hyper-v

- 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
This commit is contained in:
2013-03-22 15:49:02 +00:00
committed by Git OBS Bridge
parent 7d052ac13f
commit 04cc92c36e
3 changed files with 45 additions and 16 deletions

View File

@@ -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");