From a4fd28aeed08caf77709a372b369c3bc7d33ffac Mon Sep 17 00:00:00 2001 From: Brandon Philips Date: Sat, 9 Sep 2006 17:22:48 -0500 Subject: [PATCH] Cleanup the error handling in the main function Signed-off-by: Brandon Philips --- chunkfs.c | 51 +++++++++++++++++++++++++++++---------------------- 1 files changed, 29 insertions(+), 22 deletions(-) diff --git a/chunkfs.c b/chunkfs.c index 820fa44..fb4beb8 100644 --- a/chunkfs.c +++ b/chunkfs.c @@ -1300,29 +1300,36 @@ static struct fuse_lowlevel_ops chunkfs_ops = { int main(int argc, char *argv[]) { struct fuse_args args = FUSE_ARGS_INIT(argc, argv); - char *mountpoint; int err = -1; - int fd; - - if (fuse_parse_cmdline(&args, &mountpoint, NULL, NULL) != -1 && - (fd = fuse_mount(mountpoint, &args)) != -1) { - struct fuse_session *se; - - se = fuse_lowlevel_new(&args, &chunkfs_ops, sizeof(chunkfs_ops), - NULL); - if (se != NULL) { - if (fuse_set_signal_handlers(se) != -1) { - struct fuse_chan *ch = fuse_kern_chan_new(fd); - if (ch != NULL) { - fuse_session_add_chan(se, ch); - err = fuse_session_loop(se); - } - fuse_remove_signal_handlers(se); - } - fuse_session_destroy(se); - } - close(fd); - } + char *mountpoint = NULL; + int fd = 0; + struct fuse_session *se = NULL; + struct fuse_chan *ch = NULL; + + + if (fuse_parse_cmdline(&args, &mountpoint, NULL, NULL) == -1) + goto error; + + if ((fd = fuse_mount(mountpoint, &args)) == -1) + goto error; + + se = fuse_lowlevel_new(&args, &chunkfs_ops, sizeof(chunkfs_ops), NULL); + if (se == NULL) + goto error; + + if (fuse_set_signal_handlers(se) == -1) + goto error; + + if ((ch = fuse_kern_chan_new(fd)) == NULL) + goto error; + + fuse_session_add_chan(se, ch); + err = fuse_session_loop(se); + +error: + if (se) fuse_remove_signal_handlers(se); + if (se) fuse_session_destroy(se); + if (fd) close(fd); fuse_unmount(mountpoint); fuse_opt_free_args(&args); -- 1.4.4.1