This change makes files to include what they need, instead of having
generic inclusion headers which will include everything to everywhere.
Also the local headers havee ifndef & define protection, which makes them
to be save to include in any file, without one having to think in which
order the inclusions happen at compile time.
Signed-off-by: Sami Kerola <kerolasa(a)iki.fi>
---
src/Makefile.am | 2 +-
src/cron.c | 26 +++++++++++++++++++++++++-
src/cron.h | 51 ---------------------------------------------------
src/crontab.c | 28 +++++++++++++++++++++++++++-
src/database.c | 20 +++++++++++++++++++-
src/do_command.c | 21 ++++++++++++++++++++-
src/entry.c | 16 +++++++++++++++-
src/env.c | 10 +++++++++-
src/externs.h | 44 ++++----------------------------------------
src/funcs.h | 11 ++++++++++-
src/globals.h | 9 +++++++++
src/job.c | 7 ++++++-
src/macros.h | 6 ++++++
src/misc.c | 24 +++++++++++++++++++++---
src/popen.c | 15 ++++++++++++++-
src/pw_dup.c | 6 +++++-
src/security.c | 15 ++++++++++++++-
src/structs.h | 9 +++++++++
src/user.c | 10 +++++++++-
19 files changed, 223 insertions(+), 107 deletions(-)
delete mode 100644 src/cron.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 60dd103..86e7dc3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,7 +7,7 @@ crond_SOURCES = \
cron.c database.c user.c job.c do_command.c popen.c \
$(common_src)
crontab_SOURCES = crontab.c $(common_src)
-common_src = entry.c env.c misc.c pw_dup.c security.c cron.h \
+common_src = entry.c env.c misc.c pw_dup.c security.c \
externs.h funcs.h globals.h macros.h pathnames.h structs.h \
bitstring.h
common_nodist = cron-paths.h
diff --git a/src/cron.c b/src/cron.c
index 0c37fa4..d68f282 100644
--- a/src/cron.c
+++ b/src/cron.c
@@ -24,9 +24,33 @@
* to add clustering support.
*/
+#include "config.h"
+
#define MAIN_PROGRAM
-#include <cron.h>
+#include <errno.h>
+#include <langinfo.h>
+#include <locale.h>
+#include <pwd.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+#ifdef WITH_INOTIFY
+# include <sys/inotify.h>
+#endif
+
+#ifdef HAVE_SYS_FCNTL_H
+# include <sys/fcntl.h>
+#endif
+
+#include "funcs.h"
+#include "globals.h"
+#include "pathnames.h"
#if defined WITH_INOTIFY
int inotify_enabled;
diff --git a/src/cron.h b/src/cron.h
deleted file mode 100644
index dff8fc1..0000000
--- a/src/cron.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/* Copyright 1988,1990,1993,1994 by Paul Vixie
- * All rights reserved
- */
-
-/*
- * 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.
- */
-
-/* cron.h - header for vixie's cron
- *
- * $Id: cron.h,v 1.6 2004/01/23 18:56:42 vixie Exp $
- *
- * vix 14nov88 [rest of log is in RCS]
- * vix 14jan87 [0 or 7 can be sunday; thanks, mwm@berkeley]
- * vix 30dec86 [written]
- */
-
-#include "../config.h"
-#include "externs.h"
-
-#ifdef WITH_SELINUX
-#include <selinux/selinux.h>
-#endif
-
-#ifdef WITH_PAM
-#include <security/pam_appl.h>
-#endif
-
-#ifdef WITH_INOTIFY
-#include <sys/inotify.h>
-#endif
-
-#include "pathnames.h"
-#include "macros.h"
-#include "structs.h"
-#include "funcs.h"
-#include "globals.h"
-
diff --git a/src/crontab.c b/src/crontab.c
index baec62c..ce4664d 100644
--- a/src/crontab.c
+++ b/src/crontab.c
@@ -29,15 +29,41 @@
* to add clustering support.
*/
+#include "config.h"
+
#define MAIN_PROGRAM
-#include <cron.h>
+#include <errno.h>
+#include <locale.h>
+#include <pwd.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <utime.h>
+
+#ifdef WITH_PAM
+# include <security/pam_appl.h>
+#endif
+
#ifdef WITH_SELINUX
# include <selinux/selinux.h>
# include <selinux/context.h>
# include <selinux/av_permissions.h>
#endif
+#include "bitstring.h"
+#include "externs.h"
+#include "funcs.h"
+#include "globals.h"
+#include "macros.h"
+#include "pathnames.h"
+#include "structs.h"
+
#define NHEADER_LINES 0
enum opt_t {opt_unknown, opt_list, opt_delete, opt_edit, opt_replace, opt_hostset,
opt_hostget};
diff --git a/src/database.c b/src/database.c
index 7fe4f7b..c8f386f 100644
--- a/src/database.c
+++ b/src/database.c
@@ -27,7 +27,25 @@
* to add clustering support.
*/
-#include <cron.h>
+#include "config.h"
+
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <pwd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#ifdef WITH_INOTIFY
+# include <sys/inotify.h>
+#endif
+
+#include "funcs.h"
+#include "globals.h"
+#include "pathnames.h"
#define TMAX(a,b) ((a)>(b)?(a):(b))
diff --git a/src/do_command.c b/src/do_command.c
index 92bc448..8349877 100644
--- a/src/do_command.c
+++ b/src/do_command.c
@@ -19,7 +19,26 @@
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <cron.h>
+#include "config.h"
+
+#include <ctype.h>
+#include <errno.h>
+#include <pwd.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+#include "externs.h"
+#include "funcs.h"
+#include "globals.h"
+#include "structs.h"
+
+#ifndef isascii
+# define isascii(c) ((unsigned)(c)<=0177)
+#endif
static int child_process(entry *, char **);
static int safe_p(const char *, const char *);
diff --git a/src/entry.c b/src/entry.c
index f6a45bb..78c8a85 100644
--- a/src/entry.c
+++ b/src/entry.c
@@ -26,7 +26,21 @@
* vix 30dec86 [written]
*/
-#include <cron.h>
+#include "config.h"
+
+#include <ctype.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "bitstring.h"
+#include "funcs.h"
+#include "globals.h"
+#include "macros.h"
+#include "pathnames.h"
typedef enum ecode {
e_none, e_minute, e_hour, e_dom, e_month, e_dow,
diff --git a/src/env.c b/src/env.c
index 61ae74c..037d7c8 100644
--- a/src/env.c
+++ b/src/env.c
@@ -19,7 +19,15 @@
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <cron.h>
+#include "config.h"
+
+#include <ctype.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "globals.h"
+#include "funcs.h"
char **env_init(void) {
char **p = (char **) malloc(sizeof (char *));
diff --git a/src/externs.h b/src/externs.h
index 9c01d2c..c79ca3b 100644
--- a/src/externs.h
+++ b/src/externs.h
@@ -21,40 +21,8 @@
/* reorder these #include's at your peril */
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/wait.h>
-#ifdef HAVE_SYS_FCNTL_H
-#include <sys/fcntl.h>
-#endif
-#include <sys/file.h>
-/* stat is used even, when --with-inotify */
-#include <sys/stat.h>
-
-#include <bitstring.h>
-#include <ctype.h>
-#ifndef isascii
-#define isascii(c) ((unsigned)(c)<=0177)
-#endif
-#include <dirent.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <grp.h>
-#include <locale.h>
-#include <pwd.h>
-#include <signal.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-#include <utime.h>
-
-#if defined(SYSLOG)
-# include <syslog.h>
-#endif
+#ifndef CRONIE_EXTERNS_H
+#define CRONIE_EXTERNS_H
#if defined(LOGIN_CAP)
# include <login_cap.h>
@@ -64,12 +32,6 @@
# include <bsd_auth.h>
#endif /*BSD_AUTH*/
-/* include locale stuff for mailer "Content-Type":
- */
-#include <locale.h>
-#include <nl_types.h>
-#include <langinfo.h>
-
#define DIR_T struct dirent
#define WAIT_T int
#define SIG_T sig_t
@@ -125,3 +87,5 @@ extern int flock(int, int);
#ifndef WCOREDUMP
# define WCOREDUMP(st) (((st) & 0200) != 0)
#endif
+
+#endif /* CRONIE_EXTERNS_H */
diff --git a/src/funcs.h b/src/funcs.h
index e796574..d16d40e 100644
--- a/src/funcs.h
+++ b/src/funcs.h
@@ -20,10 +20,17 @@
*/
/* Notes:
- * This file has to be included by cron.h after data structure defs.
* We should reorg this into sections by module.
*/
+#ifndef CRONIE_FUNCS_H
+#define CRONIE_FUNCS_H
+
+#include <stdio.h>
+
+#include "externs.h"
+#include "structs.h"
+
void set_cron_uid(void),
check_spool_dir(void),
open_logfile(void),
@@ -111,3 +118,5 @@ int crontab_security_access(void);
/* PAM */
int cron_start_pam(struct passwd *pw);
void cron_close_pam(void);
+
+#endif /* CRONIE_FUNCS_H */
diff --git a/src/globals.h b/src/globals.h
index 8abdb73..4370974 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -24,6 +24,13 @@
* to add clustering support.
*/
+#ifndef CRONIE_GLOBALS_H
+#define CRONIE_GLOBALS_H
+
+#include <time.h>
+
+#include "macros.h"
+
#ifdef MAIN_PROGRAM
# define XTRN
# define INIT(x) = x
@@ -88,3 +95,5 @@ XTRN const char *DebugFlagNames[]
#else
#define DebugFlags 0
#endif /* DEBUGGING */
+
+#endif /* CRONIE_GLOBALS_H */
diff --git a/src/job.c b/src/job.c
index 5ea7d98..8ad14db 100644
--- a/src/job.c
+++ b/src/job.c
@@ -19,7 +19,12 @@
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <cron.h>
+#include "config.h"
+
+#include <stdlib.h>
+
+#include "funcs.h"
+#include "globals.h"
typedef struct _job {
struct _job *next;
diff --git a/src/macros.h b/src/macros.h
index 4981a01..fbf40b1 100644
--- a/src/macros.h
+++ b/src/macros.h
@@ -18,6 +18,10 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+
+#ifndef CRONIE_MACROS_H
+#define CRONIE_MACROS_H
+
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
@@ -130,3 +134,5 @@
#ifndef O_NOFOLLOW
#define O_NOFOLLOW 0
#endif
+
+#endif /* CRONIE_MACROS_H */
diff --git a/src/misc.c b/src/misc.c
index c08827b..70c7daf 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -23,7 +23,22 @@
* vix 30dec86 [written]
*/
-#include <cron.h>
+#include "config.h"
+
+#include "globals.h"
+
+#include <ctype.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+
+#if defined(SYSLOG)
+# include <syslog.h>
+#endif
+
#ifdef WITH_AUDIT
# include <libaudit.h>
#endif
@@ -37,7 +52,10 @@
#ifdef HAVE_FLOCK /* flock(2) */
# include <sys/file.h>
#endif
-#include <stdio.h>
+
+#include "funcs.h"
+#include "macros.h"
+#include "pathnames.h"
#if defined(SYSLOG) && defined(LOG_FILE)
# undef LOG_FILE
@@ -619,7 +637,7 @@ char *first_word(const char *s, const char *t) {
/* warning:
* heavily ascii-dependent.
*/
-void mkprint(char *dst, unsigned char *src, int len) {
+static void mkprint(char *dst, unsigned char *src, int len) {
/*
* XXX
* We know this routine can't overflow the dst buffer because mkprints()
diff --git a/src/popen.c b/src/popen.c
index caa7e8a..aa36ff7 100644
--- a/src/popen.c
+++ b/src/popen.c
@@ -30,11 +30,24 @@
*
*/
+#include "config.h"
+
+#include <errno.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+#include "funcs.h"
+#include "globals.h"
+#include "macros.h"
+
#ifdef HAVE_SYS_CDEFS_H
# include <sys/cdefs.h>
#endif
-#include <cron.h>
#include <signal.h>
/*
diff --git a/src/pw_dup.c b/src/pw_dup.c
index 23da57e..ea787cd 100644
--- a/src/pw_dup.c
+++ b/src/pw_dup.c
@@ -30,7 +30,8 @@
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <config.h>
+#include "config.h"
+
#include <sys/param.h>
#if !defined(OpenBSD) || OpenBSD < 200105
@@ -40,6 +41,9 @@
#include <stdio.h>
#include <string.h>
+#include "funcs.h"
+#include "globals.h"
+
struct passwd *
pw_dup(const struct passwd *pw) {
char *cp;
diff --git a/src/security.c b/src/security.c
index e27bddc..405dd5d 100644
--- a/src/security.c
+++ b/src/security.c
@@ -19,7 +19,20 @@
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <cron.h>
+#include "config.h"
+
+#include <errno.h>
+#include <grp.h>
+#include <pwd.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "funcs.h"
+#include "globals.h"
+
+#ifdef WITH_PAM
+# include <security/pam_appl.h>
+#endif
#ifdef WITH_SELINUX
# include <selinux/selinux.h>
diff --git a/src/structs.h b/src/structs.h
index 16cd180..99d050e 100644
--- a/src/structs.h
+++ b/src/structs.h
@@ -19,6 +19,13 @@
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#ifndef CRONIE_STRUCTS_H
+#define CRONIE_STRUCTS_H
+
+#include <time.h>
+#include "macros.h"
+#include "bitstring.h"
+
typedef struct _entry {
struct _entry *next;
struct passwd *pwd;
@@ -75,3 +82,5 @@ typedef struct _cron_db {
* variables for the main program, just
* extern them elsewhere.
*/
+
+#endif /* CRONIE_STRUCTS_H */
diff --git a/src/user.c b/src/user.c
index 367f963..9b11d01 100644
--- a/src/user.c
+++ b/src/user.c
@@ -22,7 +22,15 @@
/* vix 26jan87 [log is in RCS file]
*/
-#include <cron.h>
+#include "config.h"
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "funcs.h"
+#include "globals.h"
static const char *FileName;
--
1.8.0