diff options
author | Jason King <jasonbking@users.noreply.github.com> | 2020-07-10 13:44:17 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-10 13:44:17 -0500 |
commit | c856fee6f0598e1c3217009f068fb39b8ab8205f (patch) | |
tree | fcfd5f6444d3a9d27782137bb1ba9f6530da6f14 | |
parent | 6b440d8411d53a26b1b9e72109994c6ca28ce67e (diff) | |
download | illumos-joyent-c856fee6f0598e1c3217009f068fb39b8ab8205f.tar.gz |
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>
-rw-r--r-- | usr/src/cmd/zoneadmd/log.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/usr/src/cmd/zoneadmd/log.c b/usr/src/cmd/zoneadmd/log.c index 47f25ced72..a4ecc3e1e8 100644 --- a/usr/src/cmd/zoneadmd/log.c +++ b/usr/src/cmd/zoneadmd/log.c @@ -960,6 +960,32 @@ logstream_open(const char *logname, const char *stream, logstream_flags_t flags) 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 @@ logstream_close(int ls, boolean_t abrupt) 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 @@ logstream_close(int ls, boolean_t abrupt) close_log(lfp, "close", abrupt); - (void) memset(lfp, 0, sizeof (*lfp)); - lfp->lf_fd = -1; + logfile_reset(lfp); logstream_unlock(); } |