linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] tools/hv: Fix /var subdirectory
@ 2012-11-09 14:01 Tomas Hozza
  2012-11-09 14:01 ` [PATCH 2/3] tools/hv: Fix string types Tomas Hozza
                   ` (2 more replies)
  0 siblings, 3 replies; 27+ messages in thread
From: Tomas Hozza @ 2012-11-09 14:01 UTC (permalink / raw)
  To: olaf, kys, gregkh, linux-kernel, devel, apw, jasowang, ben; +Cc: Tomas Hozza

Initial patch by Ben Hutchings <ben@decadent.org.uk>

We will install this in /usr, so it must use /var/lib for its state.
Only programs installed under /opt should use /var/opt.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
---
 tools/hv/hv_kvp_daemon.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 54ecb95..d9b3a74 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -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)
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 2/3] tools/hv: Fix string types
  2012-11-09 14:01 [PATCH 1/3] tools/hv: Fix /var subdirectory Tomas Hozza
@ 2012-11-09 14:01 ` Tomas Hozza
  2012-11-09 15:56   ` KY Srinivasan
  2012-11-09 14:01 ` [PATCH 3/3] tools/hv: Fix permissions of created directory and files Tomas Hozza
  2012-11-09 15:56 ` [PATCH 1/3] tools/hv: Fix /var subdirectory KY Srinivasan
  2 siblings, 1 reply; 27+ messages in thread
From: Tomas Hozza @ 2012-11-09 14:01 UTC (permalink / raw)
  To: olaf, kys, gregkh, linux-kernel, devel, apw, jasowang, ben; +Cc: Tomas Hozza

Initial patch by Ben Hutchings <ben@decadent.org.uk>

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 <thozza@redhat.com>
---
 tools/hv/hv_kvp_daemon.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index d9b3a74..573b9aa 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -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;
 
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 3/3] tools/hv: Fix permissions of created directory and files
  2012-11-09 14:01 [PATCH 1/3] tools/hv: Fix /var subdirectory Tomas Hozza
  2012-11-09 14:01 ` [PATCH 2/3] tools/hv: Fix string types Tomas Hozza
@ 2012-11-09 14:01 ` Tomas Hozza
  2012-11-09 15:52   ` KY Srinivasan
  2012-11-09 15:57   ` KY Srinivasan
  2012-11-09 15:56 ` [PATCH 1/3] tools/hv: Fix /var subdirectory KY Srinivasan
  2 siblings, 2 replies; 27+ messages in thread
From: Tomas Hozza @ 2012-11-09 14:01 UTC (permalink / raw)
  To: olaf, kys, gregkh, linux-kernel, devel, apw, jasowang, ben; +Cc: Tomas Hozza

From: Ben Hutchings <ben@decadent.org.uk>

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 <ben@decadent.org.uk>
Signed-off-by: Tomas Hozza <thozza@redhat.com>
---
 tools/hv/hv_kvp_daemon.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 573b9aa..9609858 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -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


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* RE: [PATCH 3/3] tools/hv: Fix permissions of created directory and files
  2012-11-09 14:01 ` [PATCH 3/3] tools/hv: Fix permissions of created directory and files Tomas Hozza
@ 2012-11-09 15:52   ` KY Srinivasan
  2012-11-09 15:57   ` KY Srinivasan
  1 sibling, 0 replies; 27+ messages in thread
From: KY Srinivasan @ 2012-11-09 15:52 UTC (permalink / raw)
  To: Tomas Hozza, olaf, gregkh, linux-kernel, devel, apw, jasowang, ben



> -----Original Message-----
> From: Tomas Hozza [mailto:thozza@redhat.com]
> Sent: Friday, November 09, 2012 9:01 AM
> To: olaf@aepfle.de; KY Srinivasan; gregkh@linuxfoundation.org; linux-
> kernel@vger.kernel.org; devel@linuxdriverproject.org; apw@canonical.com;
> jasowang@redhat.com; ben@decadent.org.uk
> Cc: Tomas Hozza
> Subject: [PATCH 3/3] tools/hv: Fix permissions of created directory and files
> 
> From: Ben Hutchings <ben@decadent.org.uk>
> 
> 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 <ben@decadent.org.uk>
> Signed-off-by: Tomas Hozza <thozza@redhat.com>

Acked-by: K. Y. Srinivasan <kys@microsoft.com>
> ---
>  tools/hv/hv_kvp_daemon.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
> index 573b9aa..9609858 100644
> --- a/tools/hv/hv_kvp_daemon.c
> +++ b/tools/hv/hv_kvp_daemon.c
> @@ -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
> 
> 



^ permalink raw reply	[flat|nested] 27+ messages in thread

