From: Amos Jeffries Date: Mon, 2 Feb 2015 13:10:38 +0000 (-0800) Subject: Cleaup: migrate Logfile to CBDATA_CLASS API X-Git-Tag: merge-candidate-3-v1~303 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f4aecafd6d9f14dc80569324d2726da07b6b5fb;p=thirdparty%2Fsquid.git Cleaup: migrate Logfile to CBDATA_CLASS API --- diff --git a/src/log/File.cc b/src/log/File.cc index c80d2d62cd..c18a3f1e2a 100644 --- a/src/log/File.cc +++ b/src/log/File.cc @@ -18,7 +18,21 @@ #include "log/ModUdp.h" #include "log/TcpLogger.h" -CBDATA_TYPE(Logfile); +CBDATA_CLASS_INIT(Logfile); + +Logfile::Logfile(const char *aPath) : + sequence_number(0), + data(NULL), + f_linestart(NULL), + f_linewrite(NULL), + f_lineend(NULL), + f_flush(NULL), + f_rotate(NULL), + f_close(NULL) +{ + xstrncpy(path, aPath, sizeof(path)); + flags.fatal = 0; +} Logfile * logfileOpen(const char *path, size_t bufsz, int fatal_flag) @@ -27,10 +41,8 @@ logfileOpen(const char *path, size_t bufsz, int fatal_flag) const char *patharg; debugs(50, DBG_IMPORTANT, "Logfile: opening log " << path); - CBDATA_INIT_TYPE(Logfile); - Logfile *lf = cbdataAlloc(Logfile); - xstrncpy(lf->path, path, MAXPATHLEN); + Logfile *lf = new Logfile(path); patharg = path; /* need to call the per-logfile-type code */ if (strncmp(path, "stdio:", 6) == 0) { @@ -61,7 +73,7 @@ logfileOpen(const char *path, size_t bufsz, int fatal_flag) else debugs(50, DBG_IMPORTANT, "logfileOpen: " << path << ": couldn't open!"); lf->f_close(lf); - cbdataFree(lf); + delete lf; return NULL; } assert(lf->data != NULL); @@ -80,7 +92,7 @@ logfileClose(Logfile * lf) debugs(50, DBG_IMPORTANT, "Logfile: closing log " << lf->path); lf->f_flush(lf); lf->f_close(lf); - cbdataFree(lf); + delete lf; } void diff --git a/src/log/File.h b/src/log/File.h index fd9f646c9e..dbeea19461 100644 --- a/src/log/File.h +++ b/src/log/File.h @@ -9,6 +9,7 @@ #ifndef SQUID_SRC_LOG_FILE_H #define SQUID_SRC_LOG_FILE_H +#include "cbdata.h" #include "dlink.h" #if HAVE_SYS_PARAM_H @@ -36,8 +37,12 @@ typedef void LOGCLOSE(Logfile *); class Logfile { + CBDATA_CLASS(Logfile); public: + explicit Logfile(const char *aPath); + ~Logfile() {} + char path[MAXPATHLEN]; struct {