diff options
author | Bryan Drewery <bryan@shatow.net> | 2021-11-20 01:39:16 +0300 |
---|---|---|
committer | Bryan Drewery <bryan@shatow.net> | 2022-11-05 22:51:58 +0300 |
commit | 93fc1245586c2b7aa9e6c1f26fef725f1f64c17e (patch) | |
tree | ab08e052b29361a52c4edc2b9bd93d33bbcd4a44 | |
parent | ef40cd7ecd9655b403e8f8256278e52e2c430236 (diff) |
sh: Make stat(1) a builtin
This is to speedup the caching of pkg metadata which uses
'stat -f %m file'. Not much else is using stat(1).
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | Makefile.in | 26 | ||||
-rw-r--r-- | src/poudriere-sh/builtins-poudriere.def | 1 | ||||
-rw-r--r-- | src/poudriere-sh/stat.c | 26 |
4 files changed, 48 insertions, 6 deletions
diff --git a/Makefile.am b/Makefile.am index f994b4b9..0b6fc5bb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -231,6 +231,7 @@ sh_SOURCES+= \ src/poudriere-sh/rmdir.c \ src/poudriere-sh/setproctitle.c \ src/poudriere-sh/sleep.c \ + src/poudriere-sh/stat.c \ src/poudriere-sh/touch.c \ src/poudriere-sh/traps.c \ src/poudriere-sh/unlink.c diff --git a/Makefile.in b/Makefile.in index 6e4a6665..bffaf318 100644 --- a/Makefile.in +++ b/Makefile.in @@ -273,6 +273,7 @@ am_sh_OBJECTS = external/sh/sh-alias.$(OBJEXT) \ src/poudriere-sh/sh-rmdir.$(OBJEXT) \ src/poudriere-sh/sh-setproctitle.$(OBJEXT) \ src/poudriere-sh/sh-sleep.$(OBJEXT) \ + src/poudriere-sh/sh-stat.$(OBJEXT) \ src/poudriere-sh/sh-touch.$(OBJEXT) \ src/poudriere-sh/sh-traps.$(OBJEXT) \ src/poudriere-sh/sh-unlink.$(OBJEXT) \ @@ -413,6 +414,7 @@ am__depfiles_remade = external/libnv/$(DEPDIR)/libnv_la-msgio.Plo \ src/poudriere-sh/$(DEPDIR)/sh-rmdir.Po \ src/poudriere-sh/$(DEPDIR)/sh-setproctitle.Po \ src/poudriere-sh/$(DEPDIR)/sh-sleep.Po \ + src/poudriere-sh/$(DEPDIR)/sh-stat.Po \ src/poudriere-sh/$(DEPDIR)/sh-touch.Po \ src/poudriere-sh/$(DEPDIR)/sh-traps.Po \ src/poudriere-sh/$(DEPDIR)/sh-unlink.Po \ @@ -892,8 +894,9 @@ sh_SOURCES = external/sh/alias.c external/sh/alias.h \ src/poudriere-sh/mkfifo.c src/poudriere-sh/mktemp.c \ src/poudriere-sh/realpath.c src/poudriere-sh/rmdir.c \ src/poudriere-sh/setproctitle.c src/poudriere-sh/sleep.c \ - src/poudriere-sh/touch.c src/poudriere-sh/traps.c \ - src/poudriere-sh/unlink.c src/poudriere-sh/builtins.c + src/poudriere-sh/stat.c src/poudriere-sh/touch.c \ + src/poudriere-sh/traps.c src/poudriere-sh/unlink.c \ + src/poudriere-sh/builtins.c libucl_la_SOURCES = \ external/libucl/include/lua_ucl.h \ external/libucl/include/ucl.h \ @@ -1500,6 +1503,8 @@ src/poudriere-sh/sh-setproctitle.$(OBJEXT): \ src/poudriere-sh/$(DEPDIR)/$(am__dirstamp) src/poudriere-sh/sh-sleep.$(OBJEXT): src/poudriere-sh/$(am__dirstamp) \ src/poudriere-sh/$(DEPDIR)/$(am__dirstamp) +src/poudriere-sh/sh-stat.$(OBJEXT): src/poudriere-sh/$(am__dirstamp) \ + src/poudriere-sh/$(DEPDIR)/$(am__dirstamp) src/poudriere-sh/sh-touch.$(OBJEXT): src/poudriere-sh/$(am__dirstamp) \ src/poudriere-sh/$(DEPDIR)/$(am__dirstamp) src/poudriere-sh/sh-traps.$(OBJEXT): src/poudriere-sh/$(am__dirstamp) \ @@ -1726,6 +1731,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@src/poudriere-sh/$(DEPDIR)/sh-rmdir.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/poudriere-sh/$(DEPDIR)/sh-setproctitle.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/poudriere-sh/$(DEPDIR)/sh-sleep.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@src/poudriere-sh/$(DEPDIR)/sh-stat.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/poudriere-sh/$(DEPDIR)/sh-touch.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/poudriere-sh/$(DEPDIR)/sh-traps.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/poudriere-sh/$(DEPDIR)/sh-unlink.Po@am__quote@ # am--include-marker @@ -2636,6 +2642,20 @@ src/poudriere-sh/sh-sleep.obj: src/poudriere-sh/sleep.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(sh_CFLAGS) $(CFLAGS) -c -o src/poudriere-sh/sh-sleep.obj `if test -f 'src/poudriere-sh/sleep.c'; then $(CYGPATH_W) 'src/poudriere-sh/sleep.c'; else $(CYGPATH_W) '$(srcdir)/src/poudriere-sh/sleep.c'; fi` +src/poudriere-sh/sh-stat.o: src/poudriere-sh/stat.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(sh_CFLAGS) $(CFLAGS) -MT src/poudriere-sh/sh-stat.o -MD -MP -MF src/poudriere-sh/$(DEPDIR)/sh-stat.Tpo -c -o src/poudriere-sh/sh-stat.o `test -f 'src/poudriere-sh/stat.c' || echo '$(srcdir)/'`src/poudriere-sh/stat.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/poudriere-sh/$(DEPDIR)/sh-stat.Tpo src/poudriere-sh/$(DEPDIR)/sh-stat.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/poudriere-sh/stat.c' object='src/poudriere-sh/sh-stat.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(sh_CFLAGS) $(CFLAGS) -c -o src/poudriere-sh/sh-stat.o `test -f 'src/poudriere-sh/stat.c' || echo '$(srcdir)/'`src/poudriere-sh/stat.c + +src/poudriere-sh/sh-stat.obj: src/poudriere-sh/stat.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(sh_CFLAGS) $(CFLAGS) -MT src/poudriere-sh/sh-stat.obj -MD -MP -MF src/poudriere-sh/$(DEPDIR)/sh-stat.Tpo -c -o src/poudriere-sh/sh-stat.obj `if test -f 'src/poudriere-sh/stat.c'; then $(CYGPATH_W) 'src/poudriere-sh/stat.c'; else $(CYGPATH_W) '$(srcdir)/src/poudriere-sh/stat.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/poudriere-sh/$(DEPDIR)/sh-stat.Tpo src/poudriere-sh/$(DEPDIR)/sh-stat.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/poudriere-sh/stat.c' object='src/poudriere-sh/sh-stat.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(sh_CFLAGS) $(CFLAGS) -c -o src/poudriere-sh/sh-stat.obj `if test -f 'src/poudriere-sh/stat.c'; then $(CYGPATH_W) 'src/poudriere-sh/stat.c'; else $(CYGPATH_W) '$(srcdir)/src/poudriere-sh/stat.c'; fi` + src/poudriere-sh/sh-touch.o: src/poudriere-sh/touch.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(sh_CFLAGS) $(CFLAGS) -MT src/poudriere-sh/sh-touch.o -MD -MP -MF src/poudriere-sh/$(DEPDIR)/sh-touch.Tpo -c -o src/poudriere-sh/sh-touch.o `test -f 'src/poudriere-sh/touch.c' || echo '$(srcdir)/'`src/poudriere-sh/touch.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/poudriere-sh/$(DEPDIR)/sh-touch.Tpo src/poudriere-sh/$(DEPDIR)/sh-touch.Po @@ -3521,6 +3541,7 @@ distclean: distclean-recursive -rm -f src/poudriere-sh/$(DEPDIR)/sh-rmdir.Po -rm -f src/poudriere-sh/$(DEPDIR)/sh-setproctitle.Po -rm -f src/poudriere-sh/$(DEPDIR)/sh-sleep.Po + -rm -f src/poudriere-sh/$(DEPDIR)/sh-stat.Po -rm -f src/poudriere-sh/$(DEPDIR)/sh-touch.Po -rm -f src/poudriere-sh/$(DEPDIR)/sh-traps.Po -rm -f src/poudriere-sh/$(DEPDIR)/sh-unlink.Po @@ -3659,6 +3680,7 @@ maintainer-clean: maintainer-clean-recursive -rm -f src/poudriere-sh/$(DEPDIR)/sh-rmdir.Po -rm -f src/poudriere-sh/$(DEPDIR)/sh-setproctitle.Po -rm -f src/poudriere-sh/$(DEPDIR)/sh-sleep.Po + -rm -f src/poudriere-sh/$(DEPDIR)/sh-stat.Po -rm -f src/poudriere-sh/$(DEPDIR)/sh-touch.Po -rm -f src/poudriere-sh/$(DEPDIR)/sh-traps.Po -rm -f src/poudriere-sh/$(DEPDIR)/sh-unlink.Po diff --git a/src/poudriere-sh/builtins-poudriere.def b/src/poudriere-sh/builtins-poudriere.def index 7f585514..01a22fd6 100644 --- a/src/poudriere-sh/builtins-poudriere.def +++ b/src/poudriere-sh/builtins-poudriere.def @@ -26,6 +26,7 @@ rmcmd -n rm rmdircmd -n rmdir setproctitlecmd setproctitle sleepcmd -n sleep +statcmd -n stat touchcmd -n touch trap_pushcmd -n trap_push trap_popcmd -n trap_pop diff --git a/src/poudriere-sh/stat.c b/src/poudriere-sh/stat.c index 9d94399a..5180957f 100644 --- a/src/poudriere-sh/stat.c +++ b/src/poudriere-sh/stat.c @@ -39,7 +39,7 @@ __RCSID("$NetBSD: stat.c,v 1.33 2011/01/15 22:54:10 njoly Exp $" __FBSDID("$FreeBSD$"); -#if HAVE_CONFIG_H +#if defined(HAVE_CONFIG_H) && !defined(SHELL) #include "config.h" #else /* HAVE_CONFIG_H */ #define HAVE_STRUCT_STAT_ST_FLAGS 1 @@ -68,6 +68,13 @@ __FBSDID("$FreeBSD$"); #include <time.h> #include <unistd.h> +#ifdef SHELL +#define main statcmd +#include "bltin/bltin.h" +#include "helpers.h" +#define fputc(c, stream) putc((c), (stream)) +#endif + #if HAVE_STRUCT_STAT_ST_FLAGS #define DEF_F "%#Xf " #define RAW_F "%f " @@ -182,7 +189,7 @@ __FBSDID("$FreeBSD$"); #define SHOW_sizerdev 'Z' void usage(const char *); -void output(const struct stat *, const char *, +void _output(const struct stat *, const char *, const char *, int, int); int format1(const struct stat *, /* stat info */ const char *, /* the file name */ @@ -215,6 +222,11 @@ main(int argc, char *argv[]) fhandle_t fhnd; const char *file; +#ifdef SHELL + timefmt = NULL; + linkfail = 0; +#endif + am_readlink = 0; lsF = 0; fmtchar = '\0'; @@ -226,7 +238,11 @@ main(int argc, char *argv[]) statfmt = NULL; timefmt = NULL; +#ifdef SHELL + if (0) { +#else if (strcmp(getprogname(), "readlink") == 0) { +#endif am_readlink = 1; options = "fn"; synopsis = "[-fn] [file ...]"; @@ -376,7 +392,7 @@ main(int argc, char *argv[]) warn("%s: stat", file); } else - output(&st, file, statfmt, fn, nonl); + _output(&st, file, statfmt, fn, nonl); argv++; argc--; @@ -417,7 +433,7 @@ usage(const char *synopsis) * Parses a format string. */ void -output(const struct stat *st, const char *file, +_output(const struct stat *st, const char *file, const char *statfmt, int fn, int nonl) { int flags, size, prec, ofmt, hilo, what; @@ -764,7 +780,9 @@ format1(const struct stat *st, ts.tv_sec = 0; tm = localtime(&ts.tv_sec); } +#ifndef SHELL (void)setlocale(LC_TIME, ""); +#endif (void)strftime(path, sizeof(path), timefmt, tm); sdata = path; formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX | |