From 6908f7d93a6d8d24ad574054eb8f2aa722894e3c Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Sun, 18 Dec 2011 15:20:42 -0600 Subject: [PATCH] aklog: Add replacement setenv/unsetenv 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 Tested-by: Andrew Deason Reviewed-by: Derrick Brashear --- acinclude.m4 | 1 + src/aklog/Makefile.in | 4 +- src/aklog/aklog_roken.c | 116 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 src/aklog/aklog_roken.c diff --git a/acinclude.m4 b/acinclude.m4 index c58922674..80f20ac36 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -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*) diff --git a/src/aklog/Makefile.in b/src/aklog/Makefile.in index 372cda50c..68bb4d88b 100644 --- a/src/aklog/Makefile.in +++ b/src/aklog/Makefile.in @@ -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 index 000000000..3a980a994 --- /dev/null +++ b/src/aklog/aklog_roken.c @@ -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 +#include +#include + +#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 -- 2.39.5