Skip to contentSkip to conversation

make cmdline options permanent

PATCH New Ken Brush 1 participant 1 message Mar 5, 2004

lore
Share & tools
lore

Ken Brush

author
#0 lore raw

PATCH 1/1 make cmdline options permanent

I noticed this behavior in scsi_id and it was listed in the TODO as:

- Document that config file options override command line options, or fix the code. This means a '-b' in the config file disables any -g on the command line.

I chose to fix the code. Though, it appears to be a non-elegant solution to me, it seemed the least intrusive into the existing code.

-Ken

extras/scsi_id/scsi_id.c +17 -0
@@ -58,6 +58,10 @@
  */
 static const char dev_short_options[] = "bgp:";
 
+/* cmdline options */
+static char cmdline_options[sizeof(short_options)];
+static int  cmdline;
+
 char sysfs_mnt_path[SYSFS_PATH_MAX];
 
 static int all_good;
@@ -421,9 +425,17 @@
 		else
 			dprintf("option '%c'\n", option);
 
+		/* Store the option */
+		if(cmdline == 0) 
+			cmdline_options[strlen(cmdline_options)] = option;
+
 		switch (option) {
 		case 'b':
+			if((cmdline == 0) || 
+			   (cmdline == 1 && 
+		 	    strchr(cmdline_options,'b') != NULL))
 			all_good = 0;
+
 			break;
 
 		case 'c':
@@ -444,6 +456,9 @@
 			break;
 
 		case 'g':
+			if((cmdline == 0) || 
+			   (cmdline == 1 &&
+			    strchr(cmdline_options,'g') != NULL))
 			all_good = 1;
 			break;
 
@@ -486,6 +501,8 @@
 			return -1;
 		}
 	}
+	/* set cmdline to prevent squashing of the cmdline options */
+	cmdline = 1;
 	return 0;
 }