run-parts

Bernhard Fischer rep.nop at aon.at
Thu May 25 22:11:25 UTC 2006


On Thu, May 25, 2006 at 10:13:33PM +0200, Bernhard Fischer wrote:

>It's solely other stuff (looks like i managed to forget to attach it the
>first time; attached now -- including the run_parts shrink).

The run_parts thing isn't finished yet, since i forgot that there can be
multiple -a arguments so we should switch it to llist for the args..

Does anyone use the testmode#2 or can this be dropped? (Didn't look
closely yet)

I'm attaching my current version with disfunctional multiple -a, in case
someone wants to help
-------------- next part --------------
Index: debianutils/run_parts.c
===================================================================
--- debianutils/run_parts.c	(revision 15167)
+++ debianutils/run_parts.c	(working copy)
@@ -10,21 +10,7 @@
  *   Copyright (C) 1996-1999 Guy Maor <maor at debian.org>
  *
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- * 02111-1307 USA
- *
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  */
 
 /* This is my first attempt to write a program in C (well, this is my first
@@ -49,17 +35,19 @@
  * done - declare run_parts_main() as extern and any other function as static?
  */
 
-#include <getopt.h>
 #include <stdlib.h>
+#include <getopt.h> /* optind */
 
 #include "busybox.h"
 
+#if ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS
 static const struct option runparts_long_options[] = {
 	{ "test",		0,		NULL,		't' },
 	{ "umask",		1,		NULL,		'u' },
 	{ "arg",		1,		NULL,		'a' },
 	{ 0,			0,		0,			0 }
 };
+#endif
 
 extern char **environ;
 
@@ -68,47 +56,32 @@
 int run_parts_main(int argc, char **argv)
 {
 	char **args = xmalloc(2 * sizeof(char *));
-	unsigned char test_mode = 0;
 	unsigned short argcount = 1;
+	char *opt_u, *opt_a;
 	int opt;
 
 	umask(022);
-
-	while ((opt = getopt_long (argc, argv, "tu:a:",
-					runparts_long_options, NULL)) > 0)
-	{
-		switch (opt) {
-			/* Enable test mode */
-			case 't':
-				test_mode++;
-				break;
-			/* Set the umask of the programs executed */
-			case 'u':
-				/* Check and set the umask of the program executed. As stated in the original
-				 * run-parts, the octal conversion in libc is not foolproof; it will take the
-				 * 8 and 9 digits under some circumstances. We'll just have to live with it.
-				 */
-				umask(bb_xgetlarg(optarg, 8, 0, 07777));
-				break;
-			/* Pass an argument to the programs */
-			case 'a':
-				/* Add an argument to the commands that we will call.
-				 * Called once for every argument. */
-				args = xrealloc(args, (argcount + 2) * (sizeof(char *)));
-				args[argcount++] = optarg;
-				break;
-			default:
-				bb_show_usage();
-		}
+#if ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS
+	bb_applet_long_options = runparts_long_options;
+#endif
+	/* We require exactly one non-option argument: the directory name */
+	bb_opt_complementally="?1";
+	opt = bb_getopt_ulflags(argc, argv, "tu:a:", &opt_u, &opt_a);
+	if (opt & 2) /* u *//* Set the umask of the programs executed */
+		/* Check and set the umask of the program executed. As stated in the original
+		 * run-parts, the octal conversion in libc is not foolproof; it will take the
+		 * 8 and 9 digits under some circumstances. We'll just have to live with it.
+		 */
+		umask(bb_xgetlarg(opt_u, 8, 0, 07777));
+	if (opt & 4) {/* a *//* Pass an argument to the programs */
+		/* Add an argument to the commands that we will call.
+		 * Called once for every argument. */
+		args = xrealloc(args, (argcount + 2) * (sizeof(char *)));
+		args[argcount++] = opt_a;
 	}
 
-	/* We require exactly one argument: the directory name */
-	if (optind != (argc - 1)) {
-		bb_show_usage();
-	}
-
 	args[0] = argv[optind];
 	args[argcount] = 0;
 
-	return(run_parts(args, test_mode, environ));
+	return(run_parts(args, (opt & 1), environ));
 }


More information about the busybox mailing list