]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/posix-environ: Register and make it compile
authorSimon Kuenzer <simon@unikraft.io>
Thu, 9 Feb 2023 20:54:40 +0000 (21:54 +0100)
committerUnikraft <monkey@unikraft.io>
Sun, 7 May 2023 16:44:41 +0000 (16:44 +0000)
This commit integrates and enables compiling of the imported environment
helper functions (see previous commit).

Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Delia Pavel <delia_maria.pavel@stud.acs.upb.ro>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #868

12 files changed:
lib/Makefile.uk
lib/nolibc/include/stdlib.h
lib/posix-environ/Config.uk [new file with mode: 0644]
lib/posix-environ/Makefile.uk [new file with mode: 0644]
lib/posix-environ/clearenv.c
lib/posix-environ/environ.c [new file with mode: 0644]
lib/posix-environ/environ.h [new file with mode: 0644]
lib/posix-environ/exportsyms.uk [new file with mode: 0644]
lib/posix-environ/getenv.c
lib/posix-environ/putenv.c
lib/posix-environ/setenv.c
lib/posix-environ/unsetenv.c

index 01b8be253c672cb863c9fe0ffa08815ca0b2c0b9..89cda95a565fcd5499b618f798f465cbace9ade1 100644 (file)
@@ -9,6 +9,7 @@ $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/devfs))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/fdt))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/isrlib))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/nolibc))
+$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/posix-environ))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/posix-event))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/posix-libdl))
 $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/posix-mmap))
index 7455152103aefef28fab9cc5b3b51ba83c0fc857..994a93e7d438a928f6c55db808cdac4e53a9b6ac 100644 (file)
@@ -122,6 +122,14 @@ void exit(int status) __noreturn;
 void qsort(void *base, size_t nmemb, size_t size,
            int (*compar)(const void *, const void *));
 
+#if CONFIG_LIBPOSIX_ENVIRON
+int setenv(const char *name, const char *value, int overwrite);
+int unsetenv(const char *name);
+int clearenv(void);
+int putenv(char *string);
+char *getenv(const char *name);
+#endif /* CONFIG_LIBPOSIX_ENVIRON */
+
 #if CONFIG_LIBPOSIX_PROCESS
 int system(const char *command);
 #endif
diff --git a/lib/posix-environ/Config.uk b/lib/posix-environ/Config.uk
new file mode 100644 (file)
index 0000000..b8ecb7e
--- /dev/null
@@ -0,0 +1,4 @@
+config LIBPOSIX_ENVIRON
+       bool "posix-environ: Environment variables"
+       default n
+       select LIBNOLIBC if !HAVE_LIBC
diff --git a/lib/posix-environ/Makefile.uk b/lib/posix-environ/Makefile.uk
new file mode 100644 (file)
index 0000000..9e36517
--- /dev/null
@@ -0,0 +1,8 @@
+$(eval $(call addlib_s,libposix_environ,$(CONFIG_LIBPOSIX_ENVIRON)))
+
+LIBPOSIX_ENVIRON_SRCS-y += $(LIBPOSIX_ENVIRON_BASE)/setenv.c
+LIBPOSIX_ENVIRON_SRCS-y += $(LIBPOSIX_ENVIRON_BASE)/unsetenv.c
+LIBPOSIX_ENVIRON_SRCS-y += $(LIBPOSIX_ENVIRON_BASE)/clearenv.c
+LIBPOSIX_ENVIRON_SRCS-y += $(LIBPOSIX_ENVIRON_BASE)/putenv.c
+LIBPOSIX_ENVIRON_SRCS-y += $(LIBPOSIX_ENVIRON_BASE)/getenv.c
+LIBPOSIX_ENVIRON_SRCS-y += $(LIBPOSIX_ENVIRON_BASE)/environ.c
index 15d302fa176d20a03da538512cb7033bb7cc1991..ab1558c651dba5cec47cc4fe0939f86a83e61d90 100644 (file)
@@ -13,9 +13,7 @@
 #define _GNU_SOURCE
 #include <stdlib.h>
 #include <unistd.h>
