]> git.proxmox.com Git - mirror_ovs.git/blob - lib/syslog-libc.c
python: Update build system to ensure dirs.py is created.
[mirror_ovs.git] / lib / syslog-libc.c
1 /*
2 * Copyright (c) 2015, 2016 Nicira, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include "syslog-libc.h"
17
18 #include <config.h>
19
20 #include <string.h>
21 #include <syslog.h>
22 #include <unistd.h>
23
24 #include "compiler.h"
25 #include "openvswitch/dynamic-string.h"
26 #include "socket-util.h"
27 #include "syslog-provider.h"
28 #include "util.h"
29
30
31 static void syslog_libc_open(struct syslogger *this, int facility);
32 static void syslog_libc_log(struct syslogger *this, int pri, const char *msg);
33
34 static struct syslog_class syslog_libc_class = {
35 syslog_libc_open,
36 syslog_libc_log,
37 };
38
39 struct syslog_libc {
40 struct syslogger parent;
41 };
42
43
44 /* This function creates object that delegate all logging to libc's
45 * syslog implementation. */
46 struct syslogger *
47 syslog_libc_create(void)
48 {
49 struct syslog_libc *this = xmalloc(sizeof *this);
50
51 this->parent.class = &syslog_libc_class;
52 this->parent.prefix = "<%B> %D{%h %e %T} %E %A:";
53
54 return &this->parent;
55 }
56
57 static void
58 syslog_libc_open(struct syslogger *this OVS_UNUSED, int facility)
59 {
60 static char *ident;
61
62 /* openlog() is allowed to keep the pointer passed in, without making a
63 * copy. The daemonize code sometimes frees and replaces
64 * 'program_name', so make a private copy just for openlog(). (We keep
65 * a pointer to the private copy to suppress memory leak warnings in
66 * case openlog() does make its own copy.) */
67 ident = nullable_xstrdup(program_name);
68
69 openlog(ident, LOG_NDELAY, facility);
70 }
71
72 static void
73 syslog_libc_log(struct syslogger *this OVS_UNUSED, int pri, const char *msg)
74 {
75 syslog(pri, "%s", msg);
76 }