Source-Changes-HG archive

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

[src/trunk]: src/external/bsd/cron/dist - exit with ERROR_EXIT consistently



details:   https://anonhg.NetBSD.org/src/rev/aa1ddb58bf2c
branches:  trunk
changeset: 767364:aa1ddb58bf2c
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Jul 17 01:16:46 2011 +0000

description:
- exit with ERROR_EXIT consistently
- don't use warnx() for things that set errno
- check result of setlogin()
- don't call setlogin() without calling setsid()
  should fix kernel warnings like:
        cron (pid NNNNN) changing logname from root to USER
        cron (pid MMMMM) changing logname from USER to root

diffstat:

 external/bsd/cron/dist/popen.c |  28 +++++++++++++++++-----------
 1 files changed, 17 insertions(+), 11 deletions(-)

diffs (68 lines):

diff -r dfda744e7bbb -r aa1ddb58bf2c external/bsd/cron/dist/popen.c
--- a/external/bsd/cron/dist/popen.c    Sun Jul 17 01:14:25 2011 +0000
+++ b/external/bsd/cron/dist/popen.c    Sun Jul 17 01:16:46 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: popen.c,v 1.2 2010/05/06 18:53:17 christos Exp $       */
+/*     $NetBSD: popen.c,v 1.3 2011/07/17 01:16:46 christos Exp $       */
 
 /*
  * Copyright (c) 1988, 1993, 1994
@@ -44,7 +44,7 @@
 static sccsid[] = "@(#)popen.c 8.3 (Berkeley) 4/6/94";
 static char rcsid[] = "Id: popen.c,v 1.6 2003/02/16 04:40:01 vixie Exp";
 #else
-__RCSID("$NetBSD: popen.c,v 1.2 2010/05/06 18:53:17 christos Exp $");
+__RCSID("$NetBSD: popen.c,v 1.3 2011/07/17 01:16:46 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -98,26 +98,32 @@
                /* NOTREACHED */
        case 0:                         /* child */
                if (pw) {
+                       if (setsid() == -1)
+                               warn("setsid() failed for %s", pw->pw_name);
 #ifdef LOGIN_CAP
-                       if (setusercontext(0, pw, pw->pw_uid, LOGIN_SETALL) < 0) {
-                               warnx("setusercontext failed for %s",
+                       if (setusercontext(0, pw, pw->pw_uid, LOGIN_SETALL) < 0)
+                       {
+                               warn("setusercontext() failed for %s",
                                    pw->pw_name);
                                _exit(ERROR_EXIT);
                        }
 #else
                        if (setgid(pw->pw_gid) < 0 ||
                            initgroups(pw->pw_name, pw->pw_gid) < 0) {
-                               warnx("unable to set groups for %s",
+                               warn("unable to set groups for %s",
                                    pw->pw_name);
-                               _exit(1);
+                               _exit(ERROR_EXIT);
                        }
 #if (defined(BSD)) && (BSD >= 199103)
-                       setlogin(pw->pw_name);
+                       if (setlogin(pw->pw_name) < 0) {
+                               warn("setlogin() failed for %s",
+                                   pw->pw_name);
+                               _exit(ERROR_EXIT);
+                       }
 #endif /* BSD */
                        if (setuid(pw->pw_uid)) {
-                               warnx("unable to set uid for %s",
-                                   pw->pw_name);
-                               _exit(1);
+                               warn("unable to set uid for %s", pw->pw_name);
+                               _exit(ERROR_EXIT);
                        }
 #endif /* LOGIN_CAP */
                }
@@ -136,7 +142,7 @@
                        (void)close(pdes[1]);
                }
                (void)execvp(argv[0], argv);
-               _exit(1);
+               _exit(ERROR_EXIT);
        }
 
        /* parent; assume fdopen can't fail...  */



Home | Main Index | Thread Index | Old Index