svn commit: r193795 - stable/7/lib/libutil

Dag-Erling Smorgrav des at FreeBSD.org
Tue Jun 9 01:44:00 UTC 2009


Author: des
Date: Tue Jun  9 01:43:58 2009
New Revision: 193795
URL: http://svn.freebsd.org/changeset/base/193795

Log:
  merge r180815,184081-184088,184091-184094,184634,184676-184677, 185277,
  93589,193591: style and warning cleanups, libutil is now WARNS=6 clean.
  Also merged setclasscpumask(), which would have been a b***h to isolate
  from the rest of the changes.  AFAICT, nobody uses it anyway.

Modified:
  stable/7/lib/libutil/   (props changed)
  stable/7/lib/libutil/Makefile
  stable/7/lib/libutil/flopen.3
  stable/7/lib/libutil/flopen.c
  stable/7/lib/libutil/login.conf.5
  stable/7/lib/libutil/login_cap.h
  stable/7/lib/libutil/login_class.3
  stable/7/lib/libutil/login_class.c
  stable/7/lib/libutil/login_times.3
  stable/7/lib/libutil/login_times.c
  stable/7/lib/libutil/pidfile.3
  stable/7/lib/libutil/pidfile.c
  stable/7/lib/libutil/realhostname.c

Modified: stable/7/lib/libutil/Makefile
==============================================================================
--- stable/7/lib/libutil/Makefile	Tue Jun  9 01:41:45 2009	(r193794)
+++ stable/7/lib/libutil/Makefile	Tue Jun  9 01:43:58 2009	(r193795)
@@ -8,7 +8,7 @@ SHLIBDIR?= /lib
 LIB=	util
 SHLIB_MAJOR= 7
 
-SRCS=	_secure_path.c auth.c gr_util.c expand_number.c flopen.c fparseln.c \
+SRCS=	_secure_path.c auth.c expand_number.c flopen.c fparseln.c gr_util.c \
 	humanize_number.c kinfo_getfile.c kinfo_getvmmap.c kld.c \
 	login.c login_auth.c login_cap.c login_class.c \
 	login_crypt.c login_ok.c login_times.c login_tty.c logout.c \

Modified: stable/7/lib/libutil/flopen.3
==============================================================================
--- stable/7/lib/libutil/flopen.3	Tue Jun  9 01:41:45 2009	(r193794)
+++ stable/7/lib/libutil/flopen.3	Tue Jun  9 01:43:58 2009	(r193795)
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd May 10, 2007
+.Dd June 6, 2009
 .Dt FLOPEN 3
 .Os
 .Sh NAME
@@ -93,11 +93,6 @@ and
 .Xr errno 2 ,
 .Xr flock 2 ,
 .Xr open 2
-.Sh HISTORY
-The
-.Fn flopen
-function first appeared in
-.Fx 6.3 .
 .Sh AUTHORS
 .An -nosplit
 The

Modified: stable/7/lib/libutil/flopen.c
==============================================================================
--- stable/7/lib/libutil/flopen.c	Tue Jun  9 01:41:45 2009	(r193794)
+++ stable/7/lib/libutil/flopen.c	Tue Jun  9 01:43:58 2009	(r193795)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2007 Dag-Erling Coïdan Smørgrav
+ * Copyright (c) 2007 Dag-Erling Coïdan Smørgrav
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,6 @@ __FBSDID("$FreeBSD$");
 #include <sys/stat.h>
 
 #include <errno.h>
-#include <fcntl.h>
 #include <stdarg.h>
 #include <unistd.h>
 
@@ -54,13 +53,13 @@ flopen(const char *path, int flags, ...)
 		va_list ap;
 
 		va_start(ap, flags);
-		mode = va_arg(ap, int); /* mode_t promoted to int */
+		mode = (mode_t)va_arg(ap, int); /* mode_t promoted to int */
 		va_end(ap);
 	}
 
-	operation = LOCK_EX;
-	if (flags & O_NONBLOCK)
-		operation |= LOCK_NB;
+        operation = LOCK_EX;
+        if (flags & O_NONBLOCK)
+                operation |= LOCK_NB;
 
 	trunc = (flags & O_TRUNC);
 	flags &= ~O_TRUNC;
@@ -72,32 +71,32 @@ flopen(const char *path, int flags, ...)
 		if (flock(fd, operation) == -1) {
 			/* unsupported or interrupted */
 			serrno = errno;
-			close(fd);
+			(void)close(fd);
 			errno = serrno;
 			return (-1);
 		}
 		if (stat(path, &sb) == -1) {
 			/* disappeared from under our feet */
-			close(fd);
+			(void)close(fd);
 			continue;
 		}
 		if (fstat(fd, &fsb) == -1) {
 			/* can't happen [tm] */
 			serrno = errno;
-			close(fd);
+			(void)close(fd);
 			errno = serrno;
 			return (-1);
 		}
 		if (sb.st_dev != fsb.st_dev ||
 		    sb.st_ino != fsb.st_ino) {
 			/* changed under our feet */
-			close(fd);
+			(void)close(fd);
 			continue;
 		}
 		if (trunc && ftruncate(fd, 0) != 0) {
 			/* can't happen [tm] */
 			serrno = errno;
-			close(fd);
+			(void)close(fd);
 			errno = serrno;
 			return (-1);
 		}

Modified: stable/7/lib/libutil/login.conf.5
==============================================================================
--- stable/7/lib/libutil/login.conf.5	Tue Jun  9 01:41:45 2009	(r193794)
+++ stable/7/lib/libutil/login.conf.5	Tue Jun  9 01:43:58 2009	(r193795)
@@ -203,6 +203,15 @@ The maximum and current limits may be sp
 .It Sy "Name	Type	Notes	Description
 .It "charset	string		Set $MM_CHARSET environment variable to the specified
 value.
+.It "cpumask	string		List of cpus to bind the user to.
+The syntax is the same as for the
+.Fl l
+argument of
+.Xr cpuset 1 or the word
+.Ql default .
+If set to
+.Ql default
+no action is taken.
 .It "hushlogin	bool	false	Same as having a ~/.hushlogin file.
 .It "ignorenologin	bool	false	Login not prevented by nologin.
 .It "ftp-chroot	bool	false	Limit FTP access with

Modified: stable/7/lib/libutil/login_cap.h
==============================================================================
--- stable/7/lib/libutil/login_cap.h	Tue Jun  9 01:41:45 2009	(r193794)
+++ stable/7/lib/libutil/login_cap.h	Tue Jun  9 01:43:58 2009	(r193795)
@@ -48,7 +48,8 @@
 #define LOGIN_SETUSER		0x0040		/* set user (via setuid) */
 #define LOGIN_SETENV		0x0080		/* set user environment */
 #define LOGIN_SETMAC		0x0100		/* set user default MAC label */
-#define LOGIN_SETALL		0x01ff		/* set everything */
+#define LOGIN_SETCPUMASK	0x0200		/* set user cpumask */
+#define LOGIN_SETALL		0x03ff		/* set everything */
 
 #define BI_AUTH		"authorize"		/* accepted authentication */
 #define BI_REJECT	"reject"		/* rejected authentication */
