diff mbox

[15/17] makedevs: Fixed problem with unassigned variable. Added hex mode to conf file

Message ID 58a0201a699ec98dad42a3ffa03ee3f4ef2f48d7.1380892944.git.kibo@prevas.dk
State Changes Requested
Delegated to: Esben Haabendal
Headers show

Commit Message

Kim Bøndergaard Oct. 4, 2013, 1:24 p.m. UTC
---
 recipes/makedevs/makedevs-1.0.0/makedevs.c | 52 ++++++++++++++++++++++--------
 1 file changed, 38 insertions(+), 14 deletions(-)

Comments

Esben Haabendal Oct. 15, 2013, 9:49 a.m. UTC | #1
Kim Bøndergaard <kibo@prevas.dk> writes:

> ---
>  recipes/makedevs/makedevs-1.0.0/makedevs.c | 52 ++++++++++++++++++++++--------
>  1 file changed, 38 insertions(+), 14 deletions(-)
>
> diff --git a/recipes/makedevs/makedevs-1.0.0/makedevs.c b/recipes/makedevs/makedevs-1.0.0/makedevs.c
> index 5a017c5..2fb6fc9 100644
> --- a/recipes/makedevs/makedevs-1.0.0/makedevs.c
> +++ b/recipes/makedevs/makedevs-1.0.0/makedevs.c
> @@ -180,9 +180,18 @@ static void add_new_fifo(char *name, char *path, unsigned long uid,
>      Regular files must exist in the target root directory.  If a char,
>      block, fifo, or directory does not exist, it will be created.
>  
> -    count can be prepended with an 'h' to indicate the numbers to append must be hex.
> -    I.e. if start, inc and count are 0,1,h12 respectively the devices will be appended with
> -    0,1,2....9,a,b and not 0,1,2....9,10,11 which is the case if 'h' is omitted
> +    count can be prepended with 'h' to indicate the device numbers must be in hex.
> +    Notice the number specified in the file must be decimal even with 'h' prepended.
> +
> +    count can also be specified directly as a hex number by prepending 0x. 

Have you tested use of '0x' prepended to the number?

> +    I.e. to generate 12 instances of a device can be done using either:
> +       12, h12 or 0xc
> +    resulting in the device being numbered:
> +	0,1,2,....10,11
> +	0,1,2,....a,b
> +	0,1,2.....a,b
> +    respectively
> +
>  */
>  static int interpret_table_entry(char *line)
>  {
> @@ -190,23 +199,38 @@ static int interpret_table_entry(char *line)
>  	char path[4096], type;
>  	unsigned long mode = 0755, uid = 0, gid = 0, major = 0, minor = 0;
>  	unsigned long start = 0, increment = 1, count = 0;
> -	char countstr[20+1];
> -	char*pcountstr = countstr;
> +	char scanstr[8][200];
>  	int do_hex = 0;
> +	int i;
> +
> +	for(i=0; i < 8; i++) {
> +		scanstr[i][0] = '\0';
> +	}
>  
> -	if (0 > sscanf(line, "%40s %c %lo %lu %lu %lu %lu %lu %lu %20s", path,
> -		    &type, &mode, &uid, &gid, &major, &minor, &start,
> -		    &increment, countstr)) 
> +	if ( 0 > sscanf(line, "%40s %c %s %s %s %s %s %s %s %s",
> +			path, &type,
> +			scanstr[0], scanstr[1],
> +			scanstr[2], scanstr[3],
> +			scanstr[4], scanstr[5],
> +			scanstr[6], scanstr[7]))
>  	{
>  		return 1;
>  	}
> -
> -	if (countstr[0] == 'h') {
> -		pcountstr++;
> +	sscanf(scanstr[0], "%lo", &mode);
> +	sscanf(scanstr[1], "%lu", &uid);
> +	sscanf(scanstr[2], "%lu", &gid);
> +	sscanf(scanstr[3], "%lu", &major);
> +	sscanf(scanstr[4], "%lu", &minor);
> +	sscanf(scanstr[5], "%lu", &start);
> +	sscanf(scanstr[6], "%lu", &increment);
> +
> +	if (1 == sscanf(scanstr[7], "h%lu",&count))
>  		do_hex = 1;
> -	}
> -	sscanf(pcountstr,"%lu", &count);
> -	
> +	else if (1 == sscanf(scanstr[7], "%lx", &count))

This will succeed with, and convert like this:

10   -> 0x10
1C   -> 0x1c
0x10 -> 0x10
0x1C -> 0x1c

You should probably use strtol() instead, with base=0, and it will be
able to handle decimal, hexadecimal, and octal conversion properly.

To set the do_hex value, you might have to use strncmp().

> +		do_hex = 1;
> +	else 
> +		sscanf(scanstr[7], "%lu", &count);
> +
>  	if (!strcmp(path, "/")) {
>  		error_msg_and_die("Device table entries require absolute paths");
>  	}

/Esben
diff mbox

Patch

diff --git a/recipes/makedevs/makedevs-1.0.0/makedevs.c b/recipes/makedevs/makedevs-1.0.0/makedevs.c
index 5a017c5..2fb6fc9 100644
--- a/recipes/makedevs/makedevs-1.0.0/makedevs.c
+++ b/recipes/makedevs/makedevs-1.0.0/makedevs.c
@@ -180,9 +180,18 @@  static void add_new_fifo(char *name, char *path, unsigned long uid,
     Regular files must exist in the target root directory.  If a char,
     block, fifo, or directory does not exist, it will be created.
 
-    count can be prepended with an 'h' to indicate the numbers to append must be hex.
-    I.e. if start, inc and count are 0,1,h12 respectively the devices will be appended with
-    0,1,2....9,a,b and not 0,1,2....9,10,11 which is the case if 'h' is omitted
+    count can be prepended with 'h' to indicate the device numbers must be in hex.
+    Notice the number specified in the file must be decimal even with 'h' prepended.
+
+    count can also be specified directly as a hex number by prepending 0x. 
+    I.e. to generate 12 instances of a device can be done using either:
+       12, h12 or 0xc
+    resulting in the device being numbered:
+	0,1,2,....10,11
+	0,1,2,....a,b
+	0,1,2.....a,b
+    respectively
+
 */
 static int interpret_table_entry(char *line)
 {
@@ -190,23 +199,38 @@  static int interpret_table_entry(char *line)
 	char path[4096], type;
 	unsigned long mode = 0755, uid = 0, gid = 0, major = 0, minor = 0;
 	unsigned long start = 0, increment = 1, count = 0;
-	char countstr[20+1];
-	char*pcountstr = countstr;
+	char scanstr[8][200];
 	int do_hex = 0;
+	int i;
+
+	for(i=0; i < 8; i++) {
+		scanstr[i][0] = '\0';
+	}
 
-	if (0 > sscanf(line, "%40s %c %lo %lu %lu %lu %lu %lu %lu %20s", path,
-		    &type, &mode, &uid, &gid, &major, &minor, &start,
-		    &increment, countstr)) 
+	if ( 0 > sscanf(line, "%40s %c %s %s %s %s %s %s %s %s",
+			path, &type,
+			scanstr[0], scanstr[1],
+			scanstr[2], scanstr[3],
+			scanstr[4], scanstr[5],
+			scanstr[6], scanstr[7]))
 	{
 		return 1;
 	}
-
-	if (countstr[0] == 'h') {
-		pcountstr++;
+	sscanf(scanstr[0], "%lo", &mode);
+	sscanf(scanstr[1], "%lu", &uid);
+	sscanf(scanstr[2], "%lu", &gid);
+	sscanf(scanstr[3], "%lu", &major);
+	sscanf(scanstr[4], "%lu", &minor);
+	sscanf(scanstr[5], "%lu", &start);
+	sscanf(scanstr[6], "%lu", &increment);
+
+	if (1 == sscanf(scanstr[7], "h%lu",&count))
 		do_hex = 1;
-	}
-	sscanf(pcountstr,"%lu", &count);
-	
+	else if (1 == sscanf(scanstr[7], "%lx", &count))
+		do_hex = 1;
+	else 
+		sscanf(scanstr[7], "%lu", &count);
+
 	if (!strcmp(path, "/")) {
 		error_msg_and_die("Device table entries require absolute paths");
 	}