]> xenbits.xensource.com Git - unikraft/libs/python3.git/commitdiff
Add init.c for initialization
authorVlad-Andrei Badoiu <vlad_andrei.badoiu@stud.acs.upb.ro>
Wed, 16 Oct 2019 14:22:41 +0000 (17:22 +0300)
committerCostin Lupu <costin.lupu@cs.pub.ro>
Thu, 17 Oct 2019 12:26:37 +0000 (15:26 +0300)
This patch sets the environment variables that are needed during runtime for
the intepreter.

Signed-off-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@stud.acs.upb.ro>
Signed-off-by: Costin Lupu <costin.lupu@cs.pub.ro>
Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>
Config.uk
Makefile.uk
init.c [new file with mode: 0644]

index b6dab404643d48f93d716390c8f36022657281d3..530efbe59363942630e1fb1a88277b3ecb780c30 100644 (file)
--- a/Config.uk
+++ b/Config.uk
@@ -19,4 +19,17 @@ menuconfig LIBPYTHON3
        select LWIP_IPV6
 
 if LIBPYTHON3
+
+config LIBPYTHON3_PYTHONHOME
+       string "Python home directory"
+       default "/lib/python3.7"
+
+config LIBPYTHON3_PYTHONPATH
+       string "Python path"
+       default "/lib/python3.7"
+
+config LIBPYTHON3_TMPDIR
+       string "Temp directory location"
+       default "/tmp"
+
 endif
index e7c8b179783e3c911027595aa5d65d7af3a6b47b..d20fb22596f88feb0ac4350b68b68fa4641f4f5e 100644 (file)
@@ -97,6 +97,7 @@ LIBPYTHON3_COMMON_CXXFLAGS-y += $(LIBPYTHON3_COMMON_DEFINES-y)
 LIBPYTHON3_CINCLUDES-y   += $(LIBPYTHON3_COMMON_INCLUDES-y)
 LIBPYTHON3_CXXINCLUDES-y += $(LIBPYTHON3_COMMON_INCLUDES-y)
 
+LIBPYTHON3_SRCS-y += $(LIBPYTHON3_BASE)/init.c|unikraft
 LIBPYTHON3_SRCS-y += $(LIBPYTHON3_BASE)/modules_config.c|unikraft
 LIBPYTHON3_SRCS-y += $(LIBPYTHON3_BASE)/stubs.c|unikraft
 
diff --git a/init.c b/init.c
new file mode 100644 (file)
index 0000000..bc06279
--- /dev/null
+++ b/init.c
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Badoiu Vlad-Andrei <vlad_andrei.badoiu@stud.acs.upb.ro>
+ *
+ * Copyright (c) 2019, University Politehnica of Bucharest. 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 copyright holder 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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 HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
+#include <uk/config.h>
+#include <uk/essentials.h>
+#include <stdlib.h>
+
+void __constructor python_init(void)
+{
+       setenv("PYTHONHOME", CONFIG_LIBPYTHON3_PYTHONHOME, 0);
+       setenv("PYTHONPATH", CONFIG_LIBPYTHON3_PYTHONPATH, 0);
+       setenv("PYTHONUSERBASE", "site-packages", 0);
+       setenv("TMPDIR", CONFIG_LIBPYTHON3_TMPDIR, 0);
+       setenv("_PYTHON_SYSCONFIGDATA_NAME", "_sysconfigdata", 0);
+}