-/* $OpenBSD: resolve.c,v 1.97 2022/01/08 06:49:41 guenther Exp $ */
+/* $OpenBSD: resolve.c,v 1.98 2023/04/09 23:41:47 gnezdo Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
static int
_dl_origin_path(elf_object_t *object, char *origin_path)
{
- const char *dirname_path = _dl_dirname(object->load_name);
+ const char *dirname_path;
- if (dirname_path == NULL)
+ /* syscall in ld.so returns 0/-errno, where libc returns char* */
+ if (_dl___realpath(object->load_name, origin_path) < 0)
return -1;
- /* syscall in ld.so returns 0/-errno, where libc returns char* */
- if (_dl___realpath(dirname_path, origin_path) < 0)
+ dirname_path = _dl_dirname(origin_path);
+ if (dirname_path == NULL)
return -1;
+ _dl_strlcpy(origin_path, dirname_path, PATH_MAX);
+
return 0;
}
-# $OpenBSD: Makefile,v 1.1 2013/03/30 22:03:51 kurt Exp $
+# $OpenBSD: Makefile,v 1.2 2023/04/09 23:41:48 gnezdo Exp $
-SUBDIR+= libaa prog1
+SUBDIR+= libaa prog1 prog2
install:
--- /dev/null
+# $OpenBSD: Makefile,v 1.1 2023/04/09 23:41:48 gnezdo Exp $
+
+.include <bsd.obj.mk>
+
+AA_DIR=${.CURDIR}/../libaa
+
+AA_OBJDIR!= if [ -d $(AA_DIR)/${__objdir} ]; then \
+ echo "$(AA_DIR)/${__objdir}"; \
+ else \
+ echo "$(AA_DIR)"; \
+ fi
+
+PROG= prog2
+SRCS= main.c
+CPPFLAGS+= -I$(AA_DIR)
+LDADD+= -laa
+LDFLAGS+= -Wl,-z,origin,-rpath,'$$ORIGIN/../lib'
+LDFLAGS+= -L$(AA_OBJDIR)
+
+REGRESS_TARGETS = test
+
+.PHONY: test
+test: $(PROG)
+ mkdir -p lib bin bin2 bin3/bin
+ cp $(AA_OBJDIR)/libaa.so* lib
+ cp ./$(PROG) bin
+ bin/$(PROG)
+ ln -sf ../bin bin2/bin
+ bin2/bin/$(PROG)
+ ln -sf $$(realpath bin/$(PROG)) bin3/bin/$(PROG)
+ bin3/bin/$(PROG)
+
+clean:
+ rm -f a.out [Ee]rrs mklog *.core y.tab.h \
+ ${PROG} ${OBJS} ${_LEXINTM} ${_YACCINTM} ${CLEANFILES}
+ rm -rf lib bin bin2 bin3
+
+.include <bsd.regress.mk>
--- /dev/null
+/* $OpenBSD: main.c,v 1.1 2023/04/09 23:41:48 gnezdo Exp $ */
+
+/*
+ * Copyright (c) 2013 Kurt Miller <kurt@intricatesoftware.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "aa.h"
+
+int
+main()
+{
+ return (aa());
+}