]>
git.ipfire.org Git - thirdparty/systemd.git/blob - dev_d.c
2 * dev_d.c - dev.d/ multiplexer
4 * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 of the License.
12 * This essentially emulates the following shell script logic in C:
14 * export DEVNAME="whatever_dev_name_udev_just_gave"
15 * for I in "${DIR}/$DEVNAME/"*.dev "${DIR}/$1/"*.dev "${DIR}/default/"*.dev ; do
16 * if [ -f $I ]; then $I $1 ; fi
24 #include <sys/types.h>
31 #define DEVD_DIR "/etc/dev.d/"
32 #define DEVD_SUFFIX ".dev"
34 static int run_program(char *name
)
38 dbg("running %s", name
);
44 execv(name
, main_argv
);
45 dbg("exec of child failed");
48 dbg("fork of child failed");
59 * runs files in these directories in order:
60 * <node name given by udev>/
64 void dev_d_send(struct udevice
*dev
, const char *subsystem
, const char *devpath
)
67 char env_devname
[NAME_SIZE
];
74 if (dev
->type
== 'b' || dev
->type
== 'c') {
75 strfieldcpy(env_devname
, udev_root
);
76 strfieldcat(env_devname
, dev
->name
);
77 } else if (dev
->type
== 'n') {
78 strfieldcpy(env_devname
, dev
->name
);
79 setenv("DEVPATH", devpath
, 1);
81 setenv("DEVNAME", env_devname
, 1);
82 dbg("DEVNAME='%s'", env_devname
);
84 devname
= strdup(dev
->name
);
90 /* Chop the device name up into pieces based on '/' */
91 temp
= strchr(devname
, '/');
92 while (temp
!= NULL
) {
94 strcpy(dirname
, DEVD_DIR
);
95 strfieldcat(dirname
, devname
);
96 call_foreach_file(run_program
, dirname
, DEVD_SUFFIX
);
100 temp
= strchr(temp
, '/');
103 strcpy(dirname
, DEVD_DIR
);
104 strfieldcat(dirname
, dev
->name
);
105 call_foreach_file(run_program
, dirname
, DEVD_SUFFIX
);
107 strcpy(dirname
, DEVD_DIR
);
108 strfieldcat(dirname
, subsystem
);
109 call_foreach_file(run_program
, dirname
, DEVD_SUFFIX
);
111 strcpy(dirname
, DEVD_DIR
"default");
112 call_foreach_file(run_program
, dirname
, DEVD_SUFFIX
);