* RE: [PATCH 1/3] tools/hv: Fix /var subdirectory
  2012-11-09 14:01 [PATCH 1/3] tools/hv: Fix /var subdirectory Tomas Hozza
  2012-11-09 14:01 ` [PATCH 2/3] tools/hv: Fix string types Tomas Hozza
  2012-11-09 14:01 ` [PATCH 3/3] tools/hv: Fix permissions of created directory and files Tomas Hozza
@ 2012-11-09 15:56 ` KY Srinivasan
  2012-11-12  8:55   ` Tomas Hozza
  2012-11-15 23:38   ` [PATCH 1/3] tools/hv: Fix /var subdirectory gregkh
  2 siblings, 2 replies; 27+ messages in thread
From: KY Srinivasan @ 2012-11-09 15:56 UTC (permalink / raw)
  To: Tomas Hozza, olaf, gregkh, linux-kernel, devel, apw, jasowang, ben



> -----Original Message-----
> From: Tomas Hozza [mailto:thozza@redhat.com]
> Sent: Friday, November 09, 2012 9:01 AM
> To: olaf@aepfle.de; KY Srinivasan; gregkh@linuxfoundation.org; linux-
> kernel@vger.kernel.org; devel@linuxdriverproject.org; apw@canonical.com;
> jasowang@redhat.com; ben@decadent.org.uk
> Cc: Tomas Hozza
> Subject: [PATCH 1/3] tools/hv: Fix /var subdirectory
> 
> Initial patch by Ben Hutchings <ben@decadent.org.uk>
> 
> We will install this in /usr, so it must use /var/lib for its state.
> Only programs installed under /opt should use /var/opt.
> 
> Signed-off-by: Tomas Hozza <thozza@redhat.com>
> ---
>  tools/hv/hv_kvp_daemon.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
> index 54ecb95..d9b3a74 100644
> --- a/tools/hv/hv_kvp_daemon.c
> +++ b/tools/hv/hv_kvp_daemon.c
> @@ -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");

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
>  			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)
> --
> 1.7.11.7
> 
> 



^ permalink raw reply	[flat|nested] 27+ messages in thread

* RE: [PATCH 2/3] tools/hv: Fix string types
  2012-11-09 14:01 ` [PATCH 2/3] tools/hv: Fix string types Tomas Hozza
@ 2012-11-09 15:56   ` KY Srinivasan
  0 siblings, 0 replies; 27+ messages in thread
From: KY Srinivasan @ 2012-11-09 15:56 UTC (permalink / raw)
  To: Tomas Hozza, olaf, gregkh, linux-kernel, devel, apw, jasowang, ben



> -----Original Message-----
> From: Tomas Hozza [mailto:thozza@redhat.com]
> Sent: Friday, November 09, 2012 9:01 AM
> To: olaf@aepfle.de; KY Srinivasan; gregkh@linuxfoundation.org; linux-
> kernel@vger.kernel.org; devel@linuxdriverproject.org; apw@canonical.com;
> jasowang@redhat.com; ben@decadent.org.uk
> Cc: Tomas Hozza
> Subject: [PATCH 2/3] tools/hv: Fix string types
> 
> Initial patch by Ben Hutchings <ben@decadent.org.uk>
> 
> 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 <thozza@redhat.com>
Acked-by: K. Y. Srinivasan <kys@microsoft.com>
> ---
>  tools/hv/hv_kvp_daemon.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
> index d9b3a74..573b9aa 100644
> --- a/tools/hv/hv_kvp_daemon.c
> +++ b/tools/hv/hv_kvp_daemon.c
> @@ -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;
> 
> --
> 1.7.11.7
> 
> 



^ permalink raw reply	[flat|nested] 27+ messages in thread

* RE: [PATCH 3/3] tools/hv: Fix permissions of created directory and files
  2012-11-09 14:01 ` [PATCH 3/3] tools/hv: Fix permissions of created directory and files Tomas Hozza
  2012-11-09 15:52   ` KY Srinivasan
@ 2012-11-09 15:57   ` KY Srinivasan
  1 sibling, 0 replies; 27+ messages in thread
From: KY Srinivasan @ 2012-11-09 15:57 UTC (permalink / raw)
  To: Tomas Hozza, olaf, gregkh, linux-kernel, devel, apw, jasowang, ben



