1 /* misc.c - Miscellaneous stuff for cron Author: Kees J. Bot
2 * 12 Jan 1997
3 */
4 #define nil ((void*)0)
5 #include <sys/types.h>
6 #include <stdio.h>
7 #include <stdarg.h>
8 #include <stdlib.h>
9 #include <time.h>
10 #include "misc.h"
11
12 char *prog_name; /* Name of this program. */
13 time_t now; /* Cron's idea of the current time. */
14 time_t next; /* Time to run the next job. */
15
16 size_t alloc_count; /* # Of chunks of memory allocated. */
17
allocate(size_t len)18 void *allocate(size_t len)
19 /* Checked malloc(). Better not feed it length 0. */
20 {
21 void *mem;
22
23 if ((mem= malloc(len)) == nil) {
24 cronlog(LOG_ALERT, "Out of memory, exiting\n");
25 exit(1);
26 }
27 alloc_count++;
28 return mem;
29 }
30
deallocate(void * mem)31 void deallocate(void *mem)
32 {
33 if (mem != nil) {
34 free(mem);
35 alloc_count--;
36 }
37 }
38
39 static enum logto logto= SYSLOG;
40
selectlog(enum logto where)41 void selectlog(enum logto where)
42 /* Select where logging output should go, syslog or stdout. */
43 {
44 logto= where;
45 }
46
cronlog(int level,const char * fmt,...)47 void cronlog(int level, const char *fmt, ...)
48 /* Like syslog(), but may go to stderr. */
49 {
50 va_list ap;
51
52 va_start(ap, fmt);
53
54 #if __minix_vmd || !__minix
55 if (logto == SYSLOG) {
56 vsyslog(level, fmt, ap);
57 } else
58 #endif
59 {
60 fprintf(stderr, "%s: ", prog_name);
61 vfprintf(stderr, fmt, ap);
62 }
63 va_end(ap);
64 }
65
66 /*
67 * $PchId: misc.c,v 1.3 2000/07/17 19:01:57 philip Exp $
68 */
69