From patchwork Sun Mar 21 19:20:26 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 87289 Received: from lists.samba.org (fn.samba.org [216.83.154.106]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o2LJLG9u013505 for ; Sun, 21 Mar 2010 19:21:56 GMT Received: from fn.samba.org (localhost [127.0.0.1]) by lists.samba.org (Postfix) with ESMTP id D36DFAD1ED; Sun, 21 Mar 2010 13:20:57 -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.123]) by lists.samba.org (Postfix) with ESMTP id 06676AD1ED for ; Sun, 21 Mar 2010 13:20:30 -0600 (MDT) X-Authority-Analysis: v=1.0 c=1 a=HA7N9pSaMvwA:10 a=20KFwNOVAAAA:8 a=-t8pR6zsmDUdZfIuQBgA:9 a=HXCeAjmXHu0AqCjXVJAA:7 a=wGNMJB81NBzA8vQMckyOres99EMA:4 a=jEp0ucaQiEUA:10 a=YOAm2lHeAX-SFER5:21 a=RwGCM-61syeEEcTL:21 X-Cloudmark-Score: 0 X-Originating-IP: 71.70.153.3 Received: from [71.70.153.3] ([71.70.153.3:53426] helo=mail.poochiereds.net) by cdptpa-oedge02.mail.rr.com (envelope-from ) (ecelerity 2.2.2.39 r()) with ESMTP id 00/F5-06757-C7176AB4; Sun, 21 Mar 2010 19:20:28 +0000 Received: by mail.poochiereds.net (Postfix, from userid 4447) id EA9FE58057; 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:26 -0400 Message-Id: <1269199227-21446-10-git-send-email-jlayton@redhat.com> X-Mailer: git-send-email 1.6.6.1 In-Reply-To: References: Subject: [linux-cifs-client] [PATCH 09/10] mount.cifs: don't use exit(3) in mount_cifs_usage() 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 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sun, 21 Mar 2010 19:21:57 +0000 (UTC) diff --git a/mount.cifs.c b/mount.cifs.c index ac35ee4..e6ab7cc 100644 --- a/mount.cifs.c +++ b/mount.cifs.c @@ -231,7 +231,8 @@ BB end finish BB */ static char * check_for_domain(char **); -static void mount_cifs_usage(FILE *stream) +static int +mount_cifs_usage(FILE *stream) { fprintf(stream, "\nUsage: %s -o \n", thisprogram); fprintf(stream, "\nMount the remote target, specified as a UNC name,"); @@ -254,11 +255,9 @@ static void mount_cifs_usage(FILE *stream) fprintf(stream, "\nTo display the version number of the mount helper:"); fprintf(stream, "\n\t%s -V\n",thisprogram); - SAFE_FREE(mountpassword); - if (stream == stderr) - exit(EX_USAGE); - exit(0); + return EX_USAGE; + return 0; } /* caller frees username if necessary */ @@ -289,7 +288,7 @@ static int open_cred_file(char * file_name) line_buf = (char *)malloc(4096); if(line_buf == NULL) { fclose(fs); - return ENOMEM; + return EX_SYSERR; } while(fgets(line_buf,4096,fs)) { @@ -316,7 +315,7 @@ static int open_cred_file(char * file_name) if(length > 4086) { fprintf(stderr, "mount.cifs failed due to malformed username in credentials file\n"); memset(line_buf,0,4096); - exit(EX_USAGE); + return EX_USAGE; } else { got_user = 1; user_name = (char *)calloc(1 + length,1); @@ -340,7 +339,7 @@ static int open_cred_file(char * file_name) if(length > MOUNT_PASSWD_SIZE) { fprintf(stderr, "mount.cifs failed: password in credentials file too long\n"); memset(line_buf,0, 4096); - exit(EX_USAGE); + return EX_USAGE; } else { if(mountpassword == NULL) { mountpassword = (char *)calloc(MOUNT_PASSWD_SIZE+1,1); @@ -368,7 +367,7 @@ static int open_cred_file(char * file_name) } if(length > DOMAIN_SIZE) { fprintf(stderr, "mount.cifs failed: domain in credentials file too long\n"); - exit(EX_USAGE); + return EX_USAGE; } else { if(domain_name == NULL) { domain_name = (char *)calloc(DOMAIN_SIZE+1,1); @@ -648,11 +647,11 @@ static int parse_options(char ** optionsp, unsigned long * filesys_flags) } else if (strncmp(data, "cred", 4) == 0) { if (value && *value) { rc = open_cred_file(value); - if(rc) { + if (rc) { fprintf(stderr, "error %d (%s) opening credential file %s\n", rc, strerror(rc), value); SAFE_FREE(out); - return 1; + return rc; } } else { fprintf(stderr, "invalid credential file name specified\n"); @@ -1182,11 +1181,12 @@ int main(int argc, char ** argv) bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); */ - if(argc && argv) - thisprogram = argv[0]; - else - mount_cifs_usage(stderr); + if (!argc || !argv) { + rc = mount_cifs_usage(stderr); + goto mount_exit; + } + thisprogram = argv[0]; if(thisprogram == NULL) thisprogram = "mount.cifs"; @@ -1207,7 +1207,8 @@ int main(int argc, char ** argv) case '?': case 'h': /* help */ - mount_cifs_usage(stdout); + rc = mount_cifs_usage(stdout); + goto mount_exit; case 'n': ++nomtab; break; @@ -1316,12 +1317,15 @@ int main(int argc, char ** argv) break; default: fprintf(stderr, "unknown mount option %c\n",c); - mount_cifs_usage(stderr); + rc = mount_cifs_usage(stderr); + goto mount_exit; } } - if(argc < 3 || argv[optind] == NULL || argv[optind + 1] == NULL) - mount_cifs_usage(stderr); + if(argc < 3 || argv[optind] == NULL || argv[optind + 1] == NULL) { + rc = mount_cifs_usage(stderr); + goto mount_exit; + } dev_name = argv[optind]; share_name = strndup(argv[optind], MAX_UNC_LEN);