diff options
| author | Mariusz Zaborski <oshogbo@FreeBSD.org> | 2019-06-09 22:55:21 +0000 |
|---|---|---|
| committer | Mariusz Zaborski <oshogbo@FreeBSD.org> | 2019-06-09 22:55:21 +0000 |
| commit | c851fce6d779e8340609d7e2364829c61cbcb1ef (patch) | |
| tree | 884c0cb918fc098ffb8dc3ae62fc63c325afd229 /usr.bin/tail | |
| parent | 39d51a9400bf3ff4776d5ef5a7525566216144ac (diff) | |
Notes
Diffstat (limited to 'usr.bin/tail')
| -rw-r--r-- | usr.bin/tail/extern.h | 1 | ||||
| -rw-r--r-- | usr.bin/tail/forward.c | 28 | ||||
| -rw-r--r-- | usr.bin/tail/misc.c | 3 | ||||
| -rw-r--r-- | usr.bin/tail/read.c | 3 | ||||
| -rw-r--r-- | usr.bin/tail/reverse.c | 3 | ||||
| -rw-r--r-- | usr.bin/tail/tail.c | 4 |
6 files changed, 31 insertions, 11 deletions
diff --git a/usr.bin/tail/extern.h b/usr.bin/tail/extern.h index ef2c9ce0ee9a..65ddb519dc61 100644 --- a/usr.bin/tail/extern.h +++ b/usr.bin/tail/extern.h @@ -78,3 +78,4 @@ int maparound(struct mapinfo *, off_t); void printfn(const char *, int); extern int Fflag, fflag, qflag, rflag, rval, no_files; +extern fileargs_t *fa; diff --git a/usr.bin/tail/forward.c b/usr.bin/tail/forward.c index 3b697e0a5589..2888bd18816e 100644 --- a/usr.bin/tail/forward.c +++ b/usr.bin/tail/forward.c @@ -57,6 +57,9 @@ static const char sccsid[] = "@(#)forward.c 8.1 (Berkeley) 6/6/93"; #include <string.h> #include <unistd.h> +#include <libcasper.h> +#include <casper/cap_fileargs.h> + #include "extern.h" static void rlines(FILE *, const char *fn, off_t, struct stat *); @@ -310,6 +313,7 @@ follow(file_info_t *files, enum STYLE style, off_t off) int active, ev_change, i, n = -1; struct stat sb2; file_info_t *file; + FILE *ftmp; struct timespec ts; /* Position each of the files */ @@ -346,7 +350,9 @@ follow(file_info_t *files, enum STYLE style, off_t off) if (Fflag) { for (i = 0, file = files; i < no_files; i++, file++) { if (!file->fp) { - file->fp = fopen(file->file_name, "r"); + file->fp = + fileargs_fopen(fa, file->file_name, + "r"); if (file->fp != NULL && fstat(fileno(file->fp), &file->st) == -1) { @@ -359,7 +365,9 @@ follow(file_info_t *files, enum STYLE style, off_t off) } if (fileno(file->fp) == STDIN_FILENO) continue; - if (stat(file->file_name, &sb2) == -1) { + ftmp = fileargs_fopen(fa, file->file_name, "r"); + if (ftmp == NULL || + fstat(fileno(file->fp), &sb2) == -1) { if (errno != ENOENT) ierr(file->file_name); show(file); @@ -367,6 +375,9 @@ follow(file_info_t *files, enum STYLE style, off_t off) fclose(file->fp); file->fp = NULL; } + if (ftmp != NULL) { + fclose(ftmp); + } ev_change++; continue; } @@ -375,14 +386,13 @@ follow(file_info_t *files, enum STYLE style, off_t off) sb2.st_dev != file->st.st_dev || sb2.st_nlink == 0) { show(file); - file->fp = freopen(file->file_name, "r", - file->fp); - if (file->fp != NULL) - memcpy(&file->st, &sb2, - sizeof(struct stat)); - else if (errno != ENOENT) - ierr(file->file_name); + fclose(file->fp); + file->fp = ftmp; + memcpy(&file->st, &sb2, + sizeof(struct stat)); ev_change++; + } else { + fclose(ftmp); } } } diff --git a/usr.bin/tail/misc.c b/usr.bin/tail/misc.c index 137a38829b47..537cf00ccfe3 100644 --- a/usr.bin/tail/misc.c +++ b/usr.bin/tail/misc.c @@ -51,6 +51,9 @@ static const char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/6/93"; #include <string.h> #include <unistd.h> +#include <libcasper.h> +#include <casper/cap_fileargs.h> + #include "extern.h" void diff --git a/usr.bin/tail/read.c b/usr.bin/tail/read.c index c5638d961399..1e757c86195c 100644 --- a/usr.bin/tail/read.c +++ b/usr.bin/tail/read.c @@ -51,6 +51,9 @@ static const char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/6/93"; #include <string.h> #include <unistd.h> +#include <libcasper.h> +#include <casper/cap_fileargs.h> + #include "extern.h" /* diff --git a/usr.bin/tail/reverse.c b/usr.bin/tail/reverse.c index 422724c0ebab..3373f072c228 100644 --- a/usr.bin/tail/reverse.c +++ b/usr.bin/tail/reverse.c @@ -55,6 +55,9 @@ __FBSDID("$FreeBSD$"); #include <string.h> #include <unistd.h> +#include <libcasper.h> +#include <casper/cap_fileargs.h> + #include "extern.h" static void r_buf(FILE *, const char *); diff --git a/usr.bin/tail/tail.c b/usr.bin/tail/tail.c index 5985fcf51e80..abbe715e0496 100644 --- a/usr.bin/tail/tail.c +++ b/usr.bin/tail/tail.c @@ -65,6 +65,7 @@ static const char sccsid[] = "@(#)tail.c 8.1 (Berkeley) 6/6/93"; #include "extern.h" int Fflag, fflag, qflag, rflag, rval, no_files; +fileargs_t *fa; static file_info_t *files; @@ -90,10 +91,9 @@ main(int argc, char *argv[]) int i, ch, first; file_info_t *file; char *p; - fileargs_t *fa; cap_rights_t rights; - cap_rights_init(&rights, CAP_FSTAT, CAP_FCNTL, CAP_MMAP_RW); + cap_rights_init(&rights, CAP_FSTAT, CAP_FSTATFS, CAP_FCNTL, CAP_MMAP_RW); if (caph_rights_limit(STDIN_FILENO, &rights) < 0 || caph_limit_stderr() < 0 || caph_limit_stdout() < 0) err(1, "can't limit stdio rights"); |