@@ -80,7 +81,7 @@ typedef struct login_time {
 #define LTM_NONE  0x00
 #define LTM_SUN   0x01
 #define LTM_MON   0x02
-#define LTM_TUE   0x04 
+#define LTM_TUE   0x04
 #define LTM_WED   0x08
 #define LTM_THU   0x10
 #define LTM_FRI   0x20
@@ -103,7 +104,8 @@ login_cap_t *login_getclass(const char *
 login_cap_t *login_getpwclass(const struct passwd *);
 login_cap_t *login_getuserclass(const struct passwd *);
 
-const char *login_getcapstr(login_cap_t*, const char *, const char *, const char *);
+const char *login_getcapstr(login_cap_t *, const char *, const char *,
+    const char *);
 const char **login_getcaplist(login_cap_t *, const char *, const char *);
 const char *login_getstyle(login_cap_t *, const char *, const char *);
 rlim_t login_getcaptime(login_cap_t *, const char *, rlim_t, rlim_t);
@@ -113,45 +115,51 @@ const char *login_getpath(login_cap_t *,
 int login_getcapbool(login_cap_t *, const char *, int);
 const char *login_setcryptfmt(login_cap_t *, const char *, const char *);
 
-int setclasscontext(const char*, unsigned int);
-int setusercontext(login_cap_t*, const struct passwd*, uid_t, unsigned int);
+int setclasscontext(const char *, unsigned int);
+void setclasscpumask(login_cap_t *);
+int setusercontext(login_cap_t *, const struct passwd *, uid_t, unsigned int);
 void setclassresources(login_cap_t *);
 void setclassenvironment(login_cap_t *, const struct passwd *, int);
 
 /* Most of these functions are deprecated */
-int auth_approve(login_cap_t*, const char*, const char*);
+int auth_approve(login_cap_t *, const char *, const char *);
 int auth_check(const char *, const char *, const char *, const char *, int *);
 void auth_env(void);
-char *auth_mkvalue(const char *n);
-int auth_response(const char *, const char *, const char *, const char *, int *, const char *, const char *);
+char *auth_mkvalue(const char *);
+int auth_response(const char *, const char *, const char *, const char *, int *,
+    const char *, const char *);
 void auth_rmfiles(void);
 int auth_scan(int);
-int auth_script(const char*, ...);
+int auth_script(const char *, ...);
 int auth_script_data(const char *, int, const char *, ...);
 char *auth_valud(const char *);
 int auth_setopt(const char *, const char *);
 void auth_clropts(void);
 
-void auth_checknologin(login_cap_t*);
-int auth_cat(const char*);
+void auth_checknologin(login_cap_t *);
+int auth_cat(const char *);
 
-int auth_ttyok(login_cap_t*, const char *);
-int auth_hostok(login_cap_t*, const char *, char const *);
-int auth_timeok(login_cap_t*, time_t);
+int auth_ttyok(login_cap_t *, const char *);
+int auth_hostok(login_cap_t *, const char *, char const *);
+int auth_timeok(login_cap_t *, time_t);
 
 struct tm;
 
 login_time_t parse_lt(const char *);
+int in_lt(const login_time_t *, time_t *);
 int in_ltm(const login_time_t *, struct tm *, time_t *);
 int in_ltms(const login_time_t *, struct tm *, time_t *);
+int in_lts(const login_time_t *, time_t *);
 
 /* helper functions */
 
 int login_strinlist(const char **, char const *, int);
 int login_str2inlist(const char **, const char *, const char *, int);
-login_time_t * login_timelist(login_cap_t *, char const *, int *, login_time_t **);
+login_time_t * login_timelist(login_cap_t *, char const *, int *,
+    login_time_t **);
 int login_ttyok(login_cap_t *, const char *, const char *, const char *);
-int login_hostok(login_cap_t *, const char *, const char *, const char *, const char *);
+int login_hostok(login_cap_t *, const char *, const char *, const char *,
+    const char *);
 
 __END_DECLS
 

Modified: stable/7/lib/libutil/login_class.3
==============================================================================
--- stable/7/lib/libutil/login_class.3	Tue Jun  9 01:41:45 2009	(r193794)
+++ stable/7/lib/libutil/login_class.3	Tue Jun  9 01:43:58 2009	(r193795)
@@ -19,11 +19,12 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd December 28, 1996
+.Dd October 20, 2008
 .Os
 .Dt LOGIN_CLASS 3
 .Sh NAME
 .Nm setclasscontext ,
+.Nm setclasscpumask ,
 .Nm setclassenvironment ,
 .Nm setclassresources ,
 .Nm setusercontext
@@ -35,12 +36,14 @@
 .In login_cap.h
 .Ft int
 .Fn setclasscontext "const char *classname" "unsigned int flags"
-.Ft int
-.Fn setusercontext "login_cap_t *lc" "const struct passwd *pwd" "uid_t uid" "unsigned int flags"
 .Ft void
-.Fn setclassresources "login_cap_t *lc"
+.Fn setclasscpumask "login_cap_t *lc"
 .Ft void
 .Fn setclassenvironment "login_cap_t *lc" "const struct passwd *pwd" "int paths"
+.Ft void
+.Fn setclassresources "login_cap_t *lc"
+.Ft int
+.Fn setusercontext "login_cap_t *lc" "const struct passwd *pwd" "uid_t uid" "unsigned int flags"
 .Sh DESCRIPTION
 These functions provide a higher level interface to the login class
 database than those documented in
@@ -155,6 +158,18 @@ capability "setenv=var1 val1,var2 val2..
 Set the MAC label for the current process to the label specified
 in system login class database.
 .Pp
+.It LOGIN_SETCPUMASK
+Create a new
+.Xr cpuset 2
+and set the cpu affinity to the specified mask.
+The string may contain a comma separated list of numbers and/or number
+ranges as handled by the
+.Xr cpuset 1
+utility or the case-insensitive string
+.Ql default .
+If the string is
+.Ql default
+no action will be taken.
 .It LOGIN_SETALL
 Enables all of the above settings.
 .El
@@ -170,6 +185,7 @@ are substituted for the user's home dire
 respectively.
 .Pp
 The
+.Fn setclasscpumask ,
 .Fn setclassresources
 and
 .Fn setclassenvironment
@@ -186,6 +202,8 @@ or resources, a message is reported to
 .Xr syslog 3 ,
 with LOG_ERR priority and directed to the currently active facility.
 .Sh SEE ALSO
+.Xr cpuset 1 ,
+.Xr cpuset 2 ,
 .Xr setgid 2 ,
 .Xr setlogin 2 ,
 .Xr setuid 2 ,

Modified: stable/7/lib/libutil/login_class.c
==============================================================================
--- stable/7/lib/libutil/login_class.c	Tue Jun  9 01:41:45 2009	(r193794)
+++ stable/7/lib/libutil/login_class.c	Tue Jun  9 01:43:58 2009	(r193795)
@@ -25,12 +25,16 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/resource.h>
+#include <sys/param.h>
+#include <sys/cpuset.h>
 #include <sys/mac.h>
+#include <sys/resource.h>
 #include <sys/rtprio.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+
+#include <ctype.h>
+#include <err.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <login_cap.h>
@@ -89,7 +93,7 @@ setclassresources(login_cap_t *lc)
 	if (getrlimit(lr->why, &rlim) != 0)
 	    syslog(LOG_ERR, "getting %s resource limit: %m", lr->what);
 	else {
-	    char  	name_cur[40];
+	    char	name_cur[40];
 	    char	name_max[40];
 	    rlim_t	rcur = rlim.rlim_cur;
 	    rlim_t	rmax = rlim.rlim_max;
@@ -101,7 +105,7 @@ setclassresources(login_cap_t *lc)
 	    rmax = (*lr->who)(lc, lr->what, rmax, rmax);
 	    rlim.rlim_cur = (*lr->who)(lc, name_cur, rcur, rcur);
 	    rlim.rlim_max = (*lr->who)(lc, name_max, rmax, rmax);
-    
+
 	    if (setrlimit(lr->why, &rlim) == -1)
 		syslog(LOG_WARNING, "set class '%s' resource limit %s: %m", lc->lc_class, lr->what);
 	}
@@ -181,7 +185,7 @@ substvar(const char * var, const struct 
 	}
     }
 
-    return np;
+    return (np);
 }
 
 
@@ -238,6 +242,108 @@ setclassenvironment(login_cap_t *lc, con
 }
 
 
+static int
+list2cpuset(const char *list, cpuset_t *mask)
+{
+	enum { NONE, NUM, DASH } state;
+	int lastnum;
+	int curnum;
+	const char *l;
+
+	state = NONE;
+	curnum = lastnum = 0;
+	for (l = list; *l != '\0';) {
+		if (isdigit(*l)) {
+			curnum = atoi(l);
+			if (curnum > CPU_SETSIZE)
+				errx(EXIT_FAILURE,
+				    "Only %d cpus supported", CPU_SETSIZE);
+			while (isdigit(*l))
+				l++;
+			switch (state) {
+			case NONE:
+				lastnum = curnum;
+				state = NUM;
+				break;
+			case DASH:
+				for (; lastnum <= curnum; lastnum++)
+					CPU_SET(lastnum, mask);
+				state = NONE;
+				break;
+			case NUM:
+			default:
+				return (0);
+			}
+			continue;
+		}
+		switch (*l) {
+		case ',':
+			switch (state) {
+			case NONE:
+				break;
+			case NUM:
+				CPU_SET(curnum, mask);
+				state = NONE;
+				break;
+			case DASH:
+				return (0);
+				break;
+			}
+			break;
+		case '-':
+			if (state != NUM)
+				return (0);
+			state = DASH;
+			break;
+		default:
+			return (0);
+		}
+		l++;
+	}
+	switch (state) {
+		case NONE:
+			break;
+		case NUM:
+			CPU_SET(curnum, mask);
+			break;
+		case DASH:
+			return (0);
+	}
+	return (1);
+}
+
+
+void
+setclasscpumask(login_cap_t *lc)
+{
+	const char *maskstr;
+	cpuset_t maskset;
+	cpusetid_t setid;
+
+	maskstr = login_getcapstr(lc, "cpumask", NULL, NULL);
+	CPU_ZERO(&maskset);
+	if (maskstr == NULL)
+		return;
+	if (strcasecmp("default", maskstr) == 0)
+		return;
+	if (!list2cpuset(maskstr, &maskset)) {
+		syslog(LOG_WARNING,
+		    "list2cpuset(%s) invalid mask specification", maskstr);
+		return;
+	}
+
+	if (cpuset(&setid) != 0) {
+		syslog(LOG_ERR, "cpuset(): %s", strerror(errno));
+		return;
+	}
+
+	if (cpuset_setaffinity(CPU_LEVEL_CPUSET, CPU_WHICH_PID, -1,
+	    sizeof(maskset), &maskset) != 0)
+		syslog(LOG_ERR, "cpuset_setaffinity(%s): %s", maskstr,
+		    strerror(errno));
+}
+
+
 /*
  * setclasscontext()
  *
@@ -262,7 +368,7 @@ setclasscontext(const char *classname, u
 
     rc = lc ? setusercontext(lc, NULL, 0, flags) : -1;
     login_close(lc);
-    return rc;
+    return (rc);
 }
 
 
@@ -288,8 +394,11 @@ setlogincontext(login_cap_t *lc, const s
 	/* Set environment */
 	if (flags & LOGIN_SETENV)
 	    setclassenvironment(lc, pwd, 0);
+	/* Set cpu affinity */
+	if (flags & LOGIN_SETCPUMASK)
+	    setclasscpumask(lc);
     }
