The unified diff between revisions [718cfb3b..] and [1b553632..] is displayed below. It can also be downloaded as a raw diff.
This diff has been restricted to the following files: 'src/logfile.c'
#
#
# patch "src/logfile.c"
# from [1e8ab5420743ce8ca79d4d21da4c70876ff1dbe5]
# to [981127e2eedb39b4ddd6e23ba66e19e42e1bf526]
#
============================================================
--- src/logfile.c 1e8ab5420743ce8ca79d4d21da4c70876ff1dbe5
+++ src/logfile.c 981127e2eedb39b4ddd6e23ba66e19e42e1bf526
@@ -39,33 +39,38 @@ logfileOpen(const char *path, size_t buf
Logfile *
logfileOpen(const char *path, size_t bufsz, int fatal_flag)
{
- int fd;
- Logfile *lf;
- fd = file_open(path, O_WRONLY | O_CREAT | O_TEXT);
- if (DISK_ERROR == 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 {
- debug(50, 1) ("logfileOpen: %s: %s\n", path, xstrerror());
- return NULL;
+ Logfile *lf = xcalloc(1, sizeof(*lf));
+ xstrncpy(lf->path, path, MAXPATHLEN);
+ if (strcmp(path, "syslog") == 0) {
+ lf->flags.syslog = 1;
+ lf->syslog_priority = LOG_INFO;
+ lf->fd = -1;
+ } else {
+ int fd = file_open(path, O_WRONLY | O_CREAT | O_TEXT);
+ if (DISK_ERROR == 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 {
+ debug(50, 1) ("logfileOpen: %s: %s\n", path, xstrerror());
+ safe_free(lf);
+ return NULL;
+ }
}
+ lf->fd = fd;
+ if (bufsz > 0) {
+ lf->buf = xmalloc(bufsz);
+ lf->bufsz = bufsz;
+ }
}
- lf = xcalloc(1, sizeof(*lf));
- lf->fd = fd;
if (fatal_flag)
lf->flags.fatal = 1;
- xstrncpy(lf->path, path, MAXPATHLEN);
- if (bufsz > 0) {
- lf->buf = xmalloc(bufsz);
- lf->bufsz = bufsz;
- }
return lf;
}
@@ -73,7 +78,8 @@ logfileClose(Logfile * lf)
logfileClose(Logfile * lf)
{
logfileFlush(lf);
- file_close(lf->fd);
+ if (lf->fd >= 0)
+ file_close(lf->fd);
if (lf->buf)
xfree(lf->buf);
xfree(lf);
@@ -89,6 +95,8 @@ logfileRotate(Logfile * lf)
char from[MAXPATHLEN];
char to[MAXPATHLEN];
assert(lf->path);
+ if (lf->flags.syslog)
+ return;
#ifdef S_ISREG
if (stat(lf->path, &sb) == 0)
if (S_ISREG(sb.st_mode) == 0)
@@ -120,6 +128,10 @@ logfileWrite(Logfile * lf, void *buf, si
void
logfileWrite(Logfile * lf, void *buf, size_t len)
{
+ if (lf->flags.syslog) {
+ syslog(lf->syslog_priority, "%s", (char *)buf);
+ return;
+ }
if (0 == lf->bufsz) {
/* buffering disabled */
logfileWriteWrapper(lf, buf, len);