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