git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] maintenance: specify explicit stdin for crontab

From
Kevin Daudt <me@ikke.info>
Date
Mar 29, 2021, 21:09 UTC
Message-ID
<20210329210928.561586-1-me@ikke.info>

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
Next: Martin Ågren
Message 1 of 7 in “maintenance: specify explicit stdin for crontab”
  1. maintenance: specify explicit stdin for crontabKevin Daudt, Mar 29, 2021
  2. Martin ÅgrenMar 30, 2021
  3. Derrick StoleeMar 30, 2021
  4. Kevin DaudtMar 30, 2021
  5. Derrick StoleeMar 30, 2021
  6. Todd ZullingerMar 30, 2021
  7. Derrick StoleeMar 30, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.