]> git.itanic.dy.fi Git - rrdd/blob - process.h
c3b5c23653381297400e88d6cad5b3498cd82ef8
[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
18 struct event_handler {
19         int fd;
20         uint32_t events;
21         handle_event_fn_t *handle_event;
22         char *name;
23 };
24
25 struct mutex {
26         pthread_mutex_t lock;
27         int line;
28         char *file;
29         time_t lock_time;
30         char *name;
31 };
32
33 int register_event_handler(struct event_handler *handler);
34
35 int get_child_count(void);
36 int get_parent_count(void);
37
38 int init_jobcontrol(int max_jobs_requested);
39 int poll_job_requests(int timeout);
40 int do_fork(void);
41 int do_fork_limited(void);
42 int run(const char *p, char *const argv[]);
43 int harvest_zombies(int pid);
44 int run_piped(const char *cmd, char *const argv[],
45               int *stdinfd, int *stdoutfd, int *stderrfd);
46 int run_piped_stream(const char *cmd, char *const argv[],
47                      FILE **stdinf, FILE **stdoutf, FILE **stderrf);
48
49 void _mutex_lock_acquired(struct mutex *lock, char *file, int line);
50 int _mutex_lock(struct mutex *lock, char *file, int line);
51 int _mutex_unlock(struct mutex *lock);
52
53 #define mutex_lock(lock) _mutex_lock(lock, __FILE__, __LINE__)
54 #define mutex_unlock(lock) _mutex_unlock(lock)
55 #define mutex_lock_acquired(lock) _mutex_lock_acquired(lock, __FILE__, __LINE__)
56
57 enum {
58         WORK_PRIORITY_HIGH,
59         WORK_PRIORITY_LOW,
60         WORK_PRIORITIES_NUM,
61 };
62
63 int queue_work(unsigned int priority, char *name,
64         int (work_fn)(void *arg), void *arg);
65
66 #endif