tools/hv: Fix /var subdirectory
PATCH 1/3 tools/hv: Fix /var subdirectory
Initial patch by Ben Hutchings <[email protected]>
We will install this in /usr, so it must use /var/lib for its state. Only programs installed under /opt should use /var/opt.
--- tools/hv/hv_kvp_daemon.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
tools/hv/hv_kvp_daemon.c +5 -5
@@ -98,7 +98,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/"#define MAX_FILE_NAME 100#define ENTRIES_PER_BLOCK 50
@@ -235,9 +235,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 ("/var/lib/hyperv" ,F_OK )) { +if (mkdir ("/var/lib/hyperv" ,S_IRUSR |S_IWUSR |S_IROTH )) { +syslog (LOG_ERR ," Failed to create /var/lib/hyperv" );exit (EXIT_FAILURE ); } }
@@ -246,7 +246,7 @@ 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); +sprintf (fname,"/var/lib/hyperv/.kvp_pool_%d" , i); fd =open (fname,O_RDWR |O_CREAT ,S_IRUSR |S_IWUSR |S_IROTH );if (fd ==-1 )
Signature · 1 line
1.7.11.7
PATCH 2/3 tools/hv: Fix string types
Initial patch by Ben Hutchings <[email protected]>
Standard C strings are arrays of char, not __u8 (unsigned char). Declare variables and parameters accordingly, and add the necessary casts.
--- tools/hv/hv_kvp_daemon.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
tools/hv/hv_kvp_daemon.c +5 -5
@@ -300,7 +300,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;
@@ -343,7 +343,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;
@@ -397,7 +397,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;
@@ -429,8 +429,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;
Signature · 1 line
1.7.11.7
RE: [PATCH 2/3] tools/hv: Fix string types
Quoted 11 lines
-----Original Message-----
From: Tomas Hozza [mailto:[email protected]]
Sent: Friday, November 09, 2012 9:01 AM
To: [email protected]; KY Srinivasan; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Tomas Hozza
Subject: [PATCH 2/3]tools/hv: Fix string types
Quoted 7 lines
Initial patch by Ben Hutchings <[email protected]>
Standard C strings are arrays of char, not
__u8(unsigned char). Declare variables and parameters accordingly, and add the necessary casts.Signed-off-by Tomas Hozza <[email protected]>
Quoted 55 lines
--- tools/hv/hv_kvp_daemon.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)tools/hv/hv_kvp_daemon.c +2
-2@@ -300,7 +300,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;@@ -343,7 +343,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,tools/hv/hv_kvp_daemon.c +1
-1int value_size) {int i;@@ -397,7 +397,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) {tools/hv/hv_kvp_daemon.c +2
-3int i;@@ -429,8 +429,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; --1.7.11.7
PATCH 3/3 tools/hv: Fix permissions of created directory and files
In reply to Tomas HozzaFrom: Ben Hutchings <[email protected]>
It's silly to create directories without execute permission, or to give permissions to 'other' but not the group-owner.
Write the permissions in octal and 'ls -l' format since these are much easier to read than the named macros.
--- tools/hv/hv_kvp_daemon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/hv/hv_kvp_daemon.c +2 -2
@@ -236,7 +236,7 @@ static int kvp_file_init(void)int alloc_unit =sizeof (struct kvp_record ) *ENTRIES_PER_BLOCK ;if (access ("/var/lib/hyperv" ,F_OK )) { -if (mkdir ("/var/lib/hyperv" ,S_IRUSR |S_IWUSR |S_IROTH )) { +if (mkdir ("/var/lib/hyperv" ,0755 /* rwxr-xr-x */ )) {syslog (LOG_ERR ," Failed to create /var/lib/hyperv" );exit (EXIT_FAILURE ); }
@@ -247,7 +247,7 @@ static int kvp_file_init(void) records_read =0 ; num_blocks =1 ;sprintf (fname,"/var/lib/hyperv/.kvp_pool_%d" , i); - fd =open (fname,O_RDWR |O_CREAT ,S_IRUSR |S_IWUSR |S_IROTH ); + fd =open (fname,O_RDWR |O_CREAT ,0644 /* rw-r--r-- */ );if (fd ==-1 )return 1 ;
Signature · 1 line
1.7.11.7
RE: [PATCH 3/3] tools/hv: Fix permissions of created directory and files
Quoted 13 lines
-----Original Message-----
From: Tomas Hozza [mailto:[email protected]]
Sent: Friday, November 09, 2012 9:01 AM
To: [email protected]; KY Srinivasan; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Tomas Hozza
Subject: [PATCH 3/3]tools/hv: Fix permissions of created directory and filesFrom: Ben Hutchings <[email protected]>
Quoted 8 lines
It's silly to create directories without execute permission, or to give permissions to 'other' but not the group-owner.
Write the permissions in octal and 'ls -l' format since these are much easier to read than the named macros.
Signed-off-by Ben Hutchings <[email protected]>Signed-off-by Tomas Hozza <[email protected]>
Quoted 31 lines
--- tools/hv/hv_kvp_daemon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/hv/hv_kvp_daemon.c +2
-2@@ -236,7 +236,7 @@ static int kvp_file_init(void)int alloc_unit =sizeof (struct kvp_record ) *ENTRIES_PER_BLOCK ;if (access ("/var/lib/hyperv" ,F_OK )) { -if (mkdir ("/var/lib/hyperv" ,S_IRUSR |S_IWUSR |S_IROTH )) { +if (mkdir ("/var/lib/hyperv" ,0755 /* rwxr-xr-x */ )) {syslog (LOG_ERR ," Failed to create /var/lib/hyperv" );exit (EXIT_FAILURE ); }@@ -247,7 +247,7 @@ static int kvp_file_init(void) records_read =0 ; num_blocks =1 ;sprintf (fname,"/var/lib/hyperv/.kvp_pool_%d" , i); - fd =open (fname,O_RDWR |O_CREAT ,S_IRUSR |S_IWUSR | S_IROTH); + fd =open (fname,O_RDWR |O_CREAT ,0644 /* rw-r--r-- */ );if (fd ==-1 )return 1;
--
1.7.11.7
RE: [PATCH 3/3] tools/hv: Fix permissions of created directory and files
In reply to Tomas HozzaQuoted 13 lines
-----Original Message-----
From: Tomas Hozza [mailto:[email protected]]
Sent: Friday, November 09, 2012 9:01 AM
To: [email protected]; KY Srinivasan; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Tomas Hozza
Subject: [PATCH 3/3]tools/hv: Fix permissions of created directory and filesFrom: Ben Hutchings <[email protected]>
Quoted 8 lines
It's silly to create directories without execute permission, or to give permissions to 'other' but not the group-owner.
Write the permissions in octal and 'ls -l' format since these are much easier to read than the named macros.
Signed-off-by Ben Hutchings <[email protected]>Signed-off-by Tomas Hozza <[email protected]>
Quoted 31 lines
--- tools/hv/hv_kvp_daemon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/hv/hv_kvp_daemon.c +2
-2@@ -236,7 +236,7 @@ static int kvp_file_init(void)int alloc_unit =sizeof (struct kvp_record ) *ENTRIES_PER_BLOCK ;if (access ("/var/lib/hyperv" ,F_OK )) { -if (mkdir ("/var/lib/hyperv" ,S_IRUSR |S_IWUSR |S_IROTH )) { +if (mkdir ("/var/lib/hyperv" ,0755 /* rwxr-xr-x */ )) {syslog (LOG_ERR ," Failed to create /var/lib/hyperv" );exit (EXIT_FAILURE ); }@@ -247,7 +247,7 @@ static int kvp_file_init(void) records_read =0 ; num_blocks =1 ;sprintf (fname,"/var/lib/hyperv/.kvp_pool_%d" , i); - fd =open (fname,O_RDWR |O_CREAT ,S_IRUSR |S_IWUSR | S_IROTH); + fd =open (fname,O_RDWR |O_CREAT ,0644 /* rw-r--r-- */ );if (fd ==-1 )return 1;
--
1.7.11.7
Quoted 35 lines
-----Original Message-----
From: Tomas Hozza [mailto:[email protected]]
Sent: Friday, November 09, 2012 9:01 AM
To: [email protected]; KY Srinivasan; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Tomas Hozza
Subject: [PATCH 1/3]tools/hv: Fix /var subdirectoryInitial patch by Ben Hutchings <[email protected]>
We will install this in /usr, so it must use
/var/libfor its state. Only programs installed under /opt should use/var/opt.Signed-off-by Tomas Hozza <[email protected]>--- tools/hv/hv_kvp_daemon.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)tools/hv/hv_kvp_daemon.c +1
-1@@ -98,7 +98,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/"#define MAX_FILE_NAME 100#define ENTRIES_PER_BLOCK 50
tools/hv/hv_kvp_daemon.c static int kvp_file_init(void) · line 240
Quoted 9 lines
tools/hv/hv_kvp_daemon.c +3
-3@@ -235,9 +235,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 ("/var/lib/hyperv" ,F_OK )) { +if (mkdir ("/var/lib/hyperv" ,S_IRUSR |S_IWUSR |S_IROTH )) { +syslog (LOG_ERR ," Failed to create /var/lib/hyperv" );
Why don't you use the macro defined earlier for the path for /var/lib. Why not include the hyperv directory as well in the macro.
Regards,
K. Y
Quoted 17 lines
tools/hv/hv_kvp_daemon.c +1
-1exit (EXIT_FAILURE ); } }@@ -246,7 +246,7 @@ 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); +sprintf (fname,"/var/lib/hyperv/.kvp_pool_%d" , i); fd =open (fname,O_RDWR |O_CREAT ,S_IRUSR |S_IWUSR |S_IROTH );if (fd == -1)
--
1.7.11.7
PATCH 1/3 tools/hv: Fix /var subdirectory
Initial patch by Ben Hutchings <[email protected]>
We will install this in /usr, so it must use /var/lib for its state. Only programs installed under /opt should use /var/opt.
--- tools/hv/hv_kvp_daemon.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tools/hv/hv_kvp_daemon.c +6 -6
@@ -98,7 +98,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
@@ -235,9 +235,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 ,S_IRUSR |S_IWUSR |S_IROTH )) { +syslog (LOG_ERR ," Failed to create %s" ,KVP_CONFIG_LOC );exit (EXIT_FAILURE ); } }
@@ -246,7 +246,7 @@ 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); +sprintf (fname,"%s/.kvp_pool_%d" ,KVP_CONFIG_LOC , i); fd =open (fname,O_RDWR |O_CREAT ,S_IRUSR |S_IWUSR |S_IROTH );if (fd ==-1 )
@@ -1263,7 +1263,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" );
Signature · 1 line
1.7.11.7
PATCH 3/3 tools/hv: Fix permissions of created directory and files
From: Ben Hutchings <[email protected]>
It's silly to create directories without execute permission, or to give permissions to 'other' but not the group-owner.
Write the permissions in octal and 'ls -l' format since these are much easier to read than the named macros.
--- tools/hv/hv_kvp_daemon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/hv/hv_kvp_daemon.c +2 -2
@@ -236,7 +236,7 @@ static int kvp_file_init(void)int alloc_unit =sizeof (struct kvp_record ) *ENTRIES_PER_BLOCK ;if (access (KVP_CONFIG_LOC ,F_OK )) { -if (mkdir (KVP_CONFIG_LOC ,S_IRUSR |S_IWUSR |S_IROTH )) { +if (mkdir (KVP_CONFIG_LOC ,0755 /* rwxr-xr-x */ )) {syslog (LOG_ERR ," Failed to create %s" ,KVP_CONFIG_LOC );exit (EXIT_FAILURE ); }
@@ -247,7 +247,7 @@ static int kvp_file_init(void) records_read =0 ; num_blocks =1 ;sprintf (fname,"%s/.kvp_pool_%d" ,KVP_CONFIG_LOC , i); - fd =open (fname,O_RDWR |O_CREAT ,S_IRUSR |S_IWUSR |S_IROTH ); + fd =open (fname,O_RDWR |O_CREAT ,0644 /* rw-r--r-- */ );if (fd ==-1 )return 1 ;
Signature · 1 line
1.7.11.7
RE: [PATCH 3/3] tools/hv: Fix permissions of created directory and files
Quoted 13 lines
-----Original Message-----
From: Tomas Hozza [mailto:[email protected]]
Sent: Monday, November 12, 2012 3:55 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; KY Srinivasan; [email protected]
Cc: Tomas Hozza
Subject: [PATCH 3/3]tools/hv: Fix permissions of created directory and filesFrom: Ben Hutchings <[email protected]>
Quoted 8 lines
It's silly to create directories without execute permission, or to give permissions to 'other' but not the group-owner.
Write the permissions in octal and 'ls -l' format since these are much easier to read than the named macros.
Signed-off-by Ben Hutchings <[email protected]>Signed-off-by Tomas Hozza <[email protected]>
Quoted 30 lines
--- tools/hv/hv_kvp_daemon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/hv/hv_kvp_daemon.c +1
-1@@ -236,7 +236,7 @@ static int kvp_file_init(void)int alloc_unit =sizeof (struct kvp_record ) *ENTRIES_PER_BLOCK ;if (access (KVP_CONFIG_LOC ,F_OK )) { -if (mkdir (KVP_CONFIG_LOC ,S_IRUSR |S_IWUSR |S_IROTH )) { +if (mkdir (KVP_CONFIG_LOC ,0755 /* rwxr-xr-x */ )) {syslog (LOG_ERR ," Failed to create %s" ,KVP_CONFIG_LOC );exit (EXIT_FAILURE );tools/hv/hv_kvp_daemon.c +1
-1}@@ -247,7 +247,7 @@ static int kvp_file_init(void) records_read =0 ; num_blocks =1 ;sprintf (fname,"%s/.kvp_pool_%d" ,KVP_CONFIG_LOC , i); - fd =open (fname,O_RDWR |O_CREAT ,S_IRUSR |S_IWUSR | S_IROTH); + fd =open (fname,O_RDWR |O_CREAT ,0644 /* rw-r--r-- */ );if (fd ==-1 )return 1;
--
1.7.11.7
Quoted 11 lines
-----Original Message-----
From: Tomas Hozza [mailto:[email protected]]
Sent: Monday, November 12, 2012 3:55 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; KY Srinivasan; [email protected]
Cc: Tomas Hozza
Subject: [PATCH 1/3]tools/hv: Fix /var subdirectory
Quoted 6 lines
Initial patch by Ben Hutchings <[email protected]>
We will install this in /usr, so it must use
/var/libfor its state. Only programs installed under /opt should use/var/opt.Signed-off-by Tomas Hozza <[email protected]>
Quoted 53 lines
--- tools/hv/hv_kvp_daemon.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)tools/hv/hv_kvp_daemon.c +4
-4@@ -98,7 +98,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@@ -235,9 +235,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 ,S_IRUSR |S_IWUSR |S_IROTH )) { +syslog (LOG_ERR ," Failed to create %s" ,KVP_CONFIG_LOC );exit (EXIT_FAILURE ); }tools/hv/hv_kvp_daemon.c +1
-1}@@ -246,7 +246,7 @@ 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); +sprintf (fname,"%s/.kvp_pool_%d" ,KVP_CONFIG_LOC , i); fd =open (fname,O_RDWR |O_CREAT ,S_IRUSR |S_IWUSR |S_IROTH );tools/hv/hv_kvp_daemon.c +1
-2if (fd ==-1 )@@ -1263,7 +1263,7 @@ static int kvp_set_ip_info(char *if_name, structhv_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" ); --1.7.11.7
Quoted 11 lines · KY Srinivasan
Quoted 11 lines
-----Original Message-----
From: Tomas Hozza [mailto:[email protected]]
Sent: Monday, November 12, 2012 3:55 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; KY Srinivasan; [email protected]
Cc: Tomas Hozza
Subject: [PATCH 1/3]tools/hv: Fix /var subdirectory
Quoted 7 lines
Quoted 6 lines
Initial patch by Ben Hutchings <[email protected]>
We will install this in /usr, so it must use
/var/libfor its state. Only programs installed under /opt should use/var/opt.Signed-off-by Tomas Hozza <[email protected]>Acked-by K. Y. Srinivasan <[email protected]>
As I stated before, you need to rediff these, and resend them to me, I have no more hyperv patches in my queue to apply.
greg k-h
Quoted 25 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Monday, November 26, 2012 4:12 PM
To: KY Srinivasan
Cc: Tomas Hozza; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 1/3]tools/hv: Fix /var subdirectoryQuoted 13 lines · KY Srinivasan
Quoted 13 lines
-----Original Message-----
From: Tomas Hozza [mailto:[email protected]]
Sent: Monday, November 12, 2012 3:55 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; KY Srinivasan; [email protected]
Cc: Tomas Hozza
Subject: [PATCH 1/3]tools/hv: Fix /var subdirectoryInitial patch by Ben Hutchings <[email protected]>
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
We will install this in /usr, so it must use
/var/libfor its state. Only programs installed under /opt should use/var/opt.Signed-off-by Tomas Hozza <[email protected]>Acked-by K. Y. Srinivasan <[email protected]>As I stated before, you need to rediff these, and resend them to me, I have no more hyperv patches in my queue to apply.
Will do. There were totally 3 patches that Tomas had sent that I acked today. Tomas, could you rebase the patches (if needed) and re-send them.
K. Y
Quoted 3 lines
greg k-h
PATCH 1/3 tools/hv: Fix for long file names from readdir
kvp_get_if_name and kvp_mac_to_if_name copy strings into statically sized buffers which could be too small to store really long names.
Buffer sizes have been changed to PATH_MAX, include "limits.h" where PATH_MAX is defined was added and length checks ware added via snprintf.
--- tools/hv/hv_kvp_daemon.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-)
tools/hv/hv_kvp_daemon.c +9 -17
@@ -44,6 +44,7 @@#include <fcntl.h> #include <dirent.h> #include <net/if.h> +#include <limits.h> /* * KVP protocol: The user mode component first registers with the
@@ -592,26 +593,22 @@ static char *kvp_get_if_name(char *guid)DIR *dir;struct dirent *entry;FILE *file; -char *p, *q, *x; +char *p, *x;char *if_name =NULL ;char buf[256 ];char *kvp_net_dir ="/sys/class/net/" ; -char dev_id[256 ]; +char dev_id[PATH_MAX ]; dir =opendir (kvp_net_dir);if (dir ==NULL )return NULL ; -snprintf (dev_id,sizeof (dev_id),"%s" , kvp_net_dir); - q = dev_id +strlen (kvp_net_dir); -while ((entry =readdir (dir)) !=NULL ) {/* * Set the state for the next pass. */ - *q ='\0' ; -strcat (dev_id, entry->d_name); -strcat (dev_id,"/device/device_id" ); +snprintf (dev_id,sizeof (dev_id),"%s%s/device/device_id" , kvp_net_dir, + entry->d_name); file =fopen (dev_id,"r" );if (file ==NULL )
@@ -684,28 +681,23 @@ static char *kvp_mac_to_if_name(char *mac)DIR *dir;struct dirent *entry;FILE *file; -char *p, *q, *x; +char *p, *x;char *if_name =NULL ;char buf[256 ];char *kvp_net_dir ="/sys/class/net/" ; -char dev_id[256 ]; +char dev_id[PATH_MAX ];int i; dir =opendir (kvp_net_dir);if (dir ==NULL )return NULL ; -snprintf (dev_id,sizeof (dev_id), kvp_net_dir); - q = dev_id +strlen (kvp_net_dir); -while ((entry =readdir (dir)) !=NULL ) {/* * Set the state for the next pass. */ - *q ='\0' ; - -strcat (dev_id, entry->d_name); -strcat (dev_id,"/address" ); +snprintf (dev_id,sizeof (dev_id),"%s%s/address" , kvp_net_dir, + entry->d_name); file =fopen (dev_id,"r" );if (file ==NULL )
Signature · 1 line
1.7.11.7
PATCH 2/3 tools/hv: Fix /var subdirectory
Initial patch by Ben Hutchings <[email protected]>
We will install this in /usr, so it must use /var/lib for its state. Only programs installed under /opt should use /var/opt.
--- tools/hv/hv_kvp_daemon.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tools/hv/hv_kvp_daemon.c +6 -6
@@ -98,7 +98,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
@@ -235,9 +235,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 ,S_IRUSR |S_IWUSR |S_IROTH )) { +syslog (LOG_ERR ," Failed to create %s" ,KVP_CONFIG_LOC );exit (EXIT_FAILURE ); } }
@@ -246,7 +246,7 @@ 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); +sprintf (fname,"%s/.kvp_pool_%d" ,KVP_CONFIG_LOC , i); fd =open (fname,O_RDWR |O_CREAT ,S_IRUSR |S_IWUSR |S_IROTH );if (fd ==-1 )
@@ -1263,7 +1263,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" );
Signature · 1 line
1.7.11.7
Quoted 11 lines
-----Original Message-----
From: Tomas Hozza [mailto:[email protected]]
Sent: Tuesday, November 27, 2012 2:57 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; KY Srinivasan; [email protected]
Cc: Tomas Hozza
Subject: [PATCH 2/3]tools/hv: Fix /var subdirectory
Quoted 6 lines
Initial patch by Ben Hutchings <[email protected]>
We will install this in /usr, so it must use
/var/libfor its state. Only programs installed under /opt should use/var/opt.Signed-off-by Tomas Hozza <[email protected]>
Quoted 55 lines
--- tools/hv/hv_kvp_daemon.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)tools/hv/hv_kvp_daemon.c +4
-4@@ -98,7 +98,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@@ -235,9 +235,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 ,S_IRUSR |S_IWUSR |S_IROTH )) { +syslog (LOG_ERR ," Failed to create %s" ,KVP_CONFIG_LOC );exit (EXIT_FAILURE ); }tools/hv/hv_kvp_daemon.c +1
-1}@@ -246,7 +246,7 @@ 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); +sprintf (fname,"%s/.kvp_pool_%d" ,KVP_CONFIG_LOC , i); fd =open (fname,O_RDWR |O_CREAT ,S_IRUSR |S_IWUSR |S_IROTH );tools/hv/hv_kvp_daemon.c +1
-2if (fd ==-1 )@@ -1263,7 +1263,7 @@ static int kvp_set_ip_info(char *if_name, structhv_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" ); --1.7.11.7
PATCH 3/3 tools/hv: Fix permissions of created directory and files
In reply to Tomas HozzaFrom: Ben Hutchings <[email protected]>
It's silly to create directories without execute permission, or to give permissions to 'other' but not the group-owner.
Write the permissions in octal and 'ls -l' format since these are much easier to read than the named macros.
--- tools/hv/hv_kvp_daemon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/hv/hv_kvp_daemon.c +2 -2
@@ -236,7 +236,7 @@ static int kvp_file_init(void)int alloc_unit =sizeof (struct kvp_record ) *ENTRIES_PER_BLOCK ;if (access (KVP_CONFIG_LOC ,F_OK )) { -if (mkdir (KVP_CONFIG_LOC ,S_IRUSR |S_IWUSR |S_IROTH )) { +if (mkdir (KVP_CONFIG_LOC ,0755 /* rwxr-xr-x */ )) {syslog (LOG_ERR ," Failed to create %s" ,KVP_CONFIG_LOC );exit (EXIT_FAILURE ); }
@@ -247,7 +247,7 @@ static int kvp_file_init(void) records_read =0 ; num_blocks =1 ;sprintf (fname,"%s/.kvp_pool_%d" ,KVP_CONFIG_LOC , i); - fd =open (fname,O_RDWR |O_CREAT ,S_IRUSR |S_IWUSR |S_IROTH ); + fd =open (fname,O_RDWR |O_CREAT ,0644 /* rw-r--r-- */ );if (fd ==-1 )return 1 ;
Signature · 1 line
1.7.11.7
RE: [PATCH 3/3] tools/hv: Fix permissions of created directory and files
Quoted 13 lines
-----Original Message-----
From: Tomas Hozza [mailto:[email protected]]
Sent: Tuesday, November 27, 2012 2:57 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; KY Srinivasan; [email protected]
Cc: Tomas Hozza
Subject: [PATCH 3/3]tools/hv: Fix permissions of created directory and filesFrom: Ben Hutchings <[email protected]>
Quoted 8 lines
It's silly to create directories without execute permission, or to give permissions to 'other' but not the group-owner.
Write the permissions in octal and 'ls -l' format since these are much easier to read than the named macros.
Signed-off-by Ben Hutchings <[email protected]>Signed-off-by Tomas Hozza <[email protected]>
Quoted 32 lines
--- tools/hv/hv_kvp_daemon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/hv/hv_kvp_daemon.c +1
-1@@ -236,7 +236,7 @@ static int kvp_file_init(void)int alloc_unit =sizeof (struct kvp_record ) *ENTRIES_PER_BLOCK ;if (access (KVP_CONFIG_LOC ,F_OK )) { -if (mkdir (KVP_CONFIG_LOC ,S_IRUSR |S_IWUSR |S_IROTH )) { +if (mkdir (KVP_CONFIG_LOC ,0755 /* rwxr-xr-x */ )) {syslog (LOG_ERR ," Failed to create %s" ,KVP_CONFIG_LOC );exit (EXIT_FAILURE );tools/hv/hv_kvp_daemon.c +1
-1}@@ -247,7 +247,7 @@ static int kvp_file_init(void) records_read =0 ; num_blocks =1 ;sprintf (fname,"%s/.kvp_pool_%d" ,KVP_CONFIG_LOC , i); - fd =open (fname,O_RDWR |O_CREAT ,S_IRUSR |S_IWUSR | S_IROTH); + fd =open (fname,O_RDWR |O_CREAT ,0644 /* rw-r--r-- */ );if (fd ==-1 )return 1;
--
1.7.11.7
RE: [PATCH 1/3] tools/hv: Fix for long file names from readdir
In reply to Tomas HozzaQuoted 11 lines
-----Original Message-----
From: Tomas Hozza [mailto:[email protected]]
Sent: Tuesday, November 27, 2012 2:57 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; KY Srinivasan; [email protected]
Cc: Tomas Hozza
Subject: [PATCH 1/3]tools/hv: Fix for long file names from readdir
Quoted 7 lines
kvp_get_if_nameandkvp_mac_to_if_namecopy strings into statically sized buffers which could be too small to store really long names.Buffer sizes have been changed to
PATH_MAX, include "limits.h" wherePATH_MAXis defined was added and length checks ware added via snprintf.Signed-off-by Tomas Hozza <[email protected]>
Quoted 85 lines
--- tools/hv/hv_kvp_daemon.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-)tools/hv/hv_kvp_daemon.c +5
-8@@ -44,6 +44,7 @@#include <fcntl.h> #include <dirent.h> #include <net/if.h> +#include <limits.h> /* * KVP protocol: The user mode component first registers with the @@ -592,26 +593,22 @@ static char *kvp_get_if_name(char *guid)DIR *dir;struct dirent *entry;FILE *file; -char *p, *q, *x; +char *p, *x;char *if_name =NULL ;char buf[256 ];char *kvp_net_dir ="/sys/class/net/" ; -char dev_id[256 ]; +char dev_id[PATH_MAX ]; dir =opendir (kvp_net_dir);if (dir ==NULL )return NULL ; -snprintf (dev_id,sizeof (dev_id),"%s" , kvp_net_dir); - q = dev_id +strlen (kvp_net_dir); -while ((entry =readdir (dir)) !=NULL ) {/* * Set the state for the next pass. */ - *q ='\0' ; -strcat (dev_id, entry->d_name); -strcat (dev_id,"/device/device_id" ); +snprintf (dev_id,sizeof (dev_id),"%s%s/device/device_id" , kvp_net_dir, + entry->d_name); file =fopen (dev_id,"r" );tools/hv/hv_kvp_daemon.c +4
-10if (file ==NULL )@@ -684,28 +681,23 @@ static char *kvp_mac_to_if_name(char *mac)DIR *dir;struct dirent *entry;FILE *file; -char *p, *q, *x; +char *p, *x;char *if_name =NULL ;char buf[256 ];char *kvp_net_dir ="/sys/class/net/" ; -char dev_id[256 ]; +char dev_id[PATH_MAX ];int i; dir =opendir (kvp_net_dir);if (dir ==NULL )return NULL ; -snprintf (dev_id,sizeof (dev_id), kvp_net_dir); - q = dev_id +strlen (kvp_net_dir); -while ((entry =readdir (dir)) !=NULL ) {/* * Set the state for the next pass. */ - *q ='\0' ; - -strcat (dev_id, entry->d_name); -strcat (dev_id,"/address" ); +snprintf (dev_id,sizeof (dev_id),"%s%s/address" , kvp_net_dir, + entry->d_name); file =fopen (dev_id,"r" );if (file ==NULL ) --1.7.11.7
Re: [PATCH 1/3] tools/hv: Fix for long file names from readdir
In reply to Tomas HozzaQuoted 5 lines · Tomas Hozza
kvp_get_if_nameandkvp_mac_to_if_namecopy strings into statically sized buffers which could be too small to store really long names.Buffer sizes have been changed to
PATH_MAX, include "limits.h" wherePATH_MAXis defined was added and length checks ware added via snprintf.
[...]
PATH_MAX has nothing to do with any actual kernel limit; it's no more meaningful than the current value of 256. Network interface names are limited to 15 characters, thus the current array is more than long enough. So I think this is entirely unnecessary.
Using snprintf() is a good idea, but you need to check the return value and handle the truncation case somehow.
Ben.
Signature · 2 lines
Ben Hutchings Never attribute to conspiracy what can adequately be explained by stupidity.
Re: [PATCH 1/3] tools/hv: Fix for long file names from readdir
----- Original Message -----
Quoted 8 lines · Tomas Hozza
Quoted 7 lines
kvp_get_if_nameandkvp_mac_to_if_namecopy strings into statically sized buffers which could be too small to store really long names.Buffer sizes have been changed to
PATH_MAX, include "limits.h" wherePATH_MAXis defined was added and length checks ware added via snprintf.
Quoted 7 lines
[...]
PATH_MAXhas nothing to do with any actual kernel limit; it's no more meaningful than the current value of 256. Network interface names are
limited to 15 characters, thus the current array is more than long enough. So I think this is entirely unnecessary.
This is just for sanity. The value PATH_MAX was chosen after discussion with K. Y. Srinivasan and Olaf Hering instead of some "magic" number like 256 or 512.
Quoted 2 lines
Using
snprintf()is a good idea, but you need to check the return value and handle the truncation case somehow.
By using PATH_MAX sized buffer there is no need for handling the truncation case.
Tomas Hozza
Re: [PATCH 1/3] tools/hv: Fix for long file names from readdir
Quoted 19 lines · Tomas Hozza
----- Original Message -----
Quoted 8 lines · Tomas Hozza
Quoted 7 lines
kvp_get_if_nameandkvp_mac_to_if_namecopy strings into statically sized buffers which could be too small to store really long names.Buffer sizes have been changed to
PATH_MAX, include "limits.h" wherePATH_MAXis defined was added and length checks ware added via snprintf.Quoted 7 lines
[...]
PATH_MAXhas nothing to do with any actual kernel limit; it's no more meaningful than the current value of 256. Network interface names are
limited to 15 characters, thus the current array is more than long enough. So I think this is entirely unnecessary.
Quoted 3 lines
This is just for sanity. The value
PATH_MAXwas chosen after discussion with K. Y. Srinivasan and Olaf Hering instead of some "magic" number like 256 or 512.
PATH_MAX is a magic name.
Quoted 5 lines
Quoted 2 lines
Using
snprintf()is a good idea, but you need to check the return value and handle the truncation case somehow.By using
PATH_MAXsized buffer there is no need for handling the truncation case.
You are claiming two contradictory things: sprintf() may overrun the buffer, so we need the length check provided by snprintf(), but there is no need to check for truncation because we know the length is sufficient.
Ben.
Signature · 3 lines
Ben Hutchings
We get into the habit of living before acquiring the habit of thinking.
- Albert CamusRe: [PATCH 1/3] tools/hv: Fix for long file names from readdir
----- Original Message -----
Quoted 7 lines
Quoted 5 lines
This is just for sanity. The value
PATH_MAXwas chosen after discussion
with K. Y. Srinivasan and Olaf Hering instead of some "magic" number like
256 or 512.
PATH_MAXis a magic name.
It is defined in "limits.h". I would welcome some more constructive argumentation and critics.
Quoted 11 lines
Quoted 6 lines
Quoted 2 lines
Using
snprintf()is a good idea, but you need to check the return value and handle the truncation case somehow.By using
PATH_MAXsized buffer there is no need for handling the truncation
case.You are claiming two contradictory things:
sprintf()may overrun the buffer, so we need the length check provided bysnprintf(), but there is no need to check for truncation because we know the length is sufficient.
So what do you propose? How should it be solved?
Thank you.
Regards,
Tomas Hozza
Re: [PATCH 1/3] tools/hv: Fix for long file names from readdir
Quoted 11 lines · Tomas Hozza
----- Original Message -----
Quoted 7 lines
Quoted 5 lines
This is just for sanity. The value
PATH_MAXwas chosen after discussion
with K. Y. Srinivasan and Olaf Hering instead of some "magic" number like
256 or 512.
PATH_MAXis a magic name.It is defined in "
limits.h". I would welcome some more constructive argumentation and critics.
It still bears no relation to any actual limit in the C library or Linux kernel. So it's no more valid than the previous number.
In the current context we're enumerating /sys/class/net and we know that all the interface names in there are limited to IFNAMSIZ-1 = 15 (there is also potentially "bonding_masters"). The longest path name we need to use is definitely much shorter than even 256 bytes.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
Using
snprintf()is a good idea, but you need to check the return value and handle the truncation case somehow.By using
PATH_MAXsized buffer there is no need for handling the truncation
case.
Quoted 6 lines
Quoted 4 lines
You are claiming two contradictory things:
sprintf()may overrun the buffer, so we need the length check provided bysnprintf(), but there is no need to check for truncation because we know the length is sufficient.So what do you propose? How should it be solved?
if (snprintf(dev_id, sizeof(dev_id), ...) >= sizeof(dev_id)) continue;
Possibly logging a warning.
Ben.
Signature · 3 lines
Ben Hutchings Life is like a sewer: what you get out of it depends on what you put into it.
Re: [PATCH 1/3] tools/hv: Fix for long file names from readdir
Quoted 33 lines · Ben Hutchings
Quoted 11 lines · Tomas Hozza
----- Original Message -----
Quoted 7 lines
Quoted 5 lines
This is just for sanity. The value
PATH_MAXwas chosen after discussion
with K. Y. Srinivasan and Olaf Hering instead of some "magic" number like
256 or 512.
PATH_MAXis a magic name.It is defined in "
limits.h". I would welcome some more constructive argumentation and critics.It still bears no relation to any actual limit in the C library or Linux kernel. So it's no more valid than the previous number.
In the current context we're enumerating
/sys/class/netand we know that all the interface names in there are limited to IFNAMSIZ-1 = 15 (there is also potentially "bonding_masters"). The longest path name we need to use is definitely much shorter than even 256 bytes.Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
Quoted 2 lines
Using
snprintf()is a good idea, but you need to check the return value and handle the truncation case somehow.By using
PATH_MAXsized buffer there is no need for handling the truncation
case.You are claiming two contradictory things:
sprintf()may overrun the buffer, so we need the length check provided bysnprintf(), but there is no need to check for truncation because we know the length is sufficient.
Quoted 6 lines
Quoted 1 line
So what do you propose? How should it be solved?
if (snprintf(dev_id, sizeof(dev_id), ...) >= sizeof(dev_id)) continue;Possibly logging a warning.
I agree, I'm dropping this patch from my to-apply queue.
greg k-h
Quoted 2 lines · KY Srinivasan
Quoted 2 lines
-----Original Message-----
From: Tomas Hozza [mailto:[email protected]]
<snip>
KY, there have been a few of these tools/hv patches floating by, and you haven't acked all of them from what I can tell. I've applied some of them, but I know I've missed some. Can you please resend the ones I've missed that Tomas has sent, but I've not applied?
thanks,
greg k-h
Quoted 15 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Thursday, November 15, 2012 6:38 PM
To: KY Srinivasan
Cc: Tomas Hozza; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 1/3]tools/hv: Fix /var subdirectoryQuoted 2 lines · KY Srinivasan
Quoted 2 lines
-----Original Message-----
From: Tomas Hozza [mailto:[email protected]]
Quoted 6 lines
<snip>
KY, there have been a few of these
tools/hvpatches floating by, and you haven't acked all of them from what I can tell. I've applied some of them, but I know I've missed some. Can you please resend the ones I've missed that Tomas has sent, but I've not applied?
Will do. I am currently travelling in China and should be back in NJ this weekend. I will handle these after I get back to NJ.
Regards,
K. Y
Quoted 5 lines
thanks,
greg k-h