|
1 |
|
2 #include <event2/event.h> |
|
3 |
|
4 #include "lib/log.h" |
|
5 #include "lib/signals.h" |
|
6 #include "evfuse.h" |
|
7 #include "simple.h" |
|
8 |
|
9 static struct hello { |
|
10 struct event_base *ev_base; |
|
11 |
|
12 struct signals *signals; |
|
13 |
|
14 struct simple_fs *fs; |
|
15 |
|
16 struct evfuse *ev_fuse; |
|
17 |
|
18 } ctx; |
|
19 |
|
20 static struct simple_node node_list[] = { |
|
21 { 1, S_IFDIR, 0555, 0, NULL, NULL }, |
|
22 { 2, S_IFREG, 0444, 1, "hello", "Hello World!\n" }, |
|
23 { 0, 0, 0, 0, NULL, NULL }, |
|
24 }; |
|
25 |
|
26 int main (int argc, char **argv) { |
|
27 struct fuse_args fuse_args = FUSE_ARGS_INIT(argc, argv); |
|
28 |
|
29 // init libevent |
|
30 if ((ctx.ev_base = event_base_new()) == NULL) |
|
31 ERROR("event_base_new"); |
|
32 |
|
33 // setup signals |
|
34 if ((ctx.signals = signals_default(ctx.ev_base)) == NULL) |
|
35 ERROR("signals_default"); |
|
36 |
|
37 // setup fs |
|
38 if ((ctx.fs = simple_new(node_list)) == NULL) |
|
39 ERROR("simple_new"); |
|
40 |
|
41 // open fuse |
|
42 if ((ctx.ev_fuse = evfuse_new(ctx.ev_base, &fuse_args, simple_init(), ctx.fs)) == NULL) |
|
43 ERROR("evfuse_new"); |
|
44 |
|
45 // run libevent |
|
46 INFO("running libevent loop"); |
|
47 |
|
48 if (event_base_dispatch(ctx.ev_base)) |
|
49 PERROR("event_base_dispatch"); |
|
50 |
|
51 // clean shutdown |
|
52 |
|
53 error : |
|
54 // cleanup |
|
55 if (ctx.ev_fuse) |
|
56 evfuse_close(ctx.ev_fuse); |
|
57 |
|
58 /* |
|
59 if (ctx.fs) |
|
60 simple_close(ctx.fs); |
|
61 */ |
|
62 |
|
63 if (ctx.signals) |
|
64 signals_free(ctx.signals); |
|
65 |
|
66 if (ctx.ev_base) |
|
67 event_base_free(ctx.ev_base); |
|
68 |
|
69 fuse_opt_free_args(&fuse_args); |
|
70 } |
|
71 |