1 %{ 2 /*- 3 * DEVD (Device action daemon) 4 * 5 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 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 * $FreeBSD$ 31 */ 32 33 #include <sys/cdefs.h> 34 #include "devd.h" 35 #include <stdio.h> 36 #include <string.h> 37 38 %} 39 40 %union { 41 char *str; 42 int i; 43 struct eps *eps; /* EventProcStatement */ 44 struct event_proc *eventproc; 45 } 46 47 %token SEMICOLON BEGINBLOCK ENDBLOCK COMMA 48 %token <i> NUMBER 49 %token <str> STRING 50 %token <str> ID 51 %token OPTIONS SET DIRECTORY PID_FILE DEVICE_NAME ACTION MATCH 52 %token ATTACH DETACH NOMATCH NOTIFY MEDIA_TYPE CLASS SUBDEVICE 53 54 %type <eventproc> match_or_action_list 55 %type <eps> match_or_action match action 56 57 %% 58 59 config_file 60 : config_list 61 | 62 ; 63 64 config_list 65 : config 66 | config_list config 67 ; 68 69 config 70 : option_block 71 | attach_block 72 | detach_block 73 | nomatch_block 74 | notify_block 75 ; 76 77 option_block 78 : OPTIONS BEGINBLOCK options ENDBLOCK SEMICOLON 79 ; 80 81 options 82 : option 83 | options option 84 85 option 86 : directory_option 87 | pid_file_option 88 | set_option 89 ; 90 91 directory_option 92 : DIRECTORY STRING SEMICOLON { add_directory($2); } 93 ; 94 95 pid_file_option 96 : PID_FILE STRING SEMICOLON { set_pidfile($2); } 97 ; 98 99 set_option 100 : SET ID STRING SEMICOLON { set_variable($2, $3); } 101 ; 102 103 attach_block 104 : ATTACH NUMBER BEGINBLOCK match_or_action_list ENDBLOCK SEMICOLON 105 { add_attach($2, $4); } 106 | ATTACH NUMBER BEGINBLOCK ENDBLOCK SEMICOLON 107 ; 108 109 detach_block 110 : DETACH NUMBER BEGINBLOCK match_or_action_list ENDBLOCK SEMICOLON 111 { add_detach($2, $4); } 112 | DETACH NUMBER BEGINBLOCK ENDBLOCK SEMICOLON 113 ; 114 115 nomatch_block 116 : NOMATCH NUMBER BEGINBLOCK match_or_action_list ENDBLOCK SEMICOLON 117 { add_nomatch($2, $4); } 118 | NOMATCH NUMBER BEGINBLOCK ENDBLOCK SEMICOLON 119 ; 120 121 notify_block 122 : NOTIFY NUMBER BEGINBLOCK match_or_action_list ENDBLOCK SEMICOLON 123 { add_notify($2, $4); } 124 | NOTIFY NUMBER BEGINBLOCK ENDBLOCK SEMICOLON 125 ; 126 127 match_or_action_list 128 : match_or_action { $$ = add_to_event_proc( NULL, $1); } 129 | match_or_action_list match_or_action 130 { $$ = add_to_event_proc($1, $2); } 131 ; 132 133 match_or_action 134 : match 135 | action 136 ; 137 138 match 139 : MATCH STRING STRING SEMICOLON { $$ = new_match($2, $3); } 140 | DEVICE_NAME STRING SEMICOLON 141 { $$ = new_match(strdup("device-name"), $2); } 142 | MEDIA_TYPE STRING SEMICOLON 143 { $$ = new_media(strdup("media-type"), $2); } 144 | CLASS STRING SEMICOLON 145 { $$ = new_match(strdup("class"), $2); } 146 | SUBDEVICE STRING SEMICOLON 147 { $$ = new_match(strdup("subdevice"), $2); } 148 ; 149 150 action 151 : ACTION STRING SEMICOLON { $$ = new_action($2); } 152 ; 153 154 %% 155