chiark / gitweb /
[PATCH] clean up the gentoo rules file a bit more, adding dri rules.
[elogind.git] / dev_d.c
1 /*
2  * dev_d.c - dev.d/ multiplexer
3  * 
4  * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
5  *
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.
9  */
10
11 /*
12  * This essentially emulates the following shell script logic in C:
13  *      DIR="/etc/dev.d"
14  *      export DEVNODE="whatever_dev_name_udev_just_gave"
15  *      for I in "${DIR}/$DEVNODE/"*.dev "${DIR}/$1/"*.dev "${DIR}/default/"*.dev ; do
16  *              if [ -f $I ]; then $I $1 ; fi
17  *      done
18  *      exit 1;
19  */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <sys/types.h>
25 #include <sys/wait.h>
26 #include <unistd.h>
27 #include "udev.h"
28 #include "udev_lib.h"
29 #include "logging.h"
30
31 #define DEVD_DIR                        "/etc/dev.d/"
32 #define DEVD_SUFFIX                     ".dev"
33
34 static int run_program(char *name)
35 {
36         pid_t pid;
37
38         dbg("running %s", name);
39
40         pid = fork();
41         switch (pid) {
42         case 0:
43                 /* child */
44                 execv(name, main_argv);
45                 dbg("exec of child failed");
46                 exit(1);
47         case -1:
48                 dbg("fork of child failed");
49                 break;
50                 return -1;
51         default:
52                 wait(NULL);
53         }
54
55         return 0;
56 }
57
58 /* 
59  * runs files in these directories in order:
60  *      <node name given by udev>/
61  *      subsystem/
62  *      default/
63  */
64 void dev_d_send(struct udevice *dev, char *subsystem)
65 {
66         char dirname[256];
67         char devnode[NAME_SIZE];
68
69         strfieldcpy(devnode, udev_root);
70         strfieldcat(devnode, dev->name);
71         setenv("DEVNODE", devnode, 1);
72
73         strcpy(dirname, DEVD_DIR);
74         strfieldcat(dirname, dev->name);
75         call_foreach_file(run_program, dirname, DEVD_SUFFIX);
76
77         strcpy(dirname, DEVD_DIR);
78         strfieldcat(dirname, subsystem);
79         call_foreach_file(run_program, dirname, DEVD_SUFFIX);
80
81         strcpy(dirname, DEVD_DIR "default");
82         call_foreach_file(run_program, dirname, DEVD_SUFFIX);
83 }
84