]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
aklog: Add replacement setenv/unsetenv
authorAndrew Deason <adeason@sinenomine.net>
Sun, 18 Dec 2011 21:20:42 +0000 (15:20 -0600)
committerDerrick Brashear <shadow@dementix.org>
Mon, 19 Dec 2011 02:56:59 +0000 (18:56 -0800)
aklog makes use of the setenv and unsetenv functions, which do not
exist (at least) on HP-UX earlier than around 11i v3, and do not exist
on Solaris earlier than Solaris 10. Add replacement functions for
setenv and unsetenv when they are not present. Note that these
implementations are copied from libroken, and setenv was modified to
not use asprintf.

This is 1.6-specific. On the master branch, libroken takes care of
these for us. On the master branch, setenv and unsetenv from libroken
were added in 70e8451acd0426024c152073e53bc6606e0189e1.

Change-Id: I35546f1add7f4f87c6ffc484059057825887499f
Reviewed-on: http://gerrit.openafs.org/6376
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Tested-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Derrick Brashear <shadow@dementix.org>
acinclude.m4
src/aklog/Makefile.in
src/aklog/aklog_roken.c [new file with mode: 0644]

index c589226744af5b1eb5b900344daa97479a7a535a..80f20ac369570eb45bb32aa550f19b19ce49aa5f 100644 (file)
@@ -1310,6 +1310,7 @@ AC_CHECK_FUNCS(setprogname getprogname sigaction mkstemp vsnprintf strerror strc
 AC_CHECK_FUNCS(setvbuf vsyslog getcwd)
 AC_CHECK_FUNCS(regcomp regexec regerror)
 AC_CHECK_FUNCS(fseeko64 ftello64 pread preadv pwrite pwritev preadv64 pwritev64)
+AC_CHECK_FUNCS([setenv unsetenv])
 
 case $AFS_SYSNAME in
 *hp_ux* | *hpux*)
index 372cda50cc79d83bd17c7506593f48188610f498..68bb4d88b2c206bc4202efe655c658cb42b83c3e 100644 (file)
@@ -18,8 +18,8 @@ AFSLIBS = ${TOP_LIBDIR}/libprot.a ${TOP_LIBDIR}/libauth.a \
          ${TOP_LIBDIR}/libdes.a ${TOP_LIBDIR}/libafscom_err.a \
          ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/libafsutil.a
 
-SRCS=  aklog.c krb_util.c linked_list.c
-OBJS=   aklog.o krb_util.o linked_list.o
+SRCS=  aklog.c aklog_roken.c krb_util.c linked_list.c
+OBJS=   aklog.o aklog_roken.o krb_util.o linked_list.o
 
 all: aklog asetkey klog
 
diff --git a/src/aklog/aklog_roken.c b/src/aklog/aklog_roken.c
new file mode 100644 (file)
index 0000000..3a980a9
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 1995 - 1999 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* this file can go away when roken appears in this branch */
+#include <afsconfig.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef ROKEN_LIB_FUNCTION
+#error this file can go away when roken appears in this branch
+#endif
+
+#ifdef _WIN32
+#define ROKEN_LIB_FUNCTION
+#define ROKEN_LIB_CALL     __cdecl
+#else
+#define ROKEN_LIB_FUNCTION
+#define ROKEN_LIB_CALL
+#endif
+
+#ifndef HAVE_SETENV
+/*
+ * This is the easy way out, use putenv to implement setenv. We might
+ * leak some memory but that is ok since we are usally about to exec
+ * anyway.
+ */
+
+ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
+setenv(const char *var, const char *val, int rewrite)
+{
+#ifndef _WIN32
+    char *t = NULL;
+
+    if (!rewrite && getenv(var) != 0)
+       return 0;
+
+    t = malloc(strlen(var) + strlen(val) + 2);
+
+    if (t == NULL || sprintf (t, "%s=%s", var, val) < 0)
+       return -1;
+
+    if (putenv(t) == 0)
+       return 0;
+    else
+       return -1;
+#else  /* Win32 */
+    char dummy[8];
+
+    if (!rewrite && GetEnvironmentVariable(var, dummy, sizeof(dummy)/sizeof(char)) != 0)
+       return 0;
+
+    if (SetEnvironmentVariable(var, val) == 0)
+       return -1;
+    else
+       return 0;
+#endif
+}
+#endif
+
+#ifndef HAVE_UNSETENV
+extern char **environ;
+/*
+ * unsetenv --
+ */
+ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
+unsetenv(const char *name)
+{
+  int len;
+  const char *np;
+  char **p;
+
+  if (name == 0 || environ == 0)
+    return;
+
+  for (np = name; *np && *np != '='; np++)
+    /* nop */;
+  len = np - name;
+
+  for (p = environ; *p != 0; p++)
+    if (strncmp(*p, name, len) == 0 && (*p)[len] == '=')
+      break;
+
+  for (; *p != 0; p++)
+    *p = *(p + 1);
+}
+#endif