]> git.itanic.dy.fi Git - rrdd/blob - process.h
rrdtool.c: Suppress compiler warnings with a cast
[rrdd] / process.h
1 #ifndef _PROCESS_H
2 #define _PROCESS_H
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <string.h>
8 #include <sys/wait.h>
9 #include <error.h>
10 #include <errno.h>
11 #include <stdint.h>
12 #include <pthread.h>
13
14 struct event_handler;
15
16 typedef int (handle_event_fn_t)(struct event_handler *);
17 typedef int (work_fn_t)(void *);
18
19 struct event_handler {
20         int fd;
21         uint32_t events;
22         handle_event_fn_t *handle_event;
23         char *name;
24 };
25
26 struct mutex {
27         pthread_mutex_t lock;
28         int line;
29         char *file;
30         time_t lock_time;
31         char *name;
32 };
33
34 int register_event_handler(struct event_handler *handler);
35
36 int init_jobcontrol(int max_jobs_requested);
37 int poll_job_requests(int timeout);
38 int do_fork(void);
39 int run(const char *p, char *const argv[]);
40 int clear_zombie(int pid);
41 int run_piped(const char *cmd, char *const argv[],
42               int *stdinfd, int *stdoutfd, int *stderrfd);
43 int run_piped_stream(const char *cmd, char *const argv[],
44                      FILE **stdinf, FILE **stdoutf, FILE **stderrf);
45
46 void _mutex_lock_acquired(struct mutex *lock, char *file, int line);
47 int _mutex_lock(struct mutex *lock, char *file, int line);
48 int _mutex_unlock(struct mutex *lock);
49
50 #define mutex_lock(lock) _mutex_lock(lock, __FILE__, __LINE__)
51 #define mutex_unlock(lock) _mutex_unlock(lock)
52 #define mutex_lock_acquired(lock) _mutex_lock_acquired(lock, __FILE__, __LINE__)
53
54 enum {
55         WORK_PRIORITY_HIGH,
56         WORK_PRIORITY_LOW,
57         WORK_PRIORITIES_NUM,
58 };
59
60 int queue_work(unsigned int priority, char *name,
61         int (work_fn)(void *arg), void *arg);
62
63 #endif