/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/contract.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <limits.h>
#include <libuutil.h>
#include <libcontract.h>
#include <libcontract_priv.h>
#include <locale.h>
#include <langinfo.h>
static int opt_verbose;
static int opt_Verbose;
typedef struct optvect {
const char *opt_name;
} optvect_t;
{ "noorphan", CT_PR_NOORPHAN },
{ "pgrponly", CT_PR_PGRPONLY },
{ "regent", CT_PR_REGENT },
{ "inherit", CT_PR_INHERIT },
{ NULL }
};
{ NULL }
};
typedef enum lifetime {
} lifetime_t;
/*
* Exit code to use when the child exited abnormally (i.e. exited with
* a status we are unable to emulate).
*/
#define USAGESTR \
"Usage: %s [-i eventlist] [-f eventlist] [-l lifetime] \n" \
"\t[-o optionlist] [-r count [-t]] [-v]\n" \
"\t[-F fmri] [-A aux] command\n"
/*
* usage
*
* Educate the user.
*/
static void
usage(void)
{
}
/*
* bit2str
*
* Convert a bit into its string representation.
*/
static const char *
{
return (NULL);
}
/*
* str2bit
*
* Convert a string into its bit representation. If match is set, only
* look at those options with the match bit set in its opt_flags
* field.
*/
static uint_t
{
continue;
}
return (0);
}
/*
* opt2bits
*
* Given a set of textual options separated by commas or spaces,
* convert them to a set of bits. Errors are fatal, except for empty
* options (which are ignored) and duplicate options (which are
* idempotent).
*/
static void
{
int none = 0;
while (*str) {
int len;
} else {
}
if (len == 0) {
bit = 0;
} else {
none = 1;
if (result)
goto noneerr;
} else if (bit == 0) {
c);
usage();
} else if (none) {
goto noneerr;
}
}
}
return;
usage();
}
/*
* close_on_exec
*
* Given a fd, marks it close-on-exec.
*/
static int
{
return (0);
return (-1);
}
/*
* v_printf
*
* Output routine for messages printed only when -v is specified.
*/
/* PRINTFLIKE1 */
static void
{
if (opt_verbose) {
}
}
/*
* get_event
*
* Reads and acknowledges an event. Returns the event type.
*/
static uint_t
{
for (;;) {
int efd;
/*
* Normally we only need to look at critical messages.
* If we are displaying contract events, however, we
* have to read them all.
*/
if (errno != 0)
/*
* If requested, display the event.
*/
if (opt_verbose) {
continue;
}
}
/*
* We're done if this event is one of ours.
*/
break;
/*
* ACK events from other contracts.
* This shouldn't happen, but it could.
*/
O_WRONLY);
if (efd != -1) {
}
}
/*
* Note that if we want to use ctrun as a simple restarter, we
* need persistently keep track of fatal events so we can
* properly handle the death of the contract. Rather than keep
* a file or somesuch lying around, it might make more sense to
* leave the significant fatal event sitting in the queue so
* that a restarted instance of ctrun can pick it up. For now
* we'll just ACK all events.
*/
return (result);
}
/*
* abandon
*
* Given an fd for a contract's ctl file, abandon the contract and
* close the file.
*/
static void
{
}
static int chldstat;
static int chldexited;
/*
* sigchld
*
* Our SIGCHLD handler. Sets chldstat and chldexited so the
* interrupted code knows what happened.
*/
/*ARGSUSED*/
static void
{
else
chldexited = 1;
;
}
/*
* dowait
*
* Waits for the specified child to exit. Returns the exit code ctrun
* should return.
*/
static int
{
int wstatus;
do
if (wpid == -1)
return (WEXITSTATUS(wstatus));
else
return (EXIT_BADCHILD);
}
int
{
int ctfd;
int s;
int opt_transfer = 0;
(void) textdomain(TEXT_DOMAIN);
(void) uu_setpname(argv[0]);
switch (s) {
case 'a':
0, 0, INT32_MAX) == -1) {
optarg);
usage();
}
break;
case 'v':
opt_verbose = 1;
break;
case 'V':
opt_Verbose = 1;
opt_verbose = 1;
break;
case 't':
opt_transfer = 1;
break;
case 'r':
0, 0, INT32_MAX) == -1) {
optarg);
usage();
}
break;
case 'l':
} else {
optarg);
usage();
}
break;
case 'o':
optopt);
break;
case 'i':
optopt);
break;
case 'c':
optopt);
break;
case 'f':
optopt);
break;
case 'F':
break;
case 'A':
break;
default:
usage();
}
}
/*
* Basic argument sanity checks.
*/
usage();
}
usage();
}
usage();
}
usage();
}
if (argc <= 0)
usage();
/*
* Create a process contract template and our process's process
* contract bundle endpoint. Mark them close-on-exec so we
* don't have to worry about closing them in our child.
*/
if (fd == -1)
if (efd == -1)
/*
* Set the process contract's terms based on our arguments.
*/
if (opt_param & CT_PR_PGRPONLY)
else
"insufficient privileges\n"));
/*
* Activate the template.
*/
if (opt_adopt) {
/*
* Adopt a specific contract.
*/
int stfd;
O_WRONLY)) == -1)
/*
* Read the contract's terms so that we interpret its
* events properly.
*/
O_RDONLY)) == -1) ||
opt_adopt = 0;
} else {
/*
* Create a new process.
*/
if (opt_life == LT_CONTRACT) {
/*
* Since we are going to be waiting for and
* reacting to contract events, install a
* signal handler so we capture the exit status
* of our child.
*/
chldexited = 0;
"sigchld handler"));
/*
* Though we aren't waiting for our child to
* exit, as a well-behaved command launcher we
* must wait for it to exec. On success the
* pipe will simply close, and on failure the
* proper exit status will be sent.
*/
}
} else if (pid == 0) {
char a = 1;
}
if (result == -1)
gettext("exec failed"));
}
/*
* Get the newly-created contract's id and ctl fd.
*/
O_WRONLY)) == -1)
/*
* Clear the transfer parameter so that the contract
* will be freed sooner and admins won't get nervous.
*/
if (opt_transfer) {
(void) ct_pr_tmpl_set_transfer(fd, 0);
(void) ct_tmpl_activate(fd);
}
}
if (opt_life == LT_CONTRACT) {
/*
* Wait until the contract empties out.
*/
do {
if ((eff_param & CT_PR_PGRPONLY) == 0)
"fatal \"%s\" event from contract %ld\n"),
}
} while ((event & CT_PR_EV_EMPTY) == 0);
/*
* If we encountered a fatal error event, and we
* haven't expended our maximum loop count, restart.
*/
if ((errevent != 0) &&
"restarting command\n"), ctid);
if (opt_transfer) {
/*
* Add the failed contract to the new
* contract's terms so that its
* inherited subcontracts can be
* adopted by the new process.
*/
"template activate failed"));
} else {
}
goto restart;
}
/*
* At this point we are done with the contract; we
* don't want it to be inherited when we exit.
*/
/*
* In case there was a race between SIGCHLD delivery
* and contract event delivery, disable the signal
* handler and look for the child.
*/
if (chldexited == 0)
char a;
int result;
do {
if (result == 1)
} while (result == -1);
} else {
}
return (chldstat);
}