diff options
author | Stef Walter <stef@memberwebs.com> | 2009-10-24 14:10:25 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2009-10-24 14:10:25 +0000 |
commit | 9145a2db71a85064aa6a198c44da3cf753241131 (patch) | |
tree | faa3a1a60475f9e6810a3f6618593d430cc61511 | |
parent | 082ac8f970f9c2cb244ffccc7b382b259e7b4f69 (diff) |
Fixes for OpenSolaris 0906
-rw-r--r-- | bsnmp/snmppriv.h | 4 | ||||
-rw-r--r-- | common/compat.c | 102 | ||||
-rw-r--r-- | common/config-parser.c | 25 | ||||
-rw-r--r-- | configure.in | 9 |
4 files changed, 130 insertions, 10 deletions
diff --git a/bsnmp/snmppriv.h b/bsnmp/snmppriv.h index 87ef60e..fb6dea8 100644 --- a/bsnmp/snmppriv.h +++ b/bsnmp/snmppriv.h @@ -30,7 +30,11 @@ * * Private functions. */ +#include "config.h" + +#ifdef HAVE_SYS_CDEFS_H #include <sys/cdefs.h> +#endif enum asn_err snmp_binding_encode(struct asn_buf *, const struct snmp_value *); enum snmp_code snmp_pdu_encode_header(struct asn_buf *, struct snmp_pdu *); diff --git a/common/compat.c b/common/compat.c index 53de9bf..eda00d0 100644 --- a/common/compat.c +++ b/common/compat.c @@ -276,3 +276,105 @@ void strupr(char* data) } #endif /* HAVE_STRUPR */ + +#ifndef HAVE_STRNCASECMP + +int +strncasecmp(const char *s1, const char *s2, size_t n) +{ + if (n != 0) { + const unsigned char + *us1 = (const unsigned char *)s1, + *us2 = (const unsigned char *)s2; + + do { + if (tolower(*us1) != tolower(*us2++)) + return (tolower(*us1) - tolower(*--us2)); + if (*us1++ == '\0') + break; + } while (--n != 0); + } + return (0); +} + +#endif /* HAVE_STRNCASECMP */ + +#ifndef HAVE_STRCASESTR + +char * +strcasestr(const char *s, const char *find) +{ + char c, sc; + size_t len; + + if ((c = *find++) != 0) { + c = tolower((unsigned char)c); + len = strlen(find); + do { + do { + if ((sc = *s++) == 0) + return (NULL); + } while ((char)tolower((unsigned char)sc) != c); + } while (strncasecmp(s, find, len) != 0); + s--; + } + return ((char *)s); +} + +#endif /* HAVE_STRCASESTR */ + +#ifndef HAVE_DAEMON + +#include <sys/types.h> +#include <unistd.h> +#include <stdlib.h> +#include <signal.h> +#include <fcntl.h> + +int daemon(int nochdir, int noclose) +{ + struct sigaction osa, sa; + int oerrno, fd, osa_ok; + pid_t newgrp; + + /* A SIGHUP may be thrown when the parent exits below. */ + sigemptyset(&sa.sa_mask); + sa.sa_handler = SIG_IGN; + sa.sa_flags = 0; + osa_ok = sigaction(SIGHUP, &sa, &osa); + + switch(fork()) + { + case -1: + return -1; + case 0: + break; + default: + _exit(0); + } + + newgrp = setsid(); + oerrno = errno; + if(osa_ok != -1) + sigaction(SIGHUP, &osa, NULL); + if(newgrp == -1) + { + errno = oerrno; + return -1; + } + if(!nochdir) + chdir("/"); + if(!noclose && (fd = open("/dev/null", O_RDWR, 0)) != -1) + { + dup2(fd, STDIN_FILENO); + dup2(fd, STDOUT_FILENO); + dup2(fd, STDERR_FILENO); + if(fd > 2) + close(fd); + } + return 0; + +} + +#endif /* HAVE_DAEMON */ + diff --git a/common/config-parser.c b/common/config-parser.c index b5852b7..fbb9c70 100644 --- a/common/config-parser.c +++ b/common/config-parser.c @@ -245,6 +245,7 @@ parse_dir_internal(const char* subdir, void* data) { char path[MAXPATHLEN]; struct dirent* dire; + int is_dir, is_reg, is_lnk; struct stat st; char* memory; DIR* dir; @@ -271,8 +272,16 @@ parse_dir_internal(const char* subdir, void* data) else strlcpy(path, dire->d_name, MAXPATHLEN); - /* for non BSD compliant filesystem: stat() only if dirent->d_type is unknown */ - if(dire->d_type == DT_UNKNOWN) + is_dir = is_reg = is_lnk = 0; +#ifdef HAVE_STRUCT_DIRENT_D_TYPE + if(dire->d_type != DT_UNKNOWN) + { + is_dir = (dire->d_type == DT_DIR); + is_reg = (dire->d_type == DT_REG); + is_lnk = (dire->d_type == DT_LNK); + } + else +#endif { if(stat(path, &st) < 0) { @@ -281,15 +290,15 @@ parse_dir_internal(const char* subdir, void* data) } if(S_ISREG(st.st_mode)) - dire->d_type = DT_REG; + is_reg = 1; else if(S_ISDIR(st.st_mode)) - dire->d_type = DT_DIR; - else - continue; + is_dir = 1; + else if(S_ISLNK(st.st_mode)) + is_lnk = 1; } /* Descend into each sub directory */ - if(dire->d_type == DT_DIR) + if(is_dir) { /* No hidden or dot directories */ if(dire->d_name[0] == '.') @@ -302,7 +311,7 @@ parse_dir_internal(const char* subdir, void* data) continue; } - if(dire->d_type != DT_REG && dire->d_type != DT_LNK) + if(!is_reg && !is_lnk) continue; /* Build a happy path name */ diff --git a/configure.in b/configure.in index 17aa8ed..8281dbd 100644 --- a/configure.in +++ b/configure.in @@ -47,18 +47,23 @@ CFLAGS="$CFLAGS $PTHREAD_CFLAGS -D_POSIX_PTHREAD_SEMANTICS" dnl Checks for libraries AC_CHECK_LIB(rrd, rrd_update, , [echo "ERROR: librrd not found."; exit 1]) +dnl May need these for getaddrinfo +AC_CHECK_LIB(nsl, nis_lookup) +AC_CHECK_LIB(socket, getaddrinfo) dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST AC_C_INLINE +AC_CHECK_MEMBERS([struct dirent.d_type],,,[#include <dirent.h>]) dnl Check for header files. AC_HEADER_STDC AC_CHECK_HEADERS([rrd.h], , [echo "ERROR: rrd headers not found"]) -AC_CHECK_HEADERS([unistd.h stdio.h stddef.h stdlib.h assert.h errno.h stdarg.h string.h netdb.h], , +AC_CHECK_HEADERS([unistd.h stdio.h stddef.h stdlib.h assert.h errno.h stdarg.h string.h netdb.h ], , [echo "ERROR: Required C header missing"; exit 1]) +AC_CHECK_HEADERS([sys/socket.h sys/cdefs.h]) -AC_CHECK_FUNCS([strlcat strlcpy strtob]) +AC_CHECK_FUNCS([daemon strlcat strlcpy strtob strncasecmp strcasestr]) AC_CHECK_FUNCS([strerror getopt getaddrinfo], , [echo "ERROR: Required function missing"; exit 1]) |