-    return mymask;
+    return (mymask);
 }
 
 
@@ -359,13 +468,13 @@ setusercontext(login_cap_t *lc, const st
 	if (setgid(pwd->pw_gid) != 0) {
 	    syslog(LOG_ERR, "setgid(%lu): %m", (u_long)pwd->pw_gid);
 	    login_close(llc);
-	    return -1;
+	    return (-1);
 	}
 	if (initgroups(pwd->pw_name, pwd->pw_gid) == -1) {
 	    syslog(LOG_ERR, "initgroups(%s,%lu): %m", pwd->pw_name,
 		   (u_long)pwd->pw_gid);
 	    login_close(llc);
-	    return -1;
+	    return (-1);
 	}
     }
 
@@ -379,7 +488,7 @@ setusercontext(login_cap_t *lc, const st
 	    if (mac_from_text(&label, label_string) == -1) {
 		syslog(LOG_ERR, "mac_from_text('%s') for %s: %m",
 		    pwd->pw_name, label_string);
-		    return -1;
+		return (-1);
 	    }
 	    if (mac_set_proc(label) == -1)
 		error = errno;
@@ -389,7 +498,7 @@ setusercontext(login_cap_t *lc, const st
 	    if (error != 0) {
 		syslog(LOG_ERR, "mac_set_proc('%s') for %s: %s",
 		    label_string, pwd->pw_name, strerror(error));
-		return -1;
+		return (-1);
 	    }
 	}
     }
