diff options
author | Gaurav Kumar Garg <garg.gaurav52@gmail.com> | 2015-12-01 14:23:08 +0530 |
---|---|---|
committer | Niels de Vos <ndevos@redhat.com> | 2016-02-19 02:02:01 -0800 |
commit | 6b308c41dc4eddbe8b2afece14ac6ab827bc54d3 (patch) | |
tree | d6f35445d9d7299ab721dd91c9f545fbc2adfe25 /libglusterfs | |
parent | 2cbbff904fee3ecb315f2c3229380dff3d483fde (diff) |
libglusterfs: close & open cmd_history.log on log rotate
This patch is backport of: http://review.gluster.org/#/c/12832/
Post log rotate, cmd_history.log is not refreshed (closed & opened back)
due to which new commands still land up in the log rotated file.
Fix is to close and open cmd_history.log file upon log rotation
>> Change-Id: Ie6990c9d55b0afa544bc5c84de3db49ff4b1299b
>> BUG: 1286959
>> Signed-off-by: Gaurav Kumar Garg <ggarg@redhat.com>
>> Reviewed-on: http://review.gluster.org/12832
>> Smoke: Gluster Build System <jenkins@build.gluster.com>
>> CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
>> Reviewed-by: Niels de Vos <ndevos@redhat.com>
>> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
(cherry picked from commit 8fdfa0c17cf492f39e675f7502596754f6e5aeb4)
Change-Id: Ie6990c9d55b0afa544bc5c84de3db49ff4b1299b
BUG: 1304963
Signed-off-by: Gaurav Kumar Garg <ggarg@redhat.com>
Reviewed-on: http://review.gluster.org/13361
Smoke: Gluster Build System <jenkins@build.gluster.com>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Niels de Vos <ndevos@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r-- | libglusterfs/src/logging.c | 37 | ||||
-rw-r--r-- | libglusterfs/src/logging.h | 1 |
2 files changed, 36 insertions, 2 deletions
diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c index 511b1037384..0d448032c6e 100644 --- a/libglusterfs/src/logging.c +++ b/libglusterfs/src/logging.c @@ -90,8 +90,10 @@ gf_log_logrotate (int signum) ctx = THIS->ctx; - if (ctx) + if (ctx) { ctx->log.logrotate = 1; + ctx->log.cmd_history_logrotate = 1; + } } void @@ -2382,6 +2384,7 @@ gf_cmd_log (const char *domain, const char *fmt, ...) char *msg = NULL; size_t len = 0; int ret = 0; + int fd = -1; glusterfs_ctx_t *ctx = NULL; ctx = THIS->ctx; @@ -2430,6 +2433,36 @@ gf_cmd_log (const char *domain, const char *fmt, ...) strcpy (msg, str1); strcpy (msg + len, str2); + /* close and reopen cmdlogfile fd for in case of log rotate*/ + if (ctx->log.cmd_history_logrotate) { + ctx->log.cmd_history_logrotate = 0; + + if (ctx->log.cmdlogfile) { + fclose (ctx->log.cmdlogfile); + ctx->log.cmdlogfile = NULL; + } + + fd = open (ctx->log.cmd_log_filename, + O_CREAT | O_RDONLY, S_IRUSR | S_IWUSR); + if (fd < 0) { + gf_msg (THIS->name, GF_LOG_CRITICAL, errno, + LG_MSG_FILE_OP_FAILED, "failed to open " + "logfile \"%s\" \n", ctx->log.cmd_log_filename); + ret = -1; + goto out; + } + + ctx->log.cmdlogfile = fdopen (fd, "a"); + if (!ctx->log.cmdlogfile) { + gf_msg (THIS->name, GF_LOG_CRITICAL, errno, + LG_MSG_FILE_OP_FAILED, + "failed to open logfile \"%s\"" + " \n", ctx->log.cmd_log_filename); + ret = -1; + goto out; + } + } + fprintf (ctx->log.cmdlogfile, "%s\n", msg); fflush (ctx->log.cmdlogfile); @@ -2440,5 +2473,5 @@ out: FREE (str2); - return (0); + return ret; } diff --git a/libglusterfs/src/logging.h b/libglusterfs/src/logging.h index f19fe9e1002..4ad52d88e27 100644 --- a/libglusterfs/src/logging.h +++ b/libglusterfs/src/logging.h @@ -100,6 +100,7 @@ typedef enum { typedef struct gf_log_handle_ { pthread_mutex_t logfile_mutex; uint8_t logrotate; + uint8_t cmd_history_logrotate; gf_loglevel_t loglevel; int gf_log_syslog; gf_loglevel_t sys_log_level; |