> -----Original Message-----
> From: Tomas Hozza [mailto:thozza@redhat.com]
> Sent: Friday, November 09, 2012 9:01 AM
> To: olaf@aepfle.de; KY Srinivasan; gregkh@linuxfoundation.org; linux-
> kernel@vger.kernel.org; devel@linuxdriverproject.org; apw@canonical.com;
> jasowang@redhat.com; ben@decadent.org.uk
> Cc: Tomas Hozza
> Subject: [PATCH 3/3] tools/hv: Fix permissions of created directory and files
> 
> From: Ben Hutchings <ben@decadent.org.uk>
> 
> 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 <ben@decadent.org.uk>
> Signed-off-by: Tomas Hozza <thozza@redhat.com>
Acked-by: K. Y. Srinivasan <kys@microsoft.com>
> ---
>  tools/hv/hv_kvp_daemon.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
> index 573b9aa..9609858 100644
> --- a/tools/hv/hv_kvp_daemon.c
> +++ b/tools/hv/hv_kvp_daemon.c
> @@ -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
> 
> 



^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 1/3] tools/hv: Fix /var subdirectory
  2012-11-09 15:56 ` [PATCH 1/3] tools/hv: Fix /var subdirectory KY Srinivasan
@ 2012-11-12  8:55   ` Tomas Hozza
  2012-11-12  8:55     ` [PATCH 3/3] tools/hv: Fix permissions of created directory and files Tomas Hozza
  2012-11-26 20:42     ` [PATCH 1/3] tools/hv: Fix /var subdirectory KY Srinivasan
  2012-11-15 23:38   ` [PATCH 1/3] tools/hv: Fix /var subdirectory gregkh
  1 sibling, 2 replies; 27+ messages in thread
From: Tomas Hozza @ 2012-11-12  8:55 UTC (permalink / raw)
  To: gregkh, linux-kernel, devel, olaf, apw, jasowang, kys, ben; +Cc: Tomas Hozza

Initial patch by Ben Hutchings <ben@decadent.org.uk>

We will install this in /usr, so it must use /var/lib for its state.
Only programs installed under /opt should use /var/opt.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
---
 tools/hv/hv_kvp_daemon.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 54ecb95..d80a612 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -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");
 
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 3/3] tools/hv: Fix permissions of created directory and files
  2012-11-12  8:55   ` Tomas Hozza
@ 2012-11-12  8:55     ` Tomas Hozza
  2012-11-26 20:40       ` KY Srinivasan
  2012-11-26 20:42     ` [PATCH 1/3] tools/hv: Fix /var subdirectory KY Srinivasan
  1 sibling, 1 reply; 27+ messages in thread
From: Tomas Hozza @ 2012-11-12  8:55 UTC (permalink / raw)
  To: gregkh, linux-kernel, devel, olaf, apw, jasowang, kys, ben; +Cc: Tomas Hozza

From: Ben Hutchings <ben@decadent.org.uk>

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 <ben@decadent.org.uk>
Signed-off-by: Tomas Hozza <thozza@redhat.com>
---
 tools/hv/hv_kvp_daemon.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index a581b3f..17703c7 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -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;
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] tools/hv: Fix /var subdirectory
  2012-11-09 15:56 ` [PATCH 1/3] tools/hv: Fix /var subdirectory KY Srinivasan
  2012-11-12  8:55   ` Tomas Hozza
@ 2012-11-15 23:38   ` gregkh
  2012-11-15 23:52     ` KY Srinivasan
  1 sibling, 1 reply; 27+ messages in thread
From: gregkh @ 2012-11-15 23:38 UTC (permalink / raw)
  To: KY Srinivasan; +Cc: Tomas Hozza, olaf, linux-kernel, devel, apw, jasowang, ben

On Fri, Nov 09, 2012 at 03:56:14PM +0000, KY Srinivasan wrote:
> > -----Original Message-----
> > From: Tomas Hozza [mailto:thozza@redhat.com]

<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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* RE: [PATCH 1/3] tools/hv: Fix /var subdirectory
  2012-11-15 23:38   ` [PATCH 1/3] tools/hv: Fix /var subdirectory gregkh
@ 2012-11-15 23:52     ` KY Srinivasan
  0 siblings, 0 replies; 27+ messages in thread
From: KY Srinivasan @ 2012-11-15 23:52 UTC (permalink / raw)
  To: gregkh; +Cc: Tomas Hozza, olaf, linux-kernel, devel, apw, jasowang, ben



> -----Original Message-----
> From: gregkh@linuxfoundation.org [mailto:gregkh@linuxfoundation.org]
> Sent: Thursday, November 15, 2012 6:38 PM
> To: KY Srinivasan
> Cc: Tomas Hozza; olaf@aepfle.de; linux-kernel@vger.kernel.org;
> devel@linuxdriverproject.org; apw@canonical.com; jasowang@redhat.com;
> ben@decadent.org.uk
> Subject: Re: [PATCH 1/3] tools/hv: Fix /var subdirectory
> 
> On Fri, Nov 09, 2012 at 03:56:14PM +0000, KY Srinivasan wrote:
> > > -----Original Message-----
> > > From: Tomas Hozza [mailto:thozza@redhat.com]
> 
> <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?

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
> 
> thanks,
> 
> greg k-h
> 



^ permalink raw reply	[flat|nested] 27+ messages in thread

* RE: [PATCH 3/3] tools/hv: Fix permissions of created directory and files
  2012-11-12  8:55     ` [PATCH 3/3] tools/hv: Fix permissions of created directory and files Tomas Hozza
