summaryrefslogtreecommitdiffstats
path: root/ctdb/lib/replace
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2007-05-02 07:32:04 +1000
committerAndrew Tridgell <tridge@samba.org>2007-05-02 07:32:04 +1000
commit169f12940462da90d6cdbbd1c8f170fa978d959a (patch)
treebb9a82c2e458f6149939720e9291f9e2b05985bd /ctdb/lib/replace
parent3a05ad1402c20df868abb2aeb56a6d9e3be1f884 (diff)
merge latest versions of lib/replace, lib/talloc, lib/tdb and lib/events into ctdb bzr tree
(This used to be ctdb commit eaea8a9fa8d2f5e08f3af619fa1008a663f39053)
Diffstat (limited to 'ctdb/lib/replace')
-rw-r--r--ctdb/lib/replace/Makefile.in6
-rw-r--r--ctdb/lib/replace/README19
-rw-r--r--ctdb/lib/replace/libreplace.m417
-rw-r--r--ctdb/lib/replace/libreplace_macros.m49
-rw-r--r--ctdb/lib/replace/replace.c53
-rw-r--r--ctdb/lib/replace/replace.h81
-rw-r--r--ctdb/lib/replace/samba.m48
-rw-r--r--ctdb/lib/replace/snprintf.c6
-rw-r--r--ctdb/lib/replace/system/config.m43
-rw-r--r--ctdb/lib/replace/system/filesys.h4
10 files changed, 165 insertions, 41 deletions
diff --git a/ctdb/lib/replace/Makefile.in b/ctdb/lib/replace/Makefile.in
index 10ba5b9415..41454f6ec4 100644
--- a/ctdb/lib/replace/Makefile.in
+++ b/ctdb/lib/replace/Makefile.in
@@ -11,9 +11,9 @@ srcdir = @srcdir@
builddir = @builddir@
INSTALL = @INSTALL@
-.PHONY: test
+.PHONY: test all showflags install installcheck clean distclean realdistclean
-CFLAGS=-I. -I@libreplacedir@ @CFLAGS@
+CFLAGS=-I. @CFLAGS@
OBJS = @LIBREPLACEOBJ@
@@ -37,7 +37,7 @@ test: all
installcheck: install test
-TEST_OBJS = test/testsuite.o test/os2_delete.o
+TEST_OBJS = test/testsuite.o test/os2_delete.o test/strptime.o
testsuite: libreplace.a $(TEST_OBJS)
$(CC) -o testsuite $(TEST_OBJS) -L. -lreplace
diff --git a/ctdb/lib/replace/README b/ctdb/lib/replace/README
index a313984c8e..77558b2ca9 100644
--- a/ctdb/lib/replace/README
+++ b/ctdb/lib/replace/README
@@ -12,7 +12,6 @@ strlcpy
strlcat
mktime
rename
-innetgr
initgroups
memmove
strdup
@@ -21,6 +20,7 @@ setlinebuf
vsyslog
timegm
setenv
+unsetenv
strndup
strnlen
waitpid
@@ -53,6 +53,7 @@ inet_ntoa
strtoll
strtoull
socketpair
+strptime
Types:
bool
@@ -76,13 +77,27 @@ CHAR_BIT
Macros:
va_copy
__FUNCTION__
+__FILE__
+__LINE__
+__LINESTR__
+__location__
__STRING
+__STRINGSTRING
MIN
MAX
QSORT_CAST
+ZERO_STRUCT
+ZERO_STRUCTP
+ZERO_STRUCTPN
+ZERO_ARRAY
+ARRAY_SIZE
+PTR_DIFF
+
+Headers:
+stdint.h
+stdbool.h
Prerequisites:
memset (for bzero)
syslog (for vsyslog)
-setnetgrent, getnetgrent, endnetgrent (for innetgr)
mktemp (for mkstemp and mkdtemp)
diff --git a/ctdb/lib/replace/libreplace.m4 b/ctdb/lib/replace/libreplace.m4
index 3328dea95e..fa00f2c1c4 100644
--- a/ctdb/lib/replace/libreplace.m4
+++ b/ctdb/lib/replace/libreplace.m4
@@ -61,9 +61,12 @@ AC_FUNC_MEMCMP
AC_CHECK_FUNCS(pipe strftime srandom random srand rand usleep setbuffer lstat getpgrp)
-AC_CHECK_HEADERS(stdbool.h sys/select.h)
+AC_CHECK_HEADERS(stdbool.h stdint.h sys/select.h)
AC_CHECK_HEADERS(setjmp.h)
+LIBREPLACE_PROVIDE_HEADER([stdint.h])
+LIBREPLACE_PROVIDE_HEADER([stdbool.h])
+
AC_CHECK_TYPE(bool,
[AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],,
[
@@ -147,7 +150,7 @@ AC_TRY_COMPILE([
AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror)
AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
-AC_CHECK_FUNCS(waitpid strlcpy strlcat innetgr initgroups memmove strdup)
+AC_CHECK_FUNCS(waitpid strlcpy strlcat initgroups memmove strdup)
AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp socketpair)
AC_HAVE_DECL(setresuid, [#include <unistd.h>])
AC_HAVE_DECL(setresgid, [#include <unistd.h>])
@@ -260,7 +263,10 @@ AC_CHECK_HEADERS([sys/param.h limits.h])
AC_CHECK_TYPE(comparison_fn_t,
[AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
-AC_CHECK_FUNCS(strnlen setenv)
+AC_HAVE_DECL(setenv, [#include <stdlib.h>])
+AC_CHECK_FUNCS(setenv unsetenv)
+
+AC_CHECK_FUNCS(strnlen)
AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
# this test disabled as we don't actually need __VA_ARGS__ yet
@@ -323,12 +329,12 @@ m4_include(system/config.m4)
m4_include(dlfcn.m4)
m4_include(getpass.m4)
+m4_include(strptime.m4)
m4_include(win32.m4)
m4_include(timegm.m4)
m4_include(repdir.m4)
-AC_CHECK_FUNCS([syslog memset setnetgrent getnetgrent endnetgrent memcpy],,
- [AC_MSG_ERROR([Required function not found])])
+AC_CHECK_FUNCS([syslog memset memcpy],,[AC_MSG_ERROR([Required function not found])])
echo "LIBREPLACE_BROKEN_CHECKS: END"
]) dnl end AC_LIBREPLACE_BROKEN_CHECKS
@@ -348,6 +354,7 @@ AC_LIBREPLACE_LOCATION_CHECKS
AC_LIBREPLACE_CC_CHECKS
AC_LIBREPLACE_BROKEN_CHECKS
AC__LIBREPLACE_ALL_CHECKS_END
+CFLAGS="$CFLAGS -I$libreplacedir"
])
m4_include(libreplace_cc.m4)
diff --git a/ctdb/lib/replace/libreplace_macros.m4 b/ctdb/lib/replace/libreplace_macros.m4
index 0669c10c2a..f262b9b6eb 100644
--- a/ctdb/lib/replace/libreplace_macros.m4
+++ b/ctdb/lib/replace/libreplace_macros.m4
@@ -306,3 +306,12 @@ AC_DEFUN(AC_VERIFY_C_PROTOTYPE,
)
AS_IF([test $AS_TR_SH([ac_cv_c_prototype_$1]) = yes],[$3],[$4])
])
+
+AC_DEFUN(LIBREPLACE_PROVIDE_HEADER,
+[AC_CHECK_HEADER([$1],
+ [ AC_CONFIG_COMMANDS(rm-$1, [rm -f $libreplacedir/$1], [libreplacedir=$libreplacedir]) ],
+ [ AC_CONFIG_COMMANDS(mk-$1, [echo "#include \"replace.h\"" > $libreplacedir/$1], [libreplacedir=$libreplacedir]) ]
+ )
+])
+
+
diff --git a/ctdb/lib/replace/replace.c b/ctdb/lib/replace/replace.c
index 9e6c75bd35..db299130e5 100644
--- a/ctdb/lib/replace/replace.c
+++ b/ctdb/lib/replace/replace.c
@@ -154,33 +154,6 @@ time_t rep_mktime(struct tm *t)
#endif /* !HAVE_MKTIME */
-#ifndef HAVE_INNETGR
-#if defined(HAVE_SETNETGRENT) && defined(HAVE_GETNETGRENT) && defined(HAVE_ENDNETGRENT)
-/*
- * Search for a match in a netgroup. This replaces it on broken systems.
- */
-int rep_innetgr(const char *group, const char *host, const char *user,
- const char *dom)
-{
- char *hst, *usr, *dm;
-
- setnetgrent(group);
- while (getnetgrent(&hst, &usr, &dm)) {
- if (((host == 0) || (hst == 0) || !strcmp(host, hst)) &&
- ((user == 0) || (usr == 0) || !strcmp(user, usr)) &&
- ((dom == 0) || (dm == 0) || !strcmp(dom, dm))) {
- endnetgrent();
- return (1);
- }
- }
- endnetgrent();
- return (0);
-}
-#endif /* HAVE_SETNETGRENT HAVE_GETNETGRENT HAVE_ENDNETGRENT */
-#endif /* HAVE_INNETGR */
-
-
-
#ifndef HAVE_INITGROUPS
/****************************************************************************
some systems don't have an initgroups call
@@ -590,6 +563,32 @@ int rep_setenv(const char *name, const char *value, int overwrite)
}
#endif
+#ifndef HAVE_UNSETENV
+int rep_unsetenv(const char *name)
+{
+ extern char **environ;
+ size_t len = strlen(name);
+ size_t i;
+ int found = 0;
+
+ for (i=0; (environ && environ[i]); i++) {
+ if (found) {
+ environ[i-1] = environ[i];
+ continue;
+ }
+
+ if (strncmp(environ[i], name, len) == 0 && environ[i][len] == '=') {
+ free(environ[i]);
+ environ[i] = NULL;
+ found = 1;
+ continue;
+ }
+ }
+
+ return 0;
+}
+#endif
+
#ifndef HAVE_SOCKETPAIR
int rep_socketpair(int d, int type, int protocol, int sv[2])
{
diff --git a/ctdb/lib/replace/replace.h b/ctdb/lib/replace/replace.h
index 5667644025..b96356ac46 100644
--- a/ctdb/lib/replace/replace.h
+++ b/ctdb/lib/replace/replace.h
@@ -79,6 +79,29 @@
#include <stddef.h>
#endif
+/**
+ this is a warning hack. The idea is to use this everywhere that we
+ get the "discarding const" warning from gcc. That doesn't actually
+ fix the problem of course, but it means that when we do get to
+ cleaning them up we can do it by searching the code for
+ discard_const.
+
+ It also means that other error types aren't as swamped by the noise
+ of hundreds of const warnings, so we are more likely to notice when
+ we get new errors.
+
+ Please only add more uses of this macro when you find it
+ _really_ hard to fix const warnings. Our aim is to eventually use
+ this function in only a very few places.
+
+ Also, please call this via the discard_const_p() macro interface, as that
+ makes the return type safe.
+*/
+#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
+
+/** Type-safe version of discard_const */
+#define discard_const_p(type, ptr) ((type *)discard_const(ptr))
+
#ifndef HAVE_STRERROR
extern char *sys_errlist[];
#define strerror(i) sys_errlist[i]
@@ -137,7 +160,16 @@ size_t rep_strnlen(const char *s, size_t n);
#ifndef HAVE_SETENV
#define setenv rep_setenv
-int rep_setenv(const char *name, const char *value, int overwrite);
+int rep_setenv(const char *name, const char *value, int overwrite);
+#else
+#ifndef HAVE_SETENV_DECL
+int setenv(const char *name, const char *value, int overwrite);
+#endif
+#endif
+
+#ifndef HAVE_UNSETENV
+#define unsetenv rep_unsetenv
+int rep_unsetenv(const char *name);
#endif
#ifndef HAVE_SETEUID
@@ -275,6 +307,12 @@ void rep_vsyslog (int facility_priority, const char *format, va_list arglist) PR
typedef int (*comparison_fn_t)(const void *, const void *);
#endif
+#ifdef REPLACE_STRPTIME
+#define strptime rep_strptime
+struct tm;
+char *rep_strptime(const char *buf, const char *format, struct tm *tm);
+#endif
+
/* Load header file for dynamic linking stuff */
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
@@ -401,6 +439,47 @@ typedef int bool;
#define __STRING(x) #x
#endif
+#ifndef _STRINGSTRING
+#define __STRINGSTRING(x) __STRING(x)
+#endif
+
+#ifndef __LINESTR__
+#define __LINESTR__ __STRINGSTRING(__LINE__)
+#endif
+
+#ifndef __location__
+#define __location__ __FILE__ ":" __LINESTR__
+#endif
+
+/**
+ * zero a structure
+ */
+#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
+
+/**
+ * zero a structure given a pointer to the structure
+ */
+#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
+
+/**
+ * zero a structure given a pointer to the structure - no zero check
+ */
+#define ZERO_STRUCTPN(x) memset((char *)(x), 0, sizeof(*(x)))
+
+/* zero an array - note that sizeof(array) must work - ie. it must not be a
+ pointer */
+#define ZERO_ARRAY(x) memset((char *)(x), 0, sizeof(x))
+
+/**
+ * work out how many elements there are in a static array
+ */
+#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
+
+/**
+ * pointer difference macro
+ */
+#define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2)))
+
#if MMAP_BLACKLIST
#undef HAVE_MMAP
#endif
diff --git a/ctdb/lib/replace/samba.m4 b/ctdb/lib/replace/samba.m4
index 3769c7f50e..a2e04f53b1 100644
--- a/ctdb/lib/replace/samba.m4
+++ b/ctdb/lib/replace/samba.m4
@@ -3,8 +3,16 @@ AC_LIBREPLACE_BROKEN_CHECKS
SMB_EXT_LIB(LIBREPLACE_EXT, [${LIBDL}])
SMB_ENABLE(LIBREPLACE_EXT)
+# remove leading ./
LIBREPLACE_DIR=`echo ${libreplacedir} |sed -e 's/^\.\///g'`
+# remove leading srcdir .. we are looking for the relative
+# path within the samba source tree or wherever libreplace is.
+# We need to make sure the object is not forced to end up in
+# the source directory because we might be using a separate
+# build directory.
+LIBREPLACE_DIR=`echo ${LIBREPLACE_DIR} | sed -e "s|^$srcdir/||g"`
+
LIBREPLACE_OBJS=""
for obj in ${LIBREPLACEOBJ}; do
LIBREPLACE_OBJS="${LIBREPLACE_OBJS} ${LIBREPLACE_DIR}/${obj}"
diff --git a/ctdb/lib/replace/snprintf.c b/ctdb/lib/replace/snprintf.c
index b38d8dad34..9f8a7657e5 100644
--- a/ctdb/lib/replace/snprintf.c
+++ b/ctdb/lib/replace/snprintf.c
@@ -742,6 +742,8 @@ static int dopr(char *buffer, size_t maxlen, const char *format, va_list args_in
ret = currlen;
done:
+ va_end(args);
+
while (chunks) {
cnk = chunks->next;
free(chunks);
@@ -1260,16 +1262,16 @@ static int add_cnk_list_entry(struct pr_chunk_x **list,
va_list ap2;
VA_COPY(ap2, ap);
-
ret = vsnprintf(NULL, 0, format, ap2);
+ va_end(ap2);
if (ret <= 0) return ret;
(*ptr) = (char *)malloc(ret+1);
if (!*ptr) return -1;
VA_COPY(ap2, ap);
-
ret = vsnprintf(*ptr, ret+1, format, ap2);
+ va_end(ap2);
return ret;
}
diff --git a/ctdb/lib/replace/system/config.m4 b/ctdb/lib/replace/system/config.m4
index 4d66317a5e..74278787e7 100644
--- a/ctdb/lib/replace/system/config.m4
+++ b/ctdb/lib/replace/system/config.m4
@@ -1,6 +1,7 @@
# filesys
AC_HEADER_DIRENT
-AC_CHECK_HEADERS(fcntl.h sys/fcntl.h sys/acl.h sys/resource.h sys/ioctl.h sys/mode.h sys/filio.h sys/fs/s5param.h sys/filsys.h )
+AC_CHECK_HEADERS(fcntl.h sys/fcntl.h sys/resource.h sys/ioctl.h sys/mode.h sys/filio.h sys/fs/s5param.h sys/filsys.h)
+AC_CHECK_HEADERS(sys/acl.h acl/libacl.h)
# select
AC_CHECK_HEADERS(sys/select.h)
diff --git a/ctdb/lib/replace/system/filesys.h b/ctdb/lib/replace/system/filesys.h
index 1e48f7ab40..3b68abe48a 100644
--- a/ctdb/lib/replace/system/filesys.h
+++ b/ctdb/lib/replace/system/filesys.h
@@ -41,6 +41,10 @@
#include <sys/acl.h>
#endif
+#ifdef HAVE_ACL_LIBACL_H
+#include <acl/libacl.h>
+#endif
+
#ifdef HAVE_SYS_FS_S5PARAM_H
#include <sys/fs/s5param.h>
#endif