git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Kevin Daudt <me@ikke.info>
To: git@vger.kernel.org
Cc: Derrick Stolee <stolee@gmail.com>, Kevin Daudt <me@ikke.info>
Subject: [PATCH] maintenance: specify explicit stdin for crontab
Date: Mon, 29 Mar 2021 23:09:28 +0200	[thread overview]
Message-ID: <20210329210928.561586-1-me@ikke.info> (raw)

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


             reply	other threads:[~2021-03-29 21:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-29 21:09 Kevin Daudt [this message]
2021-03-30  5:41 ` [PATCH] maintenance: specify explicit stdin for crontab 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210329210928.561586-1-me@ikke.info \
    --to=me@ikke.info \
    --cc=git@vger.kernel.org \
    --cc=stolee@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).