1/* 2 * Copyright (c) 1983, 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 18 unchanged lines hidden (view full) --- 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#if defined(LIBC_SCCS) && !defined(lint) |
35static char sccsid[] = "@(#)syslog.c 8.5 (Berkeley) 4/29/95"; |
36#endif /* LIBC_SCCS and not lint */ |
37#include <sys/cdefs.h> 38__FBSDID("$FreeBSD: head/lib/libc/gen/syslog.c 90045 2002-02-01 01:32:19Z obrien $"); |
39 40#include "namespace.h" 41#include <sys/types.h> 42#include <sys/socket.h> 43#include <sys/syslog.h> 44#include <sys/uio.h> 45#include <sys/un.h> 46#include <netdb.h> --- 17 unchanged lines hidden (view full) --- 64static int connected; /* have done connect */ 65static int opened; /* have done openlog() */ 66static int LogStat = 0; /* status bits, set by openlog() */ 67static const char *LogTag = NULL; /* string to tag the entry with */ 68static int LogFacility = LOG_USER; /* default facility code */ 69static int LogMask = 0xff; /* mask of priorities to be logged */ 70extern char *__progname; /* Program name, from crt0. */ 71 |
72static void disconnectlog(void); /* disconnect from syslogd */ 73static void connectlog(void); /* (re)connect to syslogd */ |
74 75/* 76 * Format of the magic cookie passed through the stdio hook 77 */ 78struct bufcookie { 79 char *base; /* start of buffer */ 80 int left; 81}; --- 47 unchanged lines hidden (view full) --- 129#endif 130 vsyslog(pri, fmt, ap); 131 va_end(ap); 132} 133 134void 135vsyslog(pri, fmt, ap) 136 int pri; |
137 const char *fmt; |
138 va_list ap; 139{ |
140 int cnt; 141 char ch, *p; |
142 time_t now; 143 int fd, saved_errno; 144 char *stdp, tbuf[2048], fmt_cpy[1024], timbuf[26]; 145 FILE *fp, *fmt_fp; 146 struct bufcookie tbuf_cookie; 147 struct bufcookie fmt_cookie; 148 149#define INTERNALLOG LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID --- 73 unchanged lines hidden (view full) --- 223 (void)vfprintf(fp, fmt, ap); 224 (void)fclose(fp); 225 226 cnt = sizeof(tbuf) - tbuf_cookie.left; 227 228 /* Output to stderr if requested. */ 229 if (LogStat & LOG_PERROR) { 230 struct iovec iov[2]; |
231 struct iovec *v = iov; |
232 233 v->iov_base = stdp; 234 v->iov_len = cnt - (stdp - tbuf); 235 ++v; 236 v->iov_base = "\n"; 237 v->iov_len = 1; 238 (void)_writev(STDERR_FILENO, iov, 2); 239 } --- 17 unchanged lines hidden (view full) --- 257 /* 258 * Output the message to the console; don't worry about blocking, 259 * if console blocks everything will. Make sure the error reported 260 * is the one from the syslogd failure. 261 */ 262 if (LogStat & LOG_CONS && 263 (fd = _open(_PATH_CONSOLE, O_WRONLY, 0)) >= 0) { 264 struct iovec iov[2]; |
265 struct iovec *v = iov; |
266 267 p = strchr(tbuf, '>') + 1; 268 v->iov_base = p; 269 v->iov_len = cnt - (p - tbuf); 270 ++v; 271 v->iov_base = "\r\n"; 272 v->iov_len = 2; 273 (void)_writev(fd, iov, 2); --- 92 unchanged lines hidden --- |