Mercurial > illumos > git > illumos-joyent
changeset 25194:41c0e961806d
OS-8197 log file closing can cause zoneadmd to crash (#319)
Reviewed by: Dan McDonald <danmcd@joyent.com>
Reviewed by: Mike Zeller <mike.zeller@joyent.com>
Approved by: Mike Zeller <mike.zelelr@joyent.com>
author | Jason King <jasonbking@users.noreply.github.com> |
---|---|
date | Fri, 10 Jul 2020 13:44:17 -0500 |
parents | b0e40b18bed0 |
children | 86d9f1b34087 |
files | usr/src/cmd/zoneadmd/log.c |
diffstat | 1 files changed, 28 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/usr/src/cmd/zoneadmd/log.c Fri Jul 10 11:45:27 2020 +0000 +++ b/usr/src/cmd/zoneadmd/log.c Fri Jul 10 13:44:17 2020 -0500 @@ -960,6 +960,32 @@ return (ls); } +static void +logstream_reset(logstream_t *lsp) +{ + custr_t *buf = lsp->ls_cusbuf; + custr_t *obuf = lsp->ls_cusobuf; + + (void) memset(lsp, 0, sizeof (*lsp)); + lsp->ls_cusbuf = buf; + lsp->ls_cusobuf = obuf; + + custr_reset(buf); + custr_reset(obuf); +} + +static void +logfile_reset(logfile_t *lfp) +{ + custr_t *buf = lfp->lf_cus; + + (void) memset(lfp, 0, sizeof (*lfp)); + lfp->lf_cus = buf; + lfp->lf_fd = -1; + + custr_reset(buf); +} + void logstream_close(int ls, boolean_t abrupt) { @@ -982,7 +1008,7 @@ VERIFY(lsp->ls_stream[0] != '\0'); VERIFY3P(lfp, !=, NULL); - (void) memset(lsp, 0, sizeof (*lsp)); + logstream_reset(lsp); for (i = 0; i < ARRAY_SIZE(streams); i++) { if (streams[i].ls_logfile == lfp) { @@ -995,8 +1021,7 @@ close_log(lfp, "close", abrupt); - (void) memset(lfp, 0, sizeof (*lfp)); - lfp->lf_fd = -1; + logfile_reset(lfp); logstream_unlock(); }