]> git.itanic.dy.fi Git - rrdd/blob - process.h
onewire_parser: Fix "85" degree handling case
[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         char owner_name[16];
31         time_t lock_time;
32         char *name;
33 };
34
35 int register_event_handler(struct event_handler *handler);
36
37 int init_jobcontrol(int max_jobs_requested);
38 int poll_job_requests(int timeout);
39 int do_fork(void);
40 int run(const char *p, char *const argv[]);
41 int clear_zombie(int pid);
42 int run_piped(const char *cmd, char *const argv[],
43               int *stdinfd, int *stdoutfd, int *stderrfd);
44 int run_piped_stream(const char *cmd, char *const argv[],
45                      FILE **stdinf, FILE **stdoutf, FILE **stderrf);
46
47 void _mutex_lock_acquired(struct mutex *lock, char *file, int line);
48 int _mutex_lock(struct mutex *lock, char *file, int line);
49 int _mutex_unlock(struct mutex *lock);
50
51 #define mutex_lock(lock) _mutex_lock(lock, __FILE__, __LINE__)
52 #define mutex_unlock(lock) _mutex_unlock(lock)
53 #define mutex_lock_acquired(lock) _mutex_lock_acquired(lock, __FILE__, __LINE__)
54
55 enum {
56         WORK_PRIORITY_HIGH,
57         WORK_PRIORITY_LOW,
58         WORK_PRIORITIES_NUM,
59 };
60
61 int queue_work(unsigned int priority, char *name,
62         int (work_fn)(void *arg), void *arg);
63
64 #endif