1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _SYSEVENTADM_H 28 #define _SYSEVENTADM_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 /* 37 * Directory where sysevent.conf files reside 38 */ 39 #define SYSEVENT_CONFIG_DIR "/etc/sysevent/config" 40 41 /* 42 * Lock file name to serialize registry updates 43 */ 44 #define LOCK_FILENAME "sysevent.lock" 45 46 /* 47 * Required suffix for all sysevent.conf files 48 */ 49 #define SYSEVENT_CONF_SUFFIX ",sysevent.conf" 50 51 /* 52 * cmd types for list/remove 53 */ 54 #define CMD_LIST 0 55 #define CMD_REMOVE 1 56 57 /* 58 * Exit codes 59 */ 60 #define EXIT_OK 0 61 #define EXIT_NO_MATCH 1 62 #define EXIT_USAGE 2 63 #define EXIT_PERM 3 64 #define EXIT_CMD_FAILED 4 65 #define EXIT_NO_MEM 5 66 67 /* 68 * sysevent.conf record 69 */ 70 typedef struct serecord { 71 char *se_vendor; /* vendor */ 72 char *se_publisher; /* publisher */ 73 char *se_class; /* event class */ 74 char *se_subclass; /* event subclass */ 75 char *se_user; /* user */ 76 char *se_reserved1; /* reserved1 */ 77 char *se_reserved2; /* reserved2 */ 78 char *se_path; /* event path */ 79 char *se_args; /* optional args */ 80 } serecord_t; 81 82 83 /* 84 * Structures for building arbitarily long strings and argument lists 85 */ 86 typedef struct str { 87 char *s_str; 88 int s_len; 89 int s_alloc; 90 int s_hint; 91 } str_t; 92 93 94 /* 95 * Prototypes 96 */ 97 int main(int argc, char **argv); 98 static void enter_lock(char *root_dir); 99 static void exit_lock(void); 100 static void set_root_dir(char *dir); 101 static int usage(void); 102 static int add_cmd(void); 103 static int list_remove_cmd(int cmd); 104 static int list_file(char *fname); 105 static int remove_file(char *fname); 106 static int check_for_removes(FILE *fp); 107 static int restart_cmd(void); 108 109 static str_t *read_next_line(FILE *fp); 110 static serecord_t *parse_line(str_t *line); 111 112 static int matches_serecord(serecord_t *sep); 113 static void print_serecord(FILE *fp, serecord_t *sep); 114 static void free_serecord(serecord_t *sep); 115 116 static char *skip_spaces(char **cpp); 117 static char *next_field(char **cpp); 118 static void *sc_malloc(size_t n); 119 static void *sc_realloc(void *p, size_t current, size_t n); 120 static void sc_free(void *p, size_t n); 121 static char *sc_strdup(char *cp); 122 static void sc_strfree(char *s); 123 124 static str_t *initstr(int hint); 125 static void freestr(str_t *str); 126 static void resetstr(str_t *str); 127 static void strcats(str_t *str, char *s); 128 static void strcatc(str_t *str, int c); 129 static char *fstrgets(str_t *str, FILE *fp); 130 static char **build_strlist(char **, int *, int *, char *); 131 132 static void no_mem_err(void); 133 134 #ifdef __cplusplus 135 } 136 #endif 137 138 #endif /* _SYSEVENTADM_H */ 139