Skip to content

Commit

Permalink
Remove macros _getenv, _setenv _putenv and _unsetenv
Browse files Browse the repository at this point in the history
This fixes commit fcf6940

Fixes:

	$ make test
	(...)
	/usr/bin/ld: /tmp/ccSidDl6.o: in function `main':
	test-path_setenv.c:(.text+0xaf): undefined reference to `_getenv'
	/usr/bin/ld: test-path_setenv.c:(.text+0xf0): undefined reference to `_getenv'
	collect2: error: ld returned 1 exit status
  • Loading branch information
gportay committed Feb 4, 2024
1 parent a7aa067 commit d538857
Show file tree
Hide file tree
Showing 35 changed files with 141 additions and 148 deletions.
6 changes: 3 additions & 3 deletions __libc_start_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static int __dl_iterate_phdr_callback(struct dl_phdr_info *info, size_t size,
return 0;

/* is an IAMROOT_LIB? */
val = getenv("IAMROOT_LIB");
val = _getenv("IAMROOT_LIB");
if (!val)
return 0;
val = __strncpy(buf, val);
Expand Down Expand Up @@ -129,7 +129,7 @@ int __libc_start_main(int argc,
__debug("%s(argc: %i, argv: { '%s', '%s', ... }, ...)\n", __func__,
argc, argv[0], argv[1]);

argv0 = getenv("argv0");
argv0 = _getenv("argv0");
if (argv0)
argv[0] = argv0;

Expand All @@ -152,7 +152,7 @@ int __libc_start_main(int (*main)(int, char **, char **), int argc,
__debug("%s(main: %p, argc: %i, argv: { '%s', '%s', ... }, ...)\n",
__func__, main, argc, argv[0], argv[1]);

argv0 = getenv("argv0");
argv0 = _getenv("argv0");
if (argv0)
argv[0] = argv0;

Expand Down
10 changes: 5 additions & 5 deletions __verbosef.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2023 Gaël PORTAY
* Copyright 2021-2024 Gaël PORTAY
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
Expand All @@ -24,19 +24,19 @@ typedef struct {
__attribute__((visibility("hidden")))
int __getdebug()
{
return strtol(getenv("IAMROOT_DEBUG") ?: "0", NULL, 0);
return strtol(_getenv("IAMROOT_DEBUG") ?: "0", NULL, 0);
}

__attribute__((visibility("hidden")))
int __getdebug_fd()
{
return strtol(getenv("IAMROOT_DEBUG_FD") ?: "2", NULL, 0);
return strtol(_getenv("IAMROOT_DEBUG_FD") ?: "2", NULL, 0);
}

__attribute__((visibility("hidden")))
int __getno_color()
{
return strtol(getenv("NO_COLOR") ?: "0", NULL, 0);
return strtol(_getenv("NO_COLOR") ?: "0", NULL, 0);
}

__attribute__((visibility("hidden")))
Expand Down Expand Up @@ -71,7 +71,7 @@ void verbosef_init()
const char *ignore;
int ret;

ignore = getenv("IAMROOT_DEBUG_IGNORE");
ignore = _getenv("IAMROOT_DEBUG_IGNORE");
if (!ignore)
ignore = "^$";

Expand Down
4 changes: 2 additions & 2 deletions accept.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Gaël PORTAY
* Copyright 2023-2024 Gaël PORTAY
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
Expand Down Expand Up @@ -47,7 +47,7 @@ int accept(int socket, struct sockaddr *addr, socklen_t *addrlen)
if (siz == -1 && errno == ENAMETOOLONG && __inchroot()) {
char *path;

path = getenv("IAMROOT_PATH_RESOLUTION_AF_UNIX");
path = _getenv("IAMROOT_PATH_RESOLUTION_AF_UNIX");
if (path) {
int n = _snprintf(buf.sun_path, sizeof(buf.sun_path),
"%s/%s", path, buf.sun_path);
Expand Down
4 changes: 2 additions & 2 deletions accept4.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Gaël PORTAY
* Copyright 2023-2024 Gaël PORTAY
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
Expand Down Expand Up @@ -48,7 +48,7 @@ int accept4(int socket, struct sockaddr *addr, socklen_t *addrlen, int oflags)
if (siz == -1 && errno == ENAMETOOLONG && __inchroot()) {
char *path;

path = getenv("IAMROOT_PATH_RESOLUTION_AF_UNIX");
path = _getenv("IAMROOT_PATH_RESOLUTION_AF_UNIX");
if (path) {
int n = _snprintf(buf.sun_path, sizeof(buf.sun_path),
"%s/%s", path, buf.sun_path);
Expand Down
4 changes: 2 additions & 2 deletions bind.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Gaël PORTAY
* Copyright 2023-2024 Gaël PORTAY
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
Expand Down Expand Up @@ -47,7 +47,7 @@ int bind(int socket, const struct sockaddr *addr, socklen_t addrlen)
if (siz == -1 && errno == ENAMETOOLONG && __inchroot()) {
char *path;

path = getenv("IAMROOT_PATH_RESOLUTION_AF_UNIX");
path = _getenv("IAMROOT_PATH_RESOLUTION_AF_UNIX");
if (path) {
int n = _snprintf(buf.sun_path, sizeof(buf.sun_path),
"%s/%s", path, buf.sun_path);
Expand Down
5 changes: 4 additions & 1 deletion catopen.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Gaël PORTAY
* Copyright 2022-2024 Gaël PORTAY
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
Expand Down Expand Up @@ -54,6 +54,7 @@ static struct __libc {
char secure;
} libc;

#define getenv _getenv
#define do_catopen(p) __catopen(p, oflag)

/*
Expand Down Expand Up @@ -132,3 +133,5 @@ nl_catd catopen(const char *name, int oflag)
errno = ENOENT;
return (nl_catd)-1;
}

#undef getenv
36 changes: 5 additions & 31 deletions chroot.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2023 Gaël PORTAY
* Copyright 2020-2024 Gaël PORTAY
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
Expand Down Expand Up @@ -41,32 +41,6 @@ int _snprintf(char *buf, size_t bufsiz, const char *fmt, ...)
return __set_errno(ENOSPC, -1);
}

__attribute__((visibility("hidden")))
char *__getenv(const char *name)
{
char buf[BUFSIZ];
int ret;

ret = _snprintf(buf, sizeof(buf), "IAMROOT_%s", name);
if (ret == -1)
return NULL;

return getenv(buf);
}

__attribute__((visibility("hidden")))
int __setenv(const char *name, const char *value, int overwrite)
{
char buf[BUFSIZ];
int n;

n = _snprintf(buf, sizeof(buf), "IAMROOT_%s", name);
if (n == -1)
return -1;

return setenv(buf, value, overwrite);
}

__attribute__((visibility("hidden")))
int __fissymlinkat(int dfd, const char *path, int atflags)
{
Expand Down Expand Up @@ -187,24 +161,24 @@ int __isfile(const char *path)
__attribute__((visibility("hidden")))
int __getfatal()
{
return strtol(getenv("IAMROOT_FATAL") ?: "0", NULL, 0);
return strtol(_getenv("IAMROOT_FATAL") ?: "0", NULL, 0);
}

__attribute__((visibility("hidden")))
char *__getroot()
{
return getenv("IAMROOT_ROOT");
return _getenv("IAMROOT_ROOT");
}

static inline int __setrootdir(const char *path)
{
if (!path) {
__info("Exiting chroot: '%s'\n", __getrootdir());
return unsetenv("IAMROOT_ROOT");
return _unsetenv("IAMROOT_ROOT");
}

__info("Enterring chroot: '%s'\n", path);
return setenv("IAMROOT_ROOT", path, 1);
return _setenv("IAMROOT_ROOT", path, 1);
}

__attribute__((visibility("hidden")))
Expand Down
4 changes: 2 additions & 2 deletions connect.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Gaël PORTAY
* Copyright 2023-2024 Gaël PORTAY
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
Expand Down Expand Up @@ -47,7 +47,7 @@ int connect(int socket, const struct sockaddr *addr, socklen_t addrlen)
if (siz == -1 && errno == ENAMETOOLONG && __inchroot()) {
char *path;

path = getenv("IAMROOT_PATH_RESOLUTION_AF_UNIX");
path = _getenv("IAMROOT_PATH_RESOLUTION_AF_UNIX");
if (path) {
int n = _snprintf(buf.sun_path, sizeof(buf.sun_path),
"%s/%s", path, buf.sun_path);
Expand Down
Loading

0 comments on commit d538857

Please sign in to comment.