/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <libcontract.h>
#include <libcontract_priv.h>
#include <libuutil.h>
#include <poll.h>
#include <port.h>
#include <signal.h>
#include <stdarg.h>
#include <locale.h>
#include <langinfo.h>
struct {
const char *name;
int found;
} types[] = {
{ "process", 0 },
{ "device", 0 },
{ NULL }
};
typedef struct watched_fd {
int wf_fd;
int wf_type;
} watched_fd_t;
/*
* usage
*
* Educate the user.
*/
static void
usage(void)
{
"Usage: %s [-f] [-r] [-v] contract-id | contract-type ...\n"),
uu_getpname());
}
/*
* sopen
*
* Given a format string and a variable number of arguments, create a
* file name and open it. Warn with 'permerror' and return -1 if
* opening the file returned EPERM or EACCES, die with 'error' on all
* other error conditions.
*/
static int
{
int fd;
}
else
}
return (fd);
}
/*
* hdr_event
*
* Display the output header.
*/
static void
hdr_event(void)
{
(void) printf("%-8s%-8s%-5s%-4s%-9s%s\n",
"CTID", "EVID", "CRIT", "ACK", "CTTYPE", "SUMMARY");
}
/*
* get_event
*
* Read and display a contract event.
*/
static int
{
/*
* Read a contract event.
*/
return (0);
}
/*
* Emit a one-line event summary.
*/
(void) printf("%-8ld%-8lld%-5s%-4s%-9s",
/*
* Display event details, if requested.
* (Since this is also needed by ctrun, the common
* contract_event_dump is found in libcontract.)
*/
return (1);
}
/*
* get_type
*
* Given a contract type name, return an index into the 'types' array.
* Exits on failure.
*/
static int
{
int i;
return (i);
/* NOTREACHED */
}
/*
* contract_type
*
* Given a contract id, return an index into the 'types' array.
* Returns -1 on failure.
*/
static int
{
/*
* This could be faster (e.g. by reading the link itself), but
* this is the most straightforward implementation.
*/
return (-1);
return (-1);
}
return (type);
}
/*
* ctid_compar
*
* A simple contract ID comparator.
*/
static int
{
return (1);
return (-1);
return (0);
}
int
{
int opt_reliable = 0;
int opt_reset = 0;
int opt_verbose = 0;
int port_fd;
(void) textdomain(TEXT_DOMAIN);
(void) uu_setpname(argv[0]);
switch (i) {
case 'r':
opt_reliable = 1;
break;
case 'f':
opt_reset = 1;
break;
case 'v':
opt_verbose = 1;
break;
default:
usage();
}
}
if (argc <= 0)
usage();
uu_die("calloc");
uu_die("calloc");
/*
* Scan our operands for contract ids and types.
*/
nfds = 0;
nids = 0;
for (i = 0; i < argc; i++) {
int id;
/*
* If argument isn't a number between 0 and INT_MAX,
* treat it as a contract type.
*/
int type;
argv[i]);
continue;
}
nfds++;
} else {
}
}
/*
* Eliminate those contract ids which are represented by
* contract types, so we don't get duplicate event reports from
* them.
*
* Sorting the array first allows us to efficiently skip
* duplicate ids. We know that the array only contains
* integers [0, INT_MAX].
*/
last = -1;
for (i = 0; i < nids; i++) {
continue;
gettext("invalid contract id: %d\n"),
if (fd == -1)
continue;
ids[i]);
continue;
}
continue;
}
nfds++;
}
if (nfds == 0)
/*
* Handle options.
*/
if (opt_reliable)
for (i = 0; i < nfds; i++)
uu_warn("could not request reliable events");
break;
}
if (opt_reset)
for (i = 0; i < nfds; i++)
/*
* Allocate an event point, and associate all our endpoint file
* descriptors with it.
*/
goto port_error;
for (i = 0; i < nfds; i++)
goto port_error;
/*
* Loop waiting for and displaying events.
*/
hdr_event();
for (;;) {
watched_fd_t *w;
continue;
goto port_error;
}
w = pe.portev_user;
;
goto port_error;
}
return (1); /* placate cc */
}