Skip to content

Commit d42989f

Browse files
authored
Merge pull request #24 from minfrin/giveup
Avoid the final delay when running a command a specific number of times.
2 parents 4a74786 + 4af0964 commit d42989f

File tree

6 files changed

+39
-17
lines changed

6 files changed

+39
-17
lines changed

.github/workflows/full-check.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
run: |
1616
autoreconf -fi
1717
./configure
18+
make
1819
make dist
1920
head retry.1; cat retry.1 | grep -C5 "try forever" || exit 1
2021

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

22
Changes with v1.0.6
33

4+
*) Avoid the final delay when running a command a
5+
specific number of times. [Graham Leggett]
6+
47
*) Generate the man page during the dist hook, and not
58
at build time. This makes life easy for parallel and
69
cross compiled builds. [Graham Leggett]

Makefile.am

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ retry_SOURCES = retry.c
77
EXTRA_DIST = retry.spec
88
dist_man_MANS = retry.1
99

10-
retry.1: retry
11-
./retry --help | txt2man -s 1 -t "${PACKAGE_NAME}" -r "${PACKAGE_NAME}-${PACKAGE_VERSION}" > retry.1
10+
dist-hook: retry retry.1
11+
install retry.1 $(distdir)/retry.1
12+
13+
retry.1:
14+
./retry --help | txt2man -d 1 -t "${PACKAGE_NAME}" -r "${PACKAGE_NAME}-${PACKAGE_VERSION}" > retry.1
1215

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,7 @@ dnf copr enable minfrin/retry
1919
dnf install retry
2020
```
2121

22-
There is also a [PPA] for Ubuntu as follows:
23-
24-
```
25-
sudo add-apt-repository ppa:minfrin/retry
26-
sudo apt-get update
27-
sudo apt-get install retry
28-
```
22+
The retry tool is available by default on Debian derived systems.
2923

3024
# example
3125
```
@@ -57,6 +51,14 @@ retry: false returned 1, backing off for 64 seconds and trying again...
5751
retry: false returned 1, backing off for 64 seconds and trying again...
5852
retry: false returned 1, backing off for 64 seconds and trying again...
5953
^C
54+
```
55+
56+
# fixed number of times
57+
```
58+
~$ retry --times=3 -- false
59+
retry: false returned 1, backing off for 10 seconds and trying again...
60+
retry: false returned 1, backing off for 10 seconds and trying again...
61+
retry: false returned 1, giving up.
6062
```
6163

6264
[COPR]: <https://copr.fedorainfracloud.org/coprs/minfrin/retry/>

config.h.in

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
to 0 otherwise. */
1414
#undef HAVE_MALLOC
1515

16+
/* Define to 1 if you have the <memory.h> header file. */
17+
#undef HAVE_MEMORY_H
18+
1619
/* Define to 1 if stdbool.h conforms to C99. */
1720
#undef HAVE_STDBOOL_H
1821

1922
/* Define to 1 if you have the <stdint.h> header file. */
2023
#undef HAVE_STDINT_H
2124

22-
/* Define to 1 if you have the <stdio.h> header file. */
23-
#undef HAVE_STDIO_H
24-
2525
/* Define to 1 if you have the <stdlib.h> header file. */
2626
#undef HAVE_STDLIB_H
2727

@@ -67,9 +67,7 @@
6767
/* Define to the version of this package. */
6868
#undef PACKAGE_VERSION
6969

70-
/* Define to 1 if all of the C90 standard headers exist (not just the ones
71-
required in a freestanding environment). This macro is provided for
72-
backward compatibility; new code need not use it. */
70+
/* Define to 1 if you have the ANSI C header files. */
7371
#undef STDC_HEADERS
7472

7573
/* Version number of package */
@@ -89,7 +87,7 @@
8987
/* Define to rpl_malloc if the replacement function should be used. */
9088
#undef malloc
9189

92-
/* Define as a signed integer type capable of holding a process identifier. */
90+
/* Define to `int' if <sys/types.h> does not define. */
9391
#undef pid_t
9492

9593
/* Define to `unsigned int' if <sys/types.h> does not define. */

retry.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static int help(const char *name, const char *msg, int code)
120120
" when repeat has backed off. Defaults to the\n"
121121
" command name.\n"
122122
"\n"
123-
" -t times, --times=times The number of times to retry\n"
123+
" -t times, --times=times Total number of times to try\n"
124124
" the command. By default we try forever.\n"
125125
"\n"
126126
" -u criteria, --until=criteria Keep repeating the command until any one\n"
@@ -183,6 +183,13 @@ static int help(const char *name, const char *msg, int code)
183183
"\tretry: false returned 1, backing off for 64 seconds and trying again...\n"
184184
"\t^C\n"
185185
"\n"
186+
" In this example, we try three times before giving up.\n"
187+
"\n"
188+
"\t~$ retry --times=3 -- false\n"
189+
"\tretry: false returned 1, backing off for 10 seconds and trying again...\n"
190+
"\tretry: false returned 1, backing off for 10 seconds and trying again...\n"
191+
"\tretry: false returned 1, giving up.\n"
192+
"\n"
186193
"AUTHOR\n"
187194
" Graham Leggett <[email protected]>\n"
188195
"", msg ? msg : "", n, n);
@@ -595,6 +602,14 @@ int main (int argc, char **argv)
595602
free(pumps[STDOUT_FD].base);
596603
memset(&pumps[STDOUT_FD], 0, sizeof(pump_t));
597604

605+
/* last try? give up */
606+
if (times == 1) {
607+
fprintf(stderr,
608+
"%s: %s returned %d, giving up.\n",
609+
name, message ? message : argv[optind], status);
610+
break;
611+
}
612+
598613
if (delay[0]) {
599614
d = strtol(delay, &delay, 10);
600615
}

0 commit comments

Comments
 (0)