1 /* @(#) $Id: ./src/monitord/compress_log.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2009 Trend Micro Inc.
7 * This program is a free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General Public
9 * License (version 2) as published by the FSF - Free Software
15 #include "os_zlib/os_zlib.h"
18 /* gzips a log file */
19 void OS_CompressLog(char *logfile)
24 char logfileGZ[OS_FLSIZE + 1];
27 char buf[OS_MAXSTR + 1];
31 if(mond.compress == 0)
35 /* Clearing the memory */
36 memset(logfileGZ,'\0',OS_FLSIZE +1);
37 memset(buf, '\0', OS_MAXSTR + 1);
40 /* Setting the umask */
44 /* Creating the gzip file name */
45 snprintf(logfileGZ, OS_FLSIZE, "%s.gz", logfile);
48 /* Reading log file */
49 log = fopen(logfile, "r");
52 /* Do not warn in here, since the alert file may not exist. */
56 /* Opening compressed file */
57 zlog = gzopen(logfileGZ, "w");
61 merror(FOPEN_ERROR, ARGV0, logfileGZ);
67 len = fread(buf, 1, OS_MAXSTR, log);
70 if(gzwrite(zlog, buf, (unsigned)len) != len)
71 merror("%s: Compression error: %s", ARGV0, gzerror(zlog, &err));
78 /* Removing uncompressed file */