@ 2012-11-26 20:40       ` KY Srinivasan
  0 siblings, 0 replies; 27+ messages in thread
From: KY Srinivasan @ 2012-11-26 20:40 UTC (permalink / raw)
  To: Tomas Hozza, gregkh, linux-kernel, devel, olaf, apw, jasowang, ben



> -----Original Message-----
> From: Tomas Hozza [mailto:thozza@redhat.com]
> Sent: Monday, November 12, 2012 3:55 AM
> To: gregkh@linuxfoundation.org; linux-kernel@vger.kernel.org;
> devel@linuxdriverproject.org; olaf@aepfle.de; apw@canonical.com;
> jasowang@redhat.com; KY Srinivasan; ben@decadent.org.uk
> Cc: Tomas Hozza
> Subject: [PATCH 3/3] tools/hv: Fix permissions of created directory and files
> 
> From: Ben Hutchings <ben@decadent.org.uk>
> 
> 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 <ben@decadent.org.uk>
> Signed-off-by: Tomas Hozza <thozza@redhat.com>
Acked-by:  K. Y. Srinivasan <kys@microsoft.com>

> ---
>  tools/hv/hv_kvp_daemon.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
> index a581b3f..17703c7 100644
> --- a/tools/hv/hv_kvp_daemon.c
> +++ b/tools/hv/hv_kvp_daemon.c
> @@ -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;
> --
> 1.7.11.7




^ permalink raw reply	[flat|nested] 27+ messages in thread

* RE: [PATCH 1/3] tools/hv: Fix /var subdirectory
  2012-11-12  8:55   ` Tomas Hozza
  2012-11-12  8:55     ` [PATCH 3/3] tools/hv: Fix permissions of created directory and files Tomas Hozza
@ 2012-11-26 20:42     ` KY Srinivasan
  2012-11-26 21:12       ` gregkh
  1 sibling, 1 reply; 27+ messages in thread
From: KY Srinivasan @ 2012-11-26 20:42 UTC (permalink / raw)
  To: Tomas Hozza, gregkh, linux-kernel, devel, olaf, apw, jasowang, ben



> -----Original Message-----
> From: Tomas Hozza [mailto:thozza@redhat.com]
> Sent: Monday, November 12, 2012 3:55 AM
> To: gregkh@linuxfoundation.org; linux-kernel@vger.kernel.org;
> devel@linuxdriverproject.org; olaf@aepfle.de; apw@canonical.com;
> jasowang@redhat.com; KY Srinivasan; ben@decadent.org.uk
> Cc: Tomas Hozza
> Subject: [PATCH 1/3] tools/hv: Fix /var subdirectory
> 
> Initial patch by Ben Hutchings <ben@decadent.org.uk>
> 
> We will install this in /usr, so it must use /var/lib for its state.
> Only programs installed under /opt should use /var/opt.
> 
> Signed-off-by: Tomas Hozza <thozza@redhat.com>
Acked-by:  K. Y. Srinivasan <kys@microsoft.com>


> ---
>  tools/hv/hv_kvp_daemon.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
> index 54ecb95..d80a612 100644
> --- a/tools/hv/hv_kvp_daemon.c
> +++ b/tools/hv/hv_kvp_daemon.c
> @@ -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");
> 
> --
> 1.7.11.7




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] tools/hv: Fix /var subdirectory
  2012-11-26 20:42     ` [PATCH 1/3] tools/hv: Fix /var subdirectory KY Srinivasan
@ 2012-11-26 21:12       ` gregkh
  2012-11-26 21:15         ` KY Srinivasan
  0 siblings, 1 reply; 27+ messages in thread
From: gregkh @ 2012-11-26 21:12 UTC (permalink / raw)
  To: KY Srinivasan; +Cc: Tomas Hozza, linux-kernel, devel, olaf, apw, jasowang, ben

