X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=extras%2Frule_generator%2Frule_generator.functions;h=0f1b73850e886613cc165c84a1d06497d6287ee3;hb=12a362be5c1982f80dbfb75bda070208a2c99cdf;hp=14c585a86ae442f2dcfca5785b27471790b6ac79;hpb=fbcbf70bb21a618024ce8c1ea0b4f6718c2a8dd2;p=elogind.git diff --git a/extras/rule_generator/rule_generator.functions b/extras/rule_generator/rule_generator.functions index 14c585a86..0f1b73850 100644 --- a/extras/rule_generator/rule_generator.functions +++ b/extras/rule_generator/rule_generator.functions @@ -1,10 +1,21 @@ # functions used by the udev rule generator -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the -# Free Software Foundation version 2 of the License. -PATH='/sbin:/bin' +# Copyright (C) 2006 Marco d'Itri + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +PATH='/usr/bin:/bin:/usr/sbin:/sbin' # Read a single line from file $1 in the $DEVPATH directory. # The function must not return an error even if the file does not exist. @@ -34,9 +45,10 @@ writeable() { # Create a lock file for the current rules file. lock_rules_file() { - [ -e /dev/.udev/ ] || return 0 + RUNDIR=$(udevadm info --run) + [ -e "$RUNDIR" ] || return 0 - RULES_LOCK="/dev/.udev/.lock-${RULES_FILE##*/}" + RULES_LOCK="$RUNDIR/.lock-${RULES_FILE##*/}" retry=30 while ! mkdir $RULES_LOCK 2> /dev/null; do @@ -57,7 +69,8 @@ unlock_rules_file() { # Choose the real rules file if it is writeable or a temporary file if not. # Both files should be checked later when looking for existing rules. choose_rules_file() { - local tmp_rules_file="/dev/.udev/tmp-rules--${RULES_FILE##*/}" + RUNDIR=$(udevadm info --run) + local tmp_rules_file="$RUNDIR/tmp-rules--${RULES_FILE##*/}" [ -e "$RULES_FILE" -o -e "$tmp_rules_file" ] || PRINT_HEADER=1 if writeable ${RULES_FILE%/*}; then @@ -92,7 +105,9 @@ find_all_rules() { local linkre="$2" local match="$3" - [ -e $RULES_FILE ] || return - local search='.*[[:space:],]'"$key"'"\('"$linkre"'\)"[[:space:]]*\(,.*\|\\\|\)$' - echo $(sed -n -e "${match}s/${search}/\1/p" $RO_RULES_FILE $RULES_FILE) + local search='.*[[:space:],]'"$key"'"('"$linkre"')".*' + echo $(sed -n -r -e 's/^#.*//' -e "${match}s/${search}/\1/p" \ + $RO_RULES_FILE \ + $([ -e $RULES_FILE ] && echo $RULES_FILE) \ + 2>/dev/null) }