/*
- * DEBUG: section 50 Log file handling
- * AUTHOR: Adrian Chadd
- *
- * SQUID Web Proxy Cache http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- * Squid is the result of efforts by numerous individuals from
- * the Internet community; see the CONTRIBUTORS file for full
- * details. Many organizations have provided support for Squid's
- * development; see the SPONSORS file for full details. Squid is
- * Copyrighted (C) 2001 by the Regents of the University of
- * California; see the COPYRIGHT file for full details. Squid
- * incorporates software developed and/or copyrighted by other
- * sources; see the CREDITS file for full details.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ * 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.
+ * Please see the COPYING and CONTRIBUTORS files for details.
*/
+/* DEBUG: section 50 Log file handling */
+
#include "squid.h"
#include "comm.h"
#include "comm/Connection.h"
+#include "fatal.h"
+#include "fd.h"
+#include "fs_io.h"
#include "log/File.h"
#include "log/ModUdp.h"
#include "Parsing.h"
+#include "SquidConfig.h"
+
+#include <cerrno>
/*
* This logfile UDP module is mostly inspired by a patch by Tim Starling
fd_bytes(ll->fd, s, FD_WRITE);
#if 0
if (s < 0) {
- debugs(1, 1, "logfile (udp): got errno (" << errno << "):" << xstrerror());
+ int xerrno = errno;
+ debugs(1, DBG_IMPORTANT, "logfile (udp): got errno (" << errno << "):" << xstrerr(xerrno));
}
if (s != len) {
- debugs(1, 1, "logfile (udp): len=" << len << ", wrote=" << s);
+ debugs(1, DBG_IMPORTANT, "logfile (udp): len=" << len << ", wrote=" << s);
}
#endif
}
static void
-logfile_mod_udp_linestart(Logfile * lf)
+logfile_mod_udp_linestart(Logfile *)
{
}
static void
-logfile_mod_udp_lineend(Logfile * lf)
+logfile_mod_udp_lineend(Logfile *)
{
}
static void
-logfile_mod_udp_rotate(Logfile * lf)
+logfile_mod_udp_rotate(Logfile *, const int16_t)
{
- return;
}
static void
lf->data = NULL;
}
-
-
/*
* This code expects the path to be //host:port
*/
safe_free(strAddr);
Ip::Address any_addr;
- any_addr.SetAnyAddr();
+ any_addr.setAnyAddr();
// require the sending UDP port to be of the right family for the destination address.
- if (addr.IsIPv4())
- any_addr.SetIPv4();
+ if (addr.isIPv4())
+ any_addr.setIPv4();
ll->fd = comm_open(SOCK_DGRAM, IPPROTO_UDP, any_addr, COMM_NONBLOCKING, "UDP log socket");
+ int xerrno = errno;
if (ll->fd < 0) {
if (lf->flags.fatal) {
fatalf("Unable to open UDP socket for logging\n");
debugs(50, DBG_IMPORTANT, "Unable to open UDP socket for logging");
return FALSE;
}
- } else if (!comm_connect_addr(ll->fd, &addr)) {
+ } else if (!comm_connect_addr(ll->fd, addr)) {
+ xerrno = errno;
if (lf->flags.fatal) {
- fatalf("Unable to connect to %s for UDP log: %s\n", lf->path, xstrerror());
+ fatalf("Unable to connect to %s for UDP log: %s\n", lf->path, xstrerr(xerrno));
} else {
- debugs(50, DBG_IMPORTANT, "Unable to connect to " << lf->path << " for UDP log: " << xstrerror());
+ debugs(50, DBG_IMPORTANT, "Unable to connect to " << lf->path << " for UDP log: " << xstrerr(xerrno));
return FALSE;
}
}
if (ll->fd == -1) {
- if (ENOENT == errno && fatal_flag) {
+ if (ENOENT == xerrno && fatal_flag) {
fatalf("Cannot open '%s' because\n"
"\tthe parent directory does not exist.\n"
"\tPlease create the directory.\n", path);
- } else if (EACCES == errno && fatal_flag) {
+ } else if (EACCES == xerrno && fatal_flag) {
fatalf("Cannot open '%s' for writing.\n"
"\tThe parent directory must be writeable by the\n"
"\tuser '%s', which is the cache_effective_user\n"
"\tset in squid.conf.", path, Config.effectiveUser);
} else {
- debugs(50, DBG_IMPORTANT, "logfileOpen (UDP): " << lf->path << ": " << xstrerror());
+ debugs(50, DBG_IMPORTANT, "logfileOpen (UDP): " << lf->path << ": " << xstrerr(xerrno));
return 0;
}
}
* applications like netcat have a small default receive buffer and will
* truncate!
*/
- bufsz = 1400;
+ if (bufsz > 1400)
+ bufsz = 1400;
if (bufsz > 0) {
ll->buf = static_cast<char*>(xmalloc(bufsz));
ll->bufsz = bufsz;
return 1;
}
+