File: bcron.h

package info (click to toggle)
bcron 0.09-13
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 496 kB
  • sloc: ansic: 2,055; sh: 419; makefile: 110
file content (123 lines) | stat: -rw-r--r-- 3,248 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifndef BCRON__H__
#define BCRON__H__

#include <sysdeps.h>
#include <systime.h>
#include <adt/ghash.h>
#include <str/str.h>

#define BCRON_SPOOL "/var/spool/cron"
#define CRONTAB_DIR "crontabs"
#define SOCKET_PATH "/var/run/bcron-spool"
#define BCRON_USER "cron"
#define TRIGGER "trigger"

#define DEBUG_MISC 1
#define DEBUG_SCHED 2
#define DEBUG_JOBS 4
#define DEBUG_CONN 8

#define IGNORE_EXEC 1

/*****************************************************************************/
extern str tempname;
int tempfile(const char* prefix);

/*****************************************************************************/
const char* fmttm(const struct tm*);
const char* fmttime(time_t t);

/*****************************************************************************/
struct ministat
{
  int exists;
  dev_t device;
  ino_t inode;
  mode_t mode;
  size_t size;
  time_t mtime;
};

void ministat(const char* path, struct ministat* s);
void ministat2(const char* base, const char* entry, struct ministat* s);
void minifstat(int fd, struct ministat* s);

/*****************************************************************************/
struct connection
{
  int fd;
  enum { LENGTH, DATA, COMMA } state;
  unsigned long length;
  str packet;
  void* data;
};

void connection_init(struct connection* c, int fd, void* data);
int connection_read(struct connection* c,
		    void (*handler)(struct connection*));

/*****************************************************************************/
int sendpacket(int fd, const str* s);

/*****************************************************************************/
int chdir_bcron(void);

/*****************************************************************************/
typedef uint64 bitmap;

struct job_timespec
{
  bitmap minutes;		/* bitmap: 0-59 */
  bitmap hours;			/* bitmap: 0-23 */
  bitmap mdays;			/* bitmap: 1-31 */
  bitmap months;		/* bitmap: 0-11 */
  bitmap wdays;			/* bitmap: 0-6 */
  int hour_count;
};

void timespec_next_init(void);
time_t timespec_next(const struct job_timespec* ts,
		     time_t start, const struct tm* starttm);
int timespec_parse(struct job_timespec* t, const char* s);

/*****************************************************************************/
struct job
{
  struct job_timespec times;
  time_t nexttime;
  const char* runas;
  const char* command;
  str environ;
  struct job* next;
};

#define ALL_MINUTES 0xfffffffffffffffULL
#define ALL_HOURS 0xffffffUL
#define ALL_MDAYS 0xfffffffeUL
#define ALL_MONTHS 0xfffUL
#define ALL_WDAYS 0x7fUL

struct job* job_new(const struct job_timespec* times,
		    const char* runas,
		    const char* command,
		    const str* environ);
void job_free(struct job* job);
void job_exec(struct job* job);

/*****************************************************************************/
struct crontab
{
  struct ministat stat;
  struct job* jobs;
};

int crontab_parse(struct crontab* c, str* data, const char* runas);
int crontab_import(struct crontab* c, const char* path, const char* runas);
void crontab_free(struct crontab* c);

/*****************************************************************************/
extern struct ghash crontabs;
GHASH_DECL(crontabs,const char*,struct crontab);
void crontabs_load(void);

#endif