On Mon, Nov 26, 2012 at 08:42:40PM +0000, KY Srinivasan wrote:
> 
> 
> > -----Original Message-----
> > From: Tomas Hozza [mailto:thozza@redhat.com]
> > Sent: Monday, November 12, 2012 3:55 AM
> > To: gregkh@linuxfoundation.org; linux-kernel@vger.kernel.org;
> > devel@linuxdriverproject.org; olaf@aepfle.de; apw@canonical.com;
> > jasowang@redhat.com; KY Srinivasan; ben@decadent.org.uk
> > Cc: Tomas Hozza
> > Subject: [PATCH 1/3] tools/hv: Fix /var subdirectory
> > 
> > Initial patch by Ben Hutchings <ben@decadent.org.uk>
> > 
> > We will install this in /usr, so it must use /var/lib for its state.
> > Only programs installed under /opt should use /var/opt.
> > 
> > Signed-off-by: Tomas Hozza <thozza@redhat.com>
> Acked-by:  K. Y. Srinivasan <kys@microsoft.com>

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* RE: [PATCH 1/3] tools/hv: Fix /var subdirectory
  2012-11-26 21:12       ` gregkh
@ 2012-11-26 21:15         ` KY Srinivasan
  2012-11-27  7:56           ` [PATCH 1/3] tools/hv: Fix for long file names from readdir Tomas Hozza
  0 siblings, 1 reply; 27+ messages in thread
From: KY Srinivasan @ 2012-11-26 21:15 UTC (permalink / raw)
  To: gregkh; +Cc: Tomas Hozza, linux-kernel, devel, olaf, apw, jasowang, ben



> -----Original Message-----
> From: gregkh@linuxfoundation.org [mailto:gregkh@linuxfoundation.org]
> Sent: Monday, November 26, 2012 4:12 PM
> To: KY Srinivasan
> Cc: Tomas Hozza; linux-kernel@vger.kernel.org; devel@linuxdriverproject.org;
> olaf@aepfle.de; apw@canonical.com; jasowang@redhat.com;
> ben@decadent.org.uk
> Subject: Re: [PATCH 1/3] tools/hv: Fix /var subdirectory
> 
> On Mon, Nov 26, 2012 at 08:42:40PM +0000, KY Srinivasan wrote:
> >
> >
> > > -----Original Message-----
> > > From: Tomas Hozza [mailto:thozza@redhat.com]
> > > Sent: Monday, November 12, 2012 3:55 AM
> > > To: gregkh@linuxfoundation.org; linux-kernel@vger.kernel.org;
> > > devel@linuxdriverproject.org; olaf@aepfle.de; apw@canonical.com;
> > > jasowang@redhat.com; KY Srinivasan; ben@decadent.org.uk
> > > Cc: Tomas Hozza
> > > Subject: [PATCH 1/3] tools/hv: Fix /var subdirectory
> > >
> > > Initial patch by Ben Hutchings <ben@decadent.org.uk>
> > >
> > > We will install this in /usr, so it must use /var/lib for its state.
> > > Only programs installed under /opt should use /var/opt.
> > >
> > > Signed-off-by: Tomas Hozza <thozza@redhat.com>
> > Acked-by:  K. Y. Srinivasan <kys@microsoft.com>
> 
> 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
> 
> greg k-h
> 




^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 1/3] tools/hv: Fix for long file names from readdir
  2012-11-26 21:15         ` KY Srinivasan
@ 2012-11-27  7:56           ` Tomas Hozza
  2012-11-27  7:56             ` [PATCH 2/3] tools/hv: Fix /var subdirectory Tomas Hozza
                               ` (3 more replies)
  0 siblings, 4 replies; 27+ messages in thread
From: Tomas Hozza @ 2012-11-27  7:56 UTC (permalink / raw)
  To: gregkh, linux-kernel, devel, olaf, apw, jasowang, kys, ben; +Cc: Tomas Hozza

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.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
---
 tools/hv/hv_kvp_daemon.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index d25a469..90f1f07 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -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)
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 2/3] tools/hv: Fix /var subdirectory
  2012-11-27  7:56           ` [PATCH 1/3] tools/hv: Fix for long file names from readdir Tomas Hozza
@ 2012-11-27  7:56             ` Tomas Hozza
  2012-11-27 13:59               ` KY Srinivasan
  2012-11-27  7:56             ` [PATCH 3/3] tools/hv: Fix permissions of created directory and files Tomas Hozza
                               ` (2 subsequent siblings)
  3 siblings, 1 reply; 27+ messages in thread
From: Tomas Hozza @ 2012-11-27  7:56 UTC (permalink / raw)
  To: gregkh, linux-kernel, devel, olaf, apw, jasowang, kys, ben; +Cc: Tomas Hozza

Initial patch by Ben Hutchings <ben@decadent.org.uk>

