Index: trunk/minix/commands/cron/Makefile
===================================================================
--- trunk/minix/commands/cron/Makefile	(revision 9)
+++ 	(revision )
@@ -1,34 +1,0 @@
-# Makefile for cron.
-
-CFLAGS=		-D_MINIX -D_POSIX_SOURCE
-CC = exec cc
-LDFLAGS=
-
-all:	cron crontab
-
-CRON_OBJ=	cron.o tab.o misc.o
-CRONTAB_OBJ=	crontab.o tab.o misc.o
-
-cron:	$(CRON_OBJ)
-	$(CC) $(LDFLAGS) -o $@ $(CRON_OBJ)
-	install -S 8kw $@
-
-crontab:	$(CRONTAB_OBJ)
-	$(CC) $(LDFLAGS) -o $@ $(CRONTAB_OBJ)
-	install -S 4kw $@
-
-install:	/usr/bin/cron /usr/bin/crontab
-
-/usr/bin/cron:	cron
-	install -cs $? $@
-
-/usr/bin/crontab:	crontab
-	install -cs -o root -m 4755 $? $@
-
-clean:
-	rm -f *.o cron crontab core a.out
-
-# Dependencies.
-cron.o crontab.o:	misc.h tab.h
-tab.o:			misc.h tab.h
-misc.o:			misc.h
Index: trunk/minix/commands/cron/build
===================================================================
--- trunk/minix/commands/cron/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/cron/cron.c
===================================================================
--- trunk/minix/commands/cron/cron.c	(revision 9)
+++ 	(revision )
@@ -1,465 +1,0 @@
-/*	cron 1.4 - clock daemon				Author: Kees J. Bot
- *								7 Dec 1996
- */
-
-#define _MINIX_SOURCE
-#define _MINIX 1
-
-#define nil ((void*)0)
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <limits.h>
-#include <dirent.h>
-#include <time.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <pwd.h>
-#include <grp.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include "misc.h"
-#include "tab.h"
-
-#if __minix && !__minix_vmd
-#define initgroups(name, gid)	(0)
-#endif
-
-static volatile int busy;	/* Set when something is afoot, don't sleep! */
-static volatile int need_reload;/* Set if table reload required. */
-static volatile int need_quit;	/* Set if cron must exit. */
-static volatile int debug;	/* Debug level. */
-
-static void run_job(cronjob_t *job)
-/* Execute a cron job.  Register its pid in the job structure.  If a job's
- * crontab has an owner then its output is mailed to that owner, otherwise
- * no special provisions are made, so the output will go where cron's output
- * goes.  This keeps root's mailbox from filling up.
- */
-{
-	pid_t pid;
-	int need_mailer;
-	int mailfd[2], errfd[2];
-	struct passwd *pw;
-	crontab_t *tab= job->tab;
-
-	need_mailer= (tab->user != nil);
-
-	if (job->atjob) {
-		struct stat st;
-
-		need_mailer= 1;
-		if (rename(tab->file, tab->data) < 0) {
-			if (errno == ENOENT) {
-				/* Normal error, job deleted. */
-				need_reload= 1;
-			} else {
-				/* Bad error, halt processing AT jobs. */
-				log(LOG_CRIT, "Can't rename %s: %s\n",
-					tab->file, strerror(errno));
-				tab_reschedule(job);
-			}
-			return;
-		}
-		/* Will need to determine the next AT job. */
-		need_reload= 1;
-
-		if (stat(tab->data, &st) < 0) {
-			log(LOG_ERR, "Can't stat %s: %s\n",
-						tab->data, strerror(errno));
-			tab_reschedule(job);
-			return;
-		}
-		if ((pw= getpwuid(st.st_uid)) == nil) {
-			log(LOG_ERR, "Unknown owner for uid %lu of AT job %s\n",
-				(unsigned long) st.st_uid, job->cmd);
-			tab_reschedule(job);
-			return;
-		}
-	} else {
-		pw= nil;
-		if (job->user != nil && (pw= getpwnam(job->user)) == nil) {
-			log(LOG_ERR, "%s: Unknown user\n", job->user);
-			tab_reschedule(job);
-			return;
-		}
-	}
-
-	if (need_mailer) {
-		errfd[0]= -1;
-		if (pipe(errfd) < 0 || pipe(mailfd) < 0) {
-			log(LOG_ERR, "pipe() call failed: %s\n",
-							strerror(errno));
-			if (errfd[0] != -1) {
-				close(errfd[0]);
-				close(errfd[1]);
-			}
-			tab_reschedule(job);
-			return;
-		}
-		(void) fcntl(errfd[1], F_SETFD,
-				fcntl(errfd[1], F_GETFD) | FD_CLOEXEC);
-
-		if ((pid= fork()) == -1) {
-			log(LOG_ERR, "fork() call failed: %s\n",
-							strerror(errno));
-			close(errfd[0]);
-			close(errfd[1]);
-			close(mailfd[0]);
-			close(mailfd[1]);
-			tab_reschedule(job);
-			return;
-		}
-
-		if (pid == 0) {
-			/* Child that is to be the mailer. */
-			char subject[70+20], *ps;
-
-			close(errfd[0]);
-			close(mailfd[1]);
-			if (mailfd[0] != 0) {
-				dup2(mailfd[0], 0);
-				close(mailfd[0]);
-			}
-
-			memset(subject, 0, sizeof(subject));
-			sprintf(subject,
-				"Output from your %s job: %.50s",
-				job->atjob ? "AT" : "cron",
-				job->cmd);
-			if (subject[70] != 0) {
-				strcpy(subject+70-3, "...");
-			}
-			for (ps= subject; *ps != 0; ps++) {
-				if (*ps == '\n') *ps= '%';
-			}
-
-			execl("/usr/bin/mail", "mail", "-s", subject,
-						pw->pw_name, (char *) nil);
-			write(errfd[1], &errno, sizeof(errno));
-			_exit(1);
-		}
-
-		close(mailfd[0]);
-		close(errfd[1]);
-		if (read(errfd[0], &errno, sizeof(errno)) > 0) {
-			log(LOG_ERR, "can't execute /usr/bin/mail: %s\n",
-							strerror(errno));
-			close(errfd[0]);
-			close(mailfd[1]);
-			tab_reschedule(job);
-			return;
-		}
-		close(errfd[0]);
-	}
-
-	if (pipe(errfd) < 0) {
-		log(LOG_ERR, "pipe() call failed: %s\n", strerror(errno));
-		if (need_mailer) close(mailfd[1]);
-		tab_reschedule(job);
-		return;
-	}
-	(void) fcntl(errfd[1], F_SETFD, fcntl(errfd[1], F_GETFD) | FD_CLOEXEC);
-
-	if ((pid= fork()) == -1) {
-		log(LOG_ERR, "fork() call failed: %s\n", strerror(errno));
-		close(errfd[0]);
-		close(errfd[1]);
-		if (need_mailer) close(mailfd[1]);
-		tab_reschedule(job);
-		return;
-	}
-
-	if (pid == 0) {
-		/* Child that is to be the cron job. */
-		close(errfd[0]);
-		if (need_mailer) {
-			if (mailfd[1] != 1) {
-				dup2(mailfd[1], 1);
-				close(mailfd[1]);
-			}
-			dup2(1, 2);
-		}
-
-		if (pw != nil) {
-			/* Change id to the owner of the job. */
-			initgroups(pw->pw_name, pw->pw_gid);
-			setgid(pw->pw_gid);
-			setuid(pw->pw_uid);
-			chdir(pw->pw_dir);
-			if (setenv("USER", pw->pw_name, 1) < 0) goto bad;
-			if (setenv("LOGNAME", pw->pw_name, 1) < 0) goto bad;
-			if (setenv("HOME", pw->pw_dir, 1) < 0) goto bad;
-			if (setenv("SHELL", pw->pw_shell[0] == 0 ? "/bin/sh"
-						: pw->pw_shell, 1) < 0) goto bad;
-		}
-
-		if (job->atjob) {
-			execl("/bin/sh", "sh", tab->data, (char *) nil);
-		} else {
-			execl("/bin/sh", "sh", "-c", job->cmd, (char *) nil);
-		}
-	    bad:
-		write(errfd[1], &errno, sizeof(errno));
-		_exit(1);
-	}
-
-	if (need_mailer) close(mailfd[1]);
-	close(errfd[1]);
-	if (read(errfd[0], &errno, sizeof(errno)) > 0) {
-		log(LOG_ERR, "can't execute /bin/sh: %s\n", strerror(errno));
-		close(errfd[0]);
-		tab_reschedule(job);
-		return;
-	}
-	close(errfd[0]);
-	job->pid= pid;
-	if (debug >= 1) fprintf(stderr, "executing >%s<, pid = %ld\n",
-						job->cmd, (long) job->pid);
-}
-
-static void load_crontabs(void)
-/* Load all the crontabs we like to run.  We didn't bother to make a list in
- * an array or something, this is too system specific to make nice.
- */
-{
-	DIR *spool;
-#if __minix_vmd
-	FILE *pkgs;
-#endif
-
-	tab_parse("/usr/lib/crontab", nil);
-	tab_parse("/usr/local/lib/crontab", nil);
-	tab_parse("/var/lib/crontab", nil);
-
-#if __minix_vmd
-	if ((pkgs= fopen("/usr/lib/packages", "r")) != nil) {
-		char name[NAME_MAX+1];
-		char *np;
-		int c;
-		char tab[sizeof("/var/opt//lib/crontab") + NAME_MAX];
-
-		while ((c= fgetc(pkgs)) != EOF) {
-			np= name;
-			while (c != EOF && c != '/' && c != '\n') {
-				if (np < name+NAME_MAX) *np++ = c;
-				c= fgetc(pkgs);
-			}
-			*np= 0;
-			while (c != EOF && c != '\n') c= fgetc(pkgs);
-
-			if (name[0] == 0) continue;	/* ? */
-
-			strcpy(tab, "/var/opt/");
-			strcat(tab, name);
-			strcat(tab, "/lib/crontab");
-			tab_parse(tab, nil);
-		}
-		if (ferror(pkgs)) {
-			log(LOG_CRIT, "/usr/lib/packages: %s\n",
-							strerror(errno));
-		}
-		fclose(pkgs);
-	} else {
-		if (errno != ENOENT) {
-			log(LOG_ERR, "/usr/lib/packages: %s\n",
-							strerror(errno));
-		}
-	}
-#endif /* Minix-vmd */
-
-	if ((spool= opendir("/usr/spool/crontabs")) != nil) {
-		struct dirent *entry;
-		char tab[sizeof("/usr/spool/crontabs/") + NAME_MAX];
-
-		while ((entry= readdir(spool)) != nil) {
-			if (entry->d_name[0] == '.') continue;
-
-			strcpy(tab, "/usr/spool/crontabs/");
-			strcat(tab, entry->d_name);
-			tab_parse(tab, entry->d_name);
-		}
-		closedir(spool);
-	}
-
-	/* Find the first to be executed AT job. */
-	tab_find_atjob("/usr/spool/at");
-
-	tab_purge();
-	if (debug >= 2) {
-		tab_print(stderr);
-		fprintf(stderr, "%lu memory chunks in use\n",
-			(unsigned long) alloc_count);
-	}
-}
-
-static void handler(int sig)
-{
-	switch (sig) {
-	case SIGHUP:
-		need_reload= 1;
-		break;
-	case SIGINT:
-	case SIGTERM:
-		need_quit= 1;
-		break;
-	case SIGUSR1:
-		debug++;
-		break;
-	case SIGUSR2:
-		debug= 0;
-		break;
-	}
-	alarm(1);	/* A signal may come just before a blocking call. */
-	busy= 1;
-}
-
-static void usage(void)
-{
-	fprintf(stderr, "Usage: %s [-d[#]]\n", prog_name);
-	exit(1);
-}
-
-int main(int argc, char **argv)
-{
-	int i;
-	struct sigaction sa, osa;
-	FILE *pf;
-	int r;
-
-	prog_name= strrchr(argv[0], '/');
-	if (prog_name == nil) prog_name= argv[0]; else prog_name++;
-
-	i= 1;
-	while (i < argc && argv[i][0] == '-') {
-		char *opt= argv[i++] + 1;
-
-		if (opt[0] == '-' && opt[1] == 0) break;	/* -- */
-
-		while (*opt != 0) switch (*opt++) {
-		case 'd':
-			if (*opt == 0) {
-				debug= 1;
-			} else {
-				debug= strtoul(opt, &opt, 10);
-				if (*opt != 0) usage();
-			}
-			break;
-		default:
-			usage();
-		}
-	}
-	if (i != argc) usage();
-
-	selectlog(SYSLOG);
-	openlog(prog_name, LOG_PID, LOG_DAEMON);
-	setlogmask(LOG_UPTO(LOG_INFO));
-
-	/* Save process id. */
-	if ((pf= fopen(PIDFILE, "w")) == NULL) {
-		fprintf(stderr, "%s: %s\n", PIDFILE, strerror(errno));
-		exit(1);
-	}
-	fprintf(pf, "%d\n", getpid());
-	if (ferror(pf) || fclose(pf) == EOF) {
-		fprintf(stderr, "%s: %s\n", PIDFILE, strerror(errno));
-		exit(1);
-	}
-
-	sigemptyset(&sa.sa_mask);
-	sa.sa_flags= 0;
-	sa.sa_handler= handler;
-
-	/* Hangup: Reload crontab files. */
-	sigaction(SIGHUP, &sa, nil);
-
-	/* User signal 1 & 2: Raise or reset debug level. */
-	sigaction(SIGUSR1, &sa, nil);
-	sigaction(SIGUSR2, &sa, nil);
-
-	/* Interrupt and Terminate: Cleanup and exit. */
-	if (sigaction(SIGINT, nil, &osa) == 0 && osa.sa_handler != SIG_IGN) {
-		sigaction(SIGINT, &sa, nil);
-	}
-	if (sigaction(SIGTERM, nil, &osa) == 0 && osa.sa_handler != SIG_IGN) {
-		sigaction(SIGTERM, &sa, nil);
-	}
-
-	/* Alarm: Wake up and run a job. */
-	sigaction(SIGALRM, &sa, nil);
-
-	/* Initialize current time and time next to do something. */
-	time(&now);
-	next= NEVER;
-
-	/* Table load required first time. */
-	need_reload= 1;
-
-	do {
-		if (need_reload) {
-			need_reload= 0;
-			load_crontabs();
-			busy= 1;
-		}
-
-		/* Run jobs whose time has come. */
-		if (next <= now) {
-			cronjob_t *job;
-
-			if ((job= tab_nextjob()) != nil) run_job(job);
-			busy= 1;
-		}
-
-		if (busy) {
-			/* Did a job finish? */
-			r= waitpid(-1, nil, WNOHANG);
-			busy= 0;
-		} else {
-			/* Sleep until the next job must be started. */
-			if (next == NEVER) {
-				alarm(0);
-			} else {
-#if __minix_vmd
-				struct timeval tvnext;
-
-				tvnext.tv_sec= next;
-				tvnext.tv_usec= 0;
-				sysutime(UTIME_SETALARM, &tvnext);
-#else
-				alarm((next - now) > INT_MAX
-						? INT_MAX : (next - now));
-#endif
-			}
-			if (debug >= 1) fprintf(stderr, "%s: sleep until %s",
-						prog_name, ctime(&next));
-
-			closelog();	/* Don't keep resources open. */
-
-			/* Wait for a job to exit or a timeout. */
-			r= waitpid(-1, nil, 0);
-			if (r == -1 && errno == ECHILD) pause();
-			alarm(0);
-			time(&now);
-		}
-
-		if (r > 0) {
-			/* A job has finished, reschedule it. */
-			if (debug >= 1) fprintf(stderr, "pid %d has exited\n",
-									r);
-			tab_reap_job((pid_t) r);
-			busy= 1;
-		}
-	} while (!need_quit);
-
-	/* Remove the pid file to signal that cron is gone. */
-	unlink(PIDFILE);
-
-	return 0;
-}
-
-/*
- * $PchId: cron.c,v 1.4 2000/07/17 19:00:35 philip Exp $
- */
Index: trunk/minix/commands/cron/crontab.c
===================================================================
--- trunk/minix/commands/cron/crontab.c	(revision 9)
+++ 	(revision )
@@ -1,258 +1,0 @@
-/*	crontab 1.2 - user crontab manipulation		Author: Kees J. Bot
- *								12 Jan 1997
- */
-#define nil ((void*)0)
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <time.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <pwd.h>
-#include <sys/stat.h>
-#include "misc.h"
-#include "tab.h"
-
-#if __minix && !__minix_vmd
-#define seteuid(uid)	((uid),0)	/* Minix can't fiddle with uids. */
-#endif
-
-static int opentab(int uid, char *file, int how)
-/* Open a crontab file under the given uid.  How is 'r' or 'w'.  Return
- * the result of open(2).
- */
-{
-	uid_t safe_uid;
-	int flags, r, err;
-
-	switch (how) {
-	case 'r':	flags= O_RDONLY;			break;
-	case 'w':	flags= O_WRONLY | O_CREAT | O_TRUNC;	break;
-	default:	errno= EINVAL;				return -1;
-	}
-
-#if __minix && !__minix_vmd
-	/* Standard Minix has no saved uid, so use the lousy old access(). */
-	if (uid != 0) {
-		if (access(file, how == 'r' ? R_OK : W_OK) < 0) return -1;
-	}
-#endif
-
-	safe_uid= geteuid();
-	seteuid(uid);
-	r= open(file, flags, 0666);
-	err= errno;
-	seteuid(safe_uid);
-	errno= err;
-	return r;
-}
-
-static void copytab(int fd_in, char *file_in, int fd_out, char *file_out)
-/* Copy one open file to another.  Complain and exit on errors. */
-{
-	ssize_t r, w;
-	char buf[1024];
-
-	while ((r= read(fd_in, buf, sizeof(buf))) > 0) {
-		w= 0;
-		while (w < r) {
-			if ((r= write(fd_out, buf+w, r-w)) <= 0) {
-				fprintf(stderr,
-				"%s: Write error on %s: %s\n",
-					prog_name,
-					file_out,
-					r == 0 ? "End of file"
-							: strerror(errno));
-				exit(1);
-			}
-			w+= r;
-		}
-	}
-	if (r < 0) {
-		fprintf(stderr, "%s: Read error on %s: %s\n",
-			prog_name, file_in, strerror(errno));
-		exit(1);
-	}
-}
-
-static void usage(void)
-{
-	fprintf(stderr,
-		"Usage: %s -c [user] file  # Change crontab\n"
-		"       %s -l [user]       # List crontab\n"
-		"       %s -r [user]       # Remove crontab\n"
-		"       %s -p              # Tell cron to reload\n",
-		prog_name, prog_name, prog_name, prog_name);
-	exit(1);
-}
-
-int main(int argc, char **argv)
-{
-	int i;
-	int cflag, lflag, rflag, pflag;
-	uid_t uid;
-	char *user, *file;
-	struct passwd *pw;
-	static char SPOOLDIR[]= "/usr/spool/crontabs";
-	char tabfile[sizeof(SPOOLDIR) + NAME_MAX];
-
-	prog_name= strrchr(argv[0], '/');
-	if (prog_name == nil) prog_name= argv[0]; else prog_name++;
-
-	cflag= lflag= rflag= pflag= 0;
-	i= 1;
-	while (i < argc && argv[i][0] == '-') {
-		char *opt= argv[i++] + 1;
-
-		if (opt[0] == '-' && opt[1] == 0) break;	/* -- */
-
-		while (*opt != 0) switch (*opt++) {
-		case 'c':	cflag= 1;	break;
-		case 'l':	lflag= 1;	break;
-		case 'r':	rflag= 1;	break;
-		case 'p':	pflag= 1;	break;
-		default:	usage();
-		}
-	}
-	if (cflag + lflag + rflag + pflag != 1) usage();
-
-	user= file= nil;
-	if (!pflag && i < argc) user= argv[i++];
-	if (cflag) {
-		if (user == nil) usage();
-		if (i < argc) {
-			file= argv[i++];
-		} else {
-			file= user;
-			user= nil;
-		}
-	}
-	if (i != argc) usage();
-
-	if (geteuid() != 0) {
-		fprintf(stderr, "%s: No root privileges?\n", prog_name);
-	}
-	uid= getuid();
-	if (user == nil) {
-		if ((pw= getpwuid(uid)) == nil) {
-			fprintf(stderr,
-				"%s: Don't know who you (uid %lu) are!\n",
-				prog_name, (unsigned long) uid);
-			exit(1);
-		}
-	} else {
-		if ((pw= getpwnam(user)) == nil) {
-			fprintf(stderr,
-				"%s: Don't know who you (%s) are!\n",
-				prog_name, user);
-			exit(1);
-		}
-	}
-	if (uid != 0 && pw->pw_uid != uid) {
-		fprintf(stderr,
-		"%s: Only root can change the crontabs of others!\n",
-			prog_name);
-		exit(1);
-	}
-	user= pw->pw_name;
-	uid= pw->pw_uid;
-	seteuid(uid);
-	umask(0077);
-
-	selectlog(STDERR);
-	sprintf(tabfile, "%s/%s", SPOOLDIR, user);
-
-	if (lflag) {
-		int fd;
-
-		if ((fd= opentab(0, tabfile, 'r')) < 0) {
-			fprintf(stderr, "%s: Can't open %s: %s\n",
-				prog_name, tabfile, strerror(errno));
-			exit(1);
-		}
-		copytab(fd, tabfile, 1, "stdout");
-		close(fd);
-	}
-
-	if (rflag) {
-		seteuid(0);
-		if (unlink(tabfile) < 0) {
-			fprintf(stderr, "%s: Can't remove %s: %s\n",
-				prog_name, tabfile, strerror(errno));
-			exit(1);
-		}
-		seteuid(uid);
-		printf("Crontab of %s removed\n", user);
-		pflag= 1;
-	}
-
-	/* Initialize current Time */
-	time(&now);
-
-	if (cflag) {
-		int fd1, fd2;
-
-		if ((fd1= opentab(uid, file, 'r')) < 0) {
-			fprintf(stderr, "%s: Can't open %s: %s\n",
-				prog_name, file, strerror(errno));
-			exit(1);
-		}
-
-		/* Try to parse the new crontab file.  If the parsing
-		 * succeeds then 'crontabs' will be non-null.
-		 */
-		tab_parse(file, user);
-		tab_purge();
-		if (crontabs == nil) exit(1);
-
-		if ((fd2= opentab(0, tabfile, 'w')) < 0) {
-			fprintf(stderr, "%s: Can't open %s: %s\n",
-				prog_name, tabfile, strerror(errno));
-			exit(1);
-		}
-		copytab(fd1, file, fd2, tabfile);
-		close(fd1);
-		close(fd2);
-		printf("New crontab for %s installed\n", user);
-		pflag= 1;
-	}
-
-	if (pflag) {
-		/* Alert cron to the new situation. */
-		FILE *fp;
-
-		seteuid(0);
-		if ((fp= fopen(PIDFILE, "r")) != NULL) {
-			unsigned long pid;
-			int c;
-
-			pid= 0;
-			while ((c= fgetc(fp)) != EOF && c != '\n') {
-				if ((unsigned) (c - '0') >= 10) {
-					pid= 0; break;
-				}
-				pid= 10*pid + (c - '0');
-				if (pid >= 30000) { pid= 0; break; }
-			}
-			if (pid > 1 && kill((pid_t) pid, SIGHUP) == 0) {
-				pflag= 0;
-			}
-		}
-		seteuid(uid);
-		if (pflag) {
-			fprintf(stderr,
-			"%s: Alerting cron has failed; cron still running?\n",
-				prog_name);
-			exit(1);
-		}
-		printf("Cron signalled to reload tables\n");
-	}
-	return 0;
-}
-
-/*
- * $PchId: crontab.c,v 1.4 2000/07/17 18:54:50 philip Exp $
- */
Index: trunk/minix/commands/cron/misc.c
===================================================================
--- trunk/minix/commands/cron/misc.c	(revision 9)
+++ 	(revision )
@@ -1,68 +1,0 @@
-/*	misc.c - Miscellaneous stuff for cron		Author: Kees J. Bot
- *								12 Jan 1997
- */
-#define nil ((void*)0)
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <time.h>
-#include "misc.h"
-
-char *prog_name;		/* Name of this program. */
-time_t now;			/* Cron's idea of the current time. */
-time_t next;			/* Time to run the next job. */
-
-size_t alloc_count;		/* # Of chunks of memory allocated. */
-
-void *allocate(size_t len)
-/* Checked malloc().  Better not feed it length 0. */
-{
-	void *mem;
-
-	if ((mem= malloc(len)) == nil) {
-		log(LOG_ALERT, "Out of memory, exiting\n");
-		exit(1);
-	}
-	alloc_count++;
-	return mem;
-}
-
-void deallocate(void *mem)
-{
-	if (mem != nil) {
-		free(mem);
-		alloc_count--;
-	}
-}
-
-static enum logto logto= SYSLOG;
-
-void selectlog(enum logto where)
-/* Select where logging output should go, syslog or stdout. */
-{
-	logto= where;
-}
-
-void log(int level, const char *fmt, ...)
-/* Like syslog(), but may go to stderr. */
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-
-#if __minix_vmd || !__minix
-	if (logto == SYSLOG) {
-		vsyslog(level, fmt, ap);
-	} else
-#endif
-	{
-		fprintf(stderr, "%s: ", prog_name);
-		vfprintf(stderr, fmt, ap);
-	}
-	va_end(ap);
-}
-
-/*
- * $PchId: misc.c,v 1.3 2000/07/17 19:01:57 philip Exp $
- */
Index: trunk/minix/commands/cron/misc.h
===================================================================
--- trunk/minix/commands/cron/misc.h	(revision 9)
+++ 	(revision )
@@ -1,42 +1,0 @@
-/*	misc.h - miscellaneous stuff			Author: Kees J. Bot
- *								7 Dec 1996
- */
-#ifndef MISC__H
-#define MISC__H
-
-#include <time.h>
-
-/* The name of the program. */
-extern char *prog_name;
-
-/* Where cron stores it pid. */
-#define PIDFILE	"/usr/run/cron.pid"
-
-/* Cron's idea of the current time, and the time next to run something. */
-extern time_t now;
-extern time_t next;
-
-/* Memory allocation. */
-void *allocate(size_t len);
-void deallocate(void *mem);
-extern size_t alloc_count;
-
-/* Logging, by syslog or to stderr. */
-#if __minix_vmd || !__minix
-#include <sys/syslog.h>
-#else
-enum log_dummy { LOG_ERR, LOG_CRIT, LOG_ALERT };
-#define openlog(ident, opt, facility)	((void) 0)
-#define closelog()			((void) 0)
-#define setlogmask(mask)		(0)
-#endif
-
-enum logto { SYSLOG, STDERR };
-void selectlog(enum logto where);
-void log(int level, const char *fmt, ...);
-
-#endif /* MISC__H */
-
-/*
- * $PchId: misc.h,v 1.3 2000/07/17 18:56:02 philip Exp $
- */
Index: trunk/minix/commands/cron/tab.c
===================================================================
--- trunk/minix/commands/cron/tab.c	(revision 9)
+++ 	(revision )
@@ -1,816 +1,0 @@
-/*	tab.c - process crontabs and create in-core crontab data
- *							Author: Kees J. Bot
- *								7 Dec 1996
- * Changes:
- * 17 Jul 2000 by Philip Homburg
- *	- Tab_reschedule() rewritten (and fixed).
- */
-#define nil ((void*)0)
-#include <sys/types.h>
-#include <assert.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <limits.h>
-#include <time.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include "misc.h"
-#include "tab.h"
-
-static int nextbit(bitmap_t map, int bit)
-/* Return the next bit set in 'map' from 'bit' onwards, cyclic. */
-{
-	for (;;) {
-		bit= (bit+1) & 63;
-		if (bit_isset(map, bit)) break;
-	}
-	return bit;
-}
-
-void tab_reschedule(cronjob_t *job)
-/* Reschedule one job.  Compute the next time to run the job in job->rtime.
- */
-{
-	struct tm prevtm, nexttm, tmptm;
-	time_t nodst_rtime, dst_rtime;
-
-	/* AT jobs are only run once. */
-	if (job->atjob) { job->rtime= NEVER; return; }
-
-	/* Was the job scheduled late last time? */
-	if (job->late) job->rtime= now;
-
-	prevtm= *localtime(&job->rtime);
-	prevtm.tm_sec= 0;
-
-	nexttm= prevtm;
-	nexttm.tm_min++;	/* Minimal increment */
-
-	for (;;)
-	{
-		if (nexttm.tm_min > 59)
-		{
-			nexttm.tm_min= 0;
-			nexttm.tm_hour++;
-		}
-		if (nexttm.tm_hour > 23)
-		{
-			nexttm.tm_min= 0;
-			nexttm.tm_hour= 0;
-			nexttm.tm_mday++;
-		}
-		if (nexttm.tm_mday > 31)
-		{
-			nexttm.tm_hour= nexttm.tm_min= 0;
-			nexttm.tm_mday= 1;
-			nexttm.tm_mon++;
-		}
-		if (nexttm.tm_mon >= 12)
-		{
-			nexttm.tm_hour= nexttm.tm_min= 0;
-			nexttm.tm_mday= 1;
-			nexttm.tm_mon= 0;
-			nexttm.tm_year++;
-		}
-
-		/* Verify tm_year. A crontab entry cannot restrict tm_year
-		 * directly. However, certain dates (such as Feb, 29th) do
-		 * not occur every year. We limit the difference between
-		 * nexttm.tm_year and prevtm.tm_year to detect impossible dates
-		 * (e.g, Feb, 31st). In theory every date occurs within a
-		 * period of 4 years. However, some years at the end of a 
-		 * century are not leap years (e.g, the year 2100). An extra
-		 * factor of 2 should be enough.
-		 */
-		if (nexttm.tm_year-prevtm.tm_year > 2*4)
-		{
-			job->rtime= NEVER;
-			return;			/* Impossible combination */
-		}
-
-		if (!job->do_wday)
-		{
-			/* Verify the mon and mday fields. If do_wday and
-			 * do_mday are both true we have to merge both
-			 * schedules. This is done after the call to mktime.
-			 */
-			if (!bit_isset(job->mon, nexttm.tm_mon))
-			{
-				/* Clear other fields */
-				nexttm.tm_mday= 1;
-				nexttm.tm_hour= nexttm.tm_min= 0;
-
-				nexttm.tm_mon++;
-				continue;
-			}
-
-			/* Verify mday */
-			if (!bit_isset(job->mday, nexttm.tm_mday))
-			{
-				/* Clear other fields */
-				nexttm.tm_hour= nexttm.tm_min= 0;
-
-				nexttm.tm_mday++;
-				continue;
-			}
-		}
-
-		/* Verify hour */
-		if (!bit_isset(job->hour, nexttm.tm_hour))
-		{
-			/* Clear tm_min field */
-			nexttm.tm_min= 0;
-
-			nexttm.tm_hour++;
-			continue;
-		}
-
-		/* Verify min */
-		if (!bit_isset(job->min, nexttm.tm_min))
-		{
-			nexttm.tm_min++;
-			continue;
-		}
-
-		/* Verify that we don't have any problem with DST. Try
-		 * tm_isdst=0 first. */
-		tmptm= nexttm;
-		tmptm.tm_isdst= 0;
-#if 0
-		fprintf(stderr, 
-	"tab_reschedule: trying %04d-%02d-%02d %02d:%02d:%02d isdst=0\n",
-				1900+nexttm.tm_year, nexttm.tm_mon+1,
-				nexttm.tm_mday, nexttm.tm_hour,
-				nexttm.tm_min, nexttm.tm_sec);
-#endif
-		nodst_rtime= job->rtime= mktime(&tmptm);
-		if (job->rtime == -1) {
-			/* This should not happen. */
-			log(LOG_ERR,
-			"mktime failed for %04d-%02d-%02d %02d:%02d:%02d",
-				1900+nexttm.tm_year, nexttm.tm_mon+1,
-				nexttm.tm_mday, nexttm.tm_hour,
-				nexttm.tm_min, nexttm.tm_sec);
-			job->rtime= NEVER;
-			return;	
-		}
-		tmptm= *localtime(&job->rtime);
-		if (tmptm.tm_hour != nexttm.tm_hour ||
-			tmptm.tm_min != nexttm.tm_min)
-		{
-			assert(tmptm.tm_isdst);
-			tmptm= nexttm;
-			tmptm.tm_isdst= 1;
-#if 0
-			fprintf(stderr, 
-	"tab_reschedule: trying %04d-%02d-%02d %02d:%02d:%02d isdst=1\n",
-				1900+nexttm.tm_year, nexttm.tm_mon+1,
-				nexttm.tm_mday, nexttm.tm_hour,
-				nexttm.tm_min, nexttm.tm_sec);
-#endif
-			dst_rtime= job->rtime= mktime(&tmptm);
-			if (job->rtime == -1) {
-				/* This should not happen. */
-				log(LOG_ERR,
-			"mktime failed for %04d-%02d-%02d %02d:%02d:%02d\n",
-					1900+nexttm.tm_year, nexttm.tm_mon+1,
-					nexttm.tm_mday, nexttm.tm_hour,
-					nexttm.tm_min, nexttm.tm_sec);
-				job->rtime= NEVER;
-				return;	
-			}
-			tmptm= *localtime(&job->rtime);
-			if (tmptm.tm_hour != nexttm.tm_hour ||
-				tmptm.tm_min != nexttm.tm_min)
-			{
-				assert(!tmptm.tm_isdst);
-				/* We have a problem. This time neither
-				 * exists with DST nor without DST.
-				 * Use the latest time, which should be
-				 * nodst_rtime.
-				 */
-				assert(nodst_rtime > dst_rtime);
-				job->rtime= nodst_rtime;
-#if 0
-				fprintf(stderr,
-			"During DST trans. %04d-%02d-%02d %02d:%02d:%02d\n",
-					1900+nexttm.tm_year, nexttm.tm_mon+1,
-					nexttm.tm_mday, nexttm.tm_hour,
-					nexttm.tm_min, nexttm.tm_sec);
-#endif
-			}
-		}
-
-		/* Verify this the combination (tm_year, tm_mon, tm_mday). */
-		if (tmptm.tm_mday != nexttm.tm_mday ||
-			tmptm.tm_mon != nexttm.tm_mon ||
-			tmptm.tm_year != nexttm.tm_year)
-		{
-			/* Wrong day */
-#if 0
-			fprintf(stderr, "Wrong day\n");
-#endif
-			nexttm.tm_hour= nexttm.tm_min= 0;
-			nexttm.tm_mday++;
-			continue;
-		}
-
-		/* Check tm_wday */
-		if (job->do_wday && bit_isset(job->wday, tmptm.tm_wday))
-		{
-			/* OK, wday matched */
-			break;
-		}
-
-		/* Check tm_mday */
-		if (job->do_mday && bit_isset(job->mon, tmptm.tm_mon) &&
-			bit_isset(job->mday, tmptm.tm_mday))
-		{
-			/* OK, mon and mday matched */
-			break;
-		}
-
-		if (!job->do_wday && !job->do_mday)
-		{
-			/* No need to match wday and mday */
-			break;
-		}
-
-		/* Wrong day */
-#if 0
-		fprintf(stderr, "Wrong mon+mday or wday\n");
-#endif
-		nexttm.tm_hour= nexttm.tm_min= 0;
-		nexttm.tm_mday++;
-	}
-#if 0
-	fprintf(stderr, "Using %04d-%02d-%02d %02d:%02d:%02d \n",
-		1900+nexttm.tm_year, nexttm.tm_mon+1, nexttm.tm_mday,
-		nexttm.tm_hour, nexttm.tm_min, nexttm.tm_sec);
-	tmptm= *localtime(&job->rtime);
-	fprintf(stderr, "Act. %04d-%02d-%02d %02d:%02d:%02d isdst=%d\n",
-		1900+tmptm.tm_year, tmptm.tm_mon+1, tmptm.tm_mday,
-		tmptm.tm_hour, tmptm.tm_min, tmptm.tm_sec,
-		tmptm.tm_isdst);
-#endif
-
-
-	/* Is job issuing lagging behind with the progress of time? */
-	job->late= (job->rtime < now);
-
-  	/* The result is in job->rtime. */
-  	if (job->rtime < next) next= job->rtime;
-}
-
-#define isdigit(c)	((unsigned) ((c) - '0') < 10)
-
-static char *get_token(char **ptr)
-/* Return a pointer to the next token in a string.  Move *ptr to the end of
- * the token, and return a pointer to the start.  If *ptr == start of token
- * then we're stuck against a newline or end of string.
- */
-{
-	char *start, *p;
-
-	p= *ptr;
-	while (*p == ' ' || *p == '\t') p++;
-
-	start= p;
-	while (*p != ' ' && *p != '\t' && *p != '\n' && *p != 0) p++;
-	*ptr= p;
-	return start;
-}
-
-static int range_parse(char *file, char *data, bitmap_t map,
-	int min, int max, int *wildcard)
-/* Parse a comma separated series of 'n', 'n-m' or 'n:m' numbers.  'n'
- * includes number 'n' in the bit map, 'n-m' includes all numbers between
- * 'n' and 'm' inclusive, and 'n:m' includes 'n+k*m' for any k if in range.
- * Numbers must fall between 'min' and 'max'.  A '*' means all numbers.  A
- * '?' is allowed as a synonym for the current minute, which only makes sense
- * in the minute field, i.e. max must be 59.  Return true iff parsed ok.
- */
-{
-	char *p;
-	int end;
-	int n, m;
-
-	/* Clear all bits. */
-	for (n= 0; n < 8; n++) map[n]= 0;
-
-	p= data;
-	while (*p != ' ' && *p != '\t' && *p != '\n' && *p != 0) p++;
-	end= *p;
-	*p= 0;
-	p= data;
-
-	if (*p == 0) {
-		log(LOG_ERR, "%s: not enough time fields\n", file);
-		return 0;
-	}
-
-	/* Is it a '*'? */
-	if (p[0] == '*' && p[1] == 0) {
-		for (n= min; n <= max; n++) bit_set(map, n);
-		p[1]= end;
-		*wildcard= 1;
-		return 1;
-	}
-	*wildcard= 0;
-
-	/* Parse a comma separated series of numbers or ranges. */
-	for (;;) {
-		if (*p == '?' && max == 59 && p[1] != '-') {
-			n= localtime(&now)->tm_min;
-			p++;
-		} else {
-			if (!isdigit(*p)) goto syntax;
-			n= 0;
-			do {
-				n= 10 * n + (*p++ - '0');
-				if (n > max) goto range;
-			} while (isdigit(*p));
-		}
-		if (n < min) goto range;
-
-		if (*p == '-') {	/* A range of the form 'n-m'? */
-			p++;
-			if (!isdigit(*p)) goto syntax;
-			m= 0;
-			do {
-				m= 10 * m + (*p++ - '0');
-				if (m > max) goto range;
-			} while (isdigit(*p));
-			if (m < n) goto range;
-			do {
-				bit_set(map, n);
-			} while (++n <= m);
-		} else
-		if (*p == ':') {	/* A repeat of the form 'n:m'? */
-			p++;
-			if (!isdigit(*p)) goto syntax;
-			m= 0;
-			do {
-				m= 10 * m + (*p++ - '0');
-				if (m > (max-min+1)) goto range;
-			} while (isdigit(*p));
-			if (m == 0) goto range;
-			while (n >= min) n-= m;
-			while ((n+= m) <= max) bit_set(map, n);
-		} else {
-					/* Simply a number */
-			bit_set(map, n);
-		}
-		if (*p == 0) break;
-		if (*p++ != ',') goto syntax;
-	}
-	*p= end;
-	return 1;
-  syntax:
-	log(LOG_ERR, "%s: field '%s': bad syntax for a %d-%d time field\n",
-		file, data, min, max);
-	return 0;
-  range:
-	log(LOG_ERR, "%s: field '%s': values out of the %d-%d allowed range\n",
-		file, data, min, max);
-	return 0;
-}
-
-void tab_parse(char *file, char *user)
-/* Parse a crontab file and add its data to the tables.  Handle errors by
- * yourself.  Table is owned by 'user' if non-null.
- */
-{
-	crontab_t **atab, *tab;
-	cronjob_t **ajob, *job;
-	int fd;
-	struct stat st;
-	char *p, *q;
-	size_t n;
-	ssize_t r;
-	int ok, wc;
-
-	for (atab= &crontabs; (tab= *atab) != nil; atab= &tab->next) {
-		if (strcmp(file, tab->file) == 0) break;
-	}
-
-	/* Try to open the file. */
-	if ((fd= open(file, O_RDONLY)) < 0 || fstat(fd, &st) < 0) {
-		if (errno != ENOENT) {
-			log(LOG_ERR, "%s: %s\n", file, strerror(errno));
-		}
-		if (fd != -1) close(fd);
-		return;
-	}
-
-	/* Forget it if the file is awfully big. */
-	if (st.st_size > TAB_MAX) {
-		log(LOG_ERR, "%s: %lu bytes is bigger than my %lu limit\n",
-			file,
-			(unsigned long) st.st_size,
-			(unsigned long) TAB_MAX);
-		return;
-	}
-
-	/* If the file is the same as before then don't bother. */
-	if (tab != nil && st.st_mtime == tab->mtime) {
-		close(fd);
-		tab->current= 1;
-		return;
-	}
-
-	/* Create a new table structure. */
-	tab= allocate(sizeof(*tab));
-	tab->file= allocate((strlen(file) + 1) * sizeof(tab->file[0]));
-	strcpy(tab->file, file);
-	tab->user= nil;
-	if (user != nil) {
-		tab->user= allocate((strlen(user) + 1) * sizeof(tab->user[0]));
-		strcpy(tab->user, user);
-	}
-	tab->data= allocate((st.st_size + 1) * sizeof(tab->data[0]));
-	tab->jobs= nil;
-	tab->mtime= st.st_mtime;
-	tab->current= 0;
-	tab->next= *atab;
-	*atab= tab;
-
-	/* Pull a new table in core. */
-	n= 0;
-	while (n < st.st_size) {
-		if ((r = read(fd, tab->data + n, st.st_size - n)) < 0) {
-			log(LOG_CRIT, "%s: %s", file, strerror(errno));
-			close(fd);
-			return;
-		}
-		if (r == 0) break;
-		n+= r;
-	}
-	close(fd);
-	tab->data[n]= 0;
-	if (strlen(tab->data) < n) {
-		log(LOG_ERR, "%s contains a null character\n", file);
-		return;
-	}
-
-	/* Parse the file. */
-	ajob= &tab->jobs;
-	p= tab->data;
-	ok= 1;
-	while (ok && *p != 0) {
-		q= get_token(&p);
-		if (*q == '#' || q == p) {
-			/* Comment or empty. */
-			while (*p != 0 && *p++ != '\n') {}
-			continue;
-		}
-
-		/* One new job coming up. */
-		*ajob= job= allocate(sizeof(*job));
-		*(ajob= &job->next)= nil;
-		job->tab= tab;
-
-		if (!range_parse(file, q, job->min, 0, 59, &wc)) {
-			ok= 0;
-			break;
-		}
-
-		q= get_token(&p);
-		if (!range_parse(file, q, job->hour, 0, 23, &wc)) {
-			ok= 0;
-			break;
-		}
-
-		q= get_token(&p);
-		if (!range_parse(file, q, job->mday, 1, 31, &wc)) {
-			ok= 0;
-			break;
-		}
-		job->do_mday= !wc;
-
-		q= get_token(&p);
-		if (!range_parse(file, q, job->mon, 1, 12, &wc)) {
-			ok= 0;
-			break;
-		}
-		job->do_mday |= !wc;
-
-		q= get_token(&p);
-		if (!range_parse(file, q, job->wday, 0, 7, &wc)) {
-			ok= 0;
-			break;
-		}
-		job->do_wday= !wc;
-
-		/* 7 is Sunday, but 0 is a common mistake because it is in the
-		 * tm_wday range.  We allow and even prefer it internally.
-		 */
-		if (bit_isset(job->wday, 7)) {
-			bit_clr(job->wday, 7);
-			bit_set(job->wday, 0);
-		}
-
-		/* The month range is 1-12, but tm_mon likes 0-11. */
-		job->mon[0] >>= 1;
-		if (bit_isset(job->mon, 8)) bit_set(job->mon, 7);
-		job->mon[1] >>= 1;
-
-		/* Scan for options. */
-		job->user= nil;
-		while (q= get_token(&p), *q == '-') {
-			q++;
-			if (q[0] == '-' && q+1 == p) {
-				/* -- */
-				q= get_token(&p);
-				break;
-			}
-			while (q < p) switch (*q++) {
-			case 'u':
-				if (q == p) q= get_token(&p);
-				if (q == p) goto usage;
-				memmove(q-1, q, p-q);	/* gross... */
-				p[-1]= 0;
-				job->user= q-1;
-				q= p;
-				break;
-			default:
-			usage:
-				log(LOG_ERR,
-			"%s: bad option -%c, good options are: -u username\n",
-					file, q[-1]);
-				ok= 0;
-				goto endtab;
-			}
-		}
-
-		/* A crontab owned by a user can only do things as that user. */
-		if (tab->user != nil) job->user= tab->user;
-
-		/* Inspect the first character of the command. */
-		job->cmd= q;
-		if (q == p || *q == '#') {
-			/* Rest of the line is empty, i.e. the commands are on
-			 * the following lines indented by one tab.
-			 */
-			while (*p != 0 && *p++ != '\n') {}
-			if (*p++ != '\t') {
-				log(LOG_ERR, "%s: contains an empty command\n",
-					file);
-				ok= 0;
-				goto endtab;
-			}
-			while (*p != 0) {
-				if ((*q = *p++) == '\n') {
-					if (*p != '\t') break;
-					p++;
-				}
-				q++;
-			}
-		} else {
-			/* The command is on this line.  Alas we must now be
-			 * backwards compatible and change %'s to newlines.
-			 */
-			p= q;
-			while (*p != 0) {
-				if ((*q = *p++) == '\n') break;
-				if (*q == '%') *q= '\n';
-				q++;
-			}
-		}
-		*q= 0;
-		job->rtime= now;
-		job->late= 0;		/* It is on time. */
-		job->atjob= 0;		/* True cron job. */
-		job->pid= IDLE_PID;	/* Not running yet. */
-		tab_reschedule(job);	/* Compute next time to run. */
-	}
-  endtab:
-
-	if (ok) tab->current= 1;
-}
-
-void tab_find_atjob(char *atdir)
-/* Find the first to be executed AT job and kludge up an crontab job for it.
- * We set tab->file to "atdir/jobname", tab->data to "atdir/past/jobname",
- * and job->cmd to "jobname".
- */
-{
-	DIR *spool;
-	struct dirent *entry;
-	time_t t0, t1;
-	struct tm tmnow, tmt1;
-	static char template[] = "96.365.1546.00";
-	char firstjob[sizeof(template)];
-	int i;
-	crontab_t *tab;
-	cronjob_t *job;
-
-	if ((spool= opendir(atdir)) == nil) return;
-
-	tmnow= *localtime(&now);
-	t0= NEVER;
-
-	while ((entry= readdir(spool)) != nil) {
-		/* Check if the name fits the template. */
-		for (i= 0; template[i] != 0; i++) {
-			if (template[i] == '.') {
-				if (entry->d_name[i] != '.') break;
-			} else {
-				if (!isdigit(entry->d_name[i])) break;
-			}
-		}
-		if (template[i] != 0 || entry->d_name[i] != 0) continue;
-
-		/* Convert the name to a time.  Careful with the century. */
-		memset(&tmt1, 0, sizeof(tmt1));
-		tmt1.tm_year= atoi(entry->d_name+0);
-		while (tmt1.tm_year < tmnow.tm_year-10) tmt1.tm_year+= 100;
-		tmt1.tm_mday= 1+atoi(entry->d_name+3);
-		tmt1.tm_min= atoi(entry->d_name+7);
-		tmt1.tm_hour= tmt1.tm_min / 100;
-		tmt1.tm_min%= 100;
-		tmt1.tm_isdst= -1;
-		if ((t1= mktime(&tmt1)) == -1) {
-			/* Illegal time?  Try in winter time. */
-			tmt1.tm_isdst= 0;
-			if ((t1= mktime(&tmt1)) == -1) continue;
-		}
-		if (t1 < t0) {
-			t0= t1;
-			strcpy(firstjob, entry->d_name);
-		}
-	}
-	closedir(spool);
-
-	if (t0 == NEVER) return;	/* AT job spool is empty. */
-
-	/* Create new table and job structures. */
-	tab= allocate(sizeof(*tab));
-	tab->file= allocate((strlen(atdir) + 1 + sizeof(template))
-						* sizeof(tab->file[0]));
-	strcpy(tab->file, atdir);
-	strcat(tab->file, "/");
-	strcat(tab->file, firstjob);
-	tab->data= allocate((strlen(atdir) + 6 + sizeof(template))
-						* sizeof(tab->data[0]));
-	strcpy(tab->data, atdir);
-	strcat(tab->data, "/past/");
-	strcat(tab->data, firstjob);
-	tab->user= nil;
-	tab->mtime= 0;
-	tab->current= 1;
-	tab->next= crontabs;
-	crontabs= tab;
-
-	tab->jobs= job= allocate(sizeof(*job));
-	job->next= nil;
-	job->tab= tab;
-	job->user= nil;
-	job->cmd= tab->data + strlen(atdir) + 6;
-	job->rtime= t0;
-	job->late= 0;
-	job->atjob= 1;		/* One AT job disguised as a cron job. */
-	job->pid= IDLE_PID;
-
-	if (job->rtime < next) next= job->rtime;
-}
-
-void tab_purge(void)
-/* Remove table data that is no longer current.  E.g. a crontab got removed.
- */
-{
-	crontab_t **atab, *tab;
-	cronjob_t *job;
-
-	atab= &crontabs;
-	while ((tab= *atab) != nil) {
-		if (tab->current) {
-			/* Table is fine. */
-			tab->current= 0;
-			atab= &tab->next;
-		} else {
-			/* Table is not, or no longer valid; delete. */
-			*atab= tab->next;
-			while ((job= tab->jobs) != nil) {
-				tab->jobs= job->next;
-				deallocate(job);
-			}
-			deallocate(tab->data);
-			deallocate(tab->file);
-			deallocate(tab->user);
-			deallocate(tab);
-		}
-	}
-}
-
-static cronjob_t *reap_or_find(pid_t pid)
-/* Find a finished job or search for the next one to run. */
-{
-	crontab_t *tab;
-	cronjob_t *job;
-	cronjob_t *nextjob;
-
-	nextjob= nil;
-	next= NEVER;
-	for (tab= crontabs; tab != nil; tab= tab->next) {
-		for (job= tab->jobs; job != nil; job= job->next) {
-			if (job->pid == pid) {
-				job->pid= IDLE_PID;
-				tab_reschedule(job);
-			}
-			if (job->pid != IDLE_PID) continue;
-			if (job->rtime < next) next= job->rtime;
-			if (job->rtime <= now) nextjob= job;
-		}
-	}
-	return nextjob;
-}
-
-void tab_reap_job(pid_t pid)
-/* A job has finished.  Try to find it among the crontab data and reschedule
- * it.  Recompute time next to run a job.
- */
-{
-	(void) reap_or_find(pid);
-}
-
-cronjob_t *tab_nextjob(void)
-/* Find a job that should be run now.  If none are found return null.
- * Update 'next'.
- */
-{
-	return reap_or_find(NO_PID);
-}
-
-static void pr_map(FILE *fp, bitmap_t map)
-{
-	int last_bit= -1, bit;
-	char *sep;
-
-	sep= "";
-	for (bit= 0; bit < 64; bit++) {
-		if (bit_isset(map, bit)) {
-			if (last_bit == -1) last_bit= bit;
-		} else {
-			if (last_bit != -1) {
-				fprintf(fp, "%s%d", sep, last_bit);
-				if (last_bit != bit-1) {
-					fprintf(fp, "-%d", bit-1);
-				}
-				last_bit= -1;
-				sep= ",";
-			}
-		}
-	}
-}
-
-void tab_print(FILE *fp)
-/* Print out a stored crontab file for debugging purposes. */
-{
-	crontab_t *tab;
-	cronjob_t *job;
-	char *p;
-	struct tm tm;
-
-	for (tab= crontabs; tab != nil; tab= tab->next) {
-		fprintf(fp, "tab->file = \"%s\"\n", tab->file);
-		fprintf(fp, "tab->user = \"%s\"\n",
-				tab->user == nil ? "(root)" : tab->user);
-		fprintf(fp, "tab->mtime = %s", ctime(&tab->mtime));
-
-		for (job= tab->jobs; job != nil; job= job->next) {
-			if (job->atjob) {
-				fprintf(fp, "AT job");
-			} else {
-				pr_map(fp, job->min); fputc(' ', fp);
-				pr_map(fp, job->hour); fputc(' ', fp);
-				pr_map(fp, job->mday); fputc(' ', fp);
-				pr_map(fp, job->mon); fputc(' ', fp);
-				pr_map(fp, job->wday);
-			}
-			if (job->user != nil && job->user != tab->user) {
-				fprintf(fp, " -u %s", job->user);
-			}
-			fprintf(fp, "\n\t");
-			for (p= job->cmd; *p != 0; p++) {
-				fputc(*p, fp);
-				if (*p == '\n') fputc('\t', fp);
-			}
-			fputc('\n', fp);
-			tm= *localtime(&job->rtime);
-			fprintf(fp, "    rtime = %.24s%s\n", asctime(&tm),
-				tm.tm_isdst ? " (DST)" : "");
-			if (job->pid != IDLE_PID) {
-				fprintf(fp, "    pid = %ld\n", (long) job->pid);
-			}
-		}
-	}
-}
-
-/*
- * $PchId: tab.c,v 1.5 2000/07/25 22:07:51 philip Exp $
- */
Index: trunk/minix/commands/cron/tab.h
===================================================================
--- trunk/minix/commands/cron/tab.h	(revision 9)
+++ 	(revision )
@@ -1,72 +1,0 @@
-/*	tab.h - in-core crontab data			Author: Kees J. Bot
- *								7 Dec 1996
- */
-#ifndef TAB__H
-#define TAB__H
-
-#include <sys/types.h>
-#include <limits.h>
-
-struct crontab;
-
-typedef unsigned char bitmap_t[8];
-
-typedef struct cronjob {	/* One entry in a crontab file */
-	struct cronjob	*next;
-	struct crontab	*tab;		/* Associated table file. */
-	bitmap_t	min;		/* Minute (0-59) */
-	bitmap_t	hour;		/* Hour (0-23) */
-	bitmap_t	mday;		/* Day of the month (1-31) */
-	bitmap_t	mon;		/* Month (1-12) */
-	bitmap_t	wday;		/* Weekday (0-7 with 0 = 7 = Sunday) */
-	char		*user;		/* User to run it as (nil = root) */
-	char		*cmd;		/* Command to run */
-	time_t		rtime;		/* When next to run */
-	char		do_mday;	/* True iff mon or mday is not '*' */
-	char		do_wday;	/* True iff wday is not '*' */
-	char		late;		/* True iff the job is late */
-	char		atjob;		/* True iff it is an AT job */
-	pid_t		pid;		/* Process-id of job if nonzero */
-} cronjob_t;
-
-typedef struct crontab {
-	struct crontab	*next;
-	char		*file;		/* Crontab name */
-	char		*user;		/* Owner if non-null */
-	time_t		mtime;		/* Last modified time */
-	cronjob_t	*jobs;		/* List of jobs in the file */
-	char		*data;		/* File data */
-	int		current;	/* True if current, i.e. file exists */
-} crontab_t;
-
-crontab_t *crontabs;		/* All crontabs. */
-
-/* A time as far in the future as possible. */
-#define NEVER		((time_t) ((time_t) -1 < 0 ? LONG_MAX : ULONG_MAX))
-
-/* Don't trust crontabs bigger than this: */
-#define TAB_MAX		((sizeof(int) == 2 ? 8 : 128) * 1024)
-
-/* Pid if no process running, or a pid value you'll never see. */
-#define IDLE_PID	((pid_t) 0)
-#define NO_PID		((pid_t) -1)
-
-/* Bitmap operations. */
-#define bit_set(map, n)		((void) ((map)[(n) >> 3] |= (1 << ((n) & 7))))
-#define bit_clr(map, n)		((void) ((map)[(n) >> 3] &= ~(1 << ((n) & 7))))
-#define bit_isset(map, n)	(!!((map)[(n) >> 3] & (1 << ((n) & 7))))
-
-/* Functions. */
-void tab_parse(char *file, char *user);
-void tab_find_atjob(char *atdir);
-void tab_purge(void);
-void tab_reap_job(pid_t pid);
-void tab_reschedule(cronjob_t *job);
-cronjob_t *tab_nextjob(void);
-void tab_print(FILE *fp);
-
-#endif /* TAB__H */
-
-/*
- * $PchId: tab.h,v 1.3 2000/07/17 07:57:27 philip Exp $
- */
