Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 2 Apr 1997 15:54:05 -0700 (MST)
From:      Terry Lambert <terry@lambert.org>
To:        jkh@time.cdrom.com (Jordan K. Hubbard)
Cc:        terry@lambert.org, avalon@coombs.anu.edu.au, proff@suburbia.net, hackers@freebsd.org
Subject:   Re: devfs
Message-ID:  <199704022254.PAA14823@phaeton.artisoft.com>
In-Reply-To: <17949.860020385@time.cdrom.com> from "Jordan K. Hubbard" at Apr 2, 97 02:33:05 pm

next in thread | previous in thread | raw e-mail | index | archive | help
> And besides, if I were going to redo environment handling, I wouldn't
> just shove the default environment handling into the kernel and yell
> "Done!", I'd implement a whole multi-tier namespace with process
> local, group local and systemwide logical names.  Why bother adding
> more abstraction to that mechanism otherwise?  All that work just to
> achieve an equivalent status quo (with variant symlinks as the only
> added benefit) would be just silly.

What you are asking for doesn't require "terrible forethought and
consideration"... it's FREE FREE FREE with the most obvious and
simplistic implementation!


The group and system LNM's are trivial; the automatically fall out of
the design:

Process LNM's:	The environment space hung off the calling process

Group LNM's:	The environment space hung off the process group
		leader for the calling process

System LNM's:	The environment hung off the "init" process.



For backward compatability, all you have to do is add a wrapper
that specifies "ANY" on getenv and "PROCESS" on setenv/unsetenv.


Here's the replacement getenv.c and syslnm.h header... like I said,
*TRIVIAL*.  It's pretty darn obvious that you can implement the
syslnm() call by migrating most of the existing libc environment
code down.

If you want to pass down a pid_t instead of a lnm_type_t, and call
getpgrp() explicitly for "LNM_TYPE_GROUP" and pass an explicit 1 for
"LNM_TYPE_SYSTEM", you can solve the "get/modify the parent/other
environment" problem at the same time.   I would recommend doing that,
but didn't want to clutter up the initial rev. of the syslnm.h header
with inline functions to do the conversion between constants.

You may need to add an "LNM_CMD_GET_ENVP" to get a command to user
space for use with the execve(2) envp argument, assuming you don't
move that to execve(3) and keep POSIX compatability that way.

*ANY* brain-damaged code hack should be able to do this in a day,
including all necessary testing... hell, it didn't take me that
long to write everything, including the library replacements, so
I'm giving you a head start.


PS: if you need the changes to namei() for variant symbolic links,
    ask me nicely, and I will disentangle them from my other changes
    to namei() for layering fixes, Unicode, and alternate namespace
    support (used by a modified (CIFS enhanced) Samba server which
    needs to have the DOS short name remain constant across directory
    searches).


					Regards,
					Terry Lambert
					terry@lambert.org
---
Any opinions in this posting are my own and not those of my present
or previous employers.

--- BEGIN syslnm.h -----------------------------------------------------
/*
 * Copyright (c) 1996
 *	Terrence Lambert.  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. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by Terrence Lambert.
 * 4. Neither the name of the author nor the names of subsequent contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * 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.
 */

#ifndef _SYSLNM_H_
#define _SYSLNM_H_

/*
 * Length of static buffer for getenv(3) data returns
 */
#define	LNM_MAX_GET	1024		/* 1k max for using getenv()*/


/*
 * Command codes
 */
typedef enum {
	LNM_CMD_GET,			/* get a logical name*/
	LNM_CMD_SET,			/* set a logical name*/
	LNM_CMD_UNSET			/* unset a logical name*/
} lnm_cmd_t;


/*
 * Flags
 */
typedef enum {
	LNM_FLAG_NONE = 0,		/* no flags*/
	LNM_FLAG_INHERIT,		/* in inheritance order*/
	LNM_FLAG_REPLACE,		/* replace if existing*/
} lnm_flag_t;


/*
 * Tables (bitmap)
 */