@@ -398,7 +507,7 @@ setusercontext(login_cap_t *lc, const st
     if ((flags & LOGIN_SETLOGIN) && setlogin(pwd->pw_name) != 0) {
 	syslog(LOG_ERR, "setlogin(%s): %m", pwd->pw_name);
 	login_close(llc);
-	return -1;
+	return (-1);
     }
 
     mymask = (flags & LOGIN_SETUMASK) ? umask(LOGIN_DEFUMASK) : 0;
@@ -408,7 +517,7 @@ setusercontext(login_cap_t *lc, const st
     /* This needs to be done after anything that needs root privs */
     if ((flags & LOGIN_SETUSER) && setuid(uid) != 0) {
 	syslog(LOG_ERR, "setuid(%lu): %m", (u_long)uid);
-	return -1;	/* Paranoia again */
+	return (-1);	/* Paranoia again */
     }
 
     /*
@@ -423,6 +532,5 @@ setusercontext(login_cap_t *lc, const st
     if (flags & LOGIN_SETUMASK)
 	umask(mymask);
 
-    return 0;
+    return (0);
 }
-

Modified: stable/7/lib/libutil/login_times.3
==============================================================================
--- stable/7/lib/libutil/login_times.3	Tue Jun  9 01:41:45 2009	(r193794)
+++ stable/7/lib/libutil/login_times.3	Tue Jun  9 01:43:58 2009	(r193795)
@@ -19,13 +19,15 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd January 2, 1997
+.Dd October 20, 2008
 .Os
 .Dt LOGIN_TIMES 3
 .Sh NAME
 .Nm parse_lt ,
+.Nm in_lt ,
 .Nm in_ltm ,
-.Nm in_ltms
+.Nm in_ltms ,
+.Nm in_lts
 .Nd functions for parsing and checking login time periods
 .Sh LIBRARY
 .Lb libutil
@@ -36,9 +38,13 @@
 .Ft login_time_t
 .Fn parse_lt "const char *str"
 .Ft int
+.Fn in_lt "const login_time_t *lt" "time_t *ends"
+.Ft int
 .Fn in_ltm "const login_time_t *lt" "struct tm *t" "time_t *ends"
 .Ft int
 .Fn in_ltms "const login_time_t *lt" "struct tm *t" "time_t *ends"
+.Ft int
+.Fn in_lts "const login_time_t *lt" "time_t *ends"
 .Sh DESCRIPTION
 This set of functions may be used for parsing and checking login and
 session times against a predefined list of allowed login times as
@@ -135,6 +141,18 @@ elements in length, and terminated by an
 .Ar lt_dow
 field set to
 .Em LTM_NONE .
+.Pp
+The
+.Fn in_lt
+and
+.Fn in_lts
+functions are equivalent to
+.Fn in_ltm
+and
+.Fn in_ltms ,
+respectively, with the second argument set to the current time as
+returned by
+.Xr localtime 3 .
 .Sh RETURN VALUES
 The
 .Fn parse_lt

Modified: stable/7/lib/libutil/login_times.c
==============================================================================
--- stable/7/lib/libutil/login_times.c	Tue Jun  9 01:41:45 2009	(r193794)
+++ stable/7/lib/libutil/login_times.c	Tue Jun  9 01:43:58 2009	(r193795)
@@ -34,13 +34,13 @@ __FBSDID("$FreeBSD$");
 static struct
 {
     const char	*dw;
-    u_char      cn;
-    u_char      fl;
+    u_char       cn;
+    u_char       fl;
 } dws[] =
 {
     { "su", 2, LTM_SUN }, { "mo", 2, LTM_MON }, { "tu", 2, LTM_TUE },
     { "we", 2, LTM_WED }, { "th", 2, LTM_THU }, { "fr", 2, LTM_FRI },
-    { "sa", 2, LTM_SAT }, { "any",3, LTM_ANY }, { "all",3, LTM_ANY }, 
+    { "sa", 2, LTM_SAT }, { "any",3, LTM_ANY }, { "all",3, LTM_ANY },
     { "wk", 2, LTM_WK  }, { "wd", 2, LTM_WD  }, { NULL, 0, 0       }
 };
 
@@ -54,28 +54,28 @@ parse_time(char * ptr, u_short * t)
 
     *t = (u_short)((val / 100) * 60 + (val % 100));
 
-    return ptr;
+    return (ptr);
 }
 
 
 login_time_t
-parse_lt(const char * str)
+parse_lt(const char *str)
 {
     login_time_t    t;
 
     memset(&t, 0, sizeof t);
     t.lt_dow = LTM_NONE;
     if (str && *str && strcmp(str, "Never") != 0 && strcmp(str, "None") != 0) {
-	int		i;
-	login_time_t	m = t;
+	int		 i;
+	login_time_t	 m = t;
 	char		*p;
-	char		buf[64];
+	char		 buf[64];
 
 	/* Make local copy and force lowercase to simplify parsing */
-	p = strncpy(buf, str, sizeof buf);
-	buf[sizeof buf - 1] = '\0';
+	strlcpy(buf, str, sizeof buf);
 	for (i = 0; buf[i]; i++)
 	    buf[i] = (char)tolower(buf[i]);
+	p = buf;
 
 	while (isalpha(*p)) {
 
@@ -102,12 +102,12 @@ parse_lt(const char * str)
 
 	t = m;
     }
-    return t;
+    return (t);
 }
 
 
 int
-in_ltm(const login_time_t * ltm, struct tm * tt, time_t * ends)
+in_ltm(const login_time_t *ltm, struct tm *tt, time_t *ends)
 {
     int	    rc = 0;
 
@@ -130,32 +130,33 @@ in_ltm(const login_time_t * ltm, struct 
 	    }
 	}
     }
