/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <assert.h>
#include <libuutil.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <zone.h>
#include "startd.h"
/*
* This file contains functions for setting the environment for
* processes started by svc.startd.
*/
/*
* init_env()
* A clone of the work init.c does to provide as much compatibility
* for startup scripts as possible.
*/
void
init_env()
{
int i;
char **newp;
glob_env_n = 16;
uu_warn("Cannot open %s. Environment not initialized.\n",
ENVFILE);
return;
}
i = 1;
/*
* Toss newline
*/
/*
* Ignore blank or comment lines.
*/
continue;
/*
* First make a pass through the line and change
* any non-quoted semi-colons to blanks so they
* will be treated as token separators below.
*/
inquotes = 0;
if (*cp1 == '"') {
if (inquotes == 0)
inquotes = 1;
else
inquotes = 0;
} else if (*cp1 == ';') {
if (inquotes == 0)
*cp1 = ' ';
}
}
/*
* Tokens within the line are separated by blanks
* and tabs. For each token in the line which
* contains a '=' we strip out any quotes and then
* stick the token in the environment array.
*/
continue;
do {
continue;
length--;
}
/*
* init already started us with this umask, and we
* handled it in startd.c, so just skip it.
*/
continue;
/*
* Double the environment size whenever it is
* full.
*/
if (++i == glob_env_n) {
glob_env_n *= 2;
}
}
/* Append a null pointer to the environment array to mark its end. */
/*
* Get the zonename once; it is used to set SMF_ZONENAME for methods.
*/
}
static int
{
"variable \"%s\".", var);
return (0);
"variable \"%s\"; \"SMF_\" prefix is reserved.",
var);
return (0);
return (0);
}
return (1);
}
static char **
{
char **p;
char *tmp;
tmp++;
break;
}
if (*p == NULL)
return (NULL);
/*
* The first entry in the array can be ignored when it is the
* default path.
*/
"environment variable \"%s\".", *p);
}
return (p);
}
/*
* Create an environment which is appropriate for spawning an SMF
* aware process. The new environment will consist of the values from
* the global environment as modified by the supplied (local) environment.
*
* In order to preserve the correctness of the new environment,
* various checks are performed on the local environment (init_env()
* is relied upon to ensure the global environment is correct):
*
* - All SMF_ entries are ignored. All SMF_ entries should be provided
* by this function.
* - Duplicates in the entry are eliminated.
* - Malformed entries are eliminated.
*
* Detected errors are logged as warnings to the appropriate instance
* logfile, since a single bad entry should not be enough to prevent
* an SMF_ functional environment from being created. The faulty entry
* is then ignored when building the environment.
*
* If env is NULL, then the return is an environment which contains
* all default values.
*
* If "path" is non-NULL, it will silently over-ride any previous
* PATH environment variable.
*
* NB: The returned env and strings are allocated using startd_alloc().
*/
char **
{
char **nenv;
char **p, **np;
/*
* Max. of glob_env, env, four SMF_ variables,
* path, and terminating NULL.
*/
np++;
}
if (inst) {
np++;
}
if (method) {
np++;
}
np++;
np++;
np++;
}
}
if (env) {
char **dup_pos;
continue;
} else {
np++;
}
}
}
return (nenv);
}