mirror of
https://github.com/systemd/systemd.git
synced 2024-12-25 01:34:28 +03:00
ac28b86d63
> Hi, > as promised yesterday, here is a patch that drops the explicit methods > given in the udev config and implement only one type of rule. > > A rule now consists only of a number of keys to match. All known keys > are valid in any combination. The former configs should work with a few > changes: > > o the "<METHOD>, " at the beginning of the line should be removed > > o the result of the externel program is matched with RESULT= instead if ID= > the PROGRAM= key is only valid if the program exits with zero > (just exit with nozero in a script if the rule should not match) > > o rules are processed in order they appear in the file, no priority > > o if NAME="" is given, udev is instructed to ignore this device, > no node will be created > > > EXAMPLE: > > # combined BUS, SYSFS and KERNEL > BUS="usb", KERNEL="video*", SYSFS_model="Creative Labs WebCam*", NAME="test/webcam%n" > > # exec script only for the first ide drive (hda), all other will be skipped > BUS="ide", KERNEL="hda*", PROGRAM="/home/kay/src/udev.kay/extras/ide-devfs.sh %k %b %n", RESULT="hd*", NAME="%1c", SYMLINK="%2c %3c" > > > The udev-test.pl and test.block works fine here. > Please adapt your config and give it a try. > Here is a slightly better version of the patch. After a conversation with Patrick, we are now able to execute the PROGRAM and also match in all following rules with the RESULT value from this exec. EXAMPLE: We have 7 rules with RESULT and 2 with PROGRAM. Only the 5th rule matches with the callout result from the exec in the 4th rule. RULES: PROGRAM="/bin/echo abc", RESULT="no_match", NAME="web-no-2" KERNEL="video*", RESULT="123", NAME="web-no-3" KERNEL="video*", RESULT="123", NAME="web-no-4" PROGRAM="/bin/echo 123", RESULT="no_match", NAME="web-no-5" KERNEL="video*", RESULT="123", NAME="web-yes" RESULT: Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check PROGRAM Jan 11 23:36:52 pim udev[26050]: execute_program: executing '/bin/echo abc' Jan 11 23:36:52 pim udev[26050]: execute_program: result is 'abc' Jan 11 23:36:52 pim udev[26050]: namedev_name_device: PROGRAM returned successful Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='no_match', udev->program_result='abc' Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0' Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='abc' Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0' Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='abc' Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check PROGRAM Jan 11 23:36:52 pim udev[26050]: execute_program: executing '/bin/echo 123' Jan 11 23:36:52 pim udev[26050]: execute_program: result is '123' Jan 11 23:36:52 pim udev[26050]: namedev_name_device: PROGRAM returned successful Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='no_match', udev->program_result='123' Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT is not matching Jan 11 23:36:52 pim udev[26050]: namedev_name_device: process rule Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for KERNEL dev->kernel='video*' class_dev->name='video0' Jan 11 23:36:52 pim udev[26050]: namedev_name_device: KERNEL matches Jan 11 23:36:52 pim udev[26050]: namedev_name_device: check for RESULT dev->result='123', udev->program_result='123' Jan 11 23:36:52 pim udev[26050]: namedev_name_device: RESULT matches Jan 11 23:36:52 pim udev[26050]: namedev_name_device: found matching rule, 'video*' becomes '' Jan 11 23:36:52 pim udev[26050]: namedev_name_device: name, 'web-yes' is going to have owner='', group='', mode = 0600
98 lines
2.6 KiB
C
98 lines
2.6 KiB
C
/*
|
|
* udev.h
|
|
*
|
|
* Userspace devfs
|
|
*
|
|
* Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
|
|
*
|
|
* 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.
|
|
*
|
|
* 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, write to the Free Software Foundation, Inc.,
|
|
* 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
*
|
|
*/
|
|
|
|
#ifndef UDEV_H
|
|
#define UDEV_H
|
|
|
|
#include "libsysfs/libsysfs.h"
|
|
#include <sys/param.h>
|
|
|
|
#ifdef DEBUG
|
|
#include <syslog.h>
|
|
#define dbg(format, arg...) \
|
|
do { \
|
|
log_message (LOG_DEBUG , "%s: " format , __FUNCTION__ , ## arg); \
|
|
} while (0)
|
|
#else
|
|
#define dbg(format, arg...) do { } while (0)
|
|
#endif
|
|
|
|
/* Parser needs it's own debugging statement, we usually don't care about this at all */
|
|
#ifdef DEBUG_PARSER
|
|
#define dbg_parse(format, arg...) \
|
|
do { \
|
|
log_message (LOG_DEBUG , "%s: " format , __FUNCTION__ , ## arg); \
|
|
} while (0)
|
|
#else
|
|
#define dbg_parse(format, arg...) do { } while (0)
|
|
#endif
|
|
|
|
|
|
extern int log_message (int level, const char *format, ...)
|
|
__attribute__ ((format (printf, 2, 3)));
|
|
|
|
#define COMMENT_CHARACTER '#'
|
|
|
|
#define NAME_SIZE 100
|
|
#define OWNER_SIZE 30
|
|
#define GROUP_SIZE 30
|
|
|
|
struct udevice {
|
|
char name[NAME_SIZE];
|
|
char owner[OWNER_SIZE];
|
|
char group[GROUP_SIZE];
|
|
char type;
|
|
int major;
|
|
int minor;
|
|
mode_t mode;
|
|
char symlink[NAME_SIZE];
|
|
|
|
/* fields that help us in building strings */
|
|
unsigned char bus_id[SYSFS_NAME_LEN];
|
|
unsigned char program_result[NAME_SIZE];
|
|
unsigned char kernel_number[NAME_SIZE];
|
|
unsigned char kernel_name[NAME_SIZE];
|
|
|
|
};
|
|
|
|
#define strfieldcpy(to, from) \
|
|
do { \
|
|
to[sizeof(to)-1] = '\0'; \
|
|
strncpy(to, from, sizeof(to)-1); \
|
|
} while (0)
|
|
|
|
extern int udev_add_device(char *path, char *subsystem);
|
|
extern int udev_remove_device(char *path, char *subsystem);
|
|
extern void udev_init_config(void);
|
|
|
|
extern char **main_argv;
|
|
extern char **main_envp;
|
|
extern char sysfs_path[SYSFS_PATH_MAX];
|
|
extern char udev_root[PATH_MAX];
|
|
extern char udev_db_filename[PATH_MAX+NAME_MAX];
|
|
extern char udev_permissions_filename[PATH_MAX+NAME_MAX];
|
|
extern char udev_config_filename[PATH_MAX+NAME_MAX];
|
|
extern char udev_rules_filename[PATH_MAX+NAME_MAX];
|
|
extern char default_mode_str[NAME_MAX];
|
|
|
|
#endif
|