xref: /freebsd/sbin/devd/parse.y (revision 2008043f386721d58158e37e0d7e50df8095942d)
1 %{
2 /*-
3  * DEVD (Device action daemon)
4  *
5  * SPDX-License-Identifier: BSD-2-Clause
6  *
7  * Copyright (c) 2002 M. Warner Losh <imp@FreeBSD.org>
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #include <sys/cdefs.h>
32 #include "devd.h"
33 #include <stdio.h>
34 #include <string.h>
35 
36 %}
37 
38 %union {
39 	char *str;
40 	int i;
41 	struct eps *eps;	/* EventProcStatement */
42 	struct event_proc *eventproc;
43 }
44 
45 %token SEMICOLON BEGINBLOCK ENDBLOCK COMMA
46 %token <i> NUMBER
47 %token <str> STRING
48 %token <str> ID
49 %token OPTIONS SET DIRECTORY PID_FILE DEVICE_NAME ACTION MATCH
50 %token ATTACH DETACH NOMATCH NOTIFY MEDIA_TYPE CLASS SUBDEVICE
51 
52 %type <eventproc> match_or_action_list
53 %type <eps> match_or_action match action
54 
55 %%
56 
57 config_file
58 	: config_list
59 	|
60 	;
61 
62 config_list
63 	: config
64 	| config_list config
65 	;
66 
67 config
68 	: option_block
69 	| attach_block
70 	| detach_block
71 	| nomatch_block
72 	| notify_block
73 	;
74 
75 option_block
76 	: OPTIONS BEGINBLOCK options ENDBLOCK SEMICOLON
77 	;
78 
79 options
80 	: option
81 	| options option
82 
83 option
84 	: directory_option
85 	| pid_file_option
86 	| set_option
87 	;
88 
89 directory_option
90 	: DIRECTORY STRING SEMICOLON { add_directory($2); }
91 	;
92 
93 pid_file_option
94 	: PID_FILE STRING SEMICOLON { set_pidfile($2); }
95 	;
96 
97 set_option
98 	: SET ID STRING SEMICOLON { set_variable($2, $3); }
99 	;
100 
101 attach_block
102 	: ATTACH NUMBER BEGINBLOCK match_or_action_list ENDBLOCK SEMICOLON
103 		{ add_attach($2, $4); }
104 	| ATTACH NUMBER BEGINBLOCK ENDBLOCK SEMICOLON
105 	;
106 
107 detach_block
108 	: DETACH NUMBER BEGINBLOCK match_or_action_list ENDBLOCK SEMICOLON
109 		{ add_detach($2, $4); }
110 	| DETACH NUMBER BEGINBLOCK ENDBLOCK SEMICOLON
111 	;
112 
113 nomatch_block
114 	: NOMATCH NUMBER BEGINBLOCK match_or_action_list ENDBLOCK SEMICOLON
115 		{ add_nomatch($2, $4); }
116 	| NOMATCH NUMBER BEGINBLOCK ENDBLOCK SEMICOLON
117 	;
118 
119 notify_block
120 	: NOTIFY NUMBER BEGINBLOCK match_or_action_list ENDBLOCK SEMICOLON
121 		{ add_notify($2, $4); }
122 	| NOTIFY NUMBER BEGINBLOCK ENDBLOCK SEMICOLON
123 	;
124 
125 match_or_action_list
126 	: match_or_action { $$ = add_to_event_proc( NULL, $1); }
127 	| match_or_action_list match_or_action
128 			{ $$ = add_to_event_proc($1, $2); }
129 	;
130 
131 match_or_action
132 	: match
133 	| action
134 	;
135 
136 match
137 	: MATCH STRING STRING SEMICOLON	{ $$ = new_match($2, $3); }
138 	| DEVICE_NAME STRING SEMICOLON
139 		{ $$ = new_match(strdup("device-name"), $2); }
140 	| MEDIA_TYPE STRING SEMICOLON
141 		{ $$ = new_media(strdup("media-type"), $2); }
142 	| CLASS STRING SEMICOLON
143 		{ $$ = new_match(strdup("class"), $2); }
144 	| SUBDEVICE STRING SEMICOLON
145 		{ $$ = new_match(strdup("subdevice"), $2); }
146 	;
147 
148 action
149 	: ACTION STRING SEMICOLON	{ $$ = new_action($2); }
150 	;
151 
152 %%
153