assert(path);
#ifdef S_ISREG
if (stat(path, &sb) == 0)
- if (S_ISREG(sb.st_mode) == 0)
- return;
+ if (S_ISREG(sb.st_mode) == 0)
+ return;
#endif
/* Rotate numbers 0 through N up one */
for (i = rotate_count; i > 1;) {
- i--;
- snprintf(from, MAXPATHLEN, "%s.%d", path, i - 1);
- snprintf(to, MAXPATHLEN, "%s.%d", path, i);
+ i--;
+ snprintf(from, MAXPATHLEN, "%s.%d", path, i - 1);
+ snprintf(to, MAXPATHLEN, "%s.%d", path, i);
#if defined(_SQUID_OS2_) || defined(_SQUID_WIN32_)
- remove(to);
+ remove(to);
#endif
- rename(from, to);
+ rename(from, to);
}
if (rotate_count > 0) {
- snprintf(to, MAXPATHLEN, "%s.%d", path, 0);
+ snprintf(to, MAXPATHLEN, "%s.%d", path, 0);
#if defined(_SQUID_OS2_) || defined(_SQUID_WIN32_)
- remove(to);
+ remove(to);
#endif
- rename(path, to);
+ rename(path, to);
}
}
int do_buffer = 1;
if (argc < 2) {
- printf("Error: usage: %s <logfile>\n", argv[0]);
- exit(1);
+ printf("Error: usage: %s <logfile>\n", argv[0]);
+ exit(1);
}
fp = fopen(argv[1], "a");
if (fp == NULL) {
- perror("fopen");
- exit(1);
+ perror("fopen");
+ exit(1);
}
setbuf(stdout, NULL);
close(2);
dup2(t, 2);
while (fgets(buf, LOGFILE_BUF_LEN, stdin)) {
- /* First byte indicates what we're logging! */
- switch (buf[0]) {
- case 'L':
- if (buf[1] != '\0') {
- fprintf(fp, "%s", buf + 1);
- }
- if (!do_buffer)
- fflush(fp);
- break;
- case 'R':
- fclose(fp);
- rotate(argv[1], rotate_count);
- fp = fopen(argv[1], "a");
- if (fp == NULL) {
- perror("fopen");
- exit(1);
- }
- break;
- case 'T':
- break;
- case 'O':
- break;
- case 'r':
- //fprintf(fp, "SET ROTATE: %s\n", buf + 1);
- rotate_count = atoi(buf + 1);
- break;
- case 'b':
- //fprintf(fp, "SET BUFFERED: %s\n", buf + 1);
- do_buffer = (buf[1] == '1');
- break;
- case 'F':
- fflush(fp);
- break;
- default:
- /* Just in case .. */
- fprintf(fp, "%s", buf);
- break;
- }
+ /* First byte indicates what we're logging! */
+ switch (buf[0]) {
+ case 'L':
+ if (buf[1] != '\0') {
+ fprintf(fp, "%s", buf + 1);
+ }
+ if (!do_buffer)
+ fflush(fp);
+ break;
+ case 'R':
+ fclose(fp);
+ rotate(argv[1], rotate_count);
+ fp = fopen(argv[1], "a");
+ if (fp == NULL) {
+ perror("fopen");
+ exit(1);
+ }
+ break;
+ case 'T':
+ break;
+ case 'O':
+ break;
+ case 'r':
+ //fprintf(fp, "SET ROTATE: %s\n", buf + 1);
+ rotate_count = atoi(buf + 1);
+ break;
+ case 'b':
+ //fprintf(fp, "SET BUFFERED: %s\n", buf + 1);
+ do_buffer = (buf[1] == '1');
+ break;
+ case 'F':
+ fflush(fp);
+ break;
+ default:
+ /* Just in case .. */
+ fprintf(fp, "%s", buf);
+ break;
+ }
}
fclose(fp);
fp = NULL;
s->s = ipa;
*head = s;
- }
- else
+ } else
self_destruct();
}
}
#ifndef SQUID_SRC_LOG_CONFIG_H
#define SQUID_SRC_LOG_CONFIG_H
-namespace Log {
+namespace Log
+{
class LogConfig
{
patharg = path;
/* need to call the per-logfile-type code */
if (strncmp(path, "stdio:", 6) == 0) {
- patharg = path + 6;
- ret = logfile_mod_stdio_open(lf, patharg, bufsz, fatal_flag);
+ patharg = path + 6;
+ ret = logfile_mod_stdio_open(lf, patharg, bufsz, fatal_flag);
} else if (strncmp(path, "daemon:", 7) == 0) {
- patharg = path + 7;
- ret = logfile_mod_daemon_open(lf, patharg, bufsz, fatal_flag);
+ patharg = path + 7;
+ ret = logfile_mod_daemon_open(lf, patharg, bufsz, fatal_flag);
} else if (strncmp(path, "udp:", 4) == 0) {
- patharg = path + 4;
- ret = logfile_mod_udp_open(lf, patharg, bufsz, fatal_flag);
+ patharg = path + 4;
+ ret = logfile_mod_udp_open(lf, patharg, bufsz, fatal_flag);
#if HAVE_SYSLOG
} else if (strncmp(path, "syslog:", 7) == 0) {
- patharg = path + 7;
- ret = logfile_mod_syslog_open(lf, patharg, bufsz, fatal_flag);
+ patharg = path + 7;
+ ret = logfile_mod_syslog_open(lf, patharg, bufsz, fatal_flag);
#endif
} else {
- ret = logfile_mod_stdio_open(lf, patharg, bufsz, fatal_flag);
+ ret = logfile_mod_stdio_open(lf, patharg, bufsz, fatal_flag);
}
if (!ret) {
- if (fatal_flag)
- fatalf("logfileOpen: path %s: couldn't open!\n", path);
- else
- debugs(50, 1, "logfileOpen: path " << path << ": couldn't open!");
- lf->f_close(lf);
- cbdataFree(lf);
- return NULL;
+ if (fatal_flag)
+ fatalf("logfileOpen: path %s: couldn't open!\n", path);
+ else
+ debugs(50, 1, "logfileOpen: path " << path << ": couldn't open!");
+ lf->f_close(lf);
+ cbdataFree(lf);
+ return NULL;
}
assert(lf->data != NULL);
#include "config.h"
#include "dlink.h"
-class logfile_buffer_t {
+class logfile_buffer_t
+{
public:
char *buf;
int size;
typedef void LOGROTATE(Logfile *);
typedef void LOGCLOSE(Logfile *);
-class Logfile {
+class Logfile
+{
public:
char path[SQUID_MAXPATHLEN];
* 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.
#define LOGFILE_MAXBUFS 128
/* Size of the logfile buffer */
-/*
+/*
* For optimal performance this should match LOGFILE_BUFSIZ in logfile-daemon.c
*/
#define LOGFILE_BUFSZ 32768
ret = FD_WRITE_METHOD(ll->wfd, b->buf + b->written_len, b->len - b->written_len);
debugs(50, 3, "logfileHandleWrite: " << lf->path << ": write returned " << ret);
if (ret < 0) {
- if (ignoreErrno(errno)) {
- /* something temporary */
- goto reschedule;
- }
- debugs(50, DBG_IMPORTANT,"logfileHandleWrite: " << lf->path << ": error writing (" << xstrerror() << ")");
- /* XXX should handle this better */
- fatal("I don't handle this error well!");
+ if (ignoreErrno(errno)) {
+ /* something temporary */
+ goto reschedule;
+ }
+ debugs(50, DBG_IMPORTANT,"logfileHandleWrite: " << lf->path << ": error writing (" << xstrerror() << ")");
+ /* XXX should handle this better */
+ fatal("I don't handle this error well!");
}
if (ret == 0) {
- /* error? */
- debugs(50, DBG_IMPORTANT, "logfileHandleWrite: " << lf->path << ": wrote 0 bytes?");
- /* XXX should handle this better */
- fatal("I don't handle this error well!");
+ /* error? */
+ debugs(50, DBG_IMPORTANT, "logfileHandleWrite: " << lf->path << ": wrote 0 bytes?");
+ /* XXX should handle this better */
+ fatal("I don't handle this error well!");
}
/* ret > 0, so something was written */
b->written_len += ret;
assert(b->written_len <= b->len);
if (b->written_len == b->len) {
- /* written the whole buffer! */
- logfileFreeBuffer(lf, b);
- b = NULL;
+ /* written the whole buffer! */
+ logfileFreeBuffer(lf, b);
+ b = NULL;
}
/* Is there more to write? */
if (ll->bufs.head == NULL) {
- goto finish;
+ goto finish;
}
/* there is, so schedule more */
- reschedule:
+reschedule:
commSetSelect(ll->wfd, COMM_SELECT_WRITE, logfileHandleWrite, lf, 0);
ll->flush_pending = 1;
- finish:
+finish:
return;
}
{
l_daemon_t *ll = (l_daemon_t *) lf->data;
if (ll->flush_pending || ll->bufs.head == NULL) {
- return;
+ return;
}
ll->flush_pending = 1;
if (ll->bufs.head) {
- logfile_buffer_t *b = static_cast<logfile_buffer_t*>(ll->bufs.head->data);
- if (b->len + 2 <= b->size)
- logfile_mod_daemon_append(lf, "F\n", 2);
+ logfile_buffer_t *b = static_cast<logfile_buffer_t*>(ll->bufs.head->data);
+ if (b->len + 2 <= b->size)
+ logfile_mod_daemon_append(lf, "F\n", 2);
}
/* Ok, schedule a write-event */
commSetSelect(ll->wfd, COMM_SELECT_WRITE, logfileHandleWrite, lf, 0);
/* Is there a buffer? If not, create one */
if (ll->bufs.head == NULL) {
- logfileNewBuffer(lf);
+ logfileNewBuffer(lf);
}
debugs(50, 3, "logfile_mod_daemon_append: " << lf->path << ": appending " << len << " bytes");
/* Copy what can be copied */
while (len > 0) {
- b = static_cast<logfile_buffer_t*>(ll->bufs.tail->data);
- debugs(50, 3, "logfile_mod_daemon_append: current buffer has " << b->len << " of " << b->size << " bytes before append");
- s = min(len, (b->size - b->len));
- xmemcpy(b->buf + b->len, buf, s);
- len = len - s;
- buf = buf + s;
- b->len = b->len + s;
- assert(b->len <= LOGFILE_BUFSZ);
- assert(len >= 0);
- if (len > 0) {
- logfileNewBuffer(lf);
- }
+ b = static_cast<logfile_buffer_t*>(ll->bufs.tail->data);
+ debugs(50, 3, "logfile_mod_daemon_append: current buffer has " << b->len << " of " << b->size << " bytes before append");
+ s = min(len, (b->size - b->len));
+ xmemcpy(b->buf + b->len, buf, s);
+ len = len - s;
+ buf = buf + s;
+ b->len = b->len + s;
+ assert(b->len <= LOGFILE_BUFSZ);
+ assert(len >= 0);
+ if (len > 0) {
+ logfileNewBuffer(lf);
+ }
}
}
ll->eol = 1;
{
IpAddress localhost;
- args[0] = "(logfile-daemon)";
- args[1] = path;
- args[2] = NULL;
+ args[0] = "(logfile-daemon)";
+ args[1] = path;
+ args[2] = NULL;
localhost.SetLocalhost();
- ll->pid = ipcCreate(IPC_STREAM, Log::TheConfig.logfile_daemon, args, "logfile-daemon", localhost, &ll->rfd, &ll->wfd, NULL);
- if (ll->pid < 0)
- fatal("Couldn't start logfile helper");
+ ll->pid = ipcCreate(IPC_STREAM, Log::TheConfig.logfile_daemon, args, "logfile-daemon", localhost, &ll->rfd, &ll->wfd, NULL);
+ if (ll->pid < 0)
+ fatal("Couldn't start logfile helper");
}
ll->nbufs = 0;
debugs(50, 1, "Logfile Daemon: closing log " << lf->path);
logfileFlush(lf);
if (ll->rfd == ll->wfd)
- comm_close(ll->rfd);
+ comm_close(ll->rfd);
else {
comm_close(ll->rfd);
comm_close(ll->wfd);
l_daemon_t *ll = static_cast<l_daemon_t *>(lf->data);
/* Make sure the logfile buffer isn't too large */
if (ll->nbufs > LOGFILE_MAXBUFS) {
- if (ll->last_warned < squid_curtime - LOGFILE_WARN_TIME) {
- ll->last_warned = squid_curtime;
- debugs(50, DBG_IMPORTANT, "Logfile: " << lf->path << ": queue is too large; some log messages have been lost.");
- }
- return;
+ if (ll->last_warned < squid_curtime - LOGFILE_WARN_TIME) {
+ ll->last_warned = squid_curtime;
+ debugs(50, DBG_IMPORTANT, "Logfile: " << lf->path << ": queue is too large; some log messages have been lost.");
+ }
+ 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 */
ll->eol = 1;
/* Kick a write off if the head buffer is -full- */
if (ll->bufs.head != NULL) {
- b = static_cast<logfile_buffer_t*>(ll->bufs.head->data);
- if (b->node.next != NULL || !Config.onoff.buffered_logs)
- logfileQueueWrite(lf);
+ b = static_cast<logfile_buffer_t*>(ll->bufs.head->data);
+ if (b->node.next != NULL || !Config.onoff.buffered_logs)
+ logfileQueueWrite(lf);
}
}
{
l_daemon_t *ll = static_cast<l_daemon_t *>(lf->data);
if (commUnsetNonBlocking(ll->wfd)) {
- debugs(50, DBG_IMPORTANT, "Logfile Daemon: Couldn't set the pipe blocking for flush! You're now missing some log entries.");
- return;
+ debugs(50, DBG_IMPORTANT, "Logfile Daemon: Couldn't set the pipe blocking for flush! You're now missing some log entries.");
+ return;
}
while (ll->bufs.head != NULL) {
- logfileHandleWrite(ll->wfd, lf);
+ logfileHandleWrite(ll->wfd, lf);
}
if (commSetNonBlocking(ll->wfd)) {
- fatalf("Logfile Daemon: %s: Couldn't set the pipe non-blocking for flush!\n", lf->path);
- return;
+ fatalf("Logfile Daemon: %s: Couldn't set the pipe non-blocking for flush!\n", lf->path);
+ return;
}
}
* 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.
* 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.
fd_bytes(ll->fd, s, FD_WRITE);
if (s == len)
- return;
+ return;
if (!lf->flags.fatal)
- return;
+ return;
fatalf("logfileWrite (stdio): %s: %s\n", lf->path, xstrerror());
}
l_stdio_t *ll = (l_stdio_t *) lf->data;
if (0 == ll->bufsz) {
- /* buffering disabled */
- logfileWriteWrapper(lf, buf, len);
- return;
+ /* buffering disabled */
+ logfileWriteWrapper(lf, buf, len);
+ return;
}
if (ll->offset > 0 && (ll->offset + len) > ll->bufsz)
- logfileFlush(lf);
+ logfileFlush(lf);
if (len > ll->bufsz) {
- /* too big to fit in buffer */
- logfileWriteWrapper(lf, buf, len);
- return;
+ /* too big to fit in buffer */
+ logfileWriteWrapper(lf, buf, len);
+ return;
}
/* buffer it */
xmemcpy(ll->buf + ll->offset, buf, len);
{
l_stdio_t *ll = (l_stdio_t *) lf->data;
if (0 == ll->offset)
- return;
+ return;
logfileWriteWrapper(lf, ll->buf, (size_t) ll->offset);
ll->offset = 0;
}
#ifdef S_ISREG
if (stat(lf->path, &sb) == 0)
- if (S_ISREG(sb.st_mode) == 0)
- return;
+ if (S_ISREG(sb.st_mode) == 0)
+ return;
#endif
/* Rotate numbers 0 through N up one */
for (i = Config.Log.rotateNumber; i > 1;) {
- i--;
- snprintf(from, MAXPATHLEN, "%s.%d", lf->path, i - 1);
- snprintf(to, MAXPATHLEN, "%s.%d", lf->path, i);
- xrename(from, to);
+ i--;
+ snprintf(from, MAXPATHLEN, "%s.%d", lf->path, i - 1);
+ snprintf(to, MAXPATHLEN, "%s.%d", lf->path, i);
+ xrename(from, to);
}
/* Rotate the current log to .0 */
file_close(ll->fd); /* always close */
if (Config.Log.rotateNumber > 0) {
- snprintf(to, MAXPATHLEN, "%s.%d", lf->path, 0);
- xrename(lf->path, to);
+ snprintf(to, MAXPATHLEN, "%s.%d", lf->path, 0);
+ xrename(lf->path, to);
}
/* Reopen the log. It may have been renamed "manually" */
ll->fd = file_open(lf->path, O_WRONLY | O_CREAT | O_TEXT);
if (DISK_ERROR == ll->fd && lf->flags.fatal) {
- debugs(50, DBG_CRITICAL, "logfileRotate (stdio): " << lf->path << ": " << xstrerror());
- fatalf("Cannot open %s: %s", lf->path, xstrerror());
+ debugs(50, DBG_CRITICAL, "logfileRotate (stdio): " << lf->path << ": " << xstrerror());
+ fatalf("Cannot open %s: %s", lf->path, xstrerror());
}
}
lf->f_flush(lf);
if (ll->fd >= 0)
- file_close(ll->fd);
+ file_close(ll->fd);
if (ll->buf)
- xfree(ll->buf);
+ xfree(ll->buf);
xfree(lf->data);
lf->data = NULL;
ll->fd = file_open(path, O_WRONLY | O_CREAT | O_TEXT);
if (DISK_ERROR == ll->fd) {
- if (ENOENT == errno && 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) {
- 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 (stdio): " << path << ": " << xstrerror());
- return 0;
- }
+ if (ENOENT == errno && 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) {
+ 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 (stdio): " << path << ": " << xstrerror());
+ return 0;
+ }
}
if (bufsz > 0) {
- ll->buf = static_cast<char*>(xmalloc(bufsz));
- ll->bufsz = bufsz;
+ ll->buf = static_cast<char*>(xmalloc(bufsz));
+ ll->bufsz = bufsz;
}
return 1;
}
* 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.
* 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.
syslog_ntoa(const char *s)
{
#define syslog_symbol(a) #a, a
- static syslog_symbol_t symbols[] =
- {
+ static syslog_symbol_t symbols[] = {
#ifdef LOG_AUTHPRIV
- {syslog_symbol(LOG_AUTHPRIV)},
+ {syslog_symbol(LOG_AUTHPRIV)},
#endif
#ifdef LOG_DAEMON
- {syslog_symbol(LOG_DAEMON)},
+ {syslog_symbol(LOG_DAEMON)},
#endif
#ifdef LOG_LOCAL0
- {syslog_symbol(LOG_LOCAL0)},
+ {syslog_symbol(LOG_LOCAL0)},
#endif
#ifdef LOG_LOCAL1
- {syslog_symbol(LOG_LOCAL1)},
+ {syslog_symbol(LOG_LOCAL1)},
#endif
#ifdef LOG_LOCAL2
- {syslog_symbol(LOG_LOCAL2)},
+ {syslog_symbol(LOG_LOCAL2)},
#endif
#ifdef LOG_LOCAL3
- {syslog_symbol(LOG_LOCAL3)},
+ {syslog_symbol(LOG_LOCAL3)},
#endif
#ifdef LOG_LOCAL4
- {syslog_symbol(LOG_LOCAL4)},
+ {syslog_symbol(LOG_LOCAL4)},
#endif
#ifdef LOG_LOCAL5
- {syslog_symbol(LOG_LOCAL5)},
+ {syslog_symbol(LOG_LOCAL5)},
#endif
#ifdef LOG_LOCAL6
- {syslog_symbol(LOG_LOCAL6)},
+ {syslog_symbol(LOG_LOCAL6)},
#endif
#ifdef LOG_LOCAL7
- {syslog_symbol(LOG_LOCAL7)},
+ {syslog_symbol(LOG_LOCAL7)},
#endif
#ifdef LOG_USER
- {syslog_symbol(LOG_USER)},
+ {syslog_symbol(LOG_USER)},
#endif
#ifdef LOG_ERR
- {syslog_symbol(LOG_ERR)},
+ {syslog_symbol(LOG_ERR)},
#endif
#ifdef LOG_WARNING
- {syslog_symbol(LOG_WARNING)},
+ {syslog_symbol(LOG_WARNING)},
#endif
#ifdef LOG_NOTICE
- {syslog_symbol(LOG_NOTICE)},
+ {syslog_symbol(LOG_NOTICE)},
#endif
#ifdef LOG_INFO
- {syslog_symbol(LOG_INFO)},
+ {syslog_symbol(LOG_INFO)},
#endif
#ifdef LOG_DEBUG
- {syslog_symbol(LOG_DEBUG)},
+ {syslog_symbol(LOG_DEBUG)},
#endif
- {NULL, 0}
+ {NULL, 0}
};
syslog_symbol_t *p;
for (p = symbols; p->name != NULL; ++p)
- if (!strcmp(s, p->name) || !strcasecmp(s, p->name + 4))
- return p->value;
+ if (!strcmp(s, p->name) || !strcasecmp(s, p->name + 4))
+ return p->value;
debugs(1, 1, "Unknown syslog facility/priority '" << s << "'");
return 0;
ll->syslog_priority |= syslog_ntoa(priority);
xfree(priority);
if ((ll->syslog_priority & PRIORITY_MASK) == 0)
- ll->syslog_priority |= LOG_INFO;
+ ll->syslog_priority |= LOG_INFO;
}
return 1;
* 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.
* 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.
fd_bytes(ll->fd, s, FD_WRITE);
#if 0
if (s < 0) {
- debugs(1, 1, "logfile (udp): got errno (" << errno << "):" << xstrerror());
+ debugs(1, 1, "logfile (udp): got errno (" << errno << "):" << xstrerror());
}
if (s != len) {
- debugs(1, 1, "logfile (udp): len=" << len << ", wrote=" << s);
+ debugs(1, 1, "logfile (udp): len=" << len << ", wrote=" << s);
}
#endif
{
l_udp_t *ll = (l_udp_t *) lf->data;
if (0 == ll->offset)
- return;
+ return;
logfile_mod_udp_write(lf, ll->buf, (size_t) ll->offset);
ll->offset = 0;
}
l_udp_t *ll = (l_udp_t *) lf->data;
if (0 == ll->bufsz) {
- /* buffering disabled */
- logfile_mod_udp_write(lf, buf, len);
- return;
+ /* buffering disabled */
+ logfile_mod_udp_write(lf, buf, len);
+ return;
}
if (ll->offset > 0 && (ll->offset + len + 4) > ll->bufsz)
- logfile_mod_udp_flush(lf);
+ logfile_mod_udp_flush(lf);
if (len > ll->bufsz) {
- /* too big to fit in buffer */
- logfile_mod_udp_write(lf, buf, len);
- return;
+ /* too big to fit in buffer */
+ logfile_mod_udp_write(lf, buf, len);
+ return;
}
/* buffer it */
xmemcpy(ll->buf + ll->offset, buf, len);
lf->f_flush(lf);
if (ll->fd >= 0)
- file_close(ll->fd);
+ file_close(ll->fd);
if (ll->buf)
- xfree(ll->buf);
+ xfree(ll->buf);
xfree(lf->data);
lf->data = NULL;
lf->data = ll;
if (strncmp(path, "//", 2) == 0) {
- path += 2;
+ path += 2;
}
strAddr = xstrdup(path);
if (!GetHostWithPort(strAddr, &addr)) {
- if (lf->flags.fatal) {
- fatalf("Invalid UDP logging address '%s'\n", lf->path);
- } else {
- debugs(50, DBG_IMPORTANT, "Invalid UDP logging address '" << lf->path << "'");
- safe_free(strAddr);
- return FALSE;
- }
+ if (lf->flags.fatal) {
+ fatalf("Invalid UDP logging address '%s'\n", lf->path);
+ } else {
+ debugs(50, DBG_IMPORTANT, "Invalid UDP logging address '" << lf->path << "'");
+ safe_free(strAddr);
+ return FALSE;
+ }
}
safe_free(strAddr);
ll->fd = comm_open(SOCK_DGRAM, IPPROTO_UDP, no_addr, COMM_NONBLOCKING, "UDP log socket");
if (ll->fd < 0) {
- if (lf->flags.fatal) {
- fatalf("Unable to open UDP socket for logging\n");
- } else {
- debugs(50, DBG_IMPORTANT, "Unable to open UDP socket for logging");
- return FALSE;
- }
- }
- else if (comm_connect_addr(ll->fd, &addr)) {
- if (lf->flags.fatal) {
- fatalf("Unable to connect to %s for UDP log: %s\n", lf->path, xstrerror());
- } else {
- debugs(50, DBG_IMPORTANT, "Unable to connect to " << lf->path << " for UDP log: " << xstrerror());
- return FALSE;
- }
+ if (lf->flags.fatal) {
+ fatalf("Unable to open UDP socket for logging\n");
+ } else {
+ debugs(50, DBG_IMPORTANT, "Unable to open UDP socket for logging");
+ return FALSE;
+ }
+ } else if (comm_connect_addr(ll->fd, &addr)) {
+ if (lf->flags.fatal) {
+ fatalf("Unable to connect to %s for UDP log: %s\n", lf->path, xstrerror());
+ } else {
+ debugs(50, DBG_IMPORTANT, "Unable to connect to " << lf->path << " for UDP log: " << xstrerror());
+ return FALSE;
+ }
}
if (ll->fd == -1) {
- if (ENOENT == errno && 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) {
- 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());
- return 0;
- }
+ if (ENOENT == errno && 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) {
+ 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());
+ return 0;
+ }
}
/* Force buffer size to something roughly fitting inside an MTU */
/*
*/
bufsz = 1400;
if (bufsz > 0) {
- ll->buf = static_cast<char*>(xmalloc(bufsz));
- ll->bufsz = bufsz;
+ ll->buf = static_cast<char*>(xmalloc(bufsz));
+ ll->bufsz = bufsz;
}
return 1;
* 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.