[Toybox] [PATCH] make partprobe use more toybox functions

Isaac Dunham ibid.ag at gmail.com
Sat May 31 16:08:44 PDT 2014


partprobe duplicates a couple of toybox functions; this patch uses the
standard toybox functionality more thoroughly.

Additionally, this brings the help into line with standard toybox 
help messages.
--
On Sat, May 31, 2014 at 05:33:50PM -0500, Rob Landley wrote:
> Where's the patch?
> 
Argh.
Here, I hope.

> > As far as the return value, the older versions of partprobe always
> > return success; the newest versions return failure if reloading the
> > partition table fails.  I'm _guessing_ the new version returns 
> > failure if *any* devices cannot be reloaded, but I don't know.
> > 
> > If that behavior is desired instead, update_device becomes:
> > 
> > void update_device(int sd_fd, char *path)
> > {
> >   if (ioctl(sd_fd, BLKRRPART, NULL)) return;
> >   perror_msg("ioctl (BLKRRPART) failed, old layout still used");
> >   toys.exitval = 1;
> > }
> 
> perror_msg sets exitval if it's 0.
> 
Thanks for clarifying that.

> The hard part of this sort of thing is coming up with decent tests for
> everything. I keep meaning to properly attack the test suite, but it's
> about as big a timesink as doing writeups for cleanups (and updating the
> cleanup.html page with full series and stats and such)...
> 
> Rob

I don't see any way to have a test suite for this, unfortunately.

And there are quite a few other programs that will be difficult
because they're machine-specific, or time-based rather than completely
deterministic, or don't rely on textual output, or have under-specified
output...
That covers at least cal, sleep, nice/renice, kill*, pkill et al, uname,
hostname, id, df, env, and time.
There are numerous conformant ways to display the output of cal, and at
least two have already been used (see BSD ncal).

I've sent a test for cpio, and could try covering (at least) df and link
shortly.

HTH,
Isaac Dunham
-------------- next part --------------
diff --git a/toys/pending/partprobe.c b/toys/pending/partprobe.c
index 2fe3bd5..f9159f3 100644
--- a/toys/pending/partprobe.c
+++ b/toys/pending/partprobe.c
@@ -4,7 +4,7 @@
  *
  * see http://man7.org/linux/man-pages/man8/partprobe.8.html
 
-USE_PARTPROBE(NEWTOY(partprobe, NULL, TOYFLAG_SBIN))
+USE_PARTPROBE(NEWTOY(partprobe, "<1", TOYFLAG_SBIN))
 
 config PARTPROBE
   bool "partprobe"
@@ -12,7 +12,7 @@ config PARTPROBE
   help
     partprobe - Tell the kernel about partition table changes
 	
-    usage: partprobe [devices...]
+    usage: partprobe DEVICE...
 
     Asks the kernel to re-read the partition table on the specified
     devices.
@@ -20,32 +20,13 @@ config PARTPROBE
 
 #include "toys.h"
 
-void update_device(char* path)
+void update_device(int sd_fd, char *path)
 {
-  int sd_fd = open(path, 0);
-  
-  if(sd_fd < 0){
-	perror_msg("Unable to open %s", path);
-	return;
-  }
-  
   if(ioctl(sd_fd, BLKRRPART, NULL) < 0)
     perror_msg("ioctl (BLKRRPART) failed, old layout still used");
-  
-  close(sd_fd);
 }
 
 void partprobe_main(void)
 {
-  char** opt; 
-  if(*toys.optargs == NULL){
-    printf("No devices specified.\n");
-    exit(EXIT_FAILURE);
-  }
-  
-  for (opt = toys.optargs; *opt; opt++) {
-    update_device(*opt);
-  }
-  
-  exit(EXIT_SUCCESS);
+  loopfiles(toys.optargs, update_device);
 }


More information about the Toybox mailing list