summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5a8e0d7)
raw | patch | inline | side by side (parent: 5a8e0d7)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 30 Jun 2007 21:22:41 +0000 (23:22 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 30 Jun 2007 21:22:41 +0000 (23:22 +0200) |
Since OpenBSD doesn't provide a threadsafe version itself, we need to provide
it in this case.. :/
it in this case.. :/
configure.in | patch | blob | history | |
src/common.c | patch | blob | history | |
src/common.h | patch | blob | history |
diff --git a/configure.in b/configure.in
index 692dc5b717df6289fe08adac99b2e49ad4b5daac..9596cec9ff6b113ba2b3b9d54e87cf203d810655 100644 (file)
--- a/configure.in
+++ b/configure.in
AC_CHECK_FUNCS(strncasecmp strcasecmp)
AC_CHECK_FUNCS(openlog syslog closelog)
+AC_CHECK_FUNCS(getpwnam_r)
+AC_CHECK_FUNCS(getgrnam_r)
+
socket_needs_socket="no"
AC_CHECK_FUNCS(socket, [], AC_CHECK_LIB(socket, socket, [socket_needs_socket="yes"], AC_MSG_ERROR(cannot find socket)))
AM_CONDITIONAL(BUILD_WITH_LIBSOCKET, test "x$socket_needs_socket" = "xyes")
# For users module
AC_CHECK_FUNCS(getutent getutxent)
-# For quota module
-AC_CHECK_FUNCS(quotactl)
-AC_CHECK_FUNCS(getgrgid getpwuid)
-
# For interface module
AC_CHECK_FUNCS(getifaddrs)
diff --git a/src/common.c b/src/common.c
index 1addb323673814a5d8375f3114efaa654fa652f5..6333ab770db2ff6de93669387ce8c298ee096bae 100644 (file)
--- a/src/common.c
+++ b/src/common.c
#include "common.h"
#include "plugin.h"
+#if HAVE_PTHREAD_H
+# include <pthread.h>
+#endif
+
#ifdef HAVE_MATH_H
-# include <math.h>
+# include <math.h>
#endif
/* for ntohl and htonl */
extern kstat_ctl_t *kc;
#endif
+#if !HAVE_GETPWNAM_R
+static pthread_mutex_t getpwnam_r_lock = PTHREAD_MUTEX_INITIALIZER;
+#endif
+
void sstrncpy (char *d, const char *s, int len)
{
strncpy (d, s, len);
return (-1);
return (0);
} /* int parse_values */
+
+#if !HAVE_GETPWNAM_R
+int getpwnam_r (const char *name, struct passwd *pwbuf, char *buf,
+ size_t buflen, struct passwd **pwbufp)
+{
+ int status = 0;
+ struct passwd *pw;
+
+ memset (pwbuf, '\0', sizeof (struct passwd));
+
+ pthread_mutex_lock (&getpwnam_r_lock);
+
+ do
+ {
+ pw = getpwnam (name);
+ if (pw == NULL)
+ {
+ status = (errno != 0) ? errno : ENOENT;
+ break;
+ }
+
+#define GETPWNAM_COPY_MEMBER(member) \
+ if (pw->member != NULL) \
+ { \
+ int len = strlen (pw->member); \
+ if (len >= buflen) \
+ { \
+ status = ENOMEM; \
+ break; \
+ } \
+ sstrncpy (buf, pw->member, buflen); \
+ pwbuf->member = buf; \
+ buf += (len + 1); \
+ buflen -= (len + 1); \
+ }
+ GETPWNAM_COPY_MEMBER(pw_name);
+ GETPWNAM_COPY_MEMBER(pw_passwd);
+ GETPWNAM_COPY_MEMBER(pw_gecos);
+ GETPWNAM_COPY_MEMBER(pw_dir);
+ GETPWNAM_COPY_MEMBER(pw_shell);
+
+ pwbuf->pw_uid = pw->pw_uid;
+ pwbuf->pw_gid = pw->pw_gid;
+
+ *pwbufp = pwbuf;
+ } while (0);
+
+ pthread_mutex_unlock (&getpwnam_r_lock);
+
+ return (status);
+} /* int getpwnam_r */
+#endif
diff --git a/src/common.h b/src/common.h
index b07db9d4b053682d276b60aa51f1b9e9b6fff90c..f12b5e4d73b659503e3f7d959e4e1fd4cbba1a3d 100644 (file)
--- a/src/common.h
+++ b/src/common.h
#include "collectd.h"
#include "plugin.h"
+#if HAVE_PWD_H
+# include <pwd.h>
+#endif
+
#define sfree(ptr) \
if((ptr) != NULL) { \
free(ptr); \
char **ret_type, char **ret_type_instance);
int parse_values (char *buffer, value_list_t *vl, const data_set_t *ds);
+#if !HAVE_GETPWNAM_R
+int getpwnam_r (const char *name, struct passwd *pwbuf, char *buf,
+ size_t buflen, struct passwd **pwbufp);
+#endif
+
#endif /* COMMON_H */