]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/log/ModDaemon.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / log / ModDaemon.cc
index 7f563d8fc62a758671c74dab861776bf263265a6..fe2907d140bc72222f45abfb82d075c00d85b6d4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
@@ -106,15 +106,16 @@ logfileHandleWrite(int, void *data)
     ll->flush_pending = 0;
 
     int ret = FD_WRITE_METHOD(ll->wfd, b->buf + b->written_len, b->len - b->written_len);
+    int xerrno = errno;
     debugs(50, 3, lf->path << ": write returned " << ret);
     if (ret < 0) {
-        if (ignoreErrno(errno)) {
+        if (ignoreErrno(xerrno)) {
             /* something temporary */
             Comm::SetSelect(ll->wfd, COMM_SELECT_WRITE, logfileHandleWrite, lf, 0);
             ll->flush_pending = 1;
             return;
         }
-        debugs(50, DBG_IMPORTANT,"logfileHandleWrite: " << lf->path << ": error writing (" << xstrerror() << ")");
+        debugs(50, DBG_IMPORTANT,"logfileHandleWrite: " << lf->path << ": error writing (" << xstrerr(xerrno) << ")");
         /* XXX should handle this better */
         fatal("I don't handle this error well!");
     }
@@ -269,7 +270,7 @@ logfile_mod_daemon_close(Logfile * lf)
 }
 
 static void
-logfile_mod_daemon_rotate(Logfile * lf)
+logfile_mod_daemon_rotate(Logfile * lf, const int16_t)
 {
     char tb[3];
     debugs(50, DBG_IMPORTANT, "logfileRotate: " << lf->path);
@@ -297,8 +298,14 @@ logfile_mod_daemon_writeline(Logfile * lf, const char *buf, size_t len)
         }
         return;
     }
-    /* Append this data to the end buffer; create a new one if needed */
+
     /* Are we eol? If so, prefix with our logfile command byte */
+    if (ll->eol == 1) {
+        logfile_mod_daemon_append(lf, "L", 1);
+        ll->eol = 0;
+    }
+
+    /* Append this data to the end buffer; create a new one if needed */
     logfile_mod_daemon_append(lf, buf, len);
 }
 
@@ -306,12 +313,8 @@ static void
 logfile_mod_daemon_linestart(Logfile * lf)
 {
     l_daemon_t *ll = static_cast<l_daemon_t *>(lf->data);
-    char tb[2];
     assert(ll->eol == 1);
-    ll->eol = 0;
-    tb[0] = 'L';
-    tb[1] = '\0';
-    logfile_mod_daemon_append(lf, tb, 1);
+    // logfile_mod_daemon_writeline() sends the starting command
 }
 
 static void
@@ -319,7 +322,8 @@ logfile_mod_daemon_lineend(Logfile * lf)
 {
     l_daemon_t *ll = static_cast<l_daemon_t *>(lf->data);
     logfile_buffer_t *b;
-    assert(ll->eol == 0);
+    if (ll->eol == 1) // logfile_mod_daemon_writeline() wrote nothing
+        return;
     ll->eol = 1;
     /* Kick a write off if the head buffer is -full- */
     if (ll->bufs.head != NULL) {