summaryrefslogtreecommitdiffstats
path: root/lib/libutil
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2009-09-17 16:16:44 +0000
committerdes <des@FreeBSD.org>2009-09-17 16:16:44 +0000
commit9ed1a4b5ebe734049aa444f14884ed8ad4c23aee (patch)
treedea5b87c905a5175efdc56037f61b7ecb2031d98 /lib/libutil
parent5f4ee8bdfb4e4ffae101ac65837e519f1f957e43 (diff)
parent74dba11aaa299f71f2bf2b583d74575fec440e7b (diff)
downloadFreeBSD-src-9ed1a4b5ebe734049aa444f14884ed8ad4c23aee.zip
FreeBSD-src-9ed1a4b5ebe734049aa444f14884ed8ad4c23aee.tar.gz
Merge from head
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/Makefile2
-rw-r--r--lib/libutil/flopen.324
-rw-r--r--lib/libutil/flopen.c13
-rw-r--r--lib/libutil/humanize_number.c9
-rw-r--r--lib/libutil/kinfo_getfile.39
-rw-r--r--lib/libutil/kinfo_getvmmap.313
-rw-r--r--lib/libutil/login_class.c1
-rw-r--r--lib/libutil/login_tty.c10
-rw-r--r--lib/libutil/pidfile.31
9 files changed, 41 insertions, 41 deletions
diff --git a/lib/libutil/Makefile b/lib/libutil/Makefile
index 145f2c3..d7bd6dc 100644
--- a/lib/libutil/Makefile
+++ b/lib/libutil/Makefile
@@ -6,7 +6,7 @@ SHLIBDIR?= /lib
.include <bsd.own.mk>
LIB= util
-SHLIB_MAJOR= 7
+SHLIB_MAJOR= 8
SRCS= _secure_path.c auth.c expand_number.c flopen.c fparseln.c gr_util.c \
hexdump.c humanize_number.c kinfo_getfile.c kinfo_getvmmap.c kld.c \
diff --git a/lib/libutil/flopen.3 b/lib/libutil/flopen.3
index fe54b76..26d1c04 100644
--- a/lib/libutil/flopen.3
+++ b/lib/libutil/flopen.3
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd May 10, 2007
+.Dd June 6, 2009
.Dt FLOPEN 3
.Os
.Sh NAME
@@ -46,13 +46,12 @@ The
function opens or creates a file and acquires an exclusive lock on it.
It is essentially equivalent with calling
.Fn open
-with the same parameters followed by an
-.Fn fcntl
-.Dv F_SETLK
-or
-.Dv F_SETLKW
-operation with lock type
-.Dv F_WRLCK ,
+with the same parameters followed by
+.Fn flock
+with an
+.Va operation
+argument of
+.Dv LOCK_EX ,
except that
.Fn flopen
will attempt to detect and handle races that may occur between opening
@@ -87,18 +86,13 @@ returns a valid file descriptor.
Otherwise, it returns -1, and sets
.Va errno
as described in
-.Xr fcntl 2
+.Xr flock 2
and
.Xr open 2 .
.Sh SEE ALSO
.Xr errno 2 ,
-.Xr fcntl 2 ,
+.Xr flock 2 ,
.Xr open 2
-.Sh HISTORY
-The
-.Fn flopen
-function first appeared in
-.Fx 6.3 .
.Sh AUTHORS
.An -nosplit
The
diff --git a/lib/libutil/flopen.c b/lib/libutil/flopen.c
index ae98daf..754c9c0 100644
--- a/lib/libutil/flopen.c
+++ b/lib/libutil/flopen.c
@@ -28,12 +28,11 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <sys/file.h>
#include <sys/stat.h>
#include <errno.h>
-#include <fcntl.h>
#include <stdarg.h>
-#include <string.h>
#include <unistd.h>
#include <libutil.h>
@@ -42,7 +41,6 @@ int
flopen(const char *path, int flags, ...)
{
int fd, operation, serrno, trunc;
- struct flock lock;
struct stat sb, fsb;
mode_t mode;
@@ -59,10 +57,9 @@ flopen(const char *path, int flags, ...)
va_end(ap);
}
- memset(&lock, 0, sizeof lock);
- lock.l_type = ((flags & O_ACCMODE) == O_RDONLY) ? F_RDLCK : F_WRLCK;
- lock.l_whence = SEEK_SET;
- operation = (flags & O_NONBLOCK) ? F_SETLK : F_SETLKW;
+ operation = LOCK_EX;
+ if (flags & O_NONBLOCK)
+ operation |= LOCK_NB;
trunc = (flags & O_TRUNC);
flags &= ~O_TRUNC;
@@ -71,7 +68,7 @@ flopen(const char *path, int flags, ...)
if ((fd = open(path, flags, mode)) == -1)
/* non-existent or no access */
return (-1);
- if (fcntl(fd, operation, &lock) == -1) {
+ if (flock(fd, operation) == -1) {
/* unsupported or interrupted */
serrno = errno;
(void)close(fd);
diff --git a/lib/libutil/humanize_number.c b/lib/libutil/humanize_number.c
index f4c3316..de98587 100644
--- a/lib/libutil/humanize_number.c
+++ b/lib/libutil/humanize_number.c
@@ -1,4 +1,4 @@
-/* $NetBSD: humanize_number.c,v 1.13 2007/12/14 17:26:19 christos Exp $ */
+/* $NetBSD: humanize_number.c,v 1.14 2008/04/28 20:22:59 martin Exp $ */
/*
* Copyright (c) 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc.
@@ -16,13 +16,6 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
diff --git a/lib/libutil/kinfo_getfile.3 b/lib/libutil/kinfo_getfile.3
index 3da9ca2..5705bf7 100644
--- a/lib/libutil/kinfo_getfile.3
+++ b/lib/libutil/kinfo_getfile.3
@@ -58,15 +58,20 @@ mib.
While the kernel returns a packed structure, this function expands the
data into a fixed record format.
.Sh RETURN VALUES
-The
+On success the
.Fn kinfo_getfile
function returns a pointer to an array of
.Vt struct kinfo_file
-structures.
+structures as defined by
+.In sys/user.h .
The array was obtained by an internal call to
.Xr malloc 3
and must be freed by the caller with a call to
.Xr free 3 .
+On failure the
+.Fn kinfo_getfile
+function returns
+.Dv NULL .
.Sh SEE ALSO
.Xr free 3 ,
.Xr kinfo_getvmmap 3 ,
diff --git a/lib/libutil/kinfo_getvmmap.3 b/lib/libutil/kinfo_getvmmap.3
index f0e76d9..0f12b67 100644
--- a/lib/libutil/kinfo_getvmmap.3
+++ b/lib/libutil/kinfo_getvmmap.3
@@ -37,9 +37,9 @@
.In sys/types.h
.In libutil.h
.Ft struct kinfo_vmentry *
-.Fn kinfo_getfile "pid_t pid" "int *cntp"
+.Fn kinfo_getvmmap "pid_t pid" "int *cntp"
.Sh DESCRIPTION
-This function is used for obtaining the file descriptor information
+This function is used for obtaining virtual memory mapping information
of a particular process.
.Pp
The
@@ -58,15 +58,20 @@ mib.
While the kernel returns a packed structure, this function expands the
data into a fixed record format.
.Sh RETURN VALUES
-The
+On success the
.Fn kinfo_getvmmap
function returns a pointer to an array of
.Vt struct kinfo_vmentry
-structures.
+structures as defined by
+.In sys/user.h .
The array was obtained by an internal call to
.Xr malloc 3
and must be freed by the caller with a call to
.Xr free 3 .
+On failure the
+.Fn kinfo_getvmmap
+function returns
+.Dv NULL .
.Sh SEE ALSO
.Xr free 3 ,
.Xr kinfo_getfile 3 ,
diff --git a/lib/libutil/login_class.c b/lib/libutil/login_class.c
index 5074519..d54b301 100644
--- a/lib/libutil/login_class.c
+++ b/lib/libutil/login_class.c
@@ -64,6 +64,7 @@ static struct login_res {
{ "sbsize", login_getcapsize, RLIMIT_SBSIZE },
{ "vmemoryuse", login_getcapsize, RLIMIT_VMEM },
{ "pseudoterminals", login_getcapnum, RLIMIT_NPTS },
+ { "swapuse", login_getcapsize, RLIMIT_SWAP },
{ NULL, 0, 0 }
};
diff --git a/lib/libutil/login_tty.c b/lib/libutil/login_tty.c
index 51299bd..a14e244 100644
--- a/lib/libutil/login_tty.c
+++ b/lib/libutil/login_tty.c
@@ -37,17 +37,21 @@ static char sccsid[] = "@(#)login_tty.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
-#include <sys/ioctl.h>
#include <libutil.h>
#include <stdlib.h>
+#include <termios.h>
#include <unistd.h>
int
login_tty(int fd)
{
- (void) setsid();
- if (ioctl(fd, TIOCSCTTY, (char *)NULL) == -1)
+ pid_t s;
+
+ s = setsid();
+ if (s == -1)
+ return (-1);
+ if (tcsetsid(fd, s) == -1)
return (-1);
(void) dup2(fd, 0);
(void) dup2(fd, 1);
diff --git a/lib/libutil/pidfile.3 b/lib/libutil/pidfile.3
index ac8c29d..cc2b4bb 100644
--- a/lib/libutil/pidfile.3
+++ b/lib/libutil/pidfile.3
@@ -100,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.
OpenPOWER on IntegriCloud