summaryrefslogtreecommitdiff
path: root/usr/src/cmd/syseventadm/syseventadm.h
blob: e6766552701faf13076b11c342d83b200e535725 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (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
 * or http://www.opensolaris.org/os/licensing.
 * 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 2008 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef	_SYSEVENTADM_H
#define	_SYSEVENTADM_H

#ifdef	__cplusplus
extern "C" {
#endif

/*
 * Directory where sysevent.conf files reside
 */
#define	SYSEVENT_CONFIG_DIR		"/etc/sysevent/config"

/*
 * Lock file name to serialize registry updates
 */
#define	LOCK_FILENAME	"/var/run/syseventconf.lock"

/*
 * Required suffix for all sysevent.conf files
 */
#define	SYSEVENT_CONF_SUFFIX		",sysevent.conf"

/*
 * cmd types for list/remove
 */
#define	CMD_LIST	0
#define	CMD_REMOVE	1

/*
 * Exit codes
 */
#define	EXIT_OK			0
#define	EXIT_NO_MATCH		1
#define	EXIT_USAGE		2
#define	EXIT_PERM		3
#define	EXIT_CMD_FAILED		4
#define	EXIT_NO_MEM		5

/*
 * sysevent.conf record
 */
typedef struct serecord {
	char	*se_vendor;			/* vendor */
	char	*se_publisher;			/* publisher */
	char	*se_class;			/* event class */
	char	*se_subclass;			/* event subclass */
	char	*se_user;			/* user */
	char	*se_reserved1;			/* reserved1 */
	char	*se_reserved2;			/* reserved2 */
	char	*se_path;			/* event path */
	char	*se_args;			/* optional args */
} serecord_t;


/*
 * Structures for building arbitarily long strings and argument lists
 */
typedef struct str {
	char	*s_str;
	int	s_len;
	int	s_alloc;
	int	s_hint;
} str_t;


/*
 * Prototypes
 */
int main(int argc, char **argv);
static void enter_lock(char *root_dir);
static void exit_lock(void);
static void set_root_dir(char *dir);
static int usage(void);
static int add_cmd(void);
static int list_remove_cmd(int cmd);
static int list_file(char *fname);
static int remove_file(char *fname);
static int check_for_removes(FILE *fp);
static int restart_cmd(void);

static str_t *read_next_line(FILE *fp);
static serecord_t *parse_line(str_t *line);

static int matches_serecord(serecord_t *sep);
static void print_serecord(FILE *fp, serecord_t *sep);
static void free_serecord(serecord_t *sep);

static char *skip_spaces(char **cpp);
static char *next_field(char **cpp);
static void *sc_malloc(size_t n);
static void *sc_realloc(void *p, size_t current, size_t n);
static void sc_free(void *p, size_t n);
static char *sc_strdup(char *cp);
static void sc_strfree(char *s);

static str_t *initstr(int hint);
static void freestr(str_t *str);
static void resetstr(str_t *str);
static void strcats(str_t *str, char *s);
static void strcatc(str_t *str, int c);
static char *fstrgets(str_t *str, FILE *fp);
static char **build_strlist(char **, int *, int *, char *);

static void no_mem_err(void);

#ifdef	__cplusplus
}
#endif

#endif	/* _SYSEVENTADM_H */