summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2009-10-24 14:10:25 +0000
committerStef Walter <stef@memberwebs.com>2009-10-24 14:10:25 +0000
commit9145a2db71a85064aa6a198c44da3cf753241131 (patch)
treefaa3a1a60475f9e6810a3f6618593d430cc61511 /common
parent082ac8f970f9c2cb244ffccc7b382b259e7b4f69 (diff)
Fixes for OpenSolaris 0906
Diffstat (limited to 'common')
-rw-r--r--common/compat.c102
-rw-r--r--common/config-parser.c25
2 files changed, 119 insertions, 8 deletions
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 */