diff --git a/commands/Makefile b/commands/Makefile index 2ec1a6c36..b0307a8c1 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -11,7 +11,7 @@ SUBDIR= aal add_route adduser advent arp ash at autil awk \ dd de decomp16 DESCRIBE dev2name devsize df dhcpd \ dhrystone diff dirname dis88 du dumpcore easypack \ ed eject elle elvis env expand factor fgrep file \ - finger fingerd fix fold format fortune fsck \ + find finger fingerd fix fold format fortune fsck \ fsck1 ftp101 ftpd200 getty gomoku grep head host \ hostaddr id ifconfig ifdef indent install \ intr ipcrm ipcs irdpd isoread join kill last leave \ diff --git a/commands/find/Makefile b/commands/find/Makefile index 0eee9219d..176500caf 100644 --- a/commands/find/Makefile +++ b/commands/find/Makefile @@ -1,13 +1,14 @@ # $NetBSD: Makefile,v 1.12 2006/12/14 20:55:56 he Exp $ # from: @(#)Makefile 8.1 (Berkeley) 6/6/93 -.include +.include PROG= find SRCS= find.c function.c ls.c main.c misc.c operator.c option.c -WARNS= 4 + +CFLAGS += -Wall LDADD+=-lutil DPADD+=${LIBUTIL} -.include +.include diff --git a/commands/find/find.c b/commands/find/find.c index 67d5ca552..29126847c 100644 --- a/commands/find/find.c +++ b/commands/find/find.c @@ -33,13 +33,6 @@ */ #include -#ifndef lint -#if 0 -static char sccsid[] = "from: @(#)find.c 8.5 (Berkeley) 8/5/94"; -#else -__RCSID("$NetBSD: find.c,v 1.25 2007/09/25 04:10:12 lukem Exp $"); -#endif -#endif /* not lint */ #include #include @@ -54,7 +47,7 @@ __RCSID("$NetBSD: find.c,v 1.25 2007/09/25 04:10:12 lukem Exp $"); #include "find.h" -static int ftscompare(const FTSENT **, const FTSENT **); +static int ftscompare(const FTSENT * const *, const FTSENT * const *); static void sig_lock(sigset_t *); static void sig_unlock(const sigset_t *); @@ -148,7 +141,7 @@ find_formplan(char **argv) } static int -ftscompare(const FTSENT **e1, const FTSENT **e2) +ftscompare(const FTSENT * const *e1, const FTSENT * const *e2) { return (strcoll((*e1)->fts_name, (*e2)->fts_name)); @@ -160,7 +153,9 @@ sig_lock(sigset_t *s) sigset_t new; sigemptyset(&new); +#ifdef SIGINFO sigaddset(&new, SIGINFO); /* block SIGINFO */ +#endif sigprocmask(SIG_BLOCK, &new, s); } diff --git a/commands/find/find.h b/commands/find/find.h index d14b0cbaf..4949e90d1 100644 --- a/commands/find/find.h +++ b/commands/find/find.h @@ -40,14 +40,21 @@ enum ntype { N_AND = 1, /* must start > 0 */ N_AMIN, N_ANEWER, N_ATIME, N_CLOSEPAREN, N_CMIN, N_CNEWER, N_CTIME, - N_DEPTH, N_EMPTY, N_EXEC, N_EXECDIR, N_EXIT, N_EXPR, N_FALSE, N_FLAGS, - N_FOLLOW, N_FPRINT, N_FSTYPE, N_GROUP, + N_DEPTH, N_EMPTY, N_EXEC, N_EXECDIR, N_EXIT, N_EXPR, N_FALSE, + N_FOLLOW, N_FPRINT, +#ifndef _MINIX + N_FSTYPE, + N_FLAGS, +#endif + N_GROUP, N_INAME, N_INUM, N_IREGEX, N_LINKS, N_LS, N_MINDEPTH, N_MAXDEPTH, N_MMIN, N_MTIME, N_NAME, N_NEWER, N_NOGROUP, N_NOT, N_NOUSER, N_OK, N_OPENPAREN, N_OR, N_PATH, N_PERM, N_PRINT, N_PRINT0, N_PRINTX, N_PRUNE, N_REGEX, N_SIZE, N_TYPE, N_USER, N_XDEV, N_DELETE }; +typedef unsigned int u_int32_t; + /* node definition */ typedef struct _plandata { struct _plandata *next; /* next node */ @@ -61,6 +68,7 @@ typedef struct _plandata { #define F_MTFLAG 1 /* fstype */ #define F_MTTYPE 2 #define F_ATLEAST 1 /* perm */ +#define F_ANY 2 /* perm */ int flags; /* private flags */ enum ntype type; /* plan node type */ union { diff --git a/commands/find/function.c b/commands/find/function.c index c8b8613cc..b7b0fba4c 100644 --- a/commands/find/function.c +++ b/commands/find/function.c @@ -33,13 +33,6 @@ */ #include -#ifndef lint -#if 0 -static char sccsid[] = "from: @(#)function.c 8.10 (Berkeley) 5/4/95"; -#else -__RCSID("$NetBSD: function.c,v 1.64 2007/07/19 07:49:30 daniel Exp $"); -#endif -#endif /* not lint */ #include #include @@ -55,7 +48,6 @@ __RCSID("$NetBSD: function.c,v 1.64 2007/07/19 07:49:30 daniel Exp $"); #include #include #include -#include #include #include #include @@ -65,6 +57,10 @@ __RCSID("$NetBSD: function.c,v 1.64 2007/07/19 07:49:30 daniel Exp $"); #include "find.h" +typedef int bool; +#define false 0 +#define true 1 + #define COMPARE(a, b) { \ switch (plan->flags) { \ case F_EQUAL: \ @@ -78,7 +74,7 @@ __RCSID("$NetBSD: function.c,v 1.64 2007/07/19 07:49:30 daniel Exp $"); } \ } -static int64_t find_parsenum(PLAN *, const char *, const char *, char *); +static int32_t find_parsenum(PLAN *, const char *, const char *, char *); static void run_f_exec(PLAN *); int f_always_true(PLAN *, FTSENT *); int f_amin(PLAN *, FTSENT *); @@ -131,10 +127,10 @@ extern time_t now; * find_parsenum -- * Parse a string of the form [+-]# and return the value. */ -static int64_t +static int32_t find_parsenum(PLAN *plan, const char *option, const char *vp, char *endch) { - int64_t value; + int32_t value; const char *str; char *endchar; /* Pointer to character ending conversion. */ @@ -159,7 +155,7 @@ find_parsenum(PLAN *plan, const char *option, const char *vp, char *endch) * and endchar points to the beginning of the string we know we have * a syntax error. */ - value = strtoq(str, &endchar, 10); + value = strtol(str, &endchar, 10); if (value == 0 && endchar == str) errx(1, "%s: %s: illegal numeric value", option, vp); if (endchar[0] && (endch == NULL || endchar[0] != *endch)) @@ -379,12 +375,14 @@ f_delete(PLAN *plan __unused, FTSENT *entry) errx(1, "-delete: %s: relative path potentially not safe", entry->fts_accpath); +#ifndef _MINIX /* Turn off user immutable bits if running as root */ 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, entry->fts_statp->st_flags &= ~(UF_APPEND|UF_IMMUTABLE)); +#endif /* rmdir directories, unlink everything else */ if (S_ISDIR(entry->fts_statp->st_mode)) { @@ -545,9 +543,9 @@ f_exec(PLAN *plan, FTSENT *entry) fflush(stdout); fflush(stderr); - switch (pid = vfork()) { + switch (pid = fork()) { case -1: - err(1, "vfork"); + err(1, "fork"); /* NOTREACHED */ case 0: if (fchdir(dotfd)) { @@ -577,9 +575,9 @@ run_f_exec(PLAN *plan) fflush(stdout); fflush(stderr); - switch (pid = vfork()) { + switch (pid = fork()) { case -1: - err(1, "vfork"); + err(1, "fork"); /* NOTREACHED */ case 0: if (fchdir(dotfd)) { @@ -755,7 +753,7 @@ f_execdir(PLAN *plan, FTSENT *entry) fflush(stdout); fflush(stderr); - switch (pid = vfork()) { + switch (pid = fork()) { case -1: err(1, "fork"); /* NOTREACHED */ @@ -857,6 +855,7 @@ c_false(char ***argvp, int isok) } +#ifndef _MINIX /* * -flags [-]flags functions -- */ @@ -870,6 +869,8 @@ f_flags(PLAN *plan, FTSENT *entry) return ((plan->f_data | flags) == flags); else return (flags == plan->f_data); + /* MINIX has no file flags. */ + return 0; /* NOTREACHED */ } @@ -897,6 +898,7 @@ c_flags(char ***argvp, int isok) new->f_data = flagset; return (new); } +#endif /* * -follow functions -- @@ -951,6 +953,7 @@ c_fprint(char ***argvp, int isok) * * True if the file is of a certain type. */ +#ifndef _MINIX int f_fstype(PLAN *plan, FTSENT *entry) { @@ -1044,6 +1047,7 @@ c_fstype(char ***argvp, int isok) new->c_data = arg; return (new); } +#endif /* * -group gname functions -- @@ -1424,9 +1428,15 @@ f_perm(PLAN *plan, FTSENT *entry) mode_t mode; mode = entry->fts_statp->st_mode & - (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO); + (S_ISUID|S_ISGID +#ifdef S_ISTXT + |S_ISTXT +#endif + |S_IRWXU|S_IRWXG|S_IRWXO); if (plan->flags == F_ATLEAST) return ((plan->m_data | mode) == mode); + else if (plan->flags == F_ANY) + return ((plan->m_data & mode) != 0); else return (mode == plan->m_data); /* NOTREACHED */ @@ -1447,6 +1457,9 @@ c_perm(char ***argvp, int isok) if (*perm == '-') { new->flags = F_ATLEAST; ++perm; + } else if (*perm == '+') { + new->flags = F_ANY; + ++perm; } if ((set = setmode(perm)) == NULL) @@ -1562,7 +1575,7 @@ f_regex(PLAN *plan, FTSENT *entry) static PLAN * c_regex_common(char ***argvp, int isok, enum ntype type, bool icase) { - char errbuf[LINE_MAX]; + char errbuf[100]; regex_t reg; char *regexp = **argvp; char *lineregexp; @@ -1687,9 +1700,11 @@ c_type(char ***argvp, int isok) case 'p': mask = S_IFIFO; break; +#ifdef S_IFSOCK case 's': mask = S_IFSOCK; break; +#endif #ifdef S_IFWHT case 'W': case 'w': diff --git a/commands/find/ls.c b/commands/find/ls.c index 71fe95941..9cedd593e 100644 --- a/commands/find/ls.c +++ b/commands/find/ls.c @@ -30,13 +30,6 @@ */ #include -#ifndef lint -#if 0 -static char sccsid[] = "from: @(#)ls.c 8.1 (Berkeley) 6/6/93"; -#else -__RCSID("$NetBSD: ls.c,v 1.19 2006/10/11 19:51:10 apb Exp $"); -#endif -#endif /* not lint */ #include #include @@ -52,6 +45,9 @@ __RCSID("$NetBSD: ls.c,v 1.19 2006/10/11 19:51:10 apb Exp $"); #include #include #include +#include +#include +#include #include "find.h" @@ -66,19 +62,40 @@ printlong(char *name, /* filename to print */ struct stat *sb) /* stat buffer */ { char modep[15]; + static dev_t dev; + static int blocksize = 0; + long blocks = -1; - (void)printf("%7lu %6lld ", (u_long)sb->st_ino, - (long long)sb->st_blocks); + if(!blocksize || sb->st_dev != dev) { + int fd; + struct statfs fs; + blocksize = 0; + if((fd = open(name, O_RDONLY)) >= 0) { + if(fstatfs(fd, &fs) >= 0) { + blocksize = fs.f_bsize; + } + close(fd); + } + } + + if(blocksize > 0) + blocks = ((long)sb->st_size+blocksize-1)/blocksize; + + (void)printf("%7lu ", (u_long)sb->st_ino); + if(blocks >= 0) + (void)printf("%6ld ", blocks); + else + (void)printf("? "); (void)strmode(sb->st_mode, modep); - (void)printf("%s %3lu %-*s %-*s ", modep, (unsigned long)sb->st_nlink, - LOGIN_NAME_MAX, user_from_uid(sb->st_uid, 0), LOGIN_NAME_MAX, + (void)printf("%s %3lu %-10s %-10s ", modep, (unsigned long)sb->st_nlink, + user_from_uid(sb->st_uid, 0), group_from_gid(sb->st_gid, 0)); if (S_ISCHR(sb->st_mode) || S_ISBLK(sb->st_mode)) (void)printf("%3d,%5d ", major(sb->st_rdev), minor(sb->st_rdev)); else - (void)printf("%9lld ", (long long)sb->st_size); + (void)printf("%9ld ", (long)sb->st_size); printtime(sb->st_mtime); (void)printf("%s", name); if (S_ISLNK(sb->st_mode)) diff --git a/commands/find/main.c b/commands/find/main.c index 587db06a1..7fe413920 100644 --- a/commands/find/main.c +++ b/commands/find/main.c @@ -33,15 +33,6 @@ */ #include -#ifndef lint -#if 0 -static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 5/4/95"; -#else -__COPYRIGHT("@(#) Copyright (c) 1990, 1993, 1994\ - The Regents of the University of California. All rights reserved."); -__RCSID("$NetBSD: main.c,v 1.28 2008/07/21 14:19:22 lukem Exp $"); -#endif -#endif /* not lint */ #include #include @@ -86,7 +77,9 @@ main(int argc, char *argv[]) memset(&sa, 0, sizeof(sa)); sa.sa_flags = SA_RESTART; sa.sa_handler = show_path; +#ifdef SIGINFO sigaction(SIGINFO, &sa, NULL); +#endif /* array to hold dir list. at most (argc - 1) elements. */ p = start = malloc(argc * sizeof (char *)); diff --git a/commands/find/misc.c b/commands/find/misc.c index 8ba84c0a2..24bd49f3d 100644 --- a/commands/find/misc.c +++ b/commands/find/misc.c @@ -33,13 +33,6 @@ */ #include -#ifndef lint -#if 0 -static char sccsid[] = "from: @(#)misc.c 8.2 (Berkeley) 4/1/94"; -#else -__RCSID("$NetBSD: misc.c,v 1.14 2006/10/11 19:51:10 apb Exp $"); -#endif -#endif /* not lint */ #include #include diff --git a/commands/find/option.c b/commands/find/option.c index b827ab200..cdca27c73 100644 --- a/commands/find/option.c +++ b/commands/find/option.c @@ -33,13 +33,6 @@ */ #include -#ifndef lint -#if 0 -static char sccsid[] = "from: @(#)option.c 8.2 (Berkeley) 4/16/94"; -#else -__RCSID("$NetBSD: option.c,v 1.26 2007/02/06 15:33:22 perry Exp $"); -#endif -#endif /* not lint */ #include #include @@ -75,10 +68,12 @@ static OPTION const options[] = { { "-execdir", N_EXECDIR, c_execdir, 1 }, { "-exit", N_EXIT, c_exit, 0 }, { "-false", N_FALSE, c_false, 0 }, - { "-flags", N_FLAGS, c_flags, 1 }, { "-follow", N_FOLLOW, c_follow, 0 }, { "-fprint", N_FPRINT, c_fprint, 1 }, +#ifndef _MINIX + { "-flags", N_FLAGS, c_flags, 1 }, { "-fstype", N_FSTYPE, c_fstype, 1 }, +#endif { "-group", N_GROUP, c_group, 1 }, { "-iname", N_INAME, c_iname, 1 }, { "-inum", N_INUM, c_inum, 1 },