From f14763b62d364f4921ecf13fcfdc9e2996b8e35e Mon Sep 17 00:00:00 2001 From: Apple Date: Tue, 10 May 2011 01:08:35 +0000 Subject: [PATCH] shell_cmds-162.tar.gz --- Makefile | 2 +- Manpages/builtin.1 | 2 +- alias/Makefile | 2 +- apply/Makefile | 2 +- basename/Makefile | 2 +- chroot/Makefile | 2 +- date/Makefile | 2 +- date/date.c | 9 + dirname/Makefile | 2 +- echo/Makefile | 2 +- env/Makefile | 2 +- expr/Makefile | 2 +- false/Makefile | 2 +- find/Makefile | 2 +- find/extern.h | 4 + find/find.1 | 24 ++- find/find.c | 2 +- find/function.c | 130 ++++++++---- find/getdate.y | 2 +- find/ls.c | 12 +- find/main.c | 2 +- find/misc.c | 2 +- find/option.c | 8 +- getopt/Makefile | 2 +- hostname/Makefile | 2 +- id/Makefile | 2 +- id/id.c | 6 +- jot/Makefile | 2 +- jot/jot.1 | 5 +- jot/jot.c | 10 +- kill/Makefile | 2 +- killall/Makefile | 2 +- killall/killall.c | 15 +- lastcomm/Makefile | 2 +- lastcomm/lastcomm.1 | 32 +-- lastcomm/lastcomm.c | 74 +++---- lastcomm/pathnames.h | 8 +- locate/bigram/Makefile | 2 +- locate/code/Makefile | 2 +- locate/locate/Makefile | 3 +- logname/Makefile | 2 +- machine/Makefile | 2 +- mktemp/Makefile | 2 +- nice/Makefile | 2 +- nohup/Makefile | 2 +- nohup/nohup.c | 3 +- path_helper/Makefile | 2 +- printenv/Makefile | 2 +- printf/Makefile | 2 +- pwd/Makefile | 2 +- renice/Makefile | 2 +- renice/renice.8 | 1 - script/Makefile | 2 +- seq/Makefile | 10 + seq/seq.1 | 187 +++++++++++++++++ seq/seq.c | 453 +++++++++++++++++++++++++++++++++++++++++ shlock/Makefile | 2 +- shlock/shlock.1 | 62 ++++-- shlock/shlock.c | 100 +++++---- sleep/Makefile | 2 +- su/Makefile | 3 +- su/su.c | 36 +++- tee/Makefile | 2 +- test/Makefile | 2 +- time/Makefile | 2 +- true/Makefile | 2 +- uname/Makefile | 2 +- uname/uname.1 | 1 + users/Makefile | 2 +- w/Makefile | 2 +- whereis/Makefile | 2 +- whereis/whereis.1 | 6 +- which/Makefile | 2 +- who/Makefile | 2 +- xargs/Makefile | 2 +- xargs/xargs.c | 16 +- yes/Makefile | 2 +- 77 files changed, 1062 insertions(+), 258 deletions(-) create mode 100644 seq/Makefile create mode 100644 seq/seq.1 create mode 100644 seq/seq.c diff --git a/Makefile b/Makefile index 0afb832..8b86ab0 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ Embedded=$(shell tconf --test TARGET_OS_EMBEDDED) SubProjects = alias apply basename chroot date dirname echo env expr false \ find getopt hostname id jot kill killall lastcomm locate logname mktemp \ - nice nohup path_helper printenv printf pwd renice script shlock sleep \ + nice nohup path_helper printenv printf pwd renice script seq shlock sleep \ tee test time true uname users w whereis which who xargs yes ifeq ($(Embedded),NO) diff --git a/Manpages/builtin.1 b/Manpages/builtin.1 index f452c91..562e855 100644 --- a/Manpages/builtin.1 +++ b/Manpages/builtin.1 @@ -176,7 +176,7 @@ and .Xr sh 1 shells are listed here. Consult a shell's manual page for -details on the operation its builtin commands. +details on the operation of its builtin commands. Beware that the .Xr sh 1 manual page, at least, calls some of these commands diff --git a/alias/Makefile b/alias/Makefile index 9bc6d94..123299b 100644 --- a/alias/Makefile +++ b/alias/Makefile @@ -3,7 +3,7 @@ Install_Dir = /usr/bin MANPAGES = alias.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/apply/Makefile b/apply/Makefile index cace7df..6b0bc94 100644 --- a/apply/Makefile +++ b/apply/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = apply.c MANPAGES = apply.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/basename/Makefile b/basename/Makefile index 18b8543..a645b3c 100644 --- a/basename/Makefile +++ b/basename/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = basename.c MANPAGES = basename.1 dirname.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/chroot/Makefile b/chroot/Makefile index b2c8baf..cb53772 100644 --- a/chroot/Makefile +++ b/chroot/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/sbin CFILES = chroot.c MANPAGES = chroot.8 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/date/Makefile b/date/Makefile index 1c89f77..eb3ac02 100644 --- a/date/Makefile +++ b/date/Makefile @@ -5,7 +5,7 @@ HFILES = extern.h vary.h CFILES = date.c netdate.c vary.c MANPAGES = date.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic \ +Extra_CC_Flags = -Wall \ -D__FBSDID=__RCSID Extra_LD_Flags = -dead_strip diff --git a/date/date.c b/date/date.c index 64b4496..23c3b8c 100644 --- a/date/date.c +++ b/date/date.c @@ -173,7 +173,16 @@ main(int argc, char *argv[]) if (*argv && **argv == '+') format = *argv + 1; +#ifdef __APPLE__ + /* 7999711 */ + struct tm *ltp = localtime(&tval); + if (ltp == NULL) { + err(1, "localtime"); + } + lt = *ltp; +#else lt = *localtime(&tval); +#endif badv = vary_apply(v, <); if (badv) { fprintf(stderr, "%s: Cannot apply date adjustment\n", diff --git a/dirname/Makefile b/dirname/Makefile index 5df1246..be93458 100644 --- a/dirname/Makefile +++ b/dirname/Makefile @@ -3,7 +3,7 @@ Install_Dir = /usr/bin CFILES = dirname.c -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/echo/Makefile b/echo/Makefile index e843302..1763229 100644 --- a/echo/Makefile +++ b/echo/Makefile @@ -4,7 +4,7 @@ Install_Dir = /bin CFILES = echo.c MANPAGES = echo.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic \ +Extra_CC_Flags = -Wall \ -D__FBSDID=__RCSID Extra_LD_Flags = -dead_strip diff --git a/env/Makefile b/env/Makefile index 9f2f80d..a1f3756 100644 --- a/env/Makefile +++ b/env/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = env.c MANPAGES = env.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/expr/Makefile b/expr/Makefile index e40bacb..109008b 100644 --- a/expr/Makefile +++ b/expr/Makefile @@ -4,7 +4,7 @@ Install_Dir = /bin CFILES = expr.c MANPAGES = expr.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic \ +Extra_CC_Flags = -Wall \ -D__DARWIN_UNIX03=1 Extra_LD_Flags = -dead_strip diff --git a/false/Makefile b/false/Makefile index 06d5145..e6448b3 100644 --- a/false/Makefile +++ b/false/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = false.c MANPAGES = false.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/find/Makefile b/find/Makefile index 8555945..7040d66 100644 --- a/find/Makefile +++ b/find/Makefile @@ -6,7 +6,7 @@ CFILES = find.c function.c ls.c main.c misc.c operator.c option.c YFILES = getdate.y MANPAGES = find.1 -Extra_CC_Flags = -Wall -Werror -mdynamic-no-pic \ +Extra_CC_Flags = -Wall -Werror \ -D__FBSDID=__RCSID -D_DARWIN_USE_64_BIT_INODE Extra_LD_Flags = -dead_strip diff --git a/find/extern.h b/find/extern.h index 4ad1ed0..6de0ad2 100644 --- a/find/extern.h +++ b/find/extern.h @@ -115,6 +115,10 @@ exec_f f_regex; exec_f f_size; exec_f f_type; exec_f f_user; +#ifdef __APPLE__ +exec_f f_xattr; +exec_f f_xattrname; +#endif /* __APPLE__ */ extern int ftsoptions, isdeprecated, isdepth, isoutput, issort, isxargs; extern int mindepth, maxdepth; diff --git a/find/find.1 b/find/find.1 index c63342c..21734f1 100644 --- a/find/find.1 +++ b/find/find.1 @@ -33,7 +33,7 @@ .\" SUCH DAMAGE. .\" .\" @(#)find.1 8.7 (Berkeley) 5/9/95 -.\" $FreeBSD: src/usr.bin/find/find.1,v 1.86 2008/03/03 08:32:58 ru Exp $ +.\" $FreeBSD: src/usr.bin/find/find.1,v 1.87 2009/09/20 16:47:56 jilles Exp $ .\" .Dd February 24, 2008 .Dt FIND 1 @@ -211,12 +211,12 @@ units. Please refer to the .Ic -atime primary description for information on supported time units. -.\" .It Ic -acl -.\" May be used in conjunction with other primaries to locate -.\" files with extended ACLs. -.\" See -.\" .Xr acl 3 -.\" for more information. +.It Ic -acl +May be used in conjunction with other primaries to locate +files with extended ACLs. +See +.Xr acl 3 +for more information. .It Ic -amin Ar n True if the difference between the file last access time and the time .Nm @@ -312,6 +312,7 @@ character in its pathname relative to .Dq Pa \&. for security reasons. Depth-first traversal processing is implied by this option. +Following symlinks is incompatible with this option. .It Ic -depth Always true; same as the @@ -821,6 +822,11 @@ is treated as a user ID. The same thing as .Ic -path , for GNU find compatibility. +.It Ic -xattr +True if the file has any extended attributes. +.It Ic -xattrname Ar name +True if the file has an extended attribute with the specified +.Ar name . .El .Pp All primaries which take a numeric argument allow the number to be @@ -921,7 +927,7 @@ recent than the current time minus one minute. Use the .Xr echo 1 command to print out a list of all the files. -.It Li "find -L /usr/ports/packages -type l -delete" +.It Li "find -L /usr/ports/packages -type l -exec rm -- {} +" Delete all broken symbolic links in .Pa /usr/ports/packages . .It Li "find /usr/src -name CVS -prune -o -depth +6 -print" @@ -951,7 +957,7 @@ section below for details. .Xr which 1 , .Xr xargs 1 , .Xr stat 2 , -.\" .Xr acl 3 , +.Xr acl 3 , .Xr fts 3 , .Xr getgrent 3 , .Xr getpwent 3 , diff --git a/find/find.c b/find/find.c index 22f43f0..48bcd2d 100644 --- a/find/find.c +++ b/find/find.c @@ -42,7 +42,7 @@ static char sccsid[] = "@(#)find.c 8.5 (Berkeley) 8/5/94"; #endif /* not lint */ #include -__FBSDID("$FreeBSD: src/usr.bin/find/find.c,v 1.18 2006/05/14 20:23:00 krion Exp $"); +__FBSDID("$FreeBSD: src/usr.bin/find/find.c,v 1.20 2009/12/13 03:14:06 delphij Exp $"); #include #include diff --git a/find/function.c b/find/function.c index a7cbd26..01e45ea 100644 --- a/find/function.c +++ b/find/function.c @@ -41,7 +41,7 @@ static const char sccsid[] = "@(#)function.c 8.10 (Berkeley) 5/4/95"; #endif /* not lint */ #include -__FBSDID("$FreeBSD: src/usr.bin/find/function.c,v 1.60 2008/02/24 00:01:06 imp Exp $"); +__FBSDID("$FreeBSD: src/usr.bin/find/function.c,v 1.63 2009/09/04 20:01:16 trasz Exp $"); #include #include @@ -51,6 +51,9 @@ __FBSDID("$FreeBSD: src/usr.bin/find/function.c,v 1.60 2008/02/24 00:01:06 imp E #include #include #include +#ifdef __APPLE__ +#include +#endif /* __APPLE__ */ #include #include @@ -371,56 +374,115 @@ c_mXXdepth(OPTION *option, char ***argvp) return new; } -#ifndef __APPLE__ /* * -acl function -- * * Show files with EXTENDED ACL attributes. */ +#ifdef __APPLE__ int f_acl(PLAN *plan __unused, FTSENT *entry) { - int match, entries; + acl_t facl; + int match; acl_entry_t ae; + + match = 0; + if ((facl = acl_get_link_np(entry->fts_accpath, ACL_TYPE_EXTENDED)) != NULL) { + if (acl_get_entry(facl, ACL_FIRST_ENTRY, &ae) == 0) { + match = 1; + } + acl_free(facl); + } + return match; +} +#else /* !__APPLE__ */ +int +f_acl(PLAN *plan __unused, FTSENT *entry) +{ acl_t facl; + acl_type_t acl_type; + int acl_supported = 0, ret, trivial; if (S_ISLNK(entry->fts_statp->st_mode)) return 0; - if ((match = pathconf(entry->fts_accpath, _PC_ACL_EXTENDED)) <= 0) { - if (match < 0 && errno != EINVAL) - warn("%s", entry->fts_accpath); - else - return 0; + ret = pathconf(entry->fts_accpath, _PC_ACL_NFS4); + if (ret > 0) { + acl_supported = 1; + acl_type = ACL_TYPE_NFS4; + } else if (ret < 0 && errno != EINVAL) { + warn("%s", entry->fts_accpath); + return (0); } - match = 0; - if ((facl = acl_get_file(entry->fts_accpath,ACL_TYPE_ACCESS)) != NULL) { - if (acl_get_entry(facl, ACL_FIRST_ENTRY, &ae) == 1) { - /* - * POSIX.1e requires that ACLs of type ACL_TYPE_ACCESS - * must have at least three entries (owner, group, - * other). - */ - entries = 1; - while (acl_get_entry(facl, ACL_NEXT_ENTRY, &ae) == 1) { - if (++entries > 3) { - match = 1; - break; - } - } + if (acl_supported == 0) { + ret = pathconf(entry->fts_accpath, _PC_ACL_EXTENDED); + if (ret > 0) { + acl_supported = 1; + acl_type = ACL_TYPE_ACCESS; + } else if (ret < 0 && errno != EINVAL) { + warn("%s", entry->fts_accpath); + return (0); } - acl_free(facl); - } else + } + if (acl_supported == 0) + return (0); + + facl = acl_get_file(entry->fts_accpath, acl_type); + if (facl == NULL) { warn("%s", entry->fts_accpath); - return match; + return (0); + } + ret = acl_is_trivial_np(facl, &trivial); + acl_free(facl); + if (ret) { + warn("%s", entry->fts_accpath); + acl_free(facl); + return (0); + } + if (trivial) + return (0); + return (1); } +#endif /* __APPLE__ */ PLAN * c_acl(OPTION *option, char ***argvp __unused) { +#ifndef __APPLE__ ftsoptions &= ~FTS_NOSTAT; +#endif /* !__APPLE__ */ return (palloc(option)); } -#endif /* !__APPLE__ */ + +#ifdef __APPLE__ +int +f_xattr(PLAN *plan __unused, FTSENT *entry) +{ + ssize_t xattr; + int match; + + match = 0; + xattr = listxattr(entry->fts_accpath, NULL, 0, XATTR_NOFOLLOW); + if (xattr > 0) { + match = 1; + } + return match; +} + +int +f_xattrname(PLAN *plan, FTSENT *entry) +{ + ssize_t xattr; + int match; + + match = 0; + xattr = getxattr(entry->fts_accpath, plan->c_data, NULL, 0, 0, XATTR_NOFOLLOW); + if (xattr > 0) { + match = 1; + } + return match; +} +#endif /* __APPLE__ */ /* * -delete functions -- @@ -437,11 +499,13 @@ f_delete(PLAN *plan __unused, FTSENT *entry) /* sanity check */ if (isdepth == 0 || /* depth off */ - (ftsoptions & FTS_NOSTAT) || /* not stat()ing */ - !(ftsoptions & FTS_PHYSICAL) || /* physical off */ - (ftsoptions & FTS_LOGICAL)) /* or finally, logical on */ + (ftsoptions & FTS_NOSTAT)) /* not stat()ing */ errx(1, "-delete: insecure options got turned on"); + if (!(ftsoptions & FTS_PHYSICAL) || /* physical off */ + (ftsoptions & FTS_LOGICAL)) /* or finally, logical on */ + errx(1, "-delete: forbidden when symlinks are followed"); + /* Potentially unsafe - do not accept relative paths whatsoever */ if (strchr(entry->fts_accpath, '/') != NULL) errx(1, "-delete: %s: relative path potentially not safe", @@ -451,7 +515,7 @@ f_delete(PLAN *plan __unused, FTSENT *entry) if ((entry->fts_statp->st_flags & (UF_APPEND|UF_IMMUTABLE)) && !(entry->fts_statp->st_flags & (SF_APPEND|SF_IMMUTABLE)) && geteuid() == 0) - chflags(entry->fts_accpath, + lchflags(entry->fts_accpath, entry->fts_statp->st_flags &= ~(UF_APPEND|UF_IMMUTABLE)); /* rmdir directories, unlink everything else */ @@ -472,8 +536,6 @@ c_delete(OPTION *option, char ***argvp __unused) { ftsoptions &= ~FTS_NOSTAT; /* no optimise */ - ftsoptions |= FTS_PHYSICAL; /* disable -follow */ - ftsoptions &= ~FTS_LOGICAL; /* disable -follow */ isoutput = 1; /* possible output */ isdepth = 1; /* -depth implied */ @@ -1104,7 +1166,7 @@ f_name(PLAN *plan, FTSENT *entry) if (plan->flags & F_LINK) { name = fn; - if (readlink(entry->fts_path, fn, sizeof(fn)) == -1) + if (readlink(entry->fts_accpath, fn, sizeof(fn)) == -1) return 0; } else if (entry->fts_namelen == 0) { name = basename(entry->fts_path); diff --git a/find/getdate.y b/find/getdate.y index c68de33..1e56080 100644 --- a/find/getdate.y +++ b/find/getdate.y @@ -13,7 +13,7 @@ /* SUPPRESS 288 on yyerrlab *//* Label unused */ #include -__FBSDID("$FreeBSD: src/usr.bin/find/getdate.y,v 1.4 2005/08/25 13:44:02 roberto Exp $"); +__FBSDID("$FreeBSD: src/usr.bin/find/getdate.y,v 1.6 2009/12/13 03:14:06 delphij Exp $"); #include #include diff --git a/find/ls.c b/find/ls.c index cf84d57..5e62da8 100644 --- a/find/ls.c +++ b/find/ls.c @@ -38,7 +38,7 @@ static char sccsid[] = "@(#)ls.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ #include -__FBSDID("$FreeBSD: src/usr.bin/find/ls.c,v 1.17 2004/01/20 09:27:03 des Exp $"); +__FBSDID("$FreeBSD: src/usr.bin/find/ls.c,v 1.19 2009/12/13 03:14:06 delphij Exp $"); #include #include @@ -54,9 +54,10 @@ __FBSDID("$FreeBSD: src/usr.bin/find/ls.c,v 1.17 2004/01/20 09:27:03 des Exp $") #include #include #include + #ifdef __APPLE__ -/* definition from utmp.h */ -#define UT_NAMESIZE 8 +#undef MAXLOGNAME +#define MAXLOGNAME 17 #endif /* __APPLE__ */ #include "find.h" @@ -73,13 +74,8 @@ printlong(char *name, char *accpath, struct stat *sb) (void)printf("%6lu %8"PRId64" ", (u_long) sb->st_ino, sb->st_blocks); (void)strmode(sb->st_mode, modep); -#ifdef __APPLE__ - (void)printf("%s %3u %-*s %-*s ", modep, sb->st_nlink, UT_NAMESIZE, - user_from_uid(sb->st_uid, 0), UT_NAMESIZE, -#else /* !__APPLE__ */ (void)printf("%s %3u %-*s %-*s ", modep, sb->st_nlink, MAXLOGNAME - 1, user_from_uid(sb->st_uid, 0), MAXLOGNAME - 1, -#endif /* __APPLE__ */ group_from_gid(sb->st_gid, 0)); if (S_ISCHR(sb->st_mode) || S_ISBLK(sb->st_mode)) diff --git a/find/main.c b/find/main.c index 007ee14..5603517 100644 --- a/find/main.c +++ b/find/main.c @@ -47,7 +47,7 @@ static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 5/4/95"; #endif /* not lint */ #include -__FBSDID("$FreeBSD: src/usr.bin/find/main.c,v 1.16 2008/03/03 08:32:58 ru Exp $"); +__FBSDID("$FreeBSD: src/usr.bin/find/main.c,v 1.18 2009/12/13 03:14:06 delphij Exp $"); #include #include diff --git a/find/misc.c b/find/misc.c index ced8cfb..8245bb8 100644 --- a/find/misc.c +++ b/find/misc.c @@ -42,7 +42,7 @@ static char sccsid[] = "@(#)misc.c 8.2 (Berkeley) 4/1/94"; #endif /* not lint */ #include -__FBSDID("$FreeBSD: src/usr.bin/find/misc.c,v 1.8 2005/04/02 07:44:12 tjr Exp $"); +__FBSDID("$FreeBSD: src/usr.bin/find/misc.c,v 1.10 2009/12/13 03:14:06 delphij Exp $"); #include #include diff --git a/find/option.c b/find/option.c index 9ff7451..c99a180 100644 --- a/find/option.c +++ b/find/option.c @@ -41,7 +41,7 @@ static char sccsid[] = "@(#)option.c 8.2 (Berkeley) 4/16/94"; #endif /* not lint */ #include -__FBSDID("$FreeBSD: src/usr.bin/find/option.c,v 1.26 2008/02/23 16:29:04 imp Exp $"); +__FBSDID("$FreeBSD: src/usr.bin/find/option.c,v 1.28 2009/12/13 03:14:06 delphij Exp $"); #include #include @@ -67,9 +67,7 @@ static OPTION const options[] = { { "-Bnewer", c_newer, f_newer, F_TIME_B }, { "-Btime", c_Xtime, f_Xtime, F_TIME_B }, { "-a", c_and, NULL, 0 }, -#ifndef __APPLE__ { "-acl", c_acl, f_acl, 0 }, -#endif /* !__APPLE__ */ { "-amin", c_Xmin, f_Xmin, F_TIME_A }, { "-and", c_and, NULL, 0 }, { "-anewer", c_newer, f_newer, F_TIME_A }, @@ -156,6 +154,10 @@ static OPTION const options[] = { { "-uid", c_user, f_user, 0 }, { "-user", c_user, f_user, 0 }, { "-wholename", c_name, f_path, 0 }, +#ifdef __APPLE__ + { "-xattr", c_simple, f_xattr, 0 }, + { "-xattrname", c_name, f_xattrname, 0 }, +#endif /* __APPLE__ */ { "-xdev", c_xdev, f_always_true, 0 }, // -xtype }; diff --git a/getopt/Makefile b/getopt/Makefile index befe314..2bc6c18 100644 --- a/getopt/Makefile +++ b/getopt/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = getopt.c MANPAGES = getopt.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/hostname/Makefile b/hostname/Makefile index 3b6d0d9..ede49c6 100644 --- a/hostname/Makefile +++ b/hostname/Makefile @@ -4,7 +4,7 @@ Install_Dir = /bin CFILES = hostname.c MANPAGES = hostname.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic -D__FBSDID=__RCSID +Extra_CC_Flags = -Wall -D__FBSDID=__RCSID Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/id/Makefile b/id/Makefile index 8ec5d91..e4f2e47 100644 --- a/id/Makefile +++ b/id/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = id.c MANPAGES = groups.1 id.1 whoami.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic \ +Extra_CC_Flags = -Wall \ -D__FBSDID=__RCSID -DUSE_BSM_AUDIT \ -Wno-error Extra_LD_Flags = -dead_strip diff --git a/id/id.c b/id/id.c index 5bdb99c..5c5647f 100644 --- a/id/id.c +++ b/id/id.c @@ -347,14 +347,14 @@ id_print(struct passwd *pw, int use_ggl, int p_euid, int p_egid) void auditid(void) { - auditinfo_t auditinfo; + auditinfo_addr_t auditinfo; - if (getaudit(&auditinfo) < 0) + if (getaudit_addr(&auditinfo, sizeof(auditinfo)) < 0) err(1, "getaudit"); printf("auid=%d\n", auditinfo.ai_auid); printf("mask.success=0x%08x\n", auditinfo.ai_mask.am_success); printf("mask.failure=0x%08x\n", auditinfo.ai_mask.am_failure); - printf("termid.port=0x%08x\n", auditinfo.ai_termid.port); + printf("termid.port=0x%08x\n", auditinfo.ai_termid.at_port); printf("asid=%d\n", auditinfo.ai_asid); } #endif diff --git a/jot/Makefile b/jot/Makefile index 6abd3b5..0dde41c 100644 --- a/jot/Makefile +++ b/jot/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = jot.c MANPAGES = jot.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic -D__FBSDID=__RCSID +Extra_CC_Flags = -Wall -D__FBSDID=__RCSID Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/jot/jot.1 b/jot/jot.1 index 3e6488d..b94fab4 100644 --- a/jot/jot.1 +++ b/jot/jot.1 @@ -30,9 +30,9 @@ .\" SUCH DAMAGE. .\" .\" @(#)jot.1 8.1 (Berkeley) 6/6/93 -.\" $FreeBSD: src/usr.bin/jot/jot.1,v 1.23 2006/11/06 15:11:50 dds Exp $ +.\" $FreeBSD: src/usr.bin/jot/jot.1,v 1.24 2010/02/20 00:16:44 delphij Exp $ .\" -.Dd November 6, 2006 +.Dd February 19, 2010 .Dt JOT 1 .Os .Sh NAME @@ -239,6 +239,7 @@ but only one is allowed. .Xr ed 1 , .Xr expand 1 , .Xr rs 1 , +.Xr seq 1 , .Xr yes 1 , .Xr arc4random 3 , .Xr printf 3 , diff --git a/jot/jot.c b/jot/jot.c index dfed0fc..1438755 100644 --- a/jot/jot.c +++ b/jot/jot.c @@ -43,7 +43,7 @@ static char sccsid[] = "@(#)jot.c 8.1 (Berkeley) 6/6/93"; #endif #endif #include -__FBSDID("$FreeBSD: src/usr.bin/jot/jot.c,v 1.37 2006/12/09 15:23:20 delphij Exp $"); +__FBSDID("$FreeBSD: src/usr.bin/jot/jot.c,v 1.40 2009/12/13 03:14:06 delphij Exp $"); /* * jot - print sequential or random data @@ -101,13 +101,13 @@ main(int argc, char **argv) int ch; int mask = 0; int n = 0; - double begin; + double begin = BEGIN_DEF; double divisor; - double ender; - double s; + double ender = ENDER_DEF; + double s = STEP_DEF; double x, y; long i; - long reps; + long reps = REPS_DEF; while ((ch = getopt(argc, argv, "b:cnp:rs:w:")) != -1) switch (ch) { diff --git a/kill/Makefile b/kill/Makefile index d2fb76f..16cc8ef 100644 --- a/kill/Makefile +++ b/kill/Makefile @@ -4,7 +4,7 @@ Install_Dir = /bin CFILES = kill.c MANPAGES = kill.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/killall/Makefile b/killall/Makefile index 0dbd927..2579d25 100644 --- a/killall/Makefile +++ b/killall/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = killall.c MANPAGES = killall.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic \ +Extra_CC_Flags = -Wall \ -D__FBSDID=__RCSID Extra_LD_Flags = -dead_strip diff --git a/killall/killall.c b/killall/killall.c index 38d6a09..6f23a70 100644 --- a/killall/killall.c +++ b/killall/killall.c @@ -52,6 +52,10 @@ __FBSDID("$FreeBSD: src/usr.bin/killall/killall.c,v 1.31 2004/07/29 18:36:35 max #include #define OPTIONS ("c:dej:lmst:u:vz") +#ifdef __APPLE__ +#include +#endif + static void __dead2 usage(void) { @@ -122,11 +126,12 @@ kludge_signal_args(int *argc, char **argv, int *sig) /* i = 1, skip program name */ for (i = 1; i < *argc; i++) { - /* Stop if we encounter either a non-option or -- */ - if (*argv[i] != '-' || strcmp(argv[i], "--") == 0) + /* Stop kludging if we encounter -- */ + if (strcmp(argv[i], "--") == 0) kludge = 0; ptr = argv[i] + 1; - if (kludge && strchr(OPTIONS, *ptr) == NULL) { + /* Only process arguments that start with - and do not look like an existing option. */ + if (kludge && *argv[i] == '-' && *ptr && strchr(OPTIONS, *ptr) == NULL) { if (isalpha(*ptr)) { if (strcmp(ptr, "help") == 0) usage(); @@ -375,7 +380,11 @@ main(int ac, char **av) continue; mib[0] = CTL_KERN; +#if defined(__APPLE__) && TARGET_OS_EMBEDDED + mib[1] = KERN_PROCARGS2; +#else mib[1] = KERN_PROCARGS; +#endif mib[2] = thispid; syssize = (size_t)argmax; diff --git a/lastcomm/Makefile b/lastcomm/Makefile index d5e1863..a411f10 100644 --- a/lastcomm/Makefile +++ b/lastcomm/Makefile @@ -5,7 +5,7 @@ HFILES = pathnames.h CFILES = lastcomm.c MANPAGES = lastcomm.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/lastcomm/lastcomm.1 b/lastcomm/lastcomm.1 index 11698ce..96f7638 100644 --- a/lastcomm/lastcomm.1 +++ b/lastcomm/lastcomm.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: lastcomm.1,v 1.7 1997/10/19 03:47:52 lukem Exp $ +.\" $NetBSD: lastcomm.1,v 1.11 2006/12/22 08:00:20 ad Exp $ .\" .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -11,11 +11,7 @@ .\" 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 University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors +.\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" @@ -33,9 +29,9 @@ .\" .\" @(#)lastcomm.1 8.1 (Berkeley) 6/6/93 .\" -.Dd June 6, 1993 +.Dd December 22, 2006 .Dt LASTCOMM 1 -.Os BSD 3 +.Os .Sh NAME .Nm lastcomm .Nd show last commands executed in reverse order @@ -102,15 +98,23 @@ The time the process started. The elapsed time of the process. .El .Pp -The flags are encoded as follows: ``S'' indicates the command was -executed by the super-user, ``F'' indicates the command ran after +The flags are encoded as follows: +.Dq S +indicates the command was +executed by the super-user, +.Dq F +indicates the command ran after a fork, but without a following -.Xr exec , -``C'' indicates the command was run in PDP-11 compatibility mode +.Xr exec 3 , +.Dq C +indicates the command was run in PDP-11 compatibility mode (VAX only), -``D'' indicates the command terminated with the generation of a +.Dq D +indicates the command terminated with the generation of a .Pa core -file, and ``X'' indicates the command was terminated with a signal. +file, and +.Dq X +indicates the command was terminated with a signal. .Sh FILES .Bl -tag -width /var/account/acct -compact .It Pa /var/account/acct diff --git a/lastcomm/lastcomm.c b/lastcomm/lastcomm.c index 589ce7a..e712874 100644 --- a/lastcomm/lastcomm.c +++ b/lastcomm/lastcomm.c @@ -1,4 +1,4 @@ -/* $NetBSD: lastcomm.c,v 1.14 1998/04/02 10:22:03 kleink Exp $ */ +/* $NetBSD: lastcomm.c,v 1.21 2009/04/12 13:08:31 lukem Exp $ */ /* * Copyright (c) 1980, 1993 @@ -12,11 +12,7 @@ * 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 University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -35,15 +31,15 @@ #include #ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\ - The Regents of the University of California. All rights reserved.\n"); +__COPYRIGHT("@(#) Copyright (c) 1980, 1993\ + The Regents of the University of California. All rights reserved."); #endif /* not lint */ #ifndef lint #if 0 static char sccsid[] = "@(#)lastcomm.c 8.2 (Berkeley) 4/29/95"; #endif -__RCSID("$NetBSD: lastcomm.c,v 1.14 1998/04/02 10:22:03 kleink Exp $"); +__RCSID("$NetBSD: lastcomm.c,v 1.21 2009/04/12 13:08:31 lukem Exp $"); #endif /* not lint */ #include @@ -67,17 +63,16 @@ __RCSID("$NetBSD: lastcomm.c,v 1.14 1998/04/02 10:22:03 kleink Exp $"); #define UT_LINESIZE 8 #include "pathnames.h" -time_t expand __P((u_int)); -char *flagbits __P((int)); -char *getdev __P((dev_t)); -int main __P((int, char **)); -int requested __P((char *[], struct acct *)); -void usage __P((void)); +static time_t expand(u_int); +static char *flagbits(int); +static const char *getdev(dev_t); +static int requested(char *[], struct acct *); +static void usage(void) __dead; + +int main(int, char **); int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { char *p; struct acct ab; @@ -87,9 +82,10 @@ main(argc, argv) time_t t; double delta; int ch; - char *acctfile; + const char *acctfile = _PATH_ACCT; + + setprogname(argv[0]); - acctfile = _PATH_ACCT; while ((ch = getopt(argc, argv, "f:")) != -1) switch((char)ch) { case 'f': @@ -113,7 +109,7 @@ main(argc, argv) size = sb.st_size - sb.st_size % sizeof(struct acct); /* Check if any records to display. */ - if (size < sizeof(struct acct)) + if (size < (off_t)sizeof(struct acct)) exit(0); /* @@ -134,7 +130,7 @@ main(argc, argv) } else for (p = &ab.ac_comm[0]; p < &ab.ac_comm[fldsiz(acct, ac_comm)] && *p; ++p) - if (!isprint(*p)) + if (!isprint((unsigned char)*p)) *p = '?'; if (!*argv || requested(argv, &ab)) { @@ -150,8 +146,8 @@ main(argc, argv) t / (double)AHZ, ctime(&ab.ac_btime)); delta = expand(ab.ac_etime) / (double)AHZ; printf(" (%1.0f:%02.0f:%05.2f)\n", - delta / SECSPERHOUR, - fmod(delta, SECSPERHOUR) / SECSPERMIN, + floor(delta / SECSPERHOUR), + floor(fmod(delta, SECSPERHOUR) / SECSPERMIN), fmod(delta, SECSPERMIN)); } /* are we at the beginning of the file yet? */ @@ -166,9 +162,8 @@ main(argc, argv) exit(0); } -time_t -expand(t) - u_int t; +static time_t +expand(u_int t) { time_t nt; @@ -181,9 +176,8 @@ expand(t) return (nt); } -char * -flagbits(f) - int f; +static char * +flagbits(int f) { static char flags[20] = "-"; char *p; @@ -200,10 +194,8 @@ flagbits(f) return (flags); } -int -requested(argv, acp) - char *argv[]; - struct acct *acp; +static int +requested(char *argv[], struct acct *acp) { do { if (!strcmp(user_from_uid(acp->ac_uid, 0), *argv)) @@ -216,12 +208,11 @@ requested(argv, acp) return (0); } -char * -getdev(dev) - dev_t dev; +static const char * +getdev(dev_t dev) { static dev_t lastdev = (dev_t)-1; - static char *lastname; + static const char *lastname; if (dev == NODEV) /* Special case. */ return ("__"); @@ -233,10 +224,11 @@ getdev(dev) return (lastname); } -void -usage() +static void +usage(void) { (void)fprintf(stderr, - "lastcomm [ -f file ] [command ...] [user ...] [tty ...]\n"); + "Usage: %s [ -f file ] [command ...] [user ...] [tty ...]\n", + getprogname()); exit(1); } diff --git a/lastcomm/pathnames.h b/lastcomm/pathnames.h index 963d279..6ca75d8 100644 --- a/lastcomm/pathnames.h +++ b/lastcomm/pathnames.h @@ -1,4 +1,4 @@ -/* $NetBSD: pathnames.h,v 1.3 1994/12/22 01:07:05 jtc Exp $ */ +/* $NetBSD: pathnames.h,v 1.4 2003/08/07 11:14:18 agc Exp $ */ /* * Copyright (c) 1989, 1993 @@ -12,11 +12,7 @@ * 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 University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/locate/bigram/Makefile b/locate/bigram/Makefile index 3629ec1..b6b6fd2 100644 --- a/locate/bigram/Makefile +++ b/locate/bigram/Makefile @@ -3,7 +3,7 @@ Install_Dir = /usr/libexec CFILES = locate.bigram.c -Extra_CC_Flags = -Wall -mdynamic-no-pic \ +Extra_CC_Flags = -Wall \ -I../locate Extra_LD_Flags = -dead_strip diff --git a/locate/code/Makefile b/locate/code/Makefile index 0aaa7ac..351a09d 100644 --- a/locate/code/Makefile +++ b/locate/code/Makefile @@ -3,7 +3,7 @@ Install_Dir = /usr/libexec CFILES = locate.code.c -Extra_CC_Flags = -Wall -mdynamic-no-pic \ +Extra_CC_Flags = -Wall \ -I../locate Extra_LD_Flags = -dead_strip diff --git a/locate/locate/Makefile b/locate/locate/Makefile index 96c5764..c92392a 100644 --- a/locate/locate/Makefile +++ b/locate/locate/Makefile @@ -10,7 +10,7 @@ MANPAGES = locate.1 locate.updatedb.8 concatdb.sh mklocatedb.sh updatedb.sh LAUNCHD_PLISTS = com.apple.locate.plist -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make @@ -24,3 +24,4 @@ after_install: $(LN) $(DSTROOT)/usr/share/man/man8/locate.updatedb.8 $(DSTROOT)/usr/share/man/man8/locate.mklocatedb.8 $(INSTALL_DIRECTORY) $(DSTROOT)/private/etc $(INSTALL_FILE) locate.rc $(DSTROOT)/private/etc + plutil -convert binary1 "$(DSTROOT)/System/Library/LaunchDaemons/$(LAUNCHD_PLISTS)" diff --git a/logname/Makefile b/logname/Makefile index 82fb31a..f64a48a 100644 --- a/logname/Makefile +++ b/logname/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = logname.c MANPAGES = logname.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/machine/Makefile b/machine/Makefile index ef477ec..7e3f761 100644 --- a/machine/Makefile +++ b/machine/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = machine.c MANPAGES = machine.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/mktemp/Makefile b/mktemp/Makefile index 974dbd2..e563968 100644 --- a/mktemp/Makefile +++ b/mktemp/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = mktemp.c MANPAGES = mktemp.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/nice/Makefile b/nice/Makefile index 90e7aeb..2d024d9 100644 --- a/nice/Makefile +++ b/nice/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = nice.c MANPAGES = nice.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/nohup/Makefile b/nohup/Makefile index 25e5e3d..4134804 100644 --- a/nohup/Makefile +++ b/nohup/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = nohup.c MANPAGES = nohup.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/nohup/nohup.c b/nohup/nohup.c index 4262680..f77dce5 100644 --- a/nohup/nohup.c +++ b/nohup/nohup.c @@ -57,6 +57,7 @@ __FBSDID("$FreeBSD: src/usr.bin/nohup/nohup.c,v 1.10 2003/05/03 19:44:46 obrien #include #ifdef __APPLE__ +#include #include #include #endif @@ -94,7 +95,7 @@ main(int argc, char *argv[]) (void)signal(SIGHUP, SIG_IGN); -#ifdef __APPLE__ +#if defined(__APPLE__) && !TARGET_OS_EMBEDDED if (_vprocmgr_detach_from_console(0) != NULL) err(EXIT_MISC, "can't detach from console"); #endif diff --git a/path_helper/Makefile b/path_helper/Makefile index 6979d34..b4d53fa 100644 --- a/path_helper/Makefile +++ b/path_helper/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/libexec CFILES = path_helper.c MANPAGES = path_helper.8 -Extra_CC_Flags = -Wall -Werror -mdynamic-no-pic +Extra_CC_Flags = -Wall -Werror Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/printenv/Makefile b/printenv/Makefile index 5852729..ec00f21 100644 --- a/printenv/Makefile +++ b/printenv/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = printenv.c MANPAGES = printenv.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/printf/Makefile b/printf/Makefile index 573a045..ce06b7e 100644 --- a/printf/Makefile +++ b/printf/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = printf.c MANPAGES = printf.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/pwd/Makefile b/pwd/Makefile index 1343de8..3f861d1 100644 --- a/pwd/Makefile +++ b/pwd/Makefile @@ -4,7 +4,7 @@ Install_Dir = /bin CFILES = pwd.c MANPAGES = pwd.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic \ +Extra_CC_Flags = -Wall \ -D__FBSDID=__RCSID Extra_LD_Flags = -dead_strip diff --git a/renice/Makefile b/renice/Makefile index 2a8bfee..e8807d2 100644 --- a/renice/Makefile +++ b/renice/Makefile @@ -4,7 +4,7 @@ Insatll_Dir = /usr/bin CFILES = renice.c MANPAGES = renice.8 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/renice/renice.8 b/renice/renice.8 index 6d1b30b..5a03755 100644 --- a/renice/renice.8 +++ b/renice/renice.8 @@ -121,7 +121,6 @@ to map user names to user ID's .El .Sh SEE ALSO .Xr nice 1 , -.Xr rtprio 1 , .Xr getpriority 2 , .Xr setpriority 2 .Sh STANDARDS diff --git a/script/Makefile b/script/Makefile index 16014a2..e3ea256 100644 --- a/script/Makefile +++ b/script/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = script.c MANPAGES = script.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic \ +Extra_CC_Flags = -Wall \ -D__FBSDID=__RCSID Extra_LD_Flags = -dead_strip diff --git a/seq/Makefile b/seq/Makefile new file mode 100644 index 0000000..9a556a0 --- /dev/null +++ b/seq/Makefile @@ -0,0 +1,10 @@ +Project = seq +Install_Dir = /usr/bin + +CFILES = seq.c +MANPAGES = seq.1 + +Extra_CC_Flags = -Wall -D__FBSDID=__RCSID +Extra_LD_Flags = -dead_strip + +include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/seq/seq.1 b/seq/seq.1 new file mode 100644 index 0000000..4af7b99 --- /dev/null +++ b/seq/seq.1 @@ -0,0 +1,187 @@ +.\" $NetBSD: seq.1,v 1.6 2008/11/26 15:03:47 ginsbach Exp $ +.\" +.\" Copyright (c) 2005 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Brian Ginsbach. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 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. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $FreeBSD: src/usr.bin/seq/seq.1,v 1.1 2010/02/19 23:54:12 delphij Exp $ +.\" +.Dd February 19, 2010 +.Dt SEQ 1 +.Os +.Sh NAME +.Nm seq +.Nd print sequences of numbers +.Sh SYNOPSIS +.Nm +.Op Fl w +.Op Fl f Ar format +.Op Fl s Ar string +.Op Fl t Ar string +.Op Ar first Op Ar incr +.Ar last +.Sh DESCRIPTION +The +.Nm +utility prints a sequence of numbers, one per line +.Pq default , +from +.Ar first +.Pq default 1 , +to near +.Ar last +as possible, in increments of +.Ar incr +.Pq default 1 . +When +.Ar first +is larger than +.Ar last +the default +.Ar incr +is -1. +.Pp +All numbers are interpreted as floating point. +.Pp +Normally integer values are printed as decimal integers. +.Pp +The +.Nm +utility accepts the following options: +.Bl -tag -width Ar +.It Fl f Ar format +Use a +.Xr printf 3 +style +.Ar format +to print each number. +Only the +.Cm E , +.Cm e , +.Cm f , +.Cm G , +.Cm g , +and +.Cm % +conversion characters are valid, along with any optional +flags and an optional numeric minimum field width or precision. +The +.Ar format +can contain character escape sequences in backslash notation as +defined in +.St -ansiC . +The default is +.Cm %g . +.It Fl s Ar string +Use +.Ar string +to separate numbers. +The +.Ar string +can contain character escape sequences in backslash notation as +defined in +.St -ansiC . +The default is +.Cm \en . +.It Fl t Ar string +Use +.Ar string +to terminate sequence of numbers. +The +.Ar string +can contain character escape sequences in backslash notation as +defined in +.St -ansiC . +This option is useful when the default separator +does not contain a +.Cm \en . +.It Fl w +Equalize the widths of all numbers by padding with zeros as necessary. +This option has no effect with the +.Fl f +option. +If any sequence numbers will be printed in exponential notation, +the default conversion is changed to +.Cm %e . +.El +.Pp +The +.Nm +utility exits 0 on success and non-zero if an error occurs. +.Sh EXAMPLES +.Bd -literal -offset indent +# seq 1 3 +1 +2 +3 + +# seq 3 1 +3 +2 +1 + +# seq -w 0 .05 .1 +0.00 +0.05 +0.10 +.Ed +.Sh SEE ALSO +.Xr jot 1 , +.Xr printf 1 , +.Xr printf 3 +.Sh HISTORY +The +.Nm +command first appeared in +.Tn "Plan 9 from Bell Labs" . +A +.Nm +command appeared in +.Nx 3.0 , +and ported to +.Fx 9.0 . +This command was based on the command of the same name in +.Tn "Plan 9 from Bell Labs" +and the +.Tn GNU +core utilities. +The +.Tn GNU +.Nm +command first appeared in the 1.13 shell utilities release. +.Sh BUGS +The +.Fl w +option does not handle the transition from pure floating point +to exponent representation very well. +The +.Nm +command is not bug for bug compatible with the +.Tn "Plan 9 from Bell Labs" +or +.Tn GNU +versions of +.Nm . diff --git a/seq/seq.c b/seq/seq.c new file mode 100644 index 0000000..9c3623d --- /dev/null +++ b/seq/seq.c @@ -0,0 +1,453 @@ +/* $NetBSD: seq.c,v 1.5 2008/07/21 14:19:26 lukem Exp $ */ +/* + * Copyright (c) 2005 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Brian Ginsbach. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: src/usr.bin/seq/seq.c,v 1.2 2010/02/20 01:23:15 delphij Exp $"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ZERO '0' +#define SPACE ' ' + +#define MAX(a, b) (((a) < (b))? (b) : (a)) +#define ISSIGN(c) ((int)(c) == '-' || (int)(c) == '+') +#define ISEXP(c) ((int)(c) == 'e' || (int)(c) == 'E') +#define ISODIGIT(c) ((int)(c) >= '0' && (int)(c) <= '7') + +/* Globals */ + +const char *decimal_point = "."; /* default */ +char default_format[] = { "%g" }; /* default */ + +/* Prototypes */ + +double e_atof(const char *); + +int decimal_places(const char *); +int main(int, char *[]); +int numeric(const char *); +int valid_format(const char *); + +char *generate_format(double, double, double, int, char); +char *unescape(char *); + +/* + * The seq command will print out a numeric sequence from 1, the default, + * to a user specified upper limit by 1. The lower bound and increment + * maybe indicated by the user on the command line. The sequence can + * be either whole, the default, or decimal numbers. + */ +int +main(int argc, char *argv[]) +{ + int c = 0, errflg = 0; + int equalize = 0; + double first = 1.0; + double last = 0.0; + double incr = 0.0; + struct lconv *locale; + char *fmt = NULL; + const char *sep = "\n"; + const char *term = NULL; + char pad = ZERO; + + /* Determine the locale's decimal point. */ + locale = localeconv(); + if (locale && locale->decimal_point && locale->decimal_point[0] != '\0') + decimal_point = locale->decimal_point; + + /* + * Process options, but handle negative numbers separately + * least they trip up getopt(3). + */ + while ((optind < argc) && !numeric(argv[optind]) && + (c = getopt(argc, argv, "f:hs:t:w")) != -1) { + + switch (c) { + case 'f': /* format (plan9) */ + fmt = optarg; + equalize = 0; + break; + case 's': /* separator (GNU) */ + sep = unescape(optarg); + break; + case 't': /* terminator (new) */ + term = unescape(optarg); + break; + case 'w': /* equal width (plan9) */ + if (!fmt) + if (equalize++) + pad = SPACE; + break; + case 'h': /* help (GNU) */ + default: + errflg++; + break; + } + } + + argc -= optind; + argv += optind; + if (argc < 1 || argc > 3) + errflg++; + + if (errflg) { + fprintf(stderr, + "usage: %s [-w] [-f format] [-s string] [-t string] [first [incr]] last\n", + getprogname()); + exit(1); + } + + last = e_atof(argv[argc - 1]); + + if (argc > 1) + first = e_atof(argv[0]); + + if (argc > 2) { + incr = e_atof(argv[1]); + /* Plan 9/GNU don't do zero */ + if (incr == 0.0) + errx(1, "zero %screment", (first < last)? "in" : "de"); + } + + /* default is one for Plan 9/GNU work alike */ + if (incr == 0.0) + incr = (first < last) ? 1.0 : -1.0; + + if (incr <= 0.0 && first < last) + errx(1, "needs positive increment"); + + if (incr >= 0.0 && first > last) + errx(1, "needs negative decrement"); + + if (fmt != NULL) { + if (!valid_format(fmt)) + errx(1, "invalid format string: `%s'", fmt); + fmt = unescape(fmt); + /* + * XXX to be bug for bug compatible with Plan 9 add a + * newline if none found at the end of the format string. + */ + } else + fmt = generate_format(first, incr, last, equalize, pad); + + if (incr > 0) { + for (; first <= last; first += incr) { + printf(fmt, first); + fputs(sep, stdout); + } + } else { + for (; first >= last; first += incr) { + printf(fmt, first); + fputs(sep, stdout); + } + } + if (term != NULL) + fputs(term, stdout); + + return (0); +} + +/* + * numeric - verify that string is numeric + */ +int +numeric(const char *s) +{ + int seen_decimal_pt, decimal_pt_len; + + /* skip any sign */ + if (ISSIGN((unsigned char)*s)) + s++; + + seen_decimal_pt = 0; + decimal_pt_len = strlen(decimal_point); + while (*s) { + if (!isdigit((unsigned char)*s)) { + if (!seen_decimal_pt && + strncmp(s, decimal_point, decimal_pt_len) == 0) { + s += decimal_pt_len; + seen_decimal_pt = 1; + continue; + } + if (ISEXP((unsigned char)*s)) { + s++; + if (ISSIGN((unsigned char)*s) || + isdigit((unsigned char)*s)) { + s++; + continue; + } + } + break; + } + s++; + } + return (*s == '\0'); +} + +/* + * valid_format - validate user specified format string + */ +int +valid_format(const char *fmt) +{ + int conversions = 0; + + while (*fmt != '\0') { + /* scan for conversions */ + if (*fmt != '\0' && *fmt != '%') { + do { + fmt++; + } while (*fmt != '\0' && *fmt != '%'); + } + /* scan a conversion */ + if (*fmt != '\0') { + do { + fmt++; + + /* ok %% */ + if (*fmt == '%') { + fmt++; + break; + } + /* valid conversions */ + if (strchr("eEfgG", *fmt) && + conversions++ < 1) { + fmt++; + break; + } + /* flags, width and precsision */ + if (isdigit((unsigned char)*fmt) || + strchr("+- 0#.", *fmt)) + continue; + + /* oops! bad conversion format! */ + return (0); + } while (*fmt != '\0'); + } + } + + return (conversions <= 1); +} + +/* + * unescape - handle C escapes in a string + */ +char * +unescape(char *orig) +{ + char c, *cp, *new = orig; + int i; + + for (cp = orig; (*orig = *cp); cp++, orig++) { + if (*cp != '\\') + continue; + + switch (*++cp) { + case 'a': /* alert (bell) */ + *orig = '\a'; + continue; + case 'b': /* backspace */ + *orig = '\b'; + continue; + case 'e': /* escape */ + *orig = '\e'; + continue; + case 'f': /* formfeed */ + *orig = '\f'; + continue; + case 'n': /* newline */ + *orig = '\n'; + continue; + case 'r': /* carriage return */ + *orig = '\r'; + continue; + case 't': /* horizontal tab */ + *orig = '\t'; + continue; + case 'v': /* vertical tab */ + *orig = '\v'; + continue; + case '\\': /* backslash */ + *orig = '\\'; + continue; + case '\'': /* single quote */ + *orig = '\''; + continue; + case '\"': /* double quote */ + *orig = '"'; + continue; + case '0': + case '1': + case '2': + case '3': /* octal */ + case '4': + case '5': + case '6': + case '7': /* number */ + for (i = 0, c = 0; + ISODIGIT((unsigned char)*cp) && i < 3; + i++, cp++) { + c <<= 3; + c |= (*cp - '0'); + } + *orig = c; + --cp; + continue; + case 'x': /* hexidecimal number */ + cp++; /* skip 'x' */ + for (i = 0, c = 0; + isxdigit((unsigned char)*cp) && i < 2; + i++, cp++) { + c <<= 4; + if (isdigit((unsigned char)*cp)) + c |= (*cp - '0'); + else + c |= ((toupper((unsigned char)*cp) - + 'A') + 10); + } + *orig = c; + --cp; + continue; + default: + --cp; + break; + } + } + + return (new); +} + +/* + * e_atof - convert an ASCII string to a double + * exit if string is not a valid double, or if converted value would + * cause overflow or underflow + */ +double +e_atof(const char *num) +{ + char *endp; + double dbl; + + errno = 0; + dbl = strtod(num, &endp); + + if (errno == ERANGE) + /* under or overflow */ + err(2, "%s", num); + else if (*endp != '\0') + /* "junk" left in number */ + errx(2, "invalid floating point argument: %s", num); + + /* zero shall have no sign */ + if (dbl == -0.0) + dbl = 0; + return (dbl); +} + +/* + * decimal_places - count decimal places in a number (string) + */ +int +decimal_places(const char *number) +{ + int places = 0; + char *dp; + + /* look for a decimal point */ + if ((dp = strstr(number, decimal_point))) { + dp += strlen(decimal_point); + + while (isdigit((unsigned char)*dp++)) + places++; + } + return (places); +} + +/* + * generate_format - create a format string + * + * XXX to be bug for bug compatable with Plan9 and GNU return "%g" + * when "%g" prints as "%e" (this way no width adjustments are made) + */ +char * +generate_format(double first, double incr, double last, int equalize, char pad) +{ + static char buf[256]; + char cc = '\0'; + int precision, width1, width2, places; + + if (equalize == 0) + return (default_format); + + /* figure out "last" value printed */ + if (first > last) + last = first - incr * floor((first - last) / incr); + else + last = first + incr * floor((last - first) / incr); + + sprintf(buf, "%g", incr); + if (strchr(buf, 'e')) + cc = 'e'; + precision = decimal_places(buf); + + width1 = sprintf(buf, "%g", first); + if (strchr(buf, 'e')) + cc = 'e'; + if ((places = decimal_places(buf))) + width1 -= (places + strlen(decimal_point)); + + precision = MAX(places, precision); + + width2 = sprintf(buf, "%g", last); + if (strchr(buf, 'e')) + cc = 'e'; + if ((places = decimal_places(buf))) + width2 -= (places + strlen(decimal_point)); + + if (precision) { + sprintf(buf, "%%%c%d.%d%c", pad, + MAX(width1, width2) + (int) strlen(decimal_point) + + precision, precision, (cc) ? cc : 'f'); + } else { + sprintf(buf, "%%%c%d%c", pad, MAX(width1, width2), + (cc) ? cc : 'g'); + } + + return (buf); +} diff --git a/shlock/Makefile b/shlock/Makefile index b1d072e..c420d4b 100644 --- a/shlock/Makefile +++ b/shlock/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = shlock.c MANPAGES = shlock.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/shlock/shlock.1 b/shlock/shlock.1 index 9654fcb..9b1667d 100644 --- a/shlock/shlock.1 +++ b/shlock/shlock.1 @@ -1,4 +1,31 @@ -.\" $NetBSD: shlock.1,v 1.2 1997/10/19 23:08:43 lukem Exp $ +.\" $NetBSD: shlock.1,v 1.11 2008/04/30 13:11:01 martin Exp $ +.\" +.\" Copyright (c) 2006 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Erik E. Fair. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 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. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. .\" .Dd June 29, 1997 .Dt SHLOCK 1 @@ -8,11 +35,10 @@ .Nd create or verify a lock file for shell scripts .Sh SYNOPSIS .Nm +.Op Fl du +.Op Fl p Ar PID .Fl f .Ar lockfile -.Op Fl p Ar PID -.Op Fl u -.Op Fl v .Sh DESCRIPTION The .Nm @@ -26,12 +52,12 @@ If valid, will exit with a non-zero exit code. If invalid, .Nm -will remove the lock file, and +will remove the lock file, and create a new one. .Pp .Nm uses the -.Xr rename 2 +.Xr link 2 system call to make the final target lock file, which is an atomic operation (i.e. "dot locking", so named for this mechanism's original use for locking system mailboxes). @@ -46,6 +72,12 @@ with a zero signal to check for the existence of the process that holds the lock. .Pp The +.Fl d +option causes +.Nm +to be verbose about what it is doing. +.Pp +The .Fl f argument with .Ar lockfile @@ -65,13 +97,7 @@ option causes .Nm to read and write the PID as a binary pid_t, instead of as ASCII, to be compatible with the locks created by UUCP. -.Pp -The -.Fl v -option causes -.Nm -to be verbose about what it is doing. -.Sh RETURN VALUES +.Sh EXIT STATUS A zero exit code indicates a valid lock file. .Sh EXAMPLES .Ss BOURNE SHELL @@ -99,18 +125,18 @@ else endif .Ed .Pp -The examples assume that the filesystem where the lock file is to -be created is writeable by the user, and has space available. +The examples assume that the file system where the lock file is to +be created is writable by the user, and has space available. .Sh HISTORY .Nm was written for the first Network News Transfer Protocol (NNTP) software distribution, released in March 1986. The algorithm was suggested by Peter Honeyman, from work he did on HoneyDanBer UUCP. -.Sh AUTHOR -Erik E. Fair +.Sh AUTHORS +.An Erik E. Fair Aq fair@clock.org .Sh BUGS -Does not work on NFS or other network filesystem on different +Does not work on NFS or other network file system on different systems because the disparate systems have disjoint PID spaces. .Pp Cannot handle the case where a lock file was not deleted, the diff --git a/shlock/shlock.c b/shlock/shlock.c index 862e4b7..9dcb645 100644 --- a/shlock/shlock.c +++ b/shlock/shlock.c @@ -1,4 +1,33 @@ -/* $NetBSD: shlock.c,v 1.3 1998/01/09 08:06:11 perry Exp $ */ +/* $NetBSD: shlock.c,v 1.10 2008/04/28 20:24:14 martin Exp $ */ + +/*- + * Copyright (c) 2006 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Erik E. Fair. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ /* ** Program to produce reliable locks for shell scripts. @@ -32,6 +61,12 @@ ** Erik E. Fair , May 20, 1997 */ +#include + +#ifndef lint +__RCSID("$NetBSD: shlock.c,v 1.10 2008/04/28 20:24:14 martin Exp $"); +#endif + #include #include #include /* Needed on hpux */ @@ -55,9 +90,9 @@ int Debug = FALSE; char *Pname; -char *USAGE = "%s: USAGE: shlock -f file -p pid [-d][-u]\n"; -char *E_unlk = "%s: unlink(%s): %s\n"; -char *E_open = "%s: open(%s): %s\n"; +const char USAGE[] = "%s: USAGE: %s [-du] [-p PID] -f file\n"; +const char E_unlk[] = "%s: unlink(%s): %s\n"; +const char E_open[] = "%s: open(%s): %s\n"; #define dprintf if (Debug) printf @@ -67,17 +102,13 @@ char *E_open = "%s: open(%s): %s\n"; ** (and wasn't that sufficient?) */ -#ifdef __STDC__ /* the following is in case you need to make the prototypes go away. */ -#define _P(x) x - -char *xtmpfile _P((char *, pid_t, int)); -int p_exists _P((pid_t)); -int cklock _P((char *, int)); -int mklock _P((char *, pid_t, int)); -void bad_usage _P((void)); -int main _P((int, char **)); -#endif /* __STDC__ */ +char *xtmpfile(char *, pid_t, int); +int p_exists(pid_t); +int cklock(char *, int); +int mklock(char *, pid_t, int); +void bad_usage(void); +int main(int, char **); /* ** Create a temporary file, all ready to lock with. @@ -86,17 +117,14 @@ int main _P((int, char **)); ** which might not be in the same filesystem. */ char * -xtmpfile(file, pid, uucpstyle) -char *file; -pid_t pid; -int uucpstyle; +xtmpfile(char *file, pid_t pid, int uucpstyle) { int fd; int len; char *cp, buf[BUFSIZ]; static char tempname[BUFSIZ]; - sprintf(buf, "shlock%d", getpid()); + sprintf(buf, "shlock%ld", (u_long)getpid()); if ((cp = strrchr(strcpy(tempname, file), '/')) != (char *)NULL) { *++cp = '\0'; (void) strcat(tempname, buf); @@ -104,7 +132,7 @@ int uucpstyle; (void) strcpy(tempname, buf); dprintf("%s: temporary filename: %s\n", Pname, tempname); - sprintf(buf, "%d\n", pid); + sprintf(buf, "%ld\n", (u_long)pid); len = strlen(buf); openloop: if ((fd = open(tempname, O_RDWR|O_CREAT|O_EXCL, 0644)) < 0) { @@ -137,8 +165,8 @@ openloop: (write(fd, &pid, sizeof(pid)) != sizeof(pid)) : (write(fd, buf, len) < 0)) { - fprintf(stderr, "%s: write(%s,%d): %s\n", - Pname, tempname, pid, strerror(errno)); + fprintf(stderr, "%s: write(%s,%ld): %s\n", + Pname, tempname, (u_long)pid, strerror(errno)); (void) close(fd); if (unlink(tempname) < 0) { fprintf(stderr, E_unlk, @@ -155,10 +183,9 @@ openloop: ** Send null signal to find out. */ int -p_exists(pid) -pid_t pid; +p_exists(pid_t pid) { - dprintf("%s: process %d is ", Pname, pid); + dprintf("%s: process %ld is ", Pname, (u_long)pid); if (pid <= 0) { dprintf("invalid\n"); return(FALSE); @@ -196,9 +223,7 @@ pid_t pid; ** */ int -cklock(file, uucpstyle) -char *file; -int uucpstyle; +cklock(char *file, int uucpstyle) { int fd = open(file, O_RDONLY); ssize_t len; @@ -226,15 +251,13 @@ int uucpstyle; } int -mklock(file, pid, uucpstyle) -char *file; -pid_t pid; -int uucpstyle; +mklock(char *file, pid_t pid, int uucpstyle) { char *tmp; int retcode = FALSE; - dprintf("%s: trying lock <%s> for process %d\n", Pname, file, pid); + dprintf("%s: trying lock <%s> for process %ld\n", Pname, file, + (u_long)pid); if ((tmp = xtmpfile(file, pid, uucpstyle)) == (char *)NULL) return(FALSE); @@ -276,16 +299,14 @@ linkloop: } void -bad_usage() +bad_usage(void) { - fprintf(stderr, USAGE, Pname); + fprintf(stderr, USAGE, Pname, Pname); exit(LOCK_FAIL); } int -main(ac, av) -int ac; -char *av[]; +main(int ac, char **av) { int x; char *file = (char *)NULL; @@ -326,8 +347,7 @@ char *av[]; } break; default: - fprintf(stderr, USAGE, Pname); - exit(LOCK_FAIL); + bad_usage(); } } } diff --git a/sleep/Makefile b/sleep/Makefile index 5ed51f3..0dfd8e7 100644 --- a/sleep/Makefile +++ b/sleep/Makefile @@ -4,7 +4,7 @@ Install_Dir = /bin CFILES = sleep.c MANPAGES = sleep.1 -Extra_CC_Flags = -Wall -Werror -mdynamic-no-pic +Extra_CC_Flags = -Wall -Werror Extra_CC_Flags += -D__FBSDID=__RCSID Extra_LD_Flags = -dead_strip diff --git a/su/Makefile b/su/Makefile index 5e72328..ec34d8d 100644 --- a/su/Makefile +++ b/su/Makefile @@ -3,8 +3,9 @@ Project = su CFILES = su.c MANPAGES = su.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic -D__FBSDID=__RCSID +Extra_CC_Flags = -Wall -D__FBSDID=__RCSID Extra_LD_Flags = -dead_strip -lpam -lbsm +Extra_LD_Flags += -framework Security include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/su/su.c b/su/su.c index e6d64a7..10a3636 100644 --- a/su/su.c +++ b/su/su.c @@ -74,7 +74,7 @@ static char sccsid[] = "@(#)su.c 8.3 (Berkeley) 4/2/94"; #endif #include -__FBSDID("$FreeBSD: src/usr.bin/su/su.c,v 1.87 2007/10/18 11:05:30 davidxu Exp $"); +__FBSDID("$FreeBSD: src/usr.bin/su/su.c,v 1.91 2009/12/13 03:14:06 delphij Exp $"); #include #include @@ -105,6 +105,10 @@ __FBSDID("$FreeBSD: src/usr.bin/su/su.c,v 1.87 2007/10/18 11:05:30 davidxu Exp $ #include #include +#ifdef __APPLE__ +#include +#endif /* __APPLE__ */ + #define PAM_END() do { \ int local_ret; \ if (pamh != NULL) { \ @@ -174,6 +178,7 @@ main(int argc, char *argv[]) #endif /* !__APPLE__ */ char *username, *class, shellbuf[MAXPATHLEN]; const char *p, *user, *shell, *mytty, **nargv; + const void *v; struct sigaction sa, sa_int, sa_quit, sa_pipe; int temp, fds[2]; #ifdef USE_BSM_AUDIT @@ -247,7 +252,7 @@ main(int argc, char *argv[]) if (strlen(user) > MAXLOGNAME - 1) { #ifdef USE_BSM_AUDIT if (audit_submit(AUE_su, auid, - 1, EPERM, "username too long: '%s'", user)) + EPERM, 1, "username too long: '%s'", user)) errx(1, "Permission denied"); #endif errx(1, "username too long"); @@ -280,7 +285,7 @@ main(int argc, char *argv[]) pwd = getpwuid(ruid); if (pwd == NULL) { #ifdef USE_BSM_AUDIT - if (audit_submit(AUE_su, auid, 1, EPERM, + if (audit_submit(AUE_su, auid, EPERM, 1, "unable to determine invoking subject: '%s'", username)) errx(1, "Permission denied"); #endif @@ -321,7 +326,7 @@ main(int argc, char *argv[]) retcode = pam_authenticate(pamh, 0); if (retcode != PAM_SUCCESS) { #ifdef USE_BSM_AUDIT - if (audit_submit(AUE_su, auid, 1, EPERM, "bad su %s to %s on %s", + if (audit_submit(AUE_su, auid, EPERM, 1, "bad su %s to %s on %s", username, user, mytty)) errx(1, "Permission denied"); #endif @@ -333,16 +338,16 @@ main(int argc, char *argv[]) if (audit_submit(AUE_su, auid, 0, 0, "successful authentication")) errx(1, "Permission denied"); #endif - retcode = pam_get_item(pamh, PAM_USER, (const void **)&p); + retcode = pam_get_item(pamh, PAM_USER, &v); if (retcode == PAM_SUCCESS) - user = p; + user = v; else syslog(LOG_ERR, "pam_get_item(PAM_USER): %s", pam_strerror(pamh, retcode)); pwd = getpwnam(user); if (pwd == NULL) { #ifdef USE_BSM_AUDIT - if (audit_submit(AUE_su, auid, 1, EPERM, + if (audit_submit(AUE_su, auid, EPERM, 1, "unknown subject: %s", user)) errx(1, "Permission denied"); #endif @@ -358,7 +363,7 @@ main(int argc, char *argv[]) aerr = pam_strerror(pamh, retcode); if (aerr == NULL) aerr = "Unknown PAM error"; - if (audit_submit(AUE_su, auid, 1, EPERM, + if (audit_submit(AUE_su, auid, EPERM, 1, "pam_chauthtok: %s", aerr)) errx(1, "Permission denied"); #endif @@ -369,7 +374,7 @@ main(int argc, char *argv[]) } if (retcode != PAM_SUCCESS) { #ifdef USE_BSM_AUDIT - if (audit_submit(AUE_su, auid, 1, EPERM, "pam_acct_mgmt: %s", + if (audit_submit(AUE_su, auid, EPERM, 1, "pam_acct_mgmt: %s", pam_strerror(pamh, retcode))) errx(1, "Permission denied"); #endif @@ -385,7 +390,7 @@ main(int argc, char *argv[]) else { if (ruid != 0) { #ifdef USE_BSM_AUDIT - if (audit_submit(AUE_su, auid, 1, EPERM, + if (audit_submit(AUE_su, auid, EPERM, 1, "only root may use -c")) errx(1, "Permission denied"); #endif @@ -440,6 +445,17 @@ main(int argc, char *argv[]) err(1, "setusercontext"); #endif /* __APPLE__ */ +#ifdef __APPLE__ + /* 8530846 */ + if (asthem) { + retcode = SessionCreate(0, 0); + if (retcode != noErr) { + syslog(LOG_ERR, "SessionCreate: %d", retcode); + errx(1, "failed to create session."); + } + } +#endif /* __APPLE__ */ + retcode = pam_setcred(pamh, PAM_ESTABLISH_CRED); if (retcode != PAM_SUCCESS) { syslog(LOG_ERR, "pam_setcred: %s", diff --git a/tee/Makefile b/tee/Makefile index 6b6b990..00f10dc 100644 --- a/tee/Makefile +++ b/tee/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = tee.c MANPAGES = tee.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/test/Makefile b/test/Makefile index 6cf25c1..006d45c 100644 --- a/test/Makefile +++ b/test/Makefile @@ -4,7 +4,7 @@ Install_Dir = /bin CFILES = test.c MANPAGES = test.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/time/Makefile b/time/Makefile index 580f76d..1ea2a8e 100644 --- a/time/Makefile +++ b/time/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = time.c MANPAGES = time.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/true/Makefile b/true/Makefile index cf6b7f4..ca5fc5d 100644 --- a/true/Makefile +++ b/true/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = true.c MANPAGES = true.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/uname/Makefile b/uname/Makefile index ac34c9a..b49c4cf 100644 --- a/uname/Makefile +++ b/uname/Makefile @@ -4,7 +4,7 @@ Install_DIr = /usr/bin CFILES = uname.c MANPAGES = uname.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/uname/uname.1 b/uname/uname.1 index 8253ea9..0c62868 100644 --- a/uname/uname.1 +++ b/uname/uname.1 @@ -75,6 +75,7 @@ option had been specified. .Sh SEE ALSO .Xr hostname 1 , .Xr machine 1 , +.Xr sw_vers 1 , .Xr uname 3 .Sh STANDARDS The diff --git a/users/Makefile b/users/Makefile index d44db08..edb22ac 100644 --- a/users/Makefile +++ b/users/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = users.c MANPAGES = users.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/w/Makefile b/w/Makefile index 3e9d994..0792750 100644 --- a/w/Makefile +++ b/w/Makefile @@ -7,7 +7,7 @@ MANPAGES = uptime.1 w.1 Embedded=$(shell tconf --test TARGET_OS_EMBEDDED) -Extra_CC_Flags = -Wall -mdynamic-no-pic \ +Extra_CC_Flags = -Wall \ -no-cpp-precomp -Wno-error -DHAVE_KVM=0 -DHAVE_UTMPX=1 Extra_LD_Flags = -dead_strip ifeq ($(Embedded),NO) diff --git a/whereis/Makefile b/whereis/Makefile index 57c226f..2d77673 100644 --- a/whereis/Makefile +++ b/whereis/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = whereis.c MANPAGES = whereis.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make diff --git a/whereis/whereis.1 b/whereis/whereis.1 index 22dfb28..4df4b27 100644 --- a/whereis/whereis.1 +++ b/whereis/whereis.1 @@ -35,7 +35,7 @@ .\" .Dd April 27, 1995 .Dt WHEREIS 1 -.Os BSD 3 +.Os .Sh NAME .Nm whereis .Nd locate programs @@ -54,6 +54,10 @@ utility for the .Dq user.cs_path string. .Sh SEE ALSO +.Xr find 1 , +.Xr locate 1 , +.Xr man 1 , +.Xr which 1 , .Xr sysctl 8 .Sh COMPATIBILITY The historic flags and arguments for the diff --git a/which/Makefile b/which/Makefile index 96649f3..dfe7c1c 100644 --- a/which/Makefile +++ b/which/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = which.c MANPAGES = which.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic \ +Extra_CC_Flags = -Wall \ -D__FBSDID=__RCSID Extra_LD_Flags = -dead_strip diff --git a/who/Makefile b/who/Makefile index bc1168c..b984b17 100644 --- a/who/Makefile +++ b/who/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = who.c utmpentry.c MANPAGES = who.1 -Extra_CC_Flags = -Wall -Werror -mdynamic-no-pic +Extra_CC_Flags = -Wall -Werror Extra_CC_Flags += -DSUPPORT_UTMPX -D_UTMPX_COMPAT Extra_LD_Flags = -dead_strip diff --git a/xargs/Makefile b/xargs/Makefile index 464c658..9a44c26 100644 --- a/xargs/Makefile +++ b/xargs/Makefile @@ -5,7 +5,7 @@ HFILES = pathnames.h CFILES = xargs.c strnsubst.c MANPAGES = xargs.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic \ +Extra_CC_Flags = -Wall \ -D__FBSDID=__RCSID Extra_LD_Flags = -dead_strip diff --git a/xargs/xargs.c b/xargs/xargs.c index 2d42c62..2316012 100644 --- a/xargs/xargs.c +++ b/xargs/xargs.c @@ -91,6 +91,7 @@ static const char *eofstr; static int count, insingle, indouble, oflag, pflag, tflag, Rflag, rval, zflag; static int cnt, Iflag, jfound, Lflag, wasquoted, xflag; static int curprocs, maxprocs; +static size_t pad9314053; static volatile int childerr; @@ -128,11 +129,13 @@ main(int argc, char *argv[]) nargs = 5000; if ((arg_max = sysconf(_SC_ARG_MAX)) == -1) errx(1, "sysconf(_SC_ARG_MAX) failed"); - nline = arg_max - 4 * 1024; + nline = arg_max - MAXPATHLEN; /* for argv[0] from execvp() */ + pad9314053 = sizeof(char *); /* reserve for string area rounding */ while (*ep != NULL) { /* 1 byte for each '\0' */ nline -= strlen(*ep++) + 1 + sizeof(*ep); } + nline -= pad9314053; maxprocs = 1; while ((ch = getopt(argc, argv, "0E:I:J:L:n:oP:pR:s:tx")) != -1) switch(ch) { @@ -182,6 +185,7 @@ main(int argc, char *argv[]) break; case 's': nline = atoi(optarg); + pad9314053 = 0; /* assume the -s value is valid */ break; case 't': tflag = 1; @@ -225,7 +229,7 @@ main(int argc, char *argv[]) * arguments. */ if (*argv == NULL) - cnt = strlen(*bxp++ = echo); + cnt = strlen(*bxp++ = echo) + pad9314053; else { do { if (Jflag && strcmp(*argv, replstr) == 0) { @@ -233,10 +237,10 @@ main(int argc, char *argv[]) jfound = 1; argv++; for (avj = argv; *avj; avj++) - cnt += strlen(*avj) + 1; + cnt += strlen(*avj) + 1 + pad9314053; break; } - cnt += strlen(*bxp++ = *argv) + 1; + cnt += strlen(*bxp++ = *argv) + 1 + pad9314053; } while (*++argv != NULL); } @@ -382,9 +386,9 @@ arg2: * of input lines, as specified by -L is the same as * maxing out on arguments. */ - if (xp == endxp || p > ebp || ch == EOF || + if (xp == endxp || p + (count * pad9314053) > ebp || ch == EOF || (Lflag <= count && xflag) || foundeof) { - if (xflag && xp != endxp && p > ebp) + if (xflag && xp != endxp && p + (count * pad9314053) > ebp) errx(1, "insufficient space for arguments"); if (jfound) { for (avj = argv; *avj; avj++) diff --git a/yes/Makefile b/yes/Makefile index 5857ee1..c049f93 100644 --- a/yes/Makefile +++ b/yes/Makefile @@ -4,7 +4,7 @@ Install_Dir = /usr/bin CFILES = yes.c MANPAGES = yes.1 -Extra_CC_Flags = -Wall -mdynamic-no-pic +Extra_CC_Flags = -Wall Extra_LD_Flags = -dead_strip include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make -- 2.45.2