typedef enum {
	LNM_TYPE_PROCESS	= 0x01,	/* process logical name table*/
	LNM_TYPE_GROUP		= 0x02,	/* group logical name table*/
	LNM_TYPE_SYSTEM		= 0x04,	/* system logical name table*/
	LNM_TYPE_ANY		= 0x07	/* any logical name table*/
} lnm_type_t;


/*
 * Structures for commands
 */
struct lnm_get_arg {
	char		*name;		/* name to get*/
	char		*buf;		/* return buffer*/
	int		bufsize;	/* return buffer size*/
	lnm_flags_t	flags;		/* option flags*/
	lnm_type_t	table;		/* table(s) to involve*/
};


struct lnm_set_arg {
	char		*name;		/* name to set*/
	char		*buf;		/* value buffer*/
	lnm_flags_t	flags;		/* option flags*/
	lnm_type_t	table;		/* table(s) to involve*/
};


struct lnm_del_arg {
	char		*name;		/* name to set*/
	lnm_flags_t	flags;		/* option flags*/
	lnm_type_t	table;		/* table(s) to involve*/
};


#endif	/* _SYSLNM_H_*/

/*
 * EOF
 */
--- END syslnm.h -------------------------------------------------------
--- BEGIN getenv.c -----------------------------------------------------
/*
 * Copyright (c) 1996, Terrence Lambert
 * 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. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by Terrence Lambert.
 * 4. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * 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$
 */
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)getenv.c	1.0 (Lambert) 22 Jun 1996";
#endif /* LIBC_SCCS and not lint */

#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <syslnm.h>

/*
 * getenv --
 *	Returns ptr to value associated with name, if any, else NULL.
 */
char *
getenv(name)
	const char *name;
{
	static char		ret[ LNM_GET_MAX];
	struct lnm_get_arg	get;

	get.name	= name;			/* name to get*/
	get.buf		= ret;			/* store it here*/
	get.bufsize	= LNM_MAX_GET;		/* max of this many*/
	get.flags	= LNM_FLAG_INHERIT;	/* inherit values*/
	get.table	= LNM_TYPE_ANY;		/* name table to use*/

	if( syslnm( LNM_CMD_GET, (caddr_t)&get))
		return( NULL);
	else	return( ret);
}


int
putenv(str)
	const char *str;
{
	struct lnm_set_arg	set;
	char *p, *equal;
	int rval;

	if ((p = strdup(str)) == NULL)
		return (-1);
	if ((equal = index(p, '=')) == NULL) {
		(void)free(p);
		return (-1);
	}
	*equal = '\0';

	set.name	= name;			/* name to set*/
	set.buf		= equal + 1;		/* value to assign*/
	set.flags	= LNM_FLAG_REPLACE;	/* replae if exists*/
	set.table	= LNM_TYPE_PROCESS;	/* process name table*/

	rval = syslnm( LNM_CMD_SET, (caddr_t)&set);
	(void)free(p);
	return (rval);
}


/*
 * setenv --
 *	Set the value of the environmental variable "name" to be
 *	"value".  If rewrite is set, replace any current value.
 */
setenv(name, value, rewrite)
	register const char *name;
	register const char *value;
	int rewrite;
{
	struct lnm_set_arg	set;

	set.name	= name;			/* name to set*/
	set.buf		= value;		/* value to assign*/
	set.flags	=
	  ( rewrite ? LNM_FLAG_REPLACE : 0);	/* conditionally replace*/
	set.table	= LNM_TYPE_PROCESS;	/* process name table*/

	return( syslnm( LNM_CMD_SET, (caddr_t)&set));
}


/*
 * unsetenv(name) --
 *	Delete environmental variable "name".
 */
void
unsetenv(name)
	const char *name;
{
	struct lnm_del_arg	del;

	del.name	= name;			/* name to delete*/
	del.flags	= 0;			/* no flags*/
	del.table	= LNM_TYPE_PROCESS;	/* delete from process*/

	(void)syslnm( LNM_CMD_UNSET, (caddr_t)&del);
}

/*
 * EOF
 */
--- END getenv.c -------------------------------------------------------



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199704022254.PAA14823>