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 /* 24 * Copyright (c) 2000-2001 by Sun Microsystems, Inc. 25 * All rights reserved. 26 */ 27 28 #ifndef _SYSEVENT_CONF_MOD_H 29 #define _SYSEVENT_CONF_MOD_H 30 31 #pragma ident "%Z%%M% %I% %E% SMI" 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 38 /* 39 * syseventd_print debug levels for sysevent_conf_mod 40 */ 41 #define DBG_TEST 1 /* info of interest when testing */ 42 #define DBG_EXEC 2 /* path and args to exec */ 43 #define DBG_EVENTS 3 /* received events */ 44 #define DBG_MATCHES 4 /* dump specs for matching events */ 45 #define DBG_MACRO 5 /* macro expansion */ 46 #define DBG_CONF_FILE 6 /* sysevent.conf parsing */ 47 #define DBG_DETAILED 7 /* all the above and more */ 48 49 50 /* 51 * Directory where sysevent.conf files reside 52 */ 53 #define SYSEVENT_CONFIG_DIR "/etc/sysevent/config" 54 55 /* 56 * Lock file name to serialize registry updates 57 */ 58 #define LOCK_FILENAME "sysevent.lock" 59 60 /* 61 * sysevent.conf files list 62 */ 63 typedef struct conftab { 64 char *cf_conf_file; /* source conf file */ 65 struct conftab *cf_next; 66 } conftab_t; 67 68 /* 69 * sysevent.conf table 70 */ 71 typedef struct syseventtab { 72 char *se_conf_file; /* source conf file */ 73 int se_lineno; /* line number */ 74 char *se_vendor; /* vendor */ 75 char *se_publisher; /* publisher */ 76 char *se_class; /* event class */ 77 char *se_subclass; /* event subclass */ 78 char *se_user; /* user */ 79 char *se_reserved1; /* reserved1 */ 80 char *se_reserved2; /* reserved2 */ 81 char *se_path; /* event path */ 82 char *se_args; /* optional args */ 83 uid_t se_uid; /* user id */ 84 gid_t se_gid; /* group id */ 85 struct syseventtab *se_next; 86 } syseventtab_t; 87 88 typedef struct sysevent_hdr_info { 89 char *class; 90 char *subclass; 91 char *vendor; 92 char *publisher; 93 } sysevent_hdr_info_t; 94 95 96 /* 97 * Structures for building arbitarily long strings and argument lists 98 */ 99 typedef struct str { 100 char *s_str; 101 int s_len; 102 int s_alloc; 103 int s_hint; 104 } str_t; 105 106 /* 107 * Queue of commands ready to be transported to syseventconfd 108 */ 109 typedef struct cmdqueue { 110 sysevent_t *event; 111 struct cmdqueue *next; 112 } cmdqueue_t; 113 114 /* 115 * syseventconfd state 116 */ 117 enum { 118 CONFD_STATE_OK, 119 CONFD_STATE_NOT_RUNNING, 120 CONFD_STATE_STARTED, 121 CONFD_STATE_ERR, 122 CONFD_STATE_DISABLED 123 }; 124 125 126 /* 127 * Prototypes 128 */ 129 static char *skip_spaces(char **cpp); 130 static char *next_field(char **cpp); 131 static void *sc_malloc(size_t n); 132 static void *sc_realloc(void *p, size_t current, size_t n); 133 static void sc_free(void *p, size_t n); 134 static char *sc_strdup(char *cp); 135 static void sc_strfree(char *s); 136 137 static str_t *initstr(int hint); 138 static void freestr(str_t *str); 139 static void resetstr(str_t *str); 140 static int strcopys(str_t *str, char *s); 141 static int strcats(str_t *str, char *s); 142 static int strcatc(str_t *str, int c); 143 static char *fstrgets(str_t *str, FILE *fp); 144 static void strtrunc(str_t *str, int pos); 145 146 static void build_event_table(void); 147 static void free_event_table(void); 148 static int enter_lock(char *lock_file); 149 static void exit_lock(int lock_fd, char *lock_file); 150 static str_t *snip_identifier(char *id, char **end); 151 static str_t *snip_delimited_identifier(char *id, char **end); 152 static char *se_attr_type_to_str(int se_attr_type); 153 static str_t *find_macro_definition(sysevent_t *ev, nvlist_t *nvlist, 154 syseventtab_t *sep, char *token, sysevent_hdr_info_t *hdr); 155 static int expand_macros(sysevent_t *ev, nvlist_t *nvlist, 156 syseventtab_t *sep, str_t *line, sysevent_hdr_info_t *hdr); 157 static void start_syseventconfd(void); 158 static int system1(const char *s_path, const char *s); 159 static void abort_cmd_queue(void); 160 static int queue_event(sysevent_t *ev, syseventtab_t *sep, 161 sysevent_hdr_info_t *hdr); 162 static int transport_event(sysevent_t *cmd); 163 static void transport_queued_events(void); 164 static int sysevent_conf_event(sysevent_t *ev, int flag); 165 166 167 #ifdef __cplusplus 168 } 169 #endif 170 171 #endif /* _SYSEVENT_CONF_MOD_H */ 172