From patchwork Sun Mar 21 19:20:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 48231 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.samba.org (fn.samba.org [216.83.154.106]) by ozlabs.org (Postfix) with ESMTP id 9F28FB7CEF for ; Mon, 22 Mar 2010 06:20:52 +1100 (EST) Received: from fn.samba.org (localhost [127.0.0.1]) by lists.samba.org (Postfix) with ESMTP id 4684FAD1CE; Sun, 21 Mar 2010 13:20:53 -0600 (MDT) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on fn.samba.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=3.8 tests=AWL, BAYES_00, NO_MORE_FUNN, SPF_PASS autolearn=no version=3.2.5 X-Original-To: linux-cifs-client@lists.samba.org Delivered-To: linux-cifs-client@lists.samba.org Received: from cdptpa-omtalb.mail.rr.com (cdptpa-omtalb.mail.rr.com [75.180.132.120]) by lists.samba.org (Postfix) with ESMTP id A7131AD1CE for ; Sun, 21 Mar 2010 13:20:30 -0600 (MDT) X-Authority-Analysis: v=1.0 c=1 a=2EZtPNsaF9sA:10 a=20KFwNOVAAAA:8 a=KMPgPMCLtELEaSMs0xAA:9 a=a4cUGV2YpohVj9xKhvIA:7 a=25SfjiMoD0yGz7fFL-o_nmSUjNUA:4 a=jEp0ucaQiEUA:10 X-Cloudmark-Score: 0 X-Originating-IP: 71.70.153.3 Received: from [71.70.153.3] ([71.70.153.3:53425] helo=mail.poochiereds.net) by cdptpa-oedge01.mail.rr.com (envelope-from ) (ecelerity 2.2.2.39 r()) with ESMTP id 25/AF-07392-C7176AB4; Sun, 21 Mar 2010 19:20:28 +0000 Received: by mail.poochiereds.net (Postfix, from userid 4447) id DC4C458055; Sun, 21 Mar 2010 15:20:27 -0400 (EDT) From: Jeff Layton To: linux-cifs-client@lists.samba.org Date: Sun, 21 Mar 2010 15:20:25 -0400 Message-Id: <1269199227-21446-9-git-send-email-jlayton@redhat.com> X-Mailer: git-send-email 1.6.6.1 In-Reply-To: References: Subject: [linux-cifs-client] [PATCH 08/10] mount.cifs: don't use exit(3) in main() X-BeenThere: linux-cifs-client@lists.samba.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: The Linux CIFS VFS client List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-cifs-client-bounces@lists.samba.org Errors-To: linux-cifs-client-bounces@lists.samba.org Clean up error handling in main() so that cleanup tasks are completed rather than assuming exit processing will handle it. Signed-off-by: Jeff Layton --- mount.cifs.c | 30 +++++++++++++++++++----------- 1 files changed, 19 insertions(+), 11 deletions(-) diff --git a/mount.cifs.c b/mount.cifs.c index 76cf851..ac35ee4 100644 --- a/mount.cifs.c +++ b/mount.cifs.c @@ -1229,8 +1229,10 @@ int main(int argc, char ** argv) break; case 'o': orgoptions = strndup(optarg, MAX_OPTIONS_LEN); - if (!orgoptions) - exit(EX_SYSERR); + if (!orgoptions) { + rc = EX_SYSERR; + goto mount_exit; + } break; case 'r': /* mount readonly */ flags |= MS_RDONLY; @@ -1251,14 +1253,16 @@ int main(int argc, char ** argv) uid = strtoul(optarg, &ep, 10); if (*ep) { fprintf(stderr, "bad uid value \"%s\"\n", optarg); - exit(EX_USAGE); + rc = EX_USAGE; + goto mount_exit; } } else { struct passwd *pw; if (!(pw = getpwnam(optarg))) { fprintf(stderr, "bad user name \"%s\"\n", optarg); - exit(EX_USAGE); + rc = EX_USAGE; + goto mount_exit; } uid = pw->pw_uid; endpwent(); @@ -1271,14 +1275,16 @@ int main(int argc, char ** argv) gid = strtoul(optarg, &ep, 10); if (*ep) { fprintf(stderr, "bad gid value \"%s\"\n", optarg); - exit(EX_USAGE); + rc = EX_USAGE; + goto mount_exit; } } else { struct group *gr; if (!(gr = getgrnam(optarg))) { fprintf(stderr, "bad user name \"%s\"\n", optarg); - exit(EX_USAGE); + rc = EX_USAGE; + goto mount_exit; } gid = gr->gr_gid; endpwent(); @@ -1321,7 +1327,8 @@ int main(int argc, char ** argv) share_name = strndup(argv[optind], MAX_UNC_LEN); if (share_name == NULL) { fprintf(stderr, "%s: %s", thisprogram, strerror(ENOMEM)); - exit(EX_SYSERR); + rc = EX_SYSERR; + goto mount_exit; } mountpoint = argv[optind + 1]; @@ -1430,7 +1437,8 @@ int main(int argc, char ** argv) mountpassword = (char *)calloc(MOUNT_PASSWD_SIZE+1,1); if (!tmp_pass || !mountpassword) { fprintf(stderr, "Password not entered, exiting\n"); - exit(EX_USAGE); + rc = EX_USAGE; + goto mount_exit; } strlcpy(mountpassword, tmp_pass, MOUNT_PASSWD_SIZE+1); got_password = 1; @@ -1446,8 +1454,8 @@ int main(int argc, char ** argv) optlen += strlen(share_name) + 4; else { fprintf(stderr, "No server share name specified\n"); - fprintf(stderr, "\nMounting the DFS root for server not implemented yet\n"); - exit(EX_USAGE); + rc = EX_USAGE; + goto mount_exit; } if(user_name) optlen += strlen(user_name) + 6; @@ -1657,5 +1665,5 @@ mount_exit: SAFE_FREE(orgoptions); SAFE_FREE(resolved_path); SAFE_FREE(share_name); - exit(rc); + return rc; }