From 22f6089295fb8b4a33f746de254d34825eb582e0 Mon Sep 17 00:00:00 2001 From: Dave Eddy Date: Mon, 22 Jan 2018 12:01:03 -0500 Subject: [PATCH] OS-6459 logadm should use absolute paths for filenames Reviewed by: Michael Zeller --- usr/src/cmd/logadm/main.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/usr/src/cmd/logadm/main.c b/usr/src/cmd/logadm/main.c index 93a54a60ed48..716db5aa2776 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 #include #include #include #include #include +#include #include #include #include @@ -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); }