diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2016-03-20 05:13:23 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2016-03-20 05:13:23 +0000 |
commit | ab25a4124faa2de6056bc219bb94044a1c697d89 (patch) | |
tree | e6a7230369c4acb6f52a05e14d711ec50d989fef /regress | |
parent | 8a127ccbe8a5216e39894b887bfe0a867f3e84c2 (diff) |
Add regress for environ and __progname vs load-time .init functions
Diffstat (limited to 'regress')
-rw-r--r-- | regress/libexec/ld.so/Makefile | 3 | ||||
-rw-r--r-- | regress/libexec/ld.so/init-env/Makefile | 9 | ||||
-rw-r--r-- | regress/libexec/ld.so/init-env/libaa/Makefile | 3 | ||||
-rw-r--r-- | regress/libexec/ld.so/init-env/libaa/aa.C | 39 | ||||
-rw-r--r-- | regress/libexec/ld.so/init-env/libaa/shlib_version | 2 | ||||
-rw-r--r-- | regress/libexec/ld.so/init-env/prog/Makefile | 23 | ||||
-rw-r--r-- | regress/libexec/ld.so/init-env/prog/prog.c | 31 |
7 files changed, 109 insertions, 1 deletions
diff --git a/regress/libexec/ld.so/Makefile b/regress/libexec/ld.so/Makefile index 728b3b41b00..6a48b5ef214 100644 --- a/regress/libexec/ld.so/Makefile +++ b/regress/libexec/ld.so/Makefile @@ -1,9 +1,10 @@ -# $OpenBSD: Makefile,v 1.15 2014/09/07 04:14:25 guenther Exp $ +# $OpenBSD: Makefile,v 1.16 2016/03/20 05:13:22 guenther Exp $ SUBDIR+= elf hidden weak dlsym dlopen dlclose lazy #SUBDIR+= constructor SUBDIR+= link-order edgecases initfirst SUBDIR+= df_1_noopen randomdata subst dependencies +SUBDIR+= init-env install: diff --git a/regress/libexec/ld.so/init-env/Makefile b/regress/libexec/ld.so/init-env/Makefile new file mode 100644 index 00000000000..3b0e73032dc --- /dev/null +++ b/regress/libexec/ld.so/init-env/Makefile @@ -0,0 +1,9 @@ +# +# Tests for whether environ and __progname are set correctly for +# shared library constructors and whether changes made to environ +# are seen by main() +# + +SUBDIR=libaa prog + +.include <bsd.subdir.mk> diff --git a/regress/libexec/ld.so/init-env/libaa/Makefile b/regress/libexec/ld.so/init-env/libaa/Makefile new file mode 100644 index 00000000000..c4432ee7f17 --- /dev/null +++ b/regress/libexec/ld.so/init-env/libaa/Makefile @@ -0,0 +1,3 @@ +LIB=aa +SRCS= aa.C +.include <bsd.lib.mk> diff --git a/regress/libexec/ld.so/init-env/libaa/aa.C b/regress/libexec/ld.so/init-env/libaa/aa.C new file mode 100644 index 00000000000..38a02fb92ba --- /dev/null +++ b/regress/libexec/ld.so/init-env/libaa/aa.C @@ -0,0 +1,39 @@ +/* + * Public Domain 2016 Philip Guenther <guenther@openbsd.org> + * + * $OpenBSD: aa.C,v 1.1 2016/03/20 05:13:22 guenther Exp $ + */ + +#include <iostream> +#include <cstdlib> + +extern char *__progname; + +class AA { +public: + AA(const char *); +}; + +AA::AA(const char *arg) +{ + int fail = 0; + + if (getenv("PATH") != NULL) + std::cout << "OK: PATH is set\n"; + else { + std::cout << "FAILED: PATH not set\n"; + fail = 1; + } + if (__progname != NULL && __progname[0] != '\0') + std::cout << "OK: __progname is set\n"; + else { + std::cout << "FAILED: __progname not set\n"; + fail = 1; + } + setenv(arg, "foo", 1); +// if (fail) +// exit(1); +} + +AA foo("INIT_ENV_REGRESS_TEST"); + diff --git a/regress/libexec/ld.so/init-env/libaa/shlib_version b/regress/libexec/ld.so/init-env/libaa/shlib_version new file mode 100644 index 00000000000..1edea46de91 --- /dev/null +++ b/regress/libexec/ld.so/init-env/libaa/shlib_version @@ -0,0 +1,2 @@ +major=1 +minor=0 diff --git a/regress/libexec/ld.so/init-env/prog/Makefile b/regress/libexec/ld.so/init-env/prog/Makefile new file mode 100644 index 00000000000..54464144cad --- /dev/null +++ b/regress/libexec/ld.so/init-env/prog/Makefile @@ -0,0 +1,23 @@ +# $OpenBSD: Makefile,v 1.1 2016/03/20 05:13:22 guenther Exp $ + +.include <bsd.obj.mk> + +PROG=prog + +SRCS=prog.c + +AA_DIR=${.CURDIR}/../libaa +AA_OBJDIR!= if [ -d $(AA_DIR)/${__objdir} ]; then \ + echo "$(AA_DIR)/${__objdir}"; \ + else \ + echo "$(AA_DIR)"; \ + fi + +LDADD= +LDADD+=-laa +LDFLAGS=-L$(AA_OBJDIR) +LDFLAGS+= -Wl,-rpath,$(AA_OBJDIR) +NOMAN= +CC=c++ + +.include <bsd.regress.mk> diff --git a/regress/libexec/ld.so/init-env/prog/prog.c b/regress/libexec/ld.so/init-env/prog/prog.c new file mode 100644 index 00000000000..c7d1f9ded26 --- /dev/null +++ b/regress/libexec/ld.so/init-env/prog/prog.c @@ -0,0 +1,31 @@ +/* + * Public Domain 2016 Philip Guenther <guenther@openbsd.org> + * + * $OpenBSD: prog.c,v 1.1 2016/03/20 05:13:22 guenther Exp $ + */ + +#include <stdio.h> +#include <stdlib.h> + +extern char **environ; + +int +main(int argc, char **argv, char **env) +{ + int ret = 0; + + if (env == environ) + printf("OK: main's 3rd arg == environ\n"); + else { + ret = 1; + printf("FAILED: main's 3rd arg isn't environ\n"); + } + if (getenv("INIT_ENV_REGRESS_TEST") != NULL) + printf("OK: env var set by .so init function set\n"); + else { + ret = 1; + printf("FAILED: env var set by .so init function not set\n"); + } + + return ret; +} |