[PATCH 6/11] login: Use EXIT_*

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Marek Polacek <mmpolacek@xxxxxxxxx>
---
 login-utils/login.c |   51
++++++++++++++++++++++++++-------------------------
 1 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/login-utils/login.c b/login-utils/login.c
index 1802d3a..7dda310 100644
--- a/login-utils/login.c
+++ b/login-utils/login.c
@@ -97,6 +97,7 @@
 #include <sys/wait.h>
 #include <signal.h>
 #include <errno.h>
+#include <err.h>
 #include <grp.h>
 #include <pwd.h>
 #include <utmp.h>
@@ -124,7 +125,7 @@
 #  define PAM_FAIL_CHECK if (retcode != PAM_SUCCESS) { \
        fprintf(stderr,"\n%s\n",pam_strerror(pamh, retcode)); \
        syslog(LOG_ERR,"%s",pam_strerror(pamh, retcode)); \
-       pam_end(pamh, retcode); exit(1); \
+       pam_end(pamh, retcode); exit(EXIT_FAILURE); \
    }
 #  define PAM_END { \
 	pam_setcred(pamh, PAM_DELETE_CRED); \
@@ -197,14 +198,14 @@ opentty(const char * tty) {
 		syslog(LOG_ERR, _("FATAL: can't reopen tty: %s"),
 		       strerror(errno));
 		sleep(1);
-		exit(1);
+		exit(EXIT_FAILURE);
 	}

 	if (!isatty(fd)) {
 		close(fd);
 		syslog(LOG_ERR, _("FATAL: %s is not a terminal"), tty);
 		sleep(1);
-		exit(1);
+		exit(EXIT_FAILURE);
 	}

 	flags = fcntl(fd, F_GETFL);
@@ -237,7 +238,7 @@ check_ttyname(char *ttyn) {
 	    || (access(ttyn, R_OK | W_OK) != 0)) {
 		syslog(LOG_ERR, _("FATAL: bad tty"));
 		sleep(1);
-		exit(1);
+		exit(EXIT_FAILURE);
 	}
 }

@@ -443,7 +444,7 @@ main(int argc, char **argv)
 	  if (getuid()) {
 	      fprintf(stderr,
 		      _("login: -h for super-user only.\n"));
-	      exit(1);
+	      exit(EXIT_FAILURE);
 	  }
 	  hflag = 1;
 	  if (domain && (p = strchr(optarg, '.')) &&
@@ -486,7 +487,7 @@ main(int argc, char **argv)
 	default:
 	  fprintf(stderr,
 		  _("usage: login [-fp] [username]\n"));
-	  exit(1);
+	  exit(EXIT_FAILURE);
       }
     argc -= optind;
     argv += optind;
@@ -577,7 +578,7 @@ main(int argc, char **argv)
 		"login", pam_strerror(pamh, retcode));
 	syslog(LOG_ERR, _("Couldn't initialize PAM: %s"),
 	       pam_strerror(pamh, retcode));
-	exit(99);
+	exit(EXIT_FAILURE);
     }
     /* hostname & tty are either set to NULL or their correct values,
        depending on how much we know */
@@ -661,7 +662,7 @@ main(int argc, char **argv)

 	    fprintf(stderr,_("\nLogin incorrect\n"));
 	    pam_end(pamh, retcode);
-	    exit(0);
+	    exit(EXIT_SUCCESS);
 	}
     }

@@ -691,14 +692,14 @@ main(int argc, char **argv)
 	    syslog(LOG_ERR, _("NULL user name in %s:%d. Abort."),
 		   __FUNCTION__, __LINE__);
 	    pam_end(pamh, PAM_SYSTEM_ERR);
-	    exit(1);
+	    exit(EXIT_FAILURE);
     }
     if (!(pwd = getpwnam(username))) {
 	    fprintf(stderr, _("\nSession setup problem, abort.\n"));
 	    syslog(LOG_ERR, _("Invalid user name \"%s\" in %s:%d. Abort."),
 		   username, __FUNCTION__, __LINE__);
 	    pam_end(pamh, PAM_SYSTEM_ERR);
-	    exit(1);
+	    exit(EXIT_FAILURE);
     }

     /*
@@ -717,7 +718,7 @@ main(int argc, char **argv)
 	    fprintf(stderr, _("login: Out of memory\n"));
 	    syslog(LOG_ERR, "Out of memory");
 	    pam_end(pamh, PAM_SYSTEM_ERR);
-	    exit(1);
+	    exit(EXIT_FAILURE);
     }
     username = pwd->pw_name;

@@ -730,7 +731,7 @@ main(int argc, char **argv)
 	    syslog(LOG_ERR, "initgroups: %m");
 	    fprintf(stderr, _("\nSession setup problem, abort.\n"));
 	    pam_end(pamh, PAM_SYSTEM_ERR);
-	    exit(1);
+	    exit(EXIT_FAILURE);
     }

     retcode = pam_open_session(pamh, 0);
@@ -760,7 +761,7 @@ main(int argc, char **argv)
 	if (username[0] == '+') {
 	    puts(_("Illegal username"));
 	    badlogin(username);
-	    sleepexit(1);
+	    sleepexit(EXIT_FAILURE);
 	}

 	/* (void)strcpy(tbuf, username); why was this here? */
