syseventadm.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* syseventadm - command to administer the sysevent.conf registry
* - administers the general purpose event framework
*
* The current implementation of the registry using files in
* are added with the combination of the vendor, publisher, event
* class and subclass strings:
*
* [<vendor>,][<publisher>,][<class>,]sysevent.conf
*
*/
#include <stdio.h>
#include <ctype.h>
#include <dirent.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <door.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <strings.h>
#include <unistd.h>
#include <synch.h>
#include <syslog.h>
#include <thread.h>
#include <limits.h>
#include <locale.h>
#include <assert.h>
#include <libsysevent.h>
#include <zone.h>
#include <sys/sysevent_impl.h>
#include <sys/systeminfo.h>
#include "syseventadm.h"
#include "syseventadm_msg.h"
#ifndef DEBUG
#endif
static char *root_dir = "";
static char *arg_vendor = NULL;
static char *arg_publisher = NULL;
static char *arg_subclass = NULL;
static char *arg_username = NULL;
static int arg_nargs = 0;
static int lock_fd;
extern char *optarg;
extern int optind;
static int
{
"\tsyseventadm add ...\n"
"\tsyseventadm remove ...\n"
"\tsyseventadm list ...\n"
"\tsyseventadm restart\n"
"\tsyseventadm help\n");
return (EXIT_USAGE);
}
static int
{
int c;
int rval;
switch (c) {
case 'R':
/*
* Alternate root path for install, etc.
*/
break;
case 'v':
arg_vendor = optarg;
break;
case 'p':
break;
case 'c':
break;
case 's':
break;
case 'u':
break;
default:
return (usage());
}
}
}
}
rval = restart_cmd();
} else {
}
exit_lock();
return (rval);
}
int
{
char *cmd;
int rval;
(void) textdomain(TEXT_DOMAIN);
} else {
whoami++;
}
if (argc == 1) {
return (usage_gen());
}
/* Allow non-privileged users to get the help messages */
return (rval);
}
if (getuid() != 0) {
}
}
} else {
}
return (rval);
}
static void
enter_lock(char *root_dir)
{
}
if (lock_fd < 0) {
}
goto retry;
}
}
static void
{
}
}
}
static void
set_root_dir(char *dir)
{
}
static char *usage_msg[] = {
"\n"
"\tsyseventadm add [-R <rootdir>] [-v vendor] [-p publisher]\n"
"\t[-c class] [-s subclass] [-u username] path [args]\n"
"\n"
"\tsyseventadm remove [-R <rootdir>] [-v vendor] [-p publisher]\n"
"\t[-c class] [-s subclass] [-u username] [path [args]]\n"
"\n"
"\tsyseventadm list [-R <rootdir>] [-v vendor] [-p publisher]\n"
"\t[-c class] [-s subclass] [-u username] [path [args]]\n"
};
static int
usage()
{
char **msgs;
int i;
for (i = 0; i < sizeof (usage_msg)/sizeof (char *); i++) {
}
return (EXIT_USAGE);
}
static int
add_cmd(void)
{
int need_comma = 0;
int noptions = 0;
int i;
/*
* Subclass is only defined within the context of class.
* For add, path must also be specified.
*/
if (arg_vendor)
noptions++;
if (arg_publisher)
noptions++;
if (arg_class)
noptions++;
return (usage());
}
return (usage());
/*
* Generate the sysevent.conf file name
*/
if (arg_vendor) {
need_comma = 1;
}
if (arg_publisher) {
if (need_comma)
need_comma = 1;
}
if (arg_class) {
if (need_comma)
}
/*
* Prepare the line to be written to the sysevent.conf file
*/
if (arg_nargs) {
for (i = 0; i < arg_nargs; i++) {
}
}
return (EXIT_CMD_FAILED);
}
}
return (EXIT_CMD_FAILED);
}
return (EXIT_CMD_FAILED);
}
return (EXIT_CMD_FAILED);
}
return (EXIT_OK);
}
static int
list_remove_cmd(int cmd)
{
char *suffix;
int list_size = 0;
int list_alloc = 0;
char **p;
int rval;
int result;
/*
* path must be specified. Subclass is only defined within the
* context of a class.
*/
if (cmd == CMD_REMOVE) {
int noptions = 0;
if (arg_vendor)
noptions++;
if (arg_publisher)
noptions++;
if (arg_class)
noptions++;
if (arg_username)
noptions++;
if (arg_path)
noptions++;
return (usage());
}
}
return (EXIT_CMD_FAILED);
}
continue;
continue;
}
}
return (EXIT_CMD_FAILED);
}
if (dirlist) {
switch (cmd) {
case CMD_LIST:
break;
case CMD_REMOVE:
result = remove_file(*p);
break;
}
if (rval == EXIT_NO_MATCH &&
result != EXIT_NO_MATCH)
}
}
return (rval);
}
static int
{
int rval = EXIT_NO_MATCH;
return (EXIT_CMD_FAILED);
}
for (;;) {
break;
if (matches_serecord(sep)) {
}
}
}
return (rval);
}
static int
remove_file(char *fname)
{
char *raw_line;
int is_empty = 1;
return (EXIT_CMD_FAILED);
}
if (check_for_removes(fp) == 0) {
return (EXIT_NO_MATCH);
}
return (EXIT_CMD_FAILED);
}
return (EXIT_CMD_FAILED);
}
return (EXIT_CMD_FAILED);
}
for (;;) {
break;
} else {
if (!matches_serecord(sep)) {
is_empty = 0;
}
}
}
}
if (is_empty) {
return (EXIT_CMD_FAILED);
}
return (EXIT_CMD_FAILED);
}
} else {
return (EXIT_CMD_FAILED);
}
return (EXIT_CMD_FAILED);
}
return (EXIT_CMD_FAILED);
}
}
return (EXIT_OK);
}
static int
{
for (;;) {
break;
if (matches_serecord(sep)) {
return (1);
}
}
}
return (0);
}
static int
{
char *line;
char *lp;
char *token;
int i;
if (arg_vendor &&
return (0);
}
if (arg_publisher &&
return (0);
}
if (arg_class &&
return (0);
}
if (arg_subclass &&
return (0);
}
if (arg_username &&
return (0);
}
if (arg_path &&
return (0);
}
if (arg_nargs > 0) {
for (i = 0; i < arg_nargs; i++) {
return (0);
}
}
}
return (1);
}
static void
{
}
}
}
}
}
}
}
static int
restart_cmd(void)
{
return (EXIT_CMD_FAILED);
}
return (EXIT_OK);
}
static str_t *
{
char *lp;
return (NULL);
}
return (line);
}
static serecord_t *
{
char *lp;
char *user;
return (NULL);
}
return (NULL);
return (NULL);
return (NULL);
return (NULL);
return (NULL);
return (NULL);
return (NULL);
}
return (sep);
}
static void
{
}
/*
* skip_spaces() - skip to next non-space character
*/
static char *
skip_spaces(char **cpp)
{
cp++;
if (*cp == 0) {
*cpp = 0;
return (NULL);
}
return (cp);
}
/*
* Get next white-space separated field.
* next_field() will not check any characters on next line.
* Each entry is composed of a single line.
*/
static char *
next_field(char **cpp)
{
char *start;
cp++;
if (*cp == 0) {
*cpp = 0;
return (NULL);
}
cp++;
if (*cp != 0)
*cp++ = 0;
return (start);
}
/*
* The following functions are simple wrappers/equivalents
* for malloc, realloc, free, strdup and a special free
* for strdup.
*/
static void *
{
void *p;
p = malloc(n);
if (p == NULL) {
no_mem_err();
}
return (p);
}
/*ARGSUSED*/
static void *
{
p = realloc(p, n);
if (p == NULL) {
no_mem_err();
}
return (p);
}
/*ARGSUSED*/
static void
{
free(p);
}
static char *
{
char *new;
no_mem_err();
}
return (new);
}
static void
sc_strfree(char *s)
{
if (s)
free(s);
}
/*
* The following functions provide some simple dynamic string
* capability. This module has no hard-coded maximum string
* lengths and should be able to parse and generate arbitrarily
* long strings, macro expansion and command lines.
*
* Each string must be explicitly allocated and freed.
*/
/*
* Allocate a dynamic string, with a hint to indicate how
* much memory to dynamically add to the string as it grows
* beyond its existing bounds, so as to avoid excessive
* reallocs as a string grows.
*/
static str_t *
{
return (str);
}
/*
* Free a dynamically-allocated string
*/
static void
{
}
}
/*
* Reset a dynamically-allocated string, allows reuse
* rather than freeing the old and allocating a new one.
*/
static void
{
}
/*
* Concatenate a (simple) string onto a dynamically-allocated string
*/
static void
{
char *new_str;
}
}
/*
* Concatenate a character onto a dynamically-allocated string
*/
static void
{
char *new_str;
}
}
/*
* fgets() equivalent using a dynamically-allocated string
*/
static char *
{
int c;
if (c == '\n')
break;
}
return (NULL);
}
#define INITIAL_LISTSIZE 4
#define INCR_LISTSIZE 4
static char **
char **argvlist,
int *size,
int *alloc,
char *str)
{
int n;
if (*alloc == 0) {
n = sizeof (char *) * (*alloc + 1);
no_mem_err();
} else {
*alloc += INCR_LISTSIZE;
n = sizeof (char *) * (*alloc + 1);
no_mem_err();
}
}
*size += 1;
return (argvlist);
}
static void
{
exit_lock();
/*NOTREACHED*/
}