5 #include <event2/event.h> |
5 #include <event2/event.h> |
6 #include <fuse/fuse_opt.h> |
6 #include <fuse/fuse_opt.h> |
7 |
7 |
8 #include "lib/common.h" |
8 #include "lib/common.h" |
9 #include "lib/math.h" |
9 #include "lib/math.h" |
|
10 #include "lib/signals.h" |
10 #include "evfuse.h" |
11 #include "evfuse.h" |
11 |
12 |
12 const char *file_name = "hello"; |
13 const char *file_name = "hello"; |
13 const char *file_data = "Hello World\n"; |
14 const char *file_data = "Hello World\n"; |
14 |
15 |
15 static struct hello { |
16 static struct hello { |
16 struct event_base *ev_base; |
17 struct event_base *ev_base; |
|
18 |
|
19 struct signals *signals; |
17 |
20 |
18 struct evfuse *ev_fuse; |
21 struct evfuse *ev_fuse; |
19 |
22 |
20 } ctx; |
23 } ctx; |
21 |
24 |
229 }; |
232 }; |
230 |
233 |
231 |
234 |
232 int main (int argc, char **argv) { |
235 int main (int argc, char **argv) { |
233 struct fuse_args fuse_args = FUSE_ARGS_INIT(argc, argv); |
236 struct fuse_args fuse_args = FUSE_ARGS_INIT(argc, argv); |
|
237 |
|
238 // zero |
|
239 memset(&ctx, 0, sizeof(ctx)); |
234 |
240 |
235 // init libevent |
241 // init libevent |
236 if ((ctx.ev_base = event_base_new()) == NULL) |
242 if ((ctx.ev_base = event_base_new()) == NULL) |
237 FATAL("event_base_new"); |
243 ERROR("event_base_new"); |
238 |
244 |
|
245 // setup signals |
|
246 if ((ctx.signals = signals_default(ctx.ev_base)) == NULL) |
|
247 ERROR("signals_default"); |
|
248 |
239 // open fuse |
249 // open fuse |
240 if ((ctx.ev_fuse = evfuse_new(ctx.ev_base, &fuse_args, &hello_llops, &ctx)) == NULL) |
250 if ((ctx.ev_fuse = evfuse_new(ctx.ev_base, &fuse_args, &hello_llops, &ctx)) == NULL) |
241 FATAL("evfuse_new"); |
251 ERROR("evfuse_new"); |
242 |
252 |
243 // run libevent |
253 // run libevent |
244 INFO("running libevent loop"); |
254 INFO("running libevent loop"); |
245 |
255 |
246 if (event_base_dispatch(ctx.ev_base)) |
256 if (event_base_dispatch(ctx.ev_base)) |
247 PWARNING("event_base_dispatch"); |
257 PERROR("event_base_dispatch"); |
248 |
258 |
|
259 // clean shutdown |
|
260 |
|
261 error : |
249 // cleanup |
262 // cleanup |
250 event_base_free(ctx.ev_base); |
263 if (ctx.ev_fuse) |
251 } |
264 evfuse_close(ctx.ev_fuse); |
252 |
265 |
|
266 if (ctx.signals) |
|
267 signals_free(ctx.signals); |
|
268 |
|
269 if (ctx.ev_base) |
|
270 event_base_free(ctx.ev_base); |
|
271 |
|
272 fuse_opt_free_args(&fuse_args); |
|
273 } |
|
274 |