forked from pool/cronie
- update to 1.5.7: * anacron: Fix problem of anacron not being started on some desktops * crontab: switch off colors if NO_COLOR is set * crontab: crontab without arguments now works if stdin is not a TTY * crond: Fix various issues on loading the crontab databases on startup * anacron: Expand MAILTO and MAILFROM environment variables * crontab: New option to test crontab file syntax without installing it - cronie-nheader_lines.diff: refresh against 1.5.7 OBS-URL: https://build.opensuse.org/request/show/891605 OBS-URL: https://build.opensuse.org/package/show/Base:System/cronie?expand=0&rev=195
102 lines
2.8 KiB
Diff
102 lines
2.8 KiB
Diff
Index: src/crontab.c
|
|
===================================================================
|
|
--- src/crontab.c.orig
|
|
+++ src/crontab.c
|
|
@@ -64,7 +64,7 @@
|
|
#include "pathnames.h"
|
|
#include "structs.h"
|
|
|
|
-#define NHEADER_LINES 0
|
|
+#define NHEADER_LINES 3
|
|
|
|
#define COMMENT_COLOR "\x1B[34m"
|
|
#define ERROR_COLOR "\x1B[31m"
|
|
@@ -418,7 +418,7 @@ static void parse_args(int argc, char *a
|
|
static void list_cmd(void) {
|
|
char n[MAX_FNAME];
|
|
FILE *f;
|
|
- int ch;
|
|
+ int ch, x;
|
|
const int colorize = isatty(STDOUT) && getenv("NO_COLOR") == NULL;
|
|
int new_line = 1;
|
|
int in_comment = 0;
|
|
@@ -439,6 +439,22 @@ static void list_cmd(void) {
|
|
/* file is open. copy to stdout, close.
|
|
*/
|
|
Set_LineNum(1);
|
|
+ /* ignore the top few comments since we probably put them there.
|
|
+ */
|
|
+ x = 0;
|
|
+ while (EOF != (ch = get_char(f))) {
|
|
+ if ('#' != ch) {
|
|
+ putchar(ch);
|
|
+ break;
|
|
+ }
|
|
+ while (EOF != (ch = get_char(f)))
|
|
+ if (ch == '\n')
|
|
+ break;
|
|
+ if (++x >= NHEADER_LINES)
|
|
+ break;
|
|
+ }
|
|
+ /* copy the rest of the crontab (if any) to the stdout.
|
|
+ */
|
|
while (EOF != (ch = get_char(f))) {
|
|
if (colorize) {
|
|
if (!in_comment && new_line && ch == '#') {
|
|
@@ -533,7 +549,7 @@ static void edit_cmd(void) {
|
|
char n[MAX_FNAME], q[MAX_TEMPSTR];
|
|
const char *editor;
|
|
FILE *f;
|
|
- int ch = '\0', t;
|
|
+ int ch = '\0', t, x;
|
|
struct stat statbuf;
|
|
struct utimbuf utimebuf;
|
|
WAIT_T waiter;
|
|
@@ -585,10 +601,20 @@ static void edit_cmd(void) {
|
|
}
|
|
|
|
Set_LineNum(1);
|
|
- /*
|
|
- * NHEADER_LINES processing removed for clarity
|
|
- * (NHEADER_LINES == 0 in all Red Hat crontabs)
|
|
+ /* ignore the top few comments since we probably put them there.
|
|
*/
|
|
+ x = 0;
|
|
+ while (EOF != (ch = get_char(f))) {
|
|
+ if ('#' != ch) {
|
|
+ putc(ch, NewCrontab);
|
|
+ break;
|
|
+ }
|
|
+ while (EOF != (ch = get_char(f)))
|
|
+ if (ch == '\n')
|
|
+ break;
|
|
+ if (++x >= NHEADER_LINES)
|
|
+ break;
|
|
+ }
|
|
/* copy the rest of the crontab (if any) to the temp file.
|
|
*/
|
|
if (EOF != ch)
|
|
@@ -812,6 +838,7 @@ static int replace_cmd(void) {
|
|
int ch, fd;
|
|
int error = 0;
|
|
uid_t file_owner;
|
|
+ time_t now = time(NULL);
|
|
char *safename;
|
|
|
|
safename = host_specific_filename("#tmp", "XXXXXXXXXX");
|
|
@@ -839,10 +866,10 @@ static int replace_cmd(void) {
|
|
*
|
|
* VERY IMPORTANT: make sure NHEADER_LINES agrees with this code.
|
|
*/
|
|
- /*fprintf(tmp, "# DO NOT EDIT THIS FILE - edit the master and reinstall.\n");
|
|
- *fprintf(tmp, "# (%s installed on %-24.24s)\n", Filename, ctime(&now));
|
|
- *fprintf(tmp, "# (Cron version %s)\n", CRON_VERSION);
|
|
- */
|
|
+ fprintf(tmp, "# DO NOT EDIT THIS FILE - edit the master and reinstall.\n");
|
|
+ fprintf(tmp, "# (%s installed on %-24.24s)\n", Filename, ctime(&now));
|
|
+ fprintf(tmp, "# (Cronie version %s)\n", CRON_VERSION);
|
|
+
|
|
#ifdef WITH_SELINUX
|
|
if (selinux_context)
|
|
fprintf(tmp, "SELINUX_ROLE_TYPE=%s\n", selinux_context);
|