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