diff options
author | Dave Eddy <dave@daveeddy.com> | 2018-01-22 12:01:03 -0500 |
---|---|---|
committer | Trent Mick <trentm@gmail.com> | 2018-01-22 12:01:03 -0500 |
commit | 22f6089295fb8b4a33f746de254d34825eb582e0 (patch) | |
tree | 110f3912035b49fb9ecb82d3d7f0dc1a786ffa64 | |
parent | 88305497abe82aa90b20abf6c4c7924c43a27e9f (diff) | |
download | illumos-joyent-cr2977-OS-6459.tar.gz |
OS-6459 logadm should use absolute paths for filenames Reviewed by: Michael Zeller <mike.zeller@joyent.com>cr2977-OS-6459
-rw-r--r-- | usr/src/cmd/logadm/main.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/usr/src/cmd/logadm/main.c b/usr/src/cmd/logadm/main.c index 93a54a60ed..716db5aa27 100644 --- a/usr/src/cmd/logadm/main.c +++ b/usr/src/cmd/logadm/main.c @@ -20,18 +20,20 @@ */ /* * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2013, Joyent, Inc. All rights reserved. + * Copyright (c) 2018, Joyent, Inc. * * logadm/main.c -- main routines for logadm * * this program is 90% argument processing, 10% actions... */ +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <strings.h> #include <libintl.h> +#include <limits.h> #include <locale.h> #include <fcntl.h> #include <sys/types.h> @@ -574,6 +576,7 @@ static boolean_t rotatelog(struct fn *fnp, struct opts *opts) { char *fname = fn_s(fnp); + char realname[PATH_MAX]; struct stat stbuf; char nowstr[TIMESTRMAX]; struct fn *recentlog = fn_new(NULL); /* for -R cmd */ @@ -584,8 +587,21 @@ rotatelog(struct fn *fnp, struct opts *opts) const char *group; const char *mode; - if (Debug && fname != NULL) - (void) fprintf(stderr, "rotatelog: fname <%s>\n", fname); + /* + * Full resolved path is used when recording the timestamp in the + * timestamps file. + * + * ENOENT is ignored here as it will be handled by the below call to + * lstat(2). + **/ + if (realpath(fname, realname) == NULL && errno != ENOENT) { + err(EF_WARN, "realpath(\"%s\"): %s", fname, strerror(errno)); + return (B_FALSE); + } + + if (Debug) + (void) fprintf(stderr, "rotatelog: fname <%s>: %s\n", + fname, realname); if (opts_count(opts, "p") && opts_optarg_int(opts, "p") == OPTP_NEVER) return (B_TRUE); /* "-p never" forced no rotate */ @@ -767,10 +783,10 @@ rotatelog(struct fn *fnp, struct opts *opts) /* record the rotation date */ (void) strftime(nowstr, sizeof (nowstr), "%a %b %e %T %Y", gmtime(&Now)); - if (opts_count(opts, "v") && fname != NULL) + if (opts_count(opts, "v")) (void) out("# recording rotation date %s for %s\n", - nowstr, fname); - conf_set(fname, "P", STRDUP(nowstr)); + nowstr, realname); + conf_set(realname, "P", STRDUP(nowstr)); Donenames = lut_add(Donenames, fname, "1"); return (B_TRUE); } |