git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] maintenance: specify explicit stdin for crontab
@ 2021-03-29 21:09 Kevin Daudt
  2021-03-30  5:41 ` Martin Ågren
  0 siblings, 1 reply; 7+ messages in thread
From: Kevin Daudt @ 2021-03-29 21:09 UTC (permalink / raw)
  To: git; +Cc: Derrick Stolee, Kevin Daudt

There are multiple crontab implementations that require stdin for
editing a crontab to be explicitly specified as '-'.

BusyBox crontab just shows usage when executed without arguments.
[man 1 crontab][0] from openbsd states:

> The pseudo-filename '-' must be specified to read from standard
> input.

Other implementations might not require it, but accept '-', so
explicitly specify that crontab should read from stdin by passing the
'-' pseudo-filename.

[0]: https://www.unix.com/man-page/freebsd/1/crontab/

Signed-off-by: Kevin Daudt <me@ikke.info>
---
The `git maintenance start` command is currently broken on the default
alpine setup. This would fix it. I've tested `echo '* * * * * echo test'
| crontab -` on the different platforms I have access to, and it worked
without issues..
 builtin/gc.c            | 1 +
 t/helper/test-crontab.c | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/builtin/gc.c b/builtin/gc.c
index ef7226d7b..dfdb5bce9 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1904,6 +1904,7 @@ static int crontab_update_schedule(int run_maintenance, int fd, const char *cmd)
 	rewind(cron_list);
 
 	strvec_split(&crontab_edit.args, cmd);
+	strvec_push(&crontab_edit.args, "-");
 	crontab_edit.in = -1;
 	crontab_edit.git_cmd = 0;
 
diff --git a/t/helper/test-crontab.c b/t/helper/test-crontab.c
index e7c0137a4..525cb318a 100644
--- a/t/helper/test-crontab.c
+++ b/t/helper/test-crontab.c
@@ -17,7 +17,7 @@ int cmd__crontab(int argc, const char **argv)
 		if (!from)
 			return 0;
 		to = stdout;
-	} else if (argc == 2) {
+	} else if ((argc == 3 && !strcmp(argv[2], "-")) || argc == 2) {
 		from = stdin;
 		to = fopen(argv[1], "w");
 	} else
-- 
2.30.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-03-30 19:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-29 21:09 [PATCH] maintenance: specify explicit stdin for crontab Kevin Daudt
2021-03-30  5:41 ` Martin Ågren
2021-03-30 12:02   ` Derrick Stolee
2021-03-30 17:12     ` Kevin Daudt
2021-03-30 19:32       ` Derrick Stolee
2021-03-30 17:43     ` Todd Zullinger
2021-03-30 19:38       ` Derrick Stolee

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).