Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OS-6459 logadm should use absolute paths for filenames Reviewed by: Michael Zeller <[email protected]> #213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions usr/src/cmd/logadm/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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 */
Expand All @@ -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 */
Expand Down Expand Up @@ -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);
}
Expand Down