Commit e5575af6 authored by Andreas Henriksson's avatar Andreas Henriksson

Import Upstream version 1.4.8

parents
Makefile.in
Makefile
anacron/anacron
anacron/anacron-paths.h
anacron/Makefile
anacron/Makefile.in
aclocal.m4
autom4te.cache
config.guess
config.h
config.h.in
config.log
config.status
config.sub
configure
depcomp
install-sh
man/Makefile
man/Makefile.in
missing
stamp-h1
tags
.deps
*.o
src/crond
src/crontab
src/cron-paths.h
*~
*.tar.*
Original vixie-cron was written by Paul Vixie.
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1997,2000 by Internet Software Consortium, Inc.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Copyright (c) 1988, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software written by Ken Arnold and
* published in UNIX Review, Vol. 6, No. 8.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Paul Vixie.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)bitstring.h 8.1 (Berkeley) 7/19/93
*/
This diff is collapsed.
This diff is collapsed.
Changes in Anacron 2.3.1
------------------------
* documentation no longer suggests adding local directories to the PATH
Changes in Anacron 2.3
----------------------
* anacron can now read an arbitrary anacrontab file, use the -t option
Changes in Anacron 2.1/2.2
--------------------------
* Sean 'Shaleh' Perry <shaleh@(debian.org|valinux.com)> is now maintainer
* if timestamp is from the future, re-run job
* ansi cleanup / code cleaning
Changes in Anacron 2.0.1
------------------------
* Minor cosmetic changes to log messages.
* Jobs are now started with "/" as their working directory. This is
more compatible with older Anacron versions, avoids annoying errors on
some systems, and generally seems to make more sense.
Summary of major changes in Anacron 2.0
---------------------------------------
* Complete rewrite in C. Should be backwards compatible with existing
Anacron installations.
* First release as a "generic" Linux package (was a Debian package).
* No longer needs special lock-files. Locking is done on the timestamp
files.
* Sends log messages to syslogd. There's no log file now.
* Output of jobs, if any, is mailed to the user.
* Added command line options: -s -f -n -d -q -u -V -h. See the manpage.
* Specific jobs can now be selected on the command line.
* Added SIGUSR1 handling, to cleanly stop execution.
* Jobs will now be started with their current directory set to the home
of the user running Anacron (usually root).
Basic Installation
==================
In the vixie-cron directory run:
autoreconf
These commands create from configure.ac executable ./configure
Then you can start installation:
make
make install
The executable files will be installed in /usr/local/*
Options
=======
In the default package are used configure options:
--with-pam
--with-selinux
--with-audit
SUBDIRS = src man
if ANACRON
SUBDIRS += anacron
endif
if PAM
pamdir = $(sysconfdir)/pam.d
dist_pam_DATA = pam/crond
endif
EXTRA_DIST = cronie.init crond.sysconfig contrib/anacrontab \
contrib/0anacron contrib/0hourly \
contrib/dailyjobs
17. January 2008 mmaslano (at) redhat (dot) com
Rename the fork on cronie. The source code could be found here:
http://mmaslano.fedorapeople.org/cronie/ or git archive here:
git://git.fedorahosted.org/git/cronie.git
3. October 2007 mmaslano (at) redhat (dot) com
This is a clone of 'original' vixie-cron. It was used in Red Hat|Fedora
system and patched for a long time. Now was made clone tagged with
version 4.2.
Changes are mainly in git commit messages, some older changes could be
found in spec changelog (contrib/vixie-cron.spec).
What is Anacron ?
-----------------
Anacron is a periodic command scheduler. It executes commands at
intervals specified in days. Unlike cron, it does not assume that the
system is running continuously. It can therefore be used to control
the execution of daily, weekly and monthly jobs (or anything with a
period of n days), on systems that don't run 24 hours a day. When
installed and configured properly, Anacron will make sure that the
commands are run at the specified intervals as closely as
machine-uptime permits.
Every time Anacron is run, it reads a configuration file that
specifies the jobs Anacron controls, and their periods in days. If a
job wasn't executed in the last n days, where n is the period of that
job, Anacron executes it. Anacron then records the date in a special
timestamp file that it keeps for each job, so it can know when to run
it again. When all the executed commands terminate, Anacron exits.
It is recommended to run Anacron from the system boot-scripts.
This way the jobs "whose time has come" will be run shortly after the
machine boots. A delay can be specified for each job so that the
machine isn't overloaded at boot time.
In addition to running Anacron from the boot-scripts, it is also
recommended to schedule it as a daily cron-job (usually at an early
morning hour), so that if the machine is kept running for a night,
jobs for the next day will still be executed.
Why this may be useful ?
------------------------
Most Unix-like systems have daily, weekly and monthly scripts that
take care of various "housekeeping chores" such as log-rotation,
updating the "locate" and "man" databases, etc. Daily scripts are
usually scheduled as cron-jobs to execute around 1-7 AM. Weekly
scripts are scheduled to run on Sundays. On machines that are turned
off for the night or for the weekend, these scripts rarely get run.
Anacron solves this problem. These jobs can simply be scheduled as
Anacron-jobs with periods of 1, 7 and a special target called @monthly.
What Anacron is not ?
---------------------
Anacron is not an attempt to make cron redundant. It cannot
currently be used to schedule commands at intervals smaller than days.
It also does not guarantee that the commands will be executed at any
specific day or hour.
It isn't a full-time daemon. It has to be executed from boot
scripts, from cron-jobs, or explicitly.
For more details, see the anacron(8) manpage.
Requirements
------------
- A Linux system. (maybe other *NIX systems)
- A functioning syslog daemon.
- A functioning /usr/lib/sendmail command. (all MTAs should have
that).
Compilation and Installation
----------------------------
- Untar the source package.
- Check the Makefile. Edit as required.
- Check the top of "global.h". You may want to change the syslog
facility and priorities, and the path to your MTA's sendmail
compatible command (/usr/lib/sendmail).
- cd to the directory.
- Type "make".
You can safely ignore warnings of the form: "*.d: No such file or
directory"
- Become root. Type "make install".
Setup
-----
1. Locate your system's daily, weekly and monthly cron-jobs.
See your cron documentation for more details.
2. Decide which of these jobs should be controlled by Anacron.
Remember that Anacron does not guarantee execution at any specific
day of the month, day of the week, or time of day. Jobs for which
the timing is critical should probably not be controlled by
Anacron.
3. Comment these jobs out of their crontab files. (You may have to
use the "crontab" command for this. See the cron documentation.)
4. Put them in /etc/anacrontab. Note that the format is not the same
as the crontab entries. See the anacrontab(5) manpage. Here's an
example from a typical Debian system:
-----Cut
# /etc/anacrontab example
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
# format: period delay job-identifier command
1 5 cron.daily run-parts /etc/cron.daily
7 10 cron.weekly run-parts /etc/cron.weekly
@monthly 15 cron.monthly run-parts /etc/cron.monthly
-----Cut
5. Put the command "anacron -s" somewhere in your boot-scripts.
Make sure that syslogd is started before this command.
6. Schedule the command "anacron -s" as a daily cron-job (preferably
at some early morning hour). This will make sure that jobs are run
when the systems is left running for a night.
That's it.
It is a good idea to check what your daily, weekly and monthly scripts
actually do, and disable any parts that may be irrelevant for your
system.
Credits
-------
Anacron was originally conceived and implemented by Christian Schwarz
<schwarz@monet.m.isar.de>.
The current implementation is a complete rewrite by Itai Tzur
<itzur@actcom.co.il>.
Current code base maintained by Sean 'Shaleh' Perry <shaleh@(debian.org|valinux.com)>.
# Makefile.am - two binaries crond and crontab
sbin_PROGRAMS = anacron
anacron_SOURCES = \
gregor.c lock.c log.c main.c matchrx.c readtab.c runjob.c \
$(common_src)
common_src = global.h gregor.h matchrx.h
common_nodist = anacron-paths.h
nodist_anacron_SOURCES = $(common_nodist)
BUILT_SOURCES = $(common_nodist)
LDADD = $(LIBSELINUX) $(LIBPAM) $(LIBAUDIT)
# This header contains all the paths.
# If they are configurable, they are declared in configure script.
# Depends on this Makefile, because it uses make variables.
anacron-paths.h: Makefile
@echo 'creating $@'
@sed >$@ 's/ *\\$$//' <<\END #\
/* This file has been automatically generated. Do not edit. */ \
\
#ifndef _ANACRON_PATHS_H_ \
#define _ANACRON_PATHS_H_ \
#define ANACRON_SPOOL_DIR "$(ANACRON_SPOOL_DIR)" \
#define ANACRONTAB "$(ANACRONTAB)" \
#endif /* _ANACRON_PATHS_H_ */ \
END
/*
Anacron - run commands periodically
Copyright (C) 1998 Itai Tzur <itzur@actcom.co.il>
Copyright (C) 1999 Sean 'Shaleh' Perry <shaleh@debian.org>
Copyright (C) 2004 Pascal Hakim <pasc@redellipse.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
The GNU General Public License can also be found in the file
`COPYING' that comes with the Anacron source distribution.
*/
#ifndef _ANACRON_GLOBAL_H
#define _ANACRON_GLOBAL_H
/* Syslog facility and priorities messages will be logged to (see syslog(3)).
* If you change these, please update the man page. */
#define SYSLOG_FACILITY LOG_CRON
#define EXPLAIN_LEVEL LOG_NOTICE /* informational messages */
#define COMPLAIN_LEVEL LOG_ERR /* error messages */
#define DEBUG_LEVEL LOG_DEBUG /* only used when DEBUG is defined */
/* Mail interface. (All MTAs should supply this command) */
#define SENDMAIL "/usr/sbin/sendmail"
/* End of user-configurable section */
#define FAILURE_EXIT 1
#define MAX_MSG 150
#include <signal.h>
#include <time.h>
#include "anacron-paths.h"
/* Some declarations */
struct env_rec1 {
char *assign;
struct env_rec1 *next;
};
typedef struct env_rec1 env_rec;
struct job_rec1 {
int period;
int named_period;
int delay;
char *ident;
char *command;
char *mailto;
int tab_line;
int arg_num;
int timestamp_fd;
int input_fd;
int output_fd;
int mail_header_size;
pid_t job_pid;
pid_t mailer_pid;
int drop_job;
struct job_rec1 *next;
env_rec *prev_env_rec;
};
typedef struct job_rec1 job_rec;
/* Global variables */
extern pid_t primary_pid;
extern char *program_name;
extern char *anacrontab;
extern char *spooldir;
extern int old_umask;
extern sigset_t old_sigmask;
extern int serialize,force,update_only,now,no_daemon,quiet,testing_only;
extern int day_now;
extern int year,month,day_of_month;
extern int in_background;
extern job_rec *first_job_rec;
extern env_rec *first_env_rec;
extern char **args;
extern int nargs;
extern int njobs;
extern job_rec **job_array;
extern int running_jobs,running_mailers;
extern int complaints;
extern time_t start_sec;
/* time ranges for START_HOURS_RANGE */
extern int range_start;
extern int range_stop;
/* Function prototypes */
/* main.c */
int xopen(int fd, const char *file_name, int flags);
void xclose(int fd);
pid_t xfork(void);
#ifdef __GNUC__
#define PRINTF_FORMAT(n, m) \
__attribute__ ((format (printf, n, m)))
#else
#define PRINTF_FORMAT(n, m)
#endif
/* log.c */
void explain(const char *fmt, ...)PRINTF_FORMAT(1,2);
void explain_e(const char *fmt, ...)PRINTF_FORMAT(1,2);
void complain(const char *fmt, ...)PRINTF_FORMAT(1,2);
void complain_e(const char *fmt, ...)PRINTF_FORMAT(1,2);
void die(const char *fmt, ...)PRINTF_FORMAT(1,2);
void die_e(const char *fmt, ...)PRINTF_FORMAT(1,2);
void xdebug(const char *fmt, ...)PRINTF_FORMAT(1,2);
void xdebug_e(const char *fmt, ...)PRINTF_FORMAT(1,2);
void xcloselog(void);
#ifdef DEBUG
#define Debug(args) xdebug args
#define Debug_e(args) xdebug_e args
#else /* not DEBUG */
#define Debug(args) (void)(0)
#define Debug_e(args) (void)(0)
#endif /* not DEBUG */
/* readtab.c */
void read_tab(int cwd);
void arrange_jobs(void);
/* lock.c */
int consider_job(job_rec *jr);
void unlock(job_rec *jr);
void update_timestamp(job_rec *jr);
void fake_job(job_rec *jr);
/* runjob.c */
void tend_children();
void launch_job(job_rec *jr);
#endif
/*
Anacron - run commands periodically
Copyright (C) 1998 Itai Tzur <itzur@actcom.co.il>
Copyright (C) 1999 Sean 'Shaleh' Perry <shaleh@debian.org>
Copyright (C) 2004 Pascal Hakim <pasc@redellipse.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
The GNU General Public License can also be found in the file
`COPYING' that comes with the Anacron source distribution.
*/
#include <limits.h>
#include <time.h>
#include "gregor.h"
static const int
days_in_month[] = {
31, /* Jan */
28, /* Feb (non-leap) */
31, /* Mar */
30, /* Apr */
31, /* May */
30, /* Jun */
31, /* Jul */
31, /* Aug */
30, /* Sep */
31, /* Oct */
30, /* Nov */
31 /* Dec */
};
static int leap(int year);
int
day_num(int year, int month, int day)
/* Return the "day number" of the date year-month-day according to the
* "proleptic Gregorian calendar".
* If the given date is invalid, return -1.
*
* Here, "day number" is defined as the number of days since December 31,
* 1 B.C. (Gregorian). (January 1, 1 A.D. is day number 1 etc...)
*
* The Gregorian calendar was instituted by Pope Gregory XIII in 1582,
* and has gradually spread to become the international standard calendar.
* The proleptic Gregorian calendar is formed by projecting the date system
* of the Gregorian calendar to dates before its adoption.
*
* For more details, see:
* http://astro.nmsu.edu/~lhuber/leaphist.html
* http://www.magnet.ch/serendipity/hermetic/cal_stud/cal_art.htm
* and your local library.
*/
{
int dn;
int i;
int isleap; /* save three calls to leap() */
/* Some validity checks */
/* we don't deal with B.C. years here */
if (year < 1) return - 1;
/* conservative overflow estimate */
if (year > (INT_MAX / 366)) return - 1;
if (month > 12 || month < 1) return - 1;
if (day < 1) return - 1;
isleap = leap(year);
if (month != 2) {
if(day > days_in_month[month - 1]) return - 1;
}
else if ((isleap && day > 29) || (!isleap && day > 28))
return - 1;
/* First calculate the day number of December 31 last year */
/* save us from doing (year - 1) over and over */
i = year - 1;
/* 365 days in a "regular" year + number of leap days */
dn = (i * 365) + ((i / 4) - (i / 100) + (i / 400));
/* Now, day number of the last day of the previous month */
for (i = month - 1; i > 0; --i)
dn += days_in_month[i - 1];
/* Add 29 February ? */
if (month > 2 && isleap) ++dn;
/* How many days into month are we */
dn += day;
return dn;
}
static int
leap(int year)
/* Is this a leap year ? */
{
/* every year exactly divisible by 4 is "leap" */
/* unless it is exactly divisible by 100 */
/* but not by 400 */
return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
}
int
days_last_month (void)
/* How many days did last month have? */
{
struct tm time_record;
time_t current_time;
time (&current_time);
localtime_r (&current_time, &time_record);
switch (time_record.tm_mon) {
case 0: return days_in_month[11];
case 2: return days_in_month[1] + (leap (time_record.tm_year + 1900) ? 1 : 0);
default: return days_in_month[time_record.tm_mon - 1];
}
}
int
days_this_month (void)
/* How many days does this month have? */
{
struct tm time_record;
time_t current_time;
time (&current_time);
localtime_r (&current_time, &time_record);
switch (time_record.tm_mon) {
case 1: return days_in_month[1] + (leap (time_record.tm_year + 1900) ? 1 : 0);
default: return days_in_month[time_record.tm_mon];
}
}
int
days_last_year (void)
/* How many days this last year have? */
{
struct tm time_record;
time_t current_time;
time (&current_time);
localtime_r (&current_time, &time_record);
if (leap(time_record.tm_year - 1 + 1900)) {
return 366;
}
return 365;
}
int
days_this_year (void)
/* How many days does this year have */
{
struct tm time_record;
time_t current_time;
time (&current_time);
localtime_r (&current_time, &time_record);
if (leap(time_record.tm_year + 1900)) {
return 366;
}
return 365;
}
/*
Anacron - run commands periodically
Copyright (C) 1998 Itai Tzur <itzur@actcom.co.il>
Copyright (C) 1999 Sean 'Shaleh' Perry <shaleh@debian.org>
Copyright (C) 2004 Pascal Hakim <pasc@redellipse.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
The GNU General Public License can also be found in the file
`COPYING' that comes with the Anacron source distribution.
*/
int day_num(int year, int month, int day);
int days_last_month (void);
int days_this_month (void);
int days_last_year (void);
int days_this_year (void);
/*
Anacron - run commands periodically
Copyright (C) 1998 Itai Tzur <itzur@actcom.co.il>
Copyright (C) 1999 Sean 'Shaleh' Perry <shaleh@debian.org>