diff options
author | Miklos Szeredi <miklos@szeredi.hu> | 2001-11-21 10:03:39 +0000 |
---|---|---|
committer | Miklos Szeredi <miklos@szeredi.hu> | 2001-11-21 10:03:39 +0000 |
commit | cc8c975f7757ce89d15aad31df6c8b7086169653 (patch) | |
tree | 7e313f7a29871bec3496cd4e48febdcf1216d4b2 /example/null.c | |
parent | 0e8702ba48357fd1596bee4648aede7a9b2adc4e (diff) | |
download | libfuse-cc8c975f7757ce89d15aad31df6c8b7086169653.tar.gz |
writing modules made more easy
Diffstat (limited to 'example/null.c')
-rw-r--r-- | example/null.c | 94 |
1 files changed, 3 insertions, 91 deletions
diff --git a/example/null.c b/example/null.c index c9816f1..7be4ab4 100644 --- a/example/null.c +++ b/example/null.c @@ -7,13 +7,10 @@ */ #include <fuse.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> + #include <unistd.h> -#include <signal.h> #include <time.h> +#include <errno.h> #define UNUSED __attribute__((unused)) @@ -88,93 +85,8 @@ static struct fuse_operations null_oper = { write: null_write, }; -static void cleanup() -{ - close(0); - system(getenv("FUSE_UNMOUNT_CMD")); -} - -static void exit_handler() -{ - exit(0); -} - -static void set_signal_handlers() -{ - struct sigaction sa; - - sa.sa_handler = exit_handler; - sigemptyset(&(sa.sa_mask)); - sa.sa_flags = 0; - - if (sigaction(SIGHUP, &sa, NULL) == -1 || - sigaction(SIGINT, &sa, NULL) == -1 || - sigaction(SIGTERM, &sa, NULL) == -1) { - - perror("Cannot set exit signal handlers"); - exit(1); - } - - sa.sa_handler = SIG_IGN; - - if(sigaction(SIGPIPE, &sa, NULL) == -1) { - perror("Cannot set ignored signals"); - exit(1); - } -} - int main(int argc, char *argv[]) { - int argctr; - int flags; - int multithreaded; - struct fuse *fuse; - - argctr = 1; - - atexit(cleanup); - set_signal_handlers(); - - flags = 0; - multithreaded = 1; - for(; argctr < argc && argv[argctr][0] == '-'; argctr ++) { - switch(argv[argctr][1]) { - case 'd': - flags |= FUSE_DEBUG; - break; - - case 's': - multithreaded = 0; - break; - - case 'h': - fprintf(stderr, - "usage: %s [options] \n" - "Options:\n" - " -d enable debug output\n" - " -s disable multithreaded operation\n" - " -h print help\n", - argv[0]); - exit(1); - break; - - default: - fprintf(stderr, "invalid option: %s\n", argv[argctr]); - exit(1); - } - } - if(argctr != argc) { - fprintf(stderr, "missing or surplus argument\n"); - exit(1); - } - - fuse = fuse_new(0, flags); - fuse_set_operations(fuse, &null_oper); - - if(multithreaded) - fuse_loop_mt(fuse); - else - fuse_loop(fuse); - + fuse_main(argc, argv, &null_oper); return 0; } |