summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2005-09-19 16:44:09 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2005-09-19 16:44:09 +0000
commita9dcb28580511f0c15fa8eea2ec5c14eb186082e (patch)
treef8247518ad5dbea1ecd1f0a7da23d09fbb631353
parent6c2956163de3be527cc34387ee0bbfdd64a5c4ef (diff)
downloadrsyslog-a9dcb28580511f0c15fa8eea2ec5c14eb186082e.tar.gz
rsyslog-a9dcb28580511f0c15fa8eea2ec5c14eb186082e.tar.xz
rsyslog-a9dcb28580511f0c15fa8eea2ec5c14eb186082e.zip
fixed SO_BSDCOMPAT problem under SUSE
-rw-r--r--NEWS2
-rw-r--r--syslogd.c72
2 files changed, 64 insertions, 10 deletions
diff --git a/NEWS b/NEWS
index 38de71fc..02343fce 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,8 @@ Version 1.10.0 (RGer), 2005-09-??
- added display of compile-time options to -v output
- performance improvement for production build - made some checks
to happen only during debug mode
+- fixed a problem with compiling on SUSE and - while doing so - removed
+ the socket call to set SO_BSDCOMPAT in cases where it is obsolete.
---------------------------------------------------------------------------
Version 1.0.0 (RGer), 2005-09-12
- changed install doc to cover daily cron scripts - a trouble source
diff --git a/syslogd.c b/syslogd.c
index 1e93e1c4..e53d84f6 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -249,6 +249,54 @@
#endif
#endif
+
+/* The following #ifdef sequence is a small compatibility
+ * layer. It tries to work around the different availality
+ * levels of SO_BSDCOMPAT on linuxes...
+ * I borrowed this code from
+ * http://www.erlang.org/ml-archive/erlang-questions/200307/msg00037.html
+ * It still needs to be a bit better adapted to rsyslog.
+ * rgerhards 2005-09-19
+ */
+#ifndef BSD
+#include <sys/utsname.h>
+static int should_use_so_bsdcompat(void)
+{
+ static int init_done;
+ static int so_bsdcompat_is_obsolete;
+
+ if (!init_done) {
+ struct utsname utsname;
+ unsigned int version, patchlevel;
+
+ init_done = 1;
+ if (uname(&utsname) < 0) {
+ dprintf("uname: %s\r\n", strerror(errno));
+ return 1;
+ }
+ /* Format is <version>.<patchlevel>.<sublevel><extraversion>
+ where the first three are unsigned integers and the last
+ is an arbitrary string. We only care about the first two. */
+ if (sscanf(utsname.release, "%u.%u", &version, &patchlevel) != 2) {
+ dprintf("uname: unexpected release '%s'\r\n",
+ utsname.release);
+ return 1;
+ }
+ /* SO_BSCOMPAT is deprecated and triggers warnings in 2.5
+ kernels. It is a no-op in 2.4 but not in 2.2 kernels. */
+ if (version > 2 || (version == 2 && patchlevel >= 5))
+ so_bsdcompat_is_obsolete = 1;
+ }
+ return !so_bsdcompat_is_obsolete;
+}
+#else /* #ifndef BSD */
+#define should_use_so_bsdcompat() 1
+#endif /* #ifndef BSD */
+#ifndef SO_BSDCOMPAT
+/* this shall prevent compiler errors due to undfined name */
+#define SO_BSDCOMPAT 0
+#endif
+
char *ConfFile = _PATH_LOGCONF;
char *PidFile = _PATH_LOGPID;
char ctty[] = _PATH_CONSOLE;
@@ -780,11 +828,13 @@ static int create_tcp_socket(void)
* could flood our log files by sending us tons of ICMP errors.
*/
#ifndef BSD
- if (setsockopt(fd, SOL_SOCKET, SO_BSDCOMPAT, \
- (char *) &on, sizeof(on)) < 0) {
- logerror("setsockopt(BSDCOMPAT), suspending tcp inet");
- close(fd);
- return -1;
+ if (should_use_so_bsdcompat()) {
+ if (setsockopt(fd, SOL_SOCKET, SO_BSDCOMPAT, \
+ (char *) &on, sizeof(on)) < 0) {
+ logerror("setsockopt(BSDCOMPAT), suspending tcp inet");
+ close(fd);
+ return -1;
+ }
}
#endif
if (bind(fd, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
@@ -2878,11 +2928,13 @@ static int create_udp_socket()
* could flood our log files by sending us tons of ICMP errors.
*/
#ifndef BSD
- if (setsockopt(fd, SOL_SOCKET, SO_BSDCOMPAT, \
- (char *) &on, sizeof(on)) < 0) {
- logerror("setsockopt(BSDCOMPAT), suspending inet");
- close(fd);
- return -1;
+ if (should_use_so_bsdcompat()) {
+ if (setsockopt(fd, SOL_SOCKET, SO_BSDCOMPAT, \
+ (char *) &on, sizeof(on)) < 0) {
+ logerror("setsockopt(BSDCOMPAT), suspending inet");
+ close(fd);
+ return -1;
+ }
}
#endif
if (bind(fd, (struct sockaddr *) &sin, sizeof(sin)) < 0) {