summaryrefslogtreecommitdiffstats
path: root/sys/sys
diff options
context:
space:
mode:
authormux <mux@FreeBSD.org>2002-04-17 13:06:36 +0000
committermux <mux@FreeBSD.org>2002-04-17 13:06:36 +0000
commita207e41bef089b8849a230f44088a562d0b5d19f (patch)
treecb447f9f2a04a764ece9fcefc6fa6b52d19870b8 /sys/sys
parentc79270302c4767b589a4fe70da3ba9866936358f (diff)
downloadFreeBSD-src-a207e41bef089b8849a230f44088a562d0b5d19f.zip
FreeBSD-src-a207e41bef089b8849a230f44088a562d0b5d19f.tar.gz
Rework the kernel environment subsystem. We now convert the static
environment needed at boot time to a dynamic subsystem when VM is up. The dynamic kernel environment is protected by an sx lock. This adds some new functions to manipulate the kernel environment : freeenv(), setenv(), unsetenv() and testenv(). freeenv() has to be called after every getenv() when you have finished using the string. testenv() only tests if an environment variable is present, and doesn't require a freeenv() call. setenv() and unsetenv() are self explanatory. The kenv(2) syscall exports these new functionalities to userland, mainly for kenv(1). Reviewed by: peter
Diffstat (limited to 'sys/sys')
-rw-r--r--sys/sys/kenv.h43
-rw-r--r--sys/sys/syscall.h3
-rw-r--r--sys/sys/syscall.mk3
-rw-r--r--sys/sys/sysproto.h7
-rw-r--r--sys/sys/systm.h9
5 files changed, 63 insertions, 2 deletions
diff --git a/sys/sys/kenv.h b/sys/sys/kenv.h
new file mode 100644
index 0000000..0a30ddb
--- /dev/null
+++ b/sys/sys/kenv.h
@@ -0,0 +1,43 @@
+/*-
+ * Copyright (c) 2002 Maxime Henrion <mux@FreeBSD.org>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _SYS_KENV_H_
+#define _SYS_KENV_H_
+
+/*
+ * Constants for the kenv(2) syscall
+ */
+#define KENV_GET 0
+#define KENV_SET 1
+#define KENV_UNSET 2
+#define KENV_DUMP 3
+
+#define KENV_MNAMELEN 128 /* Maximum name length (for the syscall) */
+#define KENV_MVALLEN 128 /* Maximum value length (for the syscall) */
+
+#endif /* !_SYS_KENV_H_ */
diff --git a/sys/sys/syscall.h b/sys/sys/syscall.h
index fb693c6..c336453 100644
--- a/sys/sys/syscall.h
+++ b/sys/sys/syscall.h
@@ -303,4 +303,5 @@
#define SYS_kse_new 381
#define SYS_thread_wakeup 382
#define SYS_kse_yield 383
-#define SYS_MAXSYSCALL 390
+#define SYS_kenv 390
+#define SYS_MAXSYSCALL 391
diff --git a/sys/sys/syscall.mk b/sys/sys/syscall.mk
index 3d67b4e..4c25a9e 100644
--- a/sys/sys/syscall.mk
+++ b/sys/sys/syscall.mk
@@ -252,4 +252,5 @@ MIASM = \
kse_wakeup.o \
kse_new.o \
thread_wakeup.o \
- kse_yield.o
+ kse_yield.o \
+ kenv.o
diff --git a/sys/sys/sysproto.h b/sys/sys/sysproto.h
index 1f4b987..80385c0 100644
--- a/sys/sys/sysproto.h
+++ b/sys/sys/sysproto.h
@@ -1105,6 +1105,12 @@ struct thread_wakeup_args {
struct kse_yield_args {
register_t dummy;
};
+struct kenv_args {
+ char what_l_[PADL_(int)]; int what; char what_r_[PADR_(int)];
+ char name_l_[PADL_(const char *)]; const char * name; char name_r_[PADR_(const char *)];
+ char value_l_[PADL_(char *)]; char * value; char value_r_[PADR_(char *)];
+ char len_l_[PADL_(int)]; int len; char len_r_[PADR_(int)];
+};
int nosys(struct thread *, struct nosys_args *);
void sys_exit(struct thread *, struct sys_exit_args *);
int fork(struct thread *, struct fork_args *);
@@ -1354,6 +1360,7 @@ int kse_wakeup(struct thread *, struct kse_wakeup_args *);
int kse_new(struct thread *, struct kse_new_args *);
int thread_wakeup(struct thread *, struct thread_wakeup_args *);
int kse_yield(struct thread *, struct kse_yield_args *);
+int kenv(struct thread *, struct kenv_args *);
#ifdef COMPAT_43
diff --git a/sys/sys/systm.h b/sys/sys/systm.h
index e3d3602..1bcbf79 100644
--- a/sys/sys/systm.h
+++ b/sys/sys/systm.h
@@ -45,6 +45,7 @@
#include <machine/atomic.h>
#include <machine/cpufunc.h>
#include <sys/callout.h>
+#include <sys/queue.h>
extern int securelevel; /* system security level (see init(8)) */
extern int suser_enabled; /* suser() is permitted to return 0 */
@@ -90,10 +91,14 @@ extern int maxusers; /* system tune hint */
*/
extern int envmode;
extern int hintmode; /* 0 = off. 1 = config, 2 = fallback */
+extern int dynamic_kenv;
+extern struct sx kenv_lock;
extern char *kern_envp;
extern char static_env[];
extern char static_hints[]; /* by config for now */
+extern char **kenvp;
+
/*
* General function declarations.
*/
@@ -201,9 +206,13 @@ int cr_cansee(struct ucred *u1, struct ucred *u2);
int cr_canseesocket(struct ucred *cred, struct socket *so);
char *getenv(const char *name);
+void freeenv(char *env);
int getenv_int(const char *name, int *data);
int getenv_string(const char *name, char *data, int size);
int getenv_quad(const char *name, quad_t *data);
+void setenv(const char *name, const char *value);
+int unsetenv(const char *name);
+int testenv(const char *name);
#ifdef APM_FIXUP_CALLTODO
struct timeval;
OpenPOWER on IntegriCloud