move netifd_start_process dir_fd to the data structure
[project/netifd.git] / netifd.h
1 #ifndef __NETIFD_H
2 #define __NETIFD_H
3
4 #include <sys/socket.h>
5 #include <net/if.h>
6
7 #include <stdbool.h>
8 #include <stdio.h>
9
10 #include <libubox/uloop.h>
11
12 #include <libubus.h>
13
14 #include "utils.h"
15
16 #ifdef DUMMY_MODE
17 #define DEFAULT_MAIN_PATH       "./dummy"
18 #define DEFAULT_HOTPLUG_PATH    "./scripts/hotplug-cmd"
19 #define DEFAULT_RESOLV_CONF     "./tmp/resolv.conf"
20 #else
21 #define DEFAULT_MAIN_PATH       "/lib/netifd"
22 #define DEFAULT_HOTPLUG_PATH    "/sbin/hotplug-cmd"
23 #define DEFAULT_RESOLV_CONF     "/tmp/resolv.conf.auto"
24 #endif
25
26 extern const char *resolv_conf;
27 extern char *hotplug_cmd_path;
28 extern unsigned int debug_mask;
29
30 enum {
31         DEBUG_SYSTEM    = 0,
32         DEBUG_DEVICE    = 1,
33         DEBUG_INTERFACE = 2,
34 };
35
36 #ifdef DEBUG
37 #define DPRINTF(format, ...) fprintf(stderr, "%s(%d): " format, __func__, __LINE__, ## __VA_ARGS__)
38 #define D(level, format, ...) do { \
39                 if (debug_mask & (1 << (DEBUG_ ## level))) \
40                                 DPRINTF(format, ##__VA_ARGS__); \
41         } while (0)
42 #else
43 #define DPRINTF(format, ...) no_debug(0, format, ## __VA_ARGS__)
44 #define D(level, format, ...) no_debug(DEBUG_ ## level, format, ## __VA_ARGS__)
45 #endif
46
47 static inline void no_debug(int level, const char *fmt, ...)
48 {
49 }
50
51 struct netifd_process {
52         struct list_head list;
53         struct uloop_process uloop;
54         void (*cb)(struct netifd_process *, int ret);
55         int dir_fd;
56 };
57
58 int netifd_start_process(const char **argv, char **env, struct netifd_process *proc);
59 void netifd_kill_process(struct netifd_process *proc);
60
61 struct device;
62 struct interface;
63
64 extern const char *main_path;
65 void netifd_restart(void);
66 void netifd_reload(void);
67
68 #endif