We will install this in /usr, so it must use /var/lib for its state.
Only programs installed under /opt should use /var/opt.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
---
 tools/hv/hv_kvp_daemon.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 90f1f07..e266251 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -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");
 
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 3/3] tools/hv: Fix permissions of created directory and files
  2012-11-27  7:56           ` [PATCH 1/3] tools/hv: Fix for long file names from readdir Tomas Hozza
  2012-11-27  7:56             ` [PATCH 2/3] tools/hv: Fix /var subdirectory Tomas Hozza
@ 2012-11-27  7:56             ` Tomas Hozza
  2012-11-27 13:59               ` KY Srinivasan
  2012-11-27 13:58             ` [PATCH 1/3] tools/hv: Fix for long file names from readdir KY Srinivasan
  2012-11-27 14:50             ` Ben Hutchings
  3 siblings, 1 reply; 27+ messages in thread
From: Tomas Hozza @ 2012-11-27  7:56 UTC (permalink / raw)
  To: gregkh, linux-kernel, devel, olaf, apw, jasowang, kys, ben; +Cc: Tomas Hozza

From: Ben Hutchings <ben@decadent.org.uk>

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 <ben@decadent.org.uk>
Signed-off-by: Tomas Hozza <thozza@redhat.com>
---
 tools/hv/hv_kvp_daemon.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index e266251..7105c7b 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -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;
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* RE: [PATCH 1/3] tools/hv: Fix for long file names from readdir
  2012-11-27  7:56           ` [PATCH 1/3] tools/hv: Fix for long file names from readdir Tomas Hozza
  2012-11-27  7:56             ` [PATCH 2/3] tools/hv: Fix /var subdirectory Tomas Hozza
  2012-11-27  7:56             ` [PATCH 3/3] tools/hv: Fix permissions of created directory and files Tomas Hozza
@ 2012-11-27 13:58             ` KY Srinivasan
  2012-11-27 14:50             ` Ben Hutchings
  3 siblings, 0 replies; 27+ messages in thread
From: KY Srinivasan @ 2012-11-27 13:58 UTC (permalink / raw)
  To: Tomas Hozza, gregkh, linux-kernel, devel, olaf, apw, jasowang, ben



> -----Original Message-----
> From: Tomas Hozza [mailto:thozza@redhat.com]
> Sent: Tuesday, November 27, 2012 2:57 AM
> To: gregkh@linuxfoundation.org; linux-kernel@vger.kernel.org;
> devel@linuxdriverproject.org; olaf@aepfle.de; apw@canonical.com;
> jasowang@redhat.com; KY Srinivasan; ben@decadent.org.uk
> Cc: Tomas Hozza
> Subject: [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.
> 
> Signed-off-by: Tomas Hozza <thozza@redhat.com>
Acked-by:  K. Y. Srinivasan <kys@microsoft.com>

> ---
>  tools/hv/hv_kvp_daemon.c | 26 +++++++++-----------------
>  1 file changed, 9 insertions(+), 17 deletions(-)
> 
> diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
> index d25a469..90f1f07 100644
> --- a/tools/hv/hv_kvp_daemon.c
> +++ b/tools/hv/hv_kvp_daemon.c
> @@ -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)
> --
> 1.7.11.7
> 
> 




^ permalink raw reply	[flat|nested] 27+ messages in thread

* RE: [PATCH 2/3] tools/hv: Fix /var subdirectory
  2012-11-27  7:56             ` [PATCH 2/3] tools/hv: Fix /var subdirectory Tomas Hozza
@ 2012-11-27 13:59               ` KY Srinivasan
  0 siblings, 0 replies; 27+ messages in thread
From: KY Srinivasan @ 2012-11-27 13:59 UTC (permalink / raw)
  To: Tomas Hozza, gregkh, linux-kernel, devel, olaf, apw, jasowang, ben



> -----Original Message-----
> From: Tomas Hozza [mailto:thozza@redhat.com]
> Sent: Tuesday, November 27, 2012 2:57 AM
> To: gregkh@linuxfoundation.org; linux-kernel@vger.kernel.org;
> devel@linuxdriverproject.org; olaf@aepfle.de; apw@canonical.com;
> jasowang@redhat.com; KY Srinivasan; ben@decadent.org.uk
> Cc: Tomas Hozza
> Subject: [PATCH 2/3] tools/hv: Fix /var subdirectory
> 
> Initial patch by Ben Hutchings <ben@decadent.org.uk>
> 
> We will install this in /usr, so it must use /var/lib for its state.
> Only programs installed under /opt should use /var/opt.
> 
> Signed-off-by: Tomas Hozza <thozza@redhat.com>
Acked-by:  K. Y. Srinivasan <kys@microsoft.com>

> ---
>  tools/hv/hv_kvp_daemon.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
> index 90f1f07..e266251 100644
> --- a/tools/hv/hv_kvp_daemon.c
> +++ b/tools/hv/hv_kvp_daemon.c
> @@ -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");
> 
> --
> 1.7.11.7
> 
> 




^ permalink raw reply	[flat|nested] 27+ messages in thread

* RE: [PATCH 3/3] tools/hv: Fix permissions of created directory and files
  2012-11-27  7:56             ` [PATCH 3/3] tools/hv: Fix permissions of created directory and files Tomas Hozza
