ee69e7884e
While cron is specified by POSIX, there are a wide variety of implementations in use. "git maintenance" assumes that the "crontab" command can be fed from its standard input the new contents and the syntax to do so is not to have any filename argument, as POSIX describes. However, on FreeBSD, the cron implementation requires a file name argument: if the user wants to edit standard input, they must specify "-". Unfortunately, POSIX systems do not have to interpret "-" on the command line of crontab as a request to read from the standard input. Blindly adding "-" on the command line would not work as a general solution. Since POSIX tells us that cron must accept a file name argument, let's solve this problem by specifying a temporary file instead. This will ensure that we work with the vast majority of implementations. Note that because delete_tempfile closes the file for us, we should not call fclose here on the handle, since doing so will introduce a double free. Reported-by: Renato Botelho <garga@FreeBSD.org> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
36 lines
638 B
C
36 lines
638 B
C
#include "test-tool.h"
|
|
#include "cache.h"
|
|
|
|
/*
|
|
* Usage: test-tool cron <file> [-l]
|
|
*
|
|
* If -l is specified, then write the contents of <file> to stdout.
|
|
* Otherwise, write from stdin into <file>.
|
|
*/
|
|
int cmd__crontab(int argc, const char **argv)
|
|
{
|
|
int a;
|
|
FILE *from, *to;
|
|
|
|
if (argc == 3 && !strcmp(argv[2], "-l")) {
|
|
from = fopen(argv[1], "r");
|
|
if (!from)
|
|
return 0;
|
|
to = stdout;
|
|
} else if (argc == 3) {
|
|
from = fopen(argv[2], "r");
|
|
to = fopen(argv[1], "w");
|
|
} else
|
|
return error("unknown arguments");
|
|
|
|
while ((a = fgetc(from)) != EOF)
|
|
fputc(a, to);
|
|
|
|
if (argc == 3)
|
|
fclose(from);
|
|
else
|
|
fclose(to);
|
|
|
|
return 0;
|
|
}
|