-    return rc;
+    return (rc);
 }
 
 
 int
-in_lt(const login_time_t * ltm, time_t * t)
+in_lt(const login_time_t *ltm, time_t *t)
 {
-    return in_ltm(ltm, localtime(t), t);
+
+    return (in_ltm(ltm, localtime(t), t));
 }
 
 int
-in_ltms(const login_time_t * ltm, struct tm * tm, time_t * t)
+in_ltms(const login_time_t *ltm, struct tm *tm, time_t *t)
 {
     int	    i = 0;
 
     while (i < LC_MAXTIMES && ltm[i].lt_dow != LTM_NONE) {
 	if (in_ltm(ltm + i, tm, t))
-	    return i;
+	    return (i);
 	i++;
     }
-    return -1;
+    return (-1);
 }
 
 int
-in_lts(const login_time_t * ltm, time_t * t)
+in_lts(const login_time_t *ltm, time_t *t)
 {
-    return in_ltms(ltm, localtime(t), t);
-}
 
+    return (in_ltms(ltm, localtime(t), t));
+}

Modified: stable/7/lib/libutil/pidfile.3
==============================================================================
--- stable/7/lib/libutil/pidfile.3	Tue Jun  9 01:41:45 2009	(r193794)
+++ stable/7/lib/libutil/pidfile.3	Tue Jun  9 01:43:58 2009	(r193795)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd August 22, 2005
+.Dd October 20, 2008
 .Dt PIDFILE 3
 .Os
 .Sh NAME
