Your message dated Sat, 25 Jul 2009 09:51:20 +0000
with message-id <[email protected]>
and subject line Bug#537992: fixed in moreutils 0.37
has caused the Debian Bug report #537992,
regarding parallel: please add -n option
to be marked as done.
This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.
(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact [email protected]
immediately.)
--
537992: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=537992
Debian Bug Tracking System
Contact [email protected] with problems
--- Begin Message ---
Package: moreutils
Severity: normal
Tags: patch
Attached a patch to add a -n option to parallel. Note that it has the
side effect to fix a segfault if no '--' is passed to parallel.
>From b1f1f34329a2c8eb4e8034802ba5102f9e3c3b57 Mon Sep 17 00:00:00 2001
From: Pierre Habouzit <[email protected]>
Date: Wed, 22 Jul 2009 11:17:20 +0200
Subject: [PATCH] support -n option
This makes parallel stuff more than one argument to the subcommands.
It's very useful when subcommands are slow to start and are able to
process multiple files at once, that tasks are small but plenty.
For example:
$ ./parallel -n 3 echo -- a b c d e f g h
a b c
d e f
g h
Signed-off-by: Pierre Habouzit <[email protected]>
---
parallel.c | 46 +++++++++++++++++++++++++++++++---------------
parallel.docbook | 8 ++++++++
2 files changed, 39 insertions(+), 15 deletions(-)
diff --git a/parallel.c b/parallel.c
index 8045e22..99a9727 100644
--- a/parallel.c
+++ b/parallel.c
@@ -38,7 +38,7 @@ void usage() {
exit(1);
}
-void exec_child(char **command, char *argument, int replace_cb) {
+void exec_child(char **command, char **arguments, int replace_cb, int nargs) {
char **argv;
int argc = 0;
int i;
@@ -48,14 +48,14 @@ void exec_child(char **command, char *argument, int
replace_cb) {
}
if (replace_cb == 0)
argc++;
- argv = calloc(sizeof(char*), argc+1);
+ argv = calloc(sizeof(char*), argc + nargs);
for (i = 0; i < argc; i++) {
argv[i] = command[i];
if (replace_cb && (strcmp(argv[i], "{}") == 0))
- argv[i] = argument;
+ argv[i] = arguments[0];
}
if (replace_cb == 0)
- argv[i-1] = argument;
+ memcpy(argv + i - 1, arguments, nargs * sizeof(char *));
if (fork() == 0) {
/* Child */
execvp(argv[0], argv);
@@ -81,16 +81,18 @@ int main(int argc, char **argv) {
int maxjobs = -1;
int curjobs = 0;
int maxload = -1;
+ int argsatonce = 1;
int opt;
char **command = calloc(sizeof(char*), argc);
char **arguments = NULL;
int argidx = 0;
+ int arglen = 0;
int cidx = 0;
int returncode = 0;
int replace_cb = 0;
char *t;
- while ((opt = getopt(argc, argv, "+hij:l:")) != -1) {
+ while ((opt = getopt(argc, argv, "+hij:l:n:")) != -1) {
switch (opt) {
case 'h':
usage();
@@ -116,12 +118,26 @@ int main(int argc, char **argv) {
exit(2);
}
break;
+ case 'n':
+ errno = 0;
+ argsatonce = strtoul(optarg, &t, 0);
+ if (errno != 0 || argsatonce < 1 || (t-optarg) !=
strlen(optarg)) {
+ fprintf(stderr, "option '%s' is not a positive
number\n",
+ optarg);
+ exit(2);
+ }
+ break;
default: /* ’?’ */
usage();
break;
}
}
+ if (replace_cb && argsatonce > 1) {
+ fprintf(stderr, "options -i and -n are incomaptible\n");
+ exit(2);
+ }
+
if (maxjobs < 0) {
#ifdef _SC_NPROCESSORS_ONLN
maxjobs = sysconf(_SC_NPROCESSORS_ONLN);
@@ -134,18 +150,15 @@ int main(int argc, char **argv) {
while (optind < argc) {
if (strcmp(argv[optind], "--") == 0) {
int i;
- size_t mem = (sizeof (char*)) * (argc - optind);
- arguments = malloc(mem);
+ optind++;
+ arglen = argc - optind;
+ arguments = calloc(sizeof(char *), arglen);
if (! arguments) {
exit(1);
}
- memset(arguments, 0, mem);
- optind++; /* Skip the -- separator, skip after
- * malloc so we have a trailing
- * null */
- for (i = 0; i < argc - optind; i++) {
+ for (i = 0; i < arglen; i++) {
arguments[i] = strdup(argv[optind + i]);
}
optind += i;
@@ -157,15 +170,18 @@ int main(int argc, char **argv) {
optind++;
}
- while (arguments[argidx] != 0) {
+ while (argidx < arglen) {
double load;
getloadavg(&load, 1);
if ((maxjobs > 0 && curjobs < maxjobs) ||
(maxload > 0 && load < maxload)) {
- exec_child(command, arguments[argidx], replace_cb);
- argidx++;
+ if (argsatonce > arglen - argidx)
+ argsatonce = arglen - argidx;
+ exec_child(command, arguments + argidx,
+ replace_cb, argsatonce);
+ argidx += argsatonce;
curjobs++;
}
diff --git a/parallel.docbook b/parallel.docbook
index 9d5714c..2c5cf14 100644
--- a/parallel.docbook
+++ b/parallel.docbook
@@ -84,6 +84,14 @@ Written by Joey Hess
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-n</option></term>
+ <listitem>
+ <para>Number of arguments to pass to one
command at
+ once. Incompatible with -i</para>
+ </listitem>
+ </varlistentry>
+
</variablelist>
</refsect1>
--
1.6.3.3.420.gd4b46
--- End Message ---
--- Begin Message ---
Source: moreutils
Source-Version: 0.37
We believe that the bug you reported is fixed in the latest version of
moreutils, which is due to be installed in the Debian FTP archive:
moreutils_0.37.dsc
to pool/main/m/moreutils/moreutils_0.37.dsc
moreutils_0.37.tar.gz
to pool/main/m/moreutils/moreutils_0.37.tar.gz
moreutils_0.37_i386.deb
to pool/main/m/moreutils/moreutils_0.37_i386.deb
A summary of the changes between this version and the previous one is
attached.
Thank you for reporting the bug, which will now be closed. If you
have further comments please address them to [email protected],
and the maintainer will reopen the bug report if appropriate.
Debian distribution maintenance software
pp.
Joey Hess <[email protected]> (supplier of updated moreutils package)
(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing [email protected])
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Format: 1.8
Date: Sat, 25 Jul 2009 10:18:40 +0200
Source: moreutils
Binary: moreutils
Architecture: source i386
Version: 0.37
Distribution: unstable
Urgency: low
Maintainer: Joey Hess <[email protected]>
Changed-By: Joey Hess <[email protected]>
Description:
moreutils - additional unix utilities
Closes: 536597 537992 538147
Changes:
moreutils (0.37) unstable; urgency=low
.
* parallel: Clarify man page regarding CPUs. Closes: #536597
* parallel: Add -n option. Thanks, Pierre Habouzit. Closes: #537992
(As a side effect, fixes a segfault if -- was omitted.)
* parallel.1: Typo fixes. Closes: #538147
Checksums-Sha1:
3ac0394930d85d56dc042173e62828fd4baac016 822 moreutils_0.37.dsc
0bfd3328da89c65f2123a6205579219d0954e902 39445 moreutils_0.37.tar.gz
49124dc57a616edff4fdd4fb7aa3627808a26e7b 48564 moreutils_0.37_i386.deb
Checksums-Sha256:
f727edeb641f635ab0b03543f559c4d80dcd11c6d30b020d79a13d1edf204fd9 822
moreutils_0.37.dsc
21b5dcf61c1cdf2b479613e5fd4c4652780ba2be872c9631d4493fa74f30eb50 39445
moreutils_0.37.tar.gz
e51f228606f3123a0d9665573c39bae34cd53ab6cdda0390b8242ca3f98b37cc 48564
moreutils_0.37_i386.deb
Files:
cfd7c02cf9343e3dad83e272aa7f8a20 822 utils optional moreutils_0.37.dsc
0efb69ef1e913ea4dabc74bfe0e68372 39445 utils optional moreutils_0.37.tar.gz
0987e440772614603a5572660f03d045 48564 utils optional moreutils_0.37_i386.deb
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iD8DBQFKasEa2tp5zXiKP0wRAkLNAJ9OD+w2BjqZ9J6dNnMtgF1bAPqCBQCg1If8
I6do8zvWrPGlZxsuu4kFYNk=
=9cdC
-----END PGP SIGNATURE-----
--- End Message ---