diff mbox

[10/10] mount.cifs: don't use exit(3) in get_password_from_file

Message ID 1269199227-21446-11-git-send-email-jlayton@redhat.com
State New
Headers show

Commit Message

Jeff Layton March 21, 2010, 7:20 p.m. UTC
Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
 mount.cifs.c |   20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)
diff mbox

Patch

diff --git a/mount.cifs.c b/mount.cifs.c
index e6ab7cc..ca4f4e4 100644
--- a/mount.cifs.c
+++ b/mount.cifs.c
@@ -400,7 +400,7 @@  static int get_password_from_file(int file_descript, char * filename)
 
 	if (mountpassword == NULL) {
 		fprintf(stderr, "malloc failed\n");
-		exit(EX_SYSERR);
+		return EX_SYSERR;
 	}
 
 	if(filename != NULL) {
@@ -408,13 +408,13 @@  static int get_password_from_file(int file_descript, char * filename)
 		if (rc) {
 			fprintf(stderr, "mount.cifs failed: access check of %s failed: %s\n",
 					filename, strerror(errno));
-			exit(EX_SYSERR);
+			return EX_SYSERR;
 		}
 		file_descript = open(filename, O_RDONLY);
 		if(file_descript < 0) {
 			fprintf(stderr, "mount.cifs failed. %s attempting to open password file %s\n",
 				   strerror(errno),filename);
-			exit(EX_SYSERR);
+			return EX_SYSERR;
 		}
 	}
 	/* else file already open and fd provided */
@@ -425,7 +425,7 @@  static int get_password_from_file(int file_descript, char * filename)
 			fprintf(stderr, "mount.cifs failed. Error %s reading password file\n",strerror(errno));
 			if(filename != NULL)
 				close(file_descript);
-			exit(EX_SYSERR);
+			return EX_SYSERR;
 		} else if(rc == 0) {
 			if(mountpassword[0] == 0) {
 				if(verboseflag)
@@ -1308,7 +1308,9 @@  int main(int argc, char ** argv)
 			}
 			break;
 		case 'S':
-			get_password_from_file(0 /* stdin */,NULL);
+			rc = get_password_from_file(0 /* stdin */,NULL);
+			if (rc)
+				goto mount_exit;
 			break;
 		case 't':
 			break;
@@ -1368,9 +1370,13 @@  int main(int argc, char ** argv)
 			got_password = 1;
 		}
 	} else if (getenv("PASSWD_FD")) {
-		get_password_from_file(atoi(getenv("PASSWD_FD")),NULL);
+		rc = get_password_from_file(atoi(getenv("PASSWD_FD")),NULL);
+		if (rc)
+			goto mount_exit;
 	} else if (getenv("PASSWD_FILE")) {
-		get_password_from_file(0, getenv("PASSWD_FILE"));
+		rc = get_password_from_file(0, getenv("PASSWD_FILE"));
+		if (rc)
+			goto mount_exit;
 	}
 
         if (orgoptions && parse_options(&orgoptions, &flags)) {