@@ -871,7 +872,7 @@ main(int argc, char **argv)
 	/* we allow 10 tries, but after 3 we start backing off */
 	if (++cnt > 3) {
 	    if (cnt >= 10) {
-		sleepexit(1);
+		sleepexit(EXIT_FAILURE);
 	    }
 	    sleep((unsigned int)((cnt - 3) * 5));
 	}
@@ -1174,7 +1175,7 @@ Michael Riepe <michael@xxxxxxxxxxxxxxxxxxxx>
        /* error in fork() */
        fprintf(stderr, _("login: failure forking: %s"), strerror(errsv));
        PAM_END;
-       exit(0);
+       exit(EXIT_SUCCESS);
     }

     if (child_pid) {
@@ -1191,7 +1192,7 @@ Michael Riepe <michael@xxxxxxxxxxxxxxxxxxxx>
 	       ;
        openlog("login", LOG_ODELAY, LOG_AUTHPRIV);
        PAM_END;
-       exit(0);
+       exit(EXIT_SUCCESS);
     }

     /* child */
@@ -1200,7 +1201,7 @@ Michael Riepe <michael@xxxxxxxxxxxxxxxxxxxx>
     sigaction(SIGHUP, &oldsa_hup, NULL);
     sigaction(SIGTERM, &oldsa_term, NULL);
     if(got_sig)
-	    exit(1);
+	    exit(EXIT_FAILURE);

     /*
      * Problem: if the user's shell is a shell like ash that doesnt do
@@ -1226,14 +1227,14 @@ Michael Riepe <michael@xxxxxxxxxxxxxxxxxxxx>
     /* discard permissions last so can't get killed and drop core */
     if(setuid(pwd->pw_uid) < 0 && pwd->pw_uid) {
 	syslog(LOG_ALERT, _("setuid() failed"));
-	exit(1);
+	exit(EXIT_FAILURE);
     }

     /* wait until here to change directory! */
     if (chdir(pwd->pw_dir) < 0) {
 	printf(_("No directory %s!\n"), pwd->pw_dir);
 	if (chdir("/"))
-	  exit(0);
+	  exit(EXIT_SUCCESS);
 	pwd->pw_dir = "/";
 	printf(_("Logging in with home = \"/\".\n"));
     }
@@ -1270,7 +1271,7 @@ Michael Riepe <michael@xxxxxxxxxxxxxxxxxxxx>
     else
 	fprintf(stderr, _("login: no shell: %s.\n"), strerror(errsv));

-    exit(0);
+    exit(EXIT_SUCCESS);
 }

 #ifndef HAVE_SECURITY_PAM_MISC_H
@@ -1287,7 +1288,7 @@ getloginname(void) {
 	for (p = nbuf; (ch = getchar()) != '\n'; ) {
 	    if (ch == EOF) {
 		badlogin("EOF");
-		exit(0);
+		exit(EXIT_SUCCESS);
 	    }
 	    if (p < nbuf + UT_NAMESIZE)
 	      *p++ = ch;
@@ -1296,7 +1297,7 @@ getloginname(void) {
 	    if (cnt > UT_NAMESIZE + 20) {
 		fprintf(stderr, _("login name much too long.\n"));
 		badlogin(_("NAME too long"));
-		exit(0);
+		exit(EXIT_SUCCESS);
 	    }
 	}
 	if (p > nbuf) {
@@ -1314,7 +1315,7 @@ getloginname(void) {
 	if (cnt2 > 50) {
 	    fprintf(stderr, _("too many bare linefeeds.\n"));
 	    badlogin(_("EXCESSIVE linefeeds"));
-	    exit(0);
+	    exit(EXIT_SUCCESS);
 	}
     }
 }
@@ -1338,7 +1339,7 @@ timedout2(int sig) {
 	tcgetattr(0, &ti);
 	ti.c_lflag |= ECHO;
 	tcsetattr(0, TCSANOW, &ti);
-	exit(0);			/* %% */
+	exit(EXIT_SUCCESS);			/* %% */
 }

 static void
@@ -1416,7 +1417,7 @@ checknologin(void) {
 	while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0)
 	  write(fileno(stdout), tbuf, nchars);
 	close(fd);
-	sleepexit(0);
+	sleepexit(EXIT_SUCCESS);
     }
 }
 #endif
-- 
1.7.3.2


--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux