]> granicus.if.org Git - fcron/blob - global.h
added support of termios.h and lockf() for Solaris and SysV systems
[fcron] / global.h
1 /*
2  * FCRON - periodic command scheduler 
3  *
4  *  Copyright 2000-2001 Thibault Godouet <fcron@free.fr>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  * 
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  * 
20  *  The GNU General Public License can also be found in the file
21  *  `LICENSE' that comes with the fcron source distribution.
22  */
23
24  /* $Id: global.h,v 1.28 2001-05-28 18:48:48 thib Exp $ */
25
26
27 /* 
28    WARNING : this file should not be modified.
29    Compilation's options are in config.h
30 */
31
32 #ifndef __GLOBAL_H__
33 #define __GLOBAL_H__
34
35 /* config.h must be included before every other includes 
36  * (contains the compilation options) */
37 #include "config.h"
38
39
40 #include <ctype.h>
41
42 #ifdef HAVE_ERRNO_H
43 #include <errno.h>
44 #endif
45
46 #ifdef HAVE_GETOPT_H
47 #include <getopt.h>
48 #endif
49
50 #include <pwd.h>
51 #include <signal.h>
52
53 #ifdef HAVE_STDARG_H
54 #include <stdarg.h>
55 #endif
56
57 #include <stdio.h>
58 #include <stdlib.h>
59 #include <string.h>
60
61 #ifdef HAVE_SYS_FILE_H
62 #include <sys/file.h>
63 #endif
64
65 #include <sys/stat.h>
66 #include <sys/types.h>
67
68 #ifdef HAVE_SYS_WAIT_H
69 #include <sys/wait.h>
70 #endif
71
72 #ifdef HAVE_SYSLOG_H
73 #include <syslog.h>
74 #endif
75
76 #ifdef TIME_WITH_SYS_TIME
77 #include <time.h>
78 #elif HAVE_SYS_TIME_H
79 #include <sys/time.h>
80 #endif
81
82 #ifdef HAVE_SYS_TERMIOS_H
83 #include <sys/termios.h>
84 #endif
85
86 #ifdef HAVE_UNISTD_H
87 #include <unistd.h>
88 #endif
89
90 #ifdef HAVE_FCNTL_H
91 #include <fcntl.h>
92 #elif HAVE_SYS_FCNTL_H
93 #include <sys/fcntl.h>
94 #endif
95
96 #ifdef HAVE_LIMITS_H
97 #include <limits.h>
98 #endif
99
100
101 #include "bitstring.h"     /* bit arrays */
102 #include "option.h"        /* manage fcrontab's options */
103
104 /* constants for fcrontabs needed to load and save the fcrontabs to disk */
105 #include "save.h"
106 /* log part */
107 #include "log.h"
108 /* functions used by both fcrontab and fcron */
109 #include "subs.h"
110
111 /* you should not change this (nor need to do it) */
112 #define ERR     -1           
113 #define OK       0
114
115 /* options for local functions */
116 #define STD 0
117
118 /* macros */
119 #define Alloc(ptr, type) \
120         if( (ptr = calloc(1, sizeof(type))) == NULL ) \
121             die_e("Could not calloc.");
122
123 #define debug if(debug_opt) Debug
124
125 typedef struct env_t {
126     char         *e_val;        /* env value                            */
127     struct env_t *e_next;
128 } env_t ;
129
130 typedef struct CF {
131     struct CF    *cf_next;
132     struct CL    *cf_line_base;
133     char         *cf_user;      /* user-name                                 */
134     struct env_t *cf_env_base;  /* list of all env variables to set          */
135     int           cf_running;   /* number of jobs running                    */
136     signed char   cf_tzdiff;    /* time diff between system and local hour   */
137 } CF;
138
139
140 #define OPTION_SIZE 3
141 #define LAVG_SIZE 3
142 /* warning : do not change the order of the members of this structure
143  *   because some tests made are dependent to that order */
144 /* warning : if you change a field type, you may have to also make some changes
145  *   in the save/load binary fcrontab functions */
146 typedef struct CL {
147     struct CL     *cl_next;
148     struct CF     *cl_file;       /* the file in which the line is           */
149     unsigned char  cl_option[OPTION_SIZE]; /* line's option (see option.h)   */
150     char          *cl_shell;      /* shell command                           */
151     unsigned char  cl_numexe;     /* num of entries in lavg/serial queue     */
152     unsigned char  cl_lavg[LAVG_SIZE];/*load averages needed (1,5,15 mins)   */
153     time_t         cl_until;      /* timeout of the wait for a lavg value    */
154     char           cl_nice;       /* nice value to control priority          */
155     char          *cl_runas;      /* determine permissions of the job        */
156     char          *cl_mailto;     /* mail output to cl_mailto                */
157     time_t         cl_nextexe;    /* time and date of the next execution     */
158     unsigned short cl_remain;     /* remaining until next execution          */
159     long int       cl_timefreq;   /* Run every n seconds                     */
160     unsigned short cl_runfreq;    /* Run once every n matches                */
161     /* see bitstring(3) man page for more details */
162     bitstr_t       bit_decl(cl_mins, 60); /* 0-59                            */
163     bitstr_t       bit_decl(cl_hrs, 24);  /* 0-23                            */
164     bitstr_t       bit_decl(cl_days, 32); /* 1-31                            */
165     bitstr_t       bit_decl(cl_mons, 12); /* 0-11                            */
166     bitstr_t       bit_decl(cl_dow, 8);   /* 0-7, 0 and 7 are both Sunday    */
167 } CL;
168
169 typedef struct job {
170     struct CL    *j_line;
171     struct job   *j_next;
172 } job;
173
174 typedef struct lavg {
175     struct CL  *l_line;  
176     time_t      l_until;   /* the timeout of the wait for load averages */
177 } lavg;
178
179 typedef struct exe {
180     struct CL  *e_line;
181     pid_t       e_pid;
182 } exe;
183
184 #endif /* __GLOBAL_H__ */
185