Skip to contentSkip to conversation

Spaces in ZFS Pool Names

PATCH New Richard Laager 1 participant 1 message Jan 25, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Spaces in ZFS Pool Names

ZFS pool names can contain spaces.

Signature · 1 line
Richard

=== modified file 'util/getroot.c'

getroot.c +5 -2
@@ -357,7 +357,7 @@
     char cksum[257], notes[257];
     unsigned int dummy;
 
-    cmd = xasprintf ("zpool status %s", poolname);
+    cmd = xasprintf ("zpool status \"%s\"", poolname);
     fp = popen (cmd, "r");
     free (cmd);
 
@@ -382,7 +382,10 @@
 		st++;
 	      break;
 	    case 1:
-	      if (!strcmp (name, poolname))
+	      /* Use strncmp() because poolname can technically have trailing
+	       * spaces, which the sscanf() above will not catch.  Since we've
+	       * asked about this pool specifically, this should be safe. */
+	      if (!strncmp (name, poolname, strlen(name)))
 		st++;
 	      break;
 	    case 2: