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

Re: [PATCH] maintenance: specify explicit stdin for crontab

From
Derrick Stolee <stolee@gmail.com>
Date
Mar 30, 2021, 12:02 UTC
Message-ID
<25ea6f26-c829-f63f-77a1-11a28bbe7fc0@gmail.com>
In-Reply-To
<CAN0heSrSNJhy33Wi9Yq8kfnkJEyvQoadyj8joLqHtV+SYPs1sw@mail.gmail.com>
On 3/30/2021 1:41 AM, Martin Ågren wrote:
> On Mon, 29 Mar 2021 at 23:23, Kevin Daudt <me@ikke.info> wrote:
>>
>> There are multiple crontab implementations that require stdin for
>> editing a crontab to be explicitly specified as '-'.
Thank you for reporting this, especially with a patch!

However, I'm not sure about this adding of '-' being something that crontab ignores so commonly. My Ubuntu machine reports this:

$ crontab -e -
crontab: usage error: no arguments permitted after this option
usage:  crontab [-u user] file
        crontab [ -u user ] [ -i ] { -e | -l | -r }
                (default operation is replace, per 1003.2)
        -e      (edit user's crontab)
        -l      (list user's crontab)
        -r      (delete user's crontab)
        -i      (prompt before deleting user's crontab)

Is there a way we could attempt writing over stdin, notice the failure, then retry with the '-' option?

Show 33 quoted lines
> 
> [...]
> 
>> --- 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");
> 
> Would it make sense to make this
> 
>   } else if (argc == 3 && !strcmp(argv[2], "-")) {
> 
> in order to make this test-tool as picky as possible and to only accept
> the kind of usage we want to (well, need to) use? The tests as they
> stand would still pass, which I think argues for us not really needing
> that "argc == 2".
> 
> This would be followed by
> 
>   } else
>           return error("unknown arguments");
> 
> which wouldn't be super helpful if you forgot the "-", but helpful
> enough for an internal test-tool, I guess.
>
> Speaking of usage and hints, there's "Usage: ..." in a comment at the
> top of this file. It should probably be updated either way.
I agree with Martin's review here, too.

Thanks, -Stolee

Previous: Martin ÅgrenNext: Kevin Daudt
Message 3 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.