-
-static void dummy(char *old, char *new) {}
-weak_alias(dummy, __env_rm_add);
+#include "environ.h"
 
 int clearenv()
 {
diff --git a/lib/posix-environ/environ.c b/lib/posix-environ/environ.c
new file mode 100644 (file)
index 0000000..0ff3a69
--- /dev/null
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/* Copyright (c) 2023, Unikraft GmbH and The Unikraft Authors.
+ * Licensed under the BSD-3-Clause License (the "License").
+ * You may not use this file except in compliance with the License.
+ */
+#include <uk/essentials.h>
+#include "environ.h"
+
+char **__environ = __NULL;
diff --git a/lib/posix-environ/environ.h b/lib/posix-environ/environ.h
new file mode 100644 (file)
index 0000000..ae79157
--- /dev/null
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/* Copyright (c) 2023, Unikraft GmbH and The Unikraft Authors.
+ * Licensed under the BSD-3-Clause License (the "License").
+ * You may not use this file except in compliance with the License.
+ */
+#ifndef __ENVIRON_H__
+#define __ENVIRON_H__
+
+#include <uk/config.h>
+#include <stdlib.h>
+
+extern char **__environ;
+
+int __putenv(char *s, size_t l, char *r);
+void __env_rm_add(char *old, char *new);
+
+#endif /* __ENVIRON_H__ */
diff --git a/lib/posix-environ/exportsyms.uk b/lib/posix-environ/exportsyms.uk
new file mode 100644 (file)
index 0000000..b2a9dc0
--- /dev/null
@@ -0,0 +1,6 @@
+setenv
+unsetenv
+clearenv
+putenv
+getenv
+__environ
index ae9b30788bc01f9ef26731986d41775a14896756..16fc82229621dceaf01ffad9df68209e5856ef1e 100644 (file)
  * File: src/env/getenv.c
  */
 
+#define _GNU_SOURCE
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include "environ.h"
 
 char *getenv(const char *name)
 {
-       size_t l = __strchrnul(name, '=') - name;
+       size_t l = strchrnul(name, '=') - name;
        if (l && !name[l] && __environ)
                for (char **e = __environ; *e; e++)
                        if (!strncmp(name, *e, l) && l[*e] == '=')
index dfa7b692152c8b01b3758b205e6822b5f2d49833..7a0cee18d5a64c512f0ec74e93f7f1bf968b116f 100644 (file)
  * File: src/env/putenv.c
  */
 
+#define _GNU_SOURCE
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-
-static void dummy(char *old, char *new) {}
-weak_alias(dummy, __env_rm_add);
+#include "environ.h"
 
 int __putenv(char *s, size_t l, char *r)
 {
@@ -52,7 +51,7 @@ oom:
 
 int putenv(char *s)
 {
-       size_t l = __strchrnul(s, '=') - s;
+       size_t l = strchrnul(s, '=') - s;
        if (!l || !s[l]) return unsetenv(s);
        return __putenv(s, l, 0);
 }
index bfcb13cd65a9fdf3fc2f5ee7ee086e22171c381e..4de28d7c813c1153fedae6dee182583b7ffeea66 100644 (file)
  * File: src/env/setenv.c
  */
 
+#define _GNU_SOURCE
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include "environ.h"
 
 void __env_rm_add(char *old, char *new)
 {
@@ -38,7 +40,7 @@ int setenv(const char *var, const char *value, int overwrite)
        char *s;
        size_t l1, l2;
 
-       if (!var || !(l1 = __strchrnul(var, '=') - var) || var[l1]) {
+       if (!var || !(l1 = strchrnul(var, '=') - var) || var[l1]) {
                errno = EINVAL;
                return -1;
        }
index 99c045dbf59e955fd620aaa4a8678c3b0cd4eae1..963a9fb5d7e3143104e54c2fa900a7d0be52eb03 100644 (file)
  * File: src/env/unsetenv.c
  */
 
+#define _GNU_SOURCE
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
 #include <unistd.h>
-
-static void dummy(char *old, char *new) {}
-weak_alias(dummy, __env_rm_add);
+#include "environ.h"
 
 int unsetenv(const char *name)
 {
-       size_t l = __strchrnul(name, '=') - name;
+       size_t l = strchrnul(name, '=') - name;
        if (!l || name[l]) {
                errno = EINVAL;
                return -1;