@@ -51,16 +51,14 @@ The
 .Nm pidfile
 family of functions allows daemons to handle PID files.
 It uses
-.Xr flock 2
+.Xr flopen 3
 to lock a pidfile and detect already running daemons.
 .Pp
 The
 .Fn pidfile_open
 function opens (or creates) a file specified by the
 .Fa path
-argument and locks it with the
-.Xr flock 2
-system call.
+argument and locks it.
 If a file can not be locked, a PID of an already running daemon is returned in
 the
 .Fa pidptr
@@ -102,6 +100,7 @@ if an error occurs.
 If an error occurs,
 .Va errno
 will be set.
+.Pp
 .Rv -std pidfile_write pidfile_close pidfile_remove
 .Sh EXAMPLES
 The following example shows in which order these functions should be used.
@@ -233,16 +232,17 @@ function may also fail and set
 .Va errno
 for any errors specified for the
 .Xr close 2 ,
-.Xr flock 2 ,
 .Xr fstat 2 ,
 .Xr write 2 ,
 and
 .Xr unlink 2
-calls.
+system calls and the
+.Xr flopen 3
+library function.
 .Sh SEE ALSO
-.Xr flock 2 ,
 .Xr open 2 ,
-.Xr daemon 3
+.Xr daemon 3 ,
+.Xr flopen 3
 .Sh AUTHORS
 .An -nosplit
 The

Modified: stable/7/lib/libutil/pidfile.c
==============================================================================
--- stable/7/lib/libutil/pidfile.c	Tue Jun  9 01:41:45 2009	(r193794)
+++ stable/7/lib/libutil/pidfile.c	Tue Jun  9 01:43:58 2009	(r193795)
@@ -231,10 +231,6 @@ _pidfile_remove(struct pidfh *pfh, int f
 
 	if (unlink(pfh->pf_path) == -1)
 		error = errno;
-	if (flock(pfh->pf_fd, LOCK_UN) == -1) {
-		if (error == 0)
-			error = errno;
-	}
 	if (close(pfh->pf_fd) == -1) {
 		if (error == 0)
 			error = errno;

Modified: stable/7/lib/libutil/realhostname.c
==============================================================================
--- stable/7/lib/libutil/realhostname.c	Tue Jun  9 01:41:45 2009	(r193794)
+++ stable/7/lib/libutil/realhostname.c	Tue Jun  9 01:43:58 2009	(r193795)
@@ -101,7 +101,9 @@ realhostname_sa(char *host, size_t hsize
 {
 	int result, error;
 	char buf[NI_MAXHOST];
+#ifdef INET6
 	struct sockaddr_in lsin;
+#endif
 
 	result = HOSTNAME_INVALIDADDR;
 


More information about the svn-src-stable mailing list