@ 2012-11-27 13:59               ` KY Srinivasan
  0 siblings, 0 replies; 27+ messages in thread
From: KY Srinivasan @ 2012-11-27 13:59 UTC (permalink / raw)
  To: Tomas Hozza, gregkh, linux-kernel, devel, olaf, apw, jasowang, ben



> -----Original Message-----
> From: Tomas Hozza [mailto:thozza@redhat.com]
> Sent: Tuesday, November 27, 2012 2:57 AM
> To: gregkh@linuxfoundation.org; linux-kernel@vger.kernel.org;
> devel@linuxdriverproject.org; olaf@aepfle.de; apw@canonical.com;
> jasowang@redhat.com; KY Srinivasan; ben@decadent.org.uk
> Cc: Tomas Hozza
> Subject: [PATCH 3/3] tools/hv: Fix permissions of created directory and files
> 
> From: Ben Hutchings <ben@decadent.org.uk>
> 
> 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 <ben@decadent.org.uk>
> Signed-off-by: Tomas Hozza <thozza@redhat.com>
Acked-by:  K. Y. Srinivasan <kys@microsoft.com>

> ---
>  tools/hv/hv_kvp_daemon.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
> index e266251..7105c7b 100644
> --- a/tools/hv/hv_kvp_daemon.c
> +++ b/tools/hv/hv_kvp_daemon.c
> @@ -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;
> --
> 1.7.11.7
> 
> 




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] tools/hv: Fix for long file names from readdir
  2012-11-27  7:56           ` [PATCH 1/3] tools/hv: Fix for long file names from readdir Tomas Hozza
                               ` (2 preceding siblings ...)
  2012-11-27 13:58             ` [PATCH 1/3] tools/hv: Fix for long file names from readdir KY Srinivasan
@ 2012-11-27 14:50             ` Ben Hutchings
  2012-11-27 20:28               ` Tomas Hozza
  3 siblings, 1 reply; 27+ messages in thread
From: Ben Hutchings @ 2012-11-27 14:50 UTC (permalink / raw)
  To: Tomas Hozza; +Cc: gregkh, linux-kernel, devel, olaf, apw, jasowang, kys

[-- Attachment #1: Type: text/plain, Size: 842 bytes --]

On Tue, 2012-11-27 at 08:56 +0100, Tomas Hozza wrote:
> 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.
[...]

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.

-- 
Ben Hutchings
Never attribute to conspiracy what can adequately be explained by stupidity.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] tools/hv: Fix for long file names from readdir
  2012-11-27 14:50             ` Ben Hutchings
@ 2012-11-27 20:28               ` Tomas Hozza
  2012-11-27 20:41                 ` Ben Hutchings
  0 siblings, 1 reply; 27+ messages in thread
From: Tomas Hozza @ 2012-11-27 20:28 UTC (permalink / raw)
  To: Ben Hutchings; +Cc: gregkh, linux-kernel, devel, olaf, apw, jasowang, kys



----- Original Message -----
> On Tue, 2012-11-27 at 08:56 +0100, Tomas Hozza wrote:
> > 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.
> [...]
> 
> 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.

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.

> 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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] tools/hv: Fix for long file names from readdir
  2012-11-27 20:28               ` Tomas Hozza
@ 2012-11-27 20:41                 ` Ben Hutchings
  2012-12-18  8:06                   ` Tomas Hozza
  0 siblings, 1 reply; 27+ messages in thread
From: Ben Hutchings @ 2012-11-27 20:41 UTC (permalink / raw)
  To: Tomas Hozza; +Cc: gregkh, linux-kernel, devel, olaf, apw, jasowang, kys

On Tue, Nov 27, 2012 at 03:28:25PM -0500, Tomas Hozza wrote:
> 
> 
> ----- Original Message -----
> > On Tue, 2012-11-27 at 08:56 +0100, Tomas Hozza wrote:
> > > 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.
> > [...]
> > 
> > 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.
> 
> 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.

PATH_MAX is a magic name.

> > 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.
 
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.

