summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2013-04-10 02:57:21 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2013-04-10 02:57:21 +0000
commit0af05f03b2178d4ed66d756df0d7ec72c16248c7 (patch)
treeb82e48967e15c5685f8b5549b013606be66caf7e
parentae8b0483dbf4c7520407bab46a41e05336e0f899 (diff)
Get the standard path from _PATH_STDPATH instead of
sysctl({CTL_USER,USER_CS_PATH}). Expand that into the manpage too. _PATH_STDPATH suggested by miod@ Corrections from schwarze@ and jmc@ ok millert@ miod@ schwarze@ jmc@
-rw-r--r--usr.bin/which/Makefile23
-rw-r--r--usr.bin/which/whereis.114
-rw-r--r--usr.bin/which/which.c20
3 files changed, 29 insertions, 28 deletions
diff --git a/usr.bin/which/Makefile b/usr.bin/which/Makefile
index da32657eb19..aaf1ad96961 100644
--- a/usr.bin/which/Makefile
+++ b/usr.bin/which/Makefile
@@ -1,7 +1,26 @@
-# $OpenBSD: Makefile,v 1.5 1997/04/08 02:44:05 millert Exp $
+# $OpenBSD: Makefile,v 1.6 2013/04/10 02:57:20 guenther Exp $
+
+whereis_MAN = ${.OBJDIR}/whereis.1
+man_depends = ${.OBJDIR}/whereis.d
PROG= which
-MAN= which.1 whereis.1
+MAN= which.1 ${whereis_MAN}
LINKS= ${BINDIR}/which ${BINDIR}/whereis
+${whereis_MAN}: ${.CURDIR}/whereis.1 /usr/include/paths.h
+ stdpath=`printf '#include <paths.h>\n_PATH_STDPATH\n' | \
+ ${CPP} ${CPPFLAGS} -MD -MT '$${.OBJDIR}/whereis.1' \
+ -MF ${man_depends} - | \
+ sed -n 's/^[ ]*"\(.*\)".*/\1/p'` ; \
+ sed "s!_PATH_STDPATH!$${stdpath}!" < ${.CURDIR}/whereis.1 >$@
+
+CLEANFILES = ${whereis_MAN}
+cleandir: cleanlocaldepend
+cleanlocaldepend:
+ rm -f ${man_depends}
+
+.if exists(${man_depends})
+. include "${man_depends}"
+.endif
+
.include <bsd.prog.mk>
diff --git a/usr.bin/which/whereis.1 b/usr.bin/which/whereis.1
index b6a8cded6bf..8e55e1b1add 100644
--- a/usr.bin/which/whereis.1
+++ b/usr.bin/which/whereis.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: whereis.1,v 1.15 2012/01/29 17:37:58 lum Exp $
+.\" $OpenBSD: whereis.1,v 1.16 2013/04/10 02:57:20 guenther Exp $
.\" $NetBSD: whereis.1,v 1.4 1995/08/31 21:54:51 jtc Exp $
.\"
.\" Copyright (c) 1993
@@ -30,7 +30,7 @@
.\"
.\" @(#)whereis.1 8.3 (Berkeley) 4/27/95
.\"
-.Dd $Mdocdate: January 29 2012 $
+.Dd $Mdocdate: April 10 2013 $
.Dt WHEREIS 1
.Os
.Sh NAME
@@ -48,11 +48,8 @@ utility checks the standard binary directories for the specified
printing out the paths of any it finds that are executable by the
user.
.Pp
-The path searched is the string returned by the
-.Xr sysctl 8
-utility for the
-.Dq user.cs_path
-string.
+The path searched is
+.Pa _PATH_STDPATH .
.Pp
If the
.Fl a
@@ -76,8 +73,7 @@ No names were resolved.
.Xr apropos 1 ,
.Xr find 1 ,
.Xr locate 1 ,
-.Xr which 1 ,
-.Xr sysctl 8
+.Xr which 1
.Sh HISTORY
The
.Nm
diff --git a/usr.bin/which/which.c b/usr.bin/which/which.c
index 782e94a96a7..44bbd73bb53 100644
--- a/usr.bin/which/which.c
+++ b/usr.bin/which/which.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: which.c,v 1.17 2011/03/11 04:30:21 guenther Exp $ */
+/* $OpenBSD: which.c,v 1.18 2013/04/10 02:57:20 guenther Exp $ */
/*
* Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -23,6 +23,7 @@
#include <err.h>
#include <errno.h>
#include <locale.h>
+#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -69,24 +70,9 @@ main(int argc, char *argv[])
if (argc == 0)
usage();
- /*
- * which(1) uses user's $PATH.
- * whereis(1) uses user.cs_path from sysctl(3).
- */
if (strcmp(__progname, "whereis") == 0) {
- int mib[2];
-
progmode = PROG_WHEREIS;
- mib[0] = CTL_USER;
- mib[1] = USER_CS_PATH;
- if (sysctl(mib, 2, NULL, &n, NULL, 0) == -1)
- err(1, "unable to get length of user.cs_path");
- if (n == 0)
- errx(1, "user.cs_path was zero length!");
- if ((path = (char *)malloc(n)) == NULL)
- errx(1, "can't allocate memory.");
- if (sysctl(mib, 2, path, &n, NULL, 0) == -1)
- err(1, "unable to get user.cs_path");
+ path = _PATH_STDPATH;
} else {
if ((path = getenv("PATH")) == NULL)
err(1, "can't get $PATH from environment");