17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*c6fc6dddSEric Schrock * Common Development and Distribution License (the "License"). 6*c6fc6dddSEric Schrock * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*c6fc6dddSEric Schrock * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _SYSEVENTADM_H 277c478bd9Sstevel@tonic-gate #define _SYSEVENTADM_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #ifdef __cplusplus 307c478bd9Sstevel@tonic-gate extern "C" { 317c478bd9Sstevel@tonic-gate #endif 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate /* 347c478bd9Sstevel@tonic-gate * Directory where sysevent.conf files reside 357c478bd9Sstevel@tonic-gate */ 367c478bd9Sstevel@tonic-gate #define SYSEVENT_CONFIG_DIR "/etc/sysevent/config" 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate /* 397c478bd9Sstevel@tonic-gate * Lock file name to serialize registry updates 407c478bd9Sstevel@tonic-gate */ 41*c6fc6dddSEric Schrock #define LOCK_FILENAME "/var/run/syseventconf.lock" 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate /* 447c478bd9Sstevel@tonic-gate * Required suffix for all sysevent.conf files 457c478bd9Sstevel@tonic-gate */ 467c478bd9Sstevel@tonic-gate #define SYSEVENT_CONF_SUFFIX ",sysevent.conf" 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate /* 497c478bd9Sstevel@tonic-gate * cmd types for list/remove 507c478bd9Sstevel@tonic-gate */ 517c478bd9Sstevel@tonic-gate #define CMD_LIST 0 527c478bd9Sstevel@tonic-gate #define CMD_REMOVE 1 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate /* 557c478bd9Sstevel@tonic-gate * Exit codes 567c478bd9Sstevel@tonic-gate */ 577c478bd9Sstevel@tonic-gate #define EXIT_OK 0 587c478bd9Sstevel@tonic-gate #define EXIT_NO_MATCH 1 597c478bd9Sstevel@tonic-gate #define EXIT_USAGE 2 607c478bd9Sstevel@tonic-gate #define EXIT_PERM 3 617c478bd9Sstevel@tonic-gate #define EXIT_CMD_FAILED 4 627c478bd9Sstevel@tonic-gate #define EXIT_NO_MEM 5 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate /* 657c478bd9Sstevel@tonic-gate * sysevent.conf record 667c478bd9Sstevel@tonic-gate */ 677c478bd9Sstevel@tonic-gate typedef struct serecord { 687c478bd9Sstevel@tonic-gate char *se_vendor; /* vendor */ 697c478bd9Sstevel@tonic-gate char *se_publisher; /* publisher */ 707c478bd9Sstevel@tonic-gate char *se_class; /* event class */ 717c478bd9Sstevel@tonic-gate char *se_subclass; /* event subclass */ 727c478bd9Sstevel@tonic-gate char *se_user; /* user */ 737c478bd9Sstevel@tonic-gate char *se_reserved1; /* reserved1 */ 747c478bd9Sstevel@tonic-gate char *se_reserved2; /* reserved2 */ 757c478bd9Sstevel@tonic-gate char *se_path; /* event path */ 767c478bd9Sstevel@tonic-gate char *se_args; /* optional args */ 777c478bd9Sstevel@tonic-gate } serecord_t; 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate /* 817c478bd9Sstevel@tonic-gate * Structures for building arbitarily long strings and argument lists 827c478bd9Sstevel@tonic-gate */ 837c478bd9Sstevel@tonic-gate typedef struct str { 847c478bd9Sstevel@tonic-gate char *s_str; 857c478bd9Sstevel@tonic-gate int s_len; 867c478bd9Sstevel@tonic-gate int s_alloc; 877c478bd9Sstevel@tonic-gate int s_hint; 887c478bd9Sstevel@tonic-gate } str_t; 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate /* 927c478bd9Sstevel@tonic-gate * Prototypes 937c478bd9Sstevel@tonic-gate */ 947c478bd9Sstevel@tonic-gate int main(int argc, char **argv); 957c478bd9Sstevel@tonic-gate static void enter_lock(char *root_dir); 967c478bd9Sstevel@tonic-gate static void exit_lock(void); 977c478bd9Sstevel@tonic-gate static void set_root_dir(char *dir); 987c478bd9Sstevel@tonic-gate static int usage(void); 997c478bd9Sstevel@tonic-gate static int add_cmd(void); 1007c478bd9Sstevel@tonic-gate static int list_remove_cmd(int cmd); 1017c478bd9Sstevel@tonic-gate static int list_file(char *fname); 1027c478bd9Sstevel@tonic-gate static int remove_file(char *fname); 1037c478bd9Sstevel@tonic-gate static int check_for_removes(FILE *fp); 1047c478bd9Sstevel@tonic-gate static int restart_cmd(void); 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate static str_t *read_next_line(FILE *fp); 1077c478bd9Sstevel@tonic-gate static serecord_t *parse_line(str_t *line); 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate static int matches_serecord(serecord_t *sep); 1107c478bd9Sstevel@tonic-gate static void print_serecord(FILE *fp, serecord_t *sep); 1117c478bd9Sstevel@tonic-gate static void free_serecord(serecord_t *sep); 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate static char *skip_spaces(char **cpp); 1147c478bd9Sstevel@tonic-gate static char *next_field(char **cpp); 1157c478bd9Sstevel@tonic-gate static void *sc_malloc(size_t n); 1167c478bd9Sstevel@tonic-gate static void *sc_realloc(void *p, size_t current, size_t n); 1177c478bd9Sstevel@tonic-gate static void sc_free(void *p, size_t n); 1187c478bd9Sstevel@tonic-gate static char *sc_strdup(char *cp); 1197c478bd9Sstevel@tonic-gate static void sc_strfree(char *s); 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate static str_t *initstr(int hint); 1227c478bd9Sstevel@tonic-gate static void freestr(str_t *str); 1237c478bd9Sstevel@tonic-gate static void resetstr(str_t *str); 1247c478bd9Sstevel@tonic-gate static void strcats(str_t *str, char *s); 1257c478bd9Sstevel@tonic-gate static void strcatc(str_t *str, int c); 1267c478bd9Sstevel@tonic-gate static char *fstrgets(str_t *str, FILE *fp); 1277c478bd9Sstevel@tonic-gate static char **build_strlist(char **, int *, int *, char *); 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate static void no_mem_err(void); 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1327c478bd9Sstevel@tonic-gate } 1337c478bd9Sstevel@tonic-gate #endif 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate #endif /* _SYSEVENTADM_H */ 136