-- 
Ben Hutchings
We get into the habit of living before acquiring the habit of thinking.
                                                              - Albert Camus

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] tools/hv: Fix for long file names from readdir
  2012-11-27 20:41                 ` Ben Hutchings
@ 2012-12-18  8:06                   ` Tomas Hozza
  2012-12-18 12:38                     ` Ben Hutchings
  0 siblings, 1 reply; 27+ messages in thread
From: Tomas Hozza @ 2012-12-18  8:06 UTC (permalink / raw)
  To: Ben Hutchings; +Cc: gregkh, linux-kernel, devel, olaf, apw, jasowang, kys

----- Original Message -----
> > 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.
> 
> PATH_MAX is a magic name.

It is defined in "limits.h". I would welcome some more constructive
argumentation and critics.

> > > 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.
>  
> 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.

So what do you propose? How should it be solved?

Thank you.

Regards,
Tomas Hozza

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] tools/hv: Fix for long file names from readdir
  2012-12-18  8:06                   ` Tomas Hozza
@ 2012-12-18 12:38                     ` Ben Hutchings
  2013-01-17 18:41                       ` Greg KH
  0 siblings, 1 reply; 27+ messages in thread
From: Ben Hutchings @ 2012-12-18 12:38 UTC (permalink / raw)
  To: Tomas Hozza; +Cc: gregkh, linux-kernel, devel, olaf, apw, jasowang, kys

[-- Attachment #1: Type: text/plain, Size: 1593 bytes --]

On Tue, 2012-12-18 at 03:06 -0500, Tomas Hozza wrote:
> ----- Original Message -----
> > > 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.
> > 
> > PATH_MAX is 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.

> > > > 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.
> >  
> > 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.
> 
> 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.

-- 
Ben Hutchings
Life is like a sewer:
what you get out of it depends on what you put into it.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/3] tools/hv: Fix for long file names from readdir
  2012-12-18 12:38                     ` Ben Hutchings
@ 2013-01-17 18:41                       ` Greg KH
  0 siblings, 0 replies; 27+ messages in thread
From: Greg KH @ 2013-01-17 18:41 UTC (permalink / raw)
  To: Ben Hutchings; +Cc: Tomas Hozza, olaf, jasowang, linux-kernel, apw, devel

On Tue, Dec 18, 2012 at 12:38:03PM +0000, Ben Hutchings wrote:
> On Tue, 2012-12-18 at 03:06 -0500, Tomas Hozza wrote:
> > ----- Original Message -----
> > > > 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.
> > > 
> > > PATH_MAX is 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.
> 
> > > > > 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.
> > >  
> > > 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.
> > 
> > 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

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2013-01-17 18:41 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-09 14:01 [PATCH 1/3] tools/hv: Fix /var subdirectory Tomas Hozza
2012-11-09 14:01 ` [PATCH 2/3] tools/hv: Fix string types Tomas Hozza
2012-11-09 15:56   ` KY Srinivasan
2012-11-09 14:01 ` [PATCH 3/3] tools/hv: Fix permissions of created directory and files Tomas Hozza
2012-11-09 15:52   ` KY Srinivasan
2012-11-09 15:57   ` KY Srinivasan
2012-11-09 15:56 ` [PATCH 1/3] tools/hv: Fix /var subdirectory KY Srinivasan
2012-11-12  8:55   ` Tomas Hozza
2012-11-12  8:55     ` [PATCH 3/3] tools/hv: Fix permissions of created directory and files Tomas Hozza
2012-11-26 20:40       ` KY Srinivasan
2012-11-26 20:42     ` [PATCH 1/3] tools/hv: Fix /var subdirectory KY Srinivasan
2012-11-26 21:12       ` gregkh
2012-11-26 21:15         ` KY Srinivasan
2012-11-27  7:56           ` [PATCH 1/3] tools/hv: Fix for long file names from readdir Tomas Hozza
2012-11-27  7:56             ` [PATCH 2/3] tools/hv: Fix /var subdirectory Tomas Hozza
2012-11-27 13:59               ` KY Srinivasan
2012-11-27  7:56             ` [PATCH 3/3] tools/hv: Fix permissions of created directory and files Tomas Hozza
2012-11-27 13:59               ` KY Srinivasan
2012-11-27 13:58             ` [PATCH 1/3] tools/hv: Fix for long file names from readdir KY Srinivasan
2012-11-27 14:50             ` Ben Hutchings
2012-11-27 20:28               ` Tomas Hozza
2012-11-27 20:41                 ` Ben Hutchings
2012-12-18  8:06                   ` Tomas Hozza
2012-12-18 12:38                     ` Ben Hutchings
2013-01-17 18:41                       ` Greg KH
2012-11-15 23:38   ` [PATCH 1/3] tools/hv: Fix /var subdirectory gregkh
2012-11-15 23:52     ` KY Srinivasan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).