chiark / gitweb /
move udev_ctrl to libudev-private
[elogind.git] / udev / udevadm-trigger.c
1 /*
2  * Copyright (C) 2004-2006 Kay Sievers <kay@vrfy.org>
3  * Copyright (C) 2006 Hannes Reinecke <hare@suse.de>
4  *
5  *      This program is free software; you can redistribute it and/or modify it
6  *      under the terms of the GNU General Public License as published by the
7  *      Free Software Foundation version 2 of the License.
8  * 
9  *      This program is distributed in the hope that it will be useful, but
10  *      WITHOUT ANY WARRANTY; without even the implied warranty of
11  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  *      General Public License for more details.
13  * 
14  *      You should have received a copy of the GNU General Public License along
15  *      with this program; if not, write to the Free Software Foundation, Inc.,
16  *      51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  *
18  */
19
20 #include <stdlib.h>
21 #include <stddef.h>
22 #include <string.h>
23 #include <stdio.h>
24 #include <unistd.h>
25 #include <getopt.h>
26 #include <errno.h>
27 #include <dirent.h>
28 #include <fcntl.h>
29 #include <syslog.h>
30 #include <fnmatch.h>
31 #include <sys/stat.h>
32 #include <sys/types.h>
33 #include <sys/socket.h>
34 #include <sys/un.h>
35
36 #include "udev.h"
37 #include "udev_rules.h"
38
39 static int verbose;
40 static int dry_run;
41 LIST_HEAD(device_list);
42 LIST_HEAD(filter_subsystem_match_list);
43 LIST_HEAD(filter_subsystem_nomatch_list);
44 LIST_HEAD(filter_attr_match_list);
45 LIST_HEAD(filter_attr_nomatch_list);
46 static int sock = -1;
47 static struct sockaddr_un saddr;
48 static socklen_t saddrlen;
49
50 /* devices that should run last cause of their dependencies */
51 static int delay_device(const char *devpath)
52 {
53         static const char *delay_device_list[] = {
54                 "*/md*",
55                 "*/dm-*",
56                 NULL
57         };
58         int i;
59
60         for (i = 0; delay_device_list[i] != NULL; i++)
61                 if (fnmatch(delay_device_list[i], devpath, 0) == 0)
62                         return 1;
63         return 0;
64 }
65
66 static int device_list_insert(struct udev *udev, const char *path)
67 {
68         char filename[PATH_SIZE];
69         char devpath[PATH_SIZE];
70         struct stat statbuf;
71
72         dbg(udev, "add '%s'\n" , path);
73
74         /* we only have a device, if we have an uevent file */
75         strlcpy(filename, path, sizeof(filename));
76         strlcat(filename, "/uevent", sizeof(filename));
77         if (stat(filename, &statbuf) < 0)
78                 return -1;
79         if (!(statbuf.st_mode & S_IWUSR))
80                 return -1;
81
82         strlcpy(devpath, &path[strlen(udev_get_sys_path(udev))], sizeof(devpath));
83
84         /* resolve possible link to real target */
85         if (lstat(path, &statbuf) < 0)
86                 return -1;
87         if (S_ISLNK(statbuf.st_mode))
88                 if (sysfs_resolve_link(udev, devpath, sizeof(devpath)) != 0)
89                         return -1;
90
91         name_list_add(udev, &device_list, devpath, 1);
92         return 0;
93 }
94
95 static void trigger_uevent(struct udev *udev, const char *devpath, const char *action)
96 {
97         char filename[PATH_SIZE];
98         int fd;
99
100         strlcpy(filename, udev_get_sys_path(udev), sizeof(filename));
101         strlcat(filename, devpath, sizeof(filename));
102         strlcat(filename, "/uevent", sizeof(filename));
103
104         if (verbose)
105                 printf("%s\n", devpath);
106
107         if (dry_run)
108                 return;
109
110         fd = open(filename, O_WRONLY);
111         if (fd < 0) {
112                 dbg(udev, "error on opening %s: %s\n", filename, strerror(errno));
113                 return;
114         }
115
116         if (write(fd, action, strlen(action)) < 0)
117                 info(udev, "error writing '%s' to '%s': %s\n", action, filename, strerror(errno));
118
119         close(fd);
120 }
121
122 static int pass_to_socket(struct udev *udev, const char *devpath, const char *action, const char *env)
123 {
124         struct udevice *udevice;
125         struct name_entry *name_loop;
126         char buf[4096];
127         size_t bufpos = 0;
128         ssize_t count;
129         char path[PATH_SIZE];
130         int fd;
131         char link_target[PATH_SIZE];
132         int len;
133         int err = 0;
134
135         if (verbose)
136                 printf("%s\n", devpath);
137
138         udevice = udev_device_init(udev);
139         if (udevice == NULL)
140                 return -1;
141         udev_db_get_device(udevice, devpath);
142
143         /* add header */
144         bufpos = snprintf(buf, sizeof(buf)-1, "%s@%s", action, devpath);
145         bufpos++;
146
147         /* add cookie */
148         if (env != NULL) {
149                 bufpos += snprintf(&buf[bufpos], sizeof(buf)-1, "%s", env);
150                 bufpos++;
151         }
152
153         /* add standard keys */
154         bufpos += snprintf(&buf[bufpos], sizeof(buf)-1, "DEVPATH=%s", devpath);
155         bufpos++;
156         bufpos += snprintf(&buf[bufpos], sizeof(buf)-1, "ACTION=%s", action);
157         bufpos++;
158
159         /* add subsystem */
160         strlcpy(path, udev_get_sys_path(udev), sizeof(path));
161         strlcat(path, devpath, sizeof(path));
162         strlcat(path, "/subsystem", sizeof(path));
163         len = readlink(path, link_target, sizeof(link_target));
164         if (len > 0) {
165                 char *pos;
166
167                 link_target[len] = '\0';
168                 pos = strrchr(link_target, '/');
169                 if (pos != NULL) {
170                         bufpos += snprintf(&buf[bufpos], sizeof(buf)-1, "SUBSYSTEM=%s", &pos[1]);
171                         bufpos++;
172                 }
173         }
174
175         /* add symlinks and node name */
176         path[0] = '\0';
177         list_for_each_entry(name_loop, &udevice->symlink_list, node) {
178                 strlcat(path, udev_get_dev_path(udev), sizeof(path));
179                 strlcat(path, "/", sizeof(path));
180                 strlcat(path, name_loop->name, sizeof(path));
181                 strlcat(path, " ", sizeof(path));
182         }
183         remove_trailing_chars(path, ' ');
184         if (path[0] != '\0') {
185                 bufpos += snprintf(&buf[bufpos], sizeof(buf)-1, "DEVLINKS=%s", path);
186                 bufpos++;
187         }
188         if (udevice->name[0] != '\0') {
189                 strlcpy(path, udev_get_dev_path(udev), sizeof(path));
190                 strlcat(path, "/", sizeof(path));
191                 strlcat(path, udevice->name, sizeof(path));
192                 bufpos += snprintf(&buf[bufpos], sizeof(buf)-1, "DEVNAME=%s", path);
193                 bufpos++;
194         }
195
196         /* add keys from device "uevent" file */
197         strlcpy(path, udev_get_sys_path(udev), sizeof(path));
198         strlcat(path, devpath, sizeof(path));
199         strlcat(path, "/uevent", sizeof(path));
200         fd = open(path, O_RDONLY);
201         if (fd >= 0) {
202                 char value[4096];
203
204                 count = read(fd, value, sizeof(value));
205                 close(fd);
206                 if (count > 0) {
207                         char *key;
208
209                         value[count] = '\0';
210                         key = value;
211                         while (key[0] != '\0') {
212                                 char *next;
213
214                                 next = strchr(key, '\n');
215                                 if (next == NULL)
216                                         break;
217                                 next[0] = '\0';
218                                 bufpos += strlcpy(&buf[bufpos], key, sizeof(buf) - bufpos-1);
219                                 bufpos++;
220                                 key = &next[1];
221                         }
222                 }
223         }
224
225         /* add keys from database */
226         list_for_each_entry(name_loop, &udevice->env_list, node) {
227                 bufpos += strlcpy(&buf[bufpos], name_loop->name, sizeof(buf) - bufpos-1);
228                 bufpos++;
229         }
230         if (bufpos > sizeof(buf))
231                 bufpos = sizeof(buf);
232
233         count = sendto(sock, &buf, bufpos, 0, (struct sockaddr *)&saddr, saddrlen);
234         if (count < 0)
235                 err = -1;
236
237         return err;
238 }
239
240 static void exec_list(struct udev *udev, const char *action, const char *env)
241 {
242         struct name_entry *loop_device;
243         struct name_entry *tmp_device;
244
245         list_for_each_entry_safe(loop_device, tmp_device, &device_list, node) {
246                 if (delay_device(loop_device->name))
247                         continue;
248                 if (sock >= 0)
249                         pass_to_socket(udev, loop_device->name, action, env);
250                 else
251                         trigger_uevent(udev, loop_device->name, action);
252                 list_del(&loop_device->node);
253                 free(loop_device);
254         }
255
256         /* trigger remaining delayed devices */
257         list_for_each_entry_safe(loop_device, tmp_device, &device_list, node) {
258                 if (sock >= 0)
259                         pass_to_socket(udev, loop_device->name, action, env);
260                 else
261                         trigger_uevent(udev, loop_device->name, action);
262                 list_del(&loop_device->node);
263                 free(loop_device);
264         }
265 }
266
267 static int subsystem_filtered(const char *subsystem)
268 {
269         struct name_entry *loop_name;
270
271         /* skip devices matching the listed subsystems */
272         list_for_each_entry(loop_name, &filter_subsystem_nomatch_list, node)
273                 if (fnmatch(loop_name->name, subsystem, 0) == 0)
274                         return 1;
275
276         /* skip devices not matching the listed subsystems */
277         if (!list_empty(&filter_subsystem_match_list)) {
278                 list_for_each_entry(loop_name, &filter_subsystem_match_list, node)
279                         if (fnmatch(loop_name->name, subsystem, 0) == 0)
280                                 return 0;
281                 return 1;
282         }
283
284         return 0;
285 }
286
287 static int attr_match(const char *path, const char *attr_value)
288 {
289         char attr[NAME_SIZE];
290         char file[PATH_SIZE];
291         char *match_value;
292
293         strlcpy(attr, attr_value, sizeof(attr));
294
295         /* separate attr and match value */
296         match_value = strchr(attr, '=');
297         if (match_value != NULL) {
298                 match_value[0] = '\0';
299                 match_value = &match_value[1];
300         }
301
302         strlcpy(file, path, sizeof(file));
303         strlcat(file, "/", sizeof(file));
304         strlcat(file, attr, sizeof(file));
305
306         if (match_value != NULL) {
307                 /* match file content */
308                 char value[NAME_SIZE];
309                 int fd;
310                 ssize_t size;
311
312                 fd = open(file, O_RDONLY);
313                 if (fd < 0)
314                         return 0;
315                 size = read(fd, value, sizeof(value));
316                 close(fd);
317                 if (size < 0)
318                         return 0;
319                 value[size] = '\0';
320                 remove_trailing_chars(value, '\n');
321
322                 /* match if attribute value matches */
323                 if (fnmatch(match_value, value, 0) == 0)
324                         return 1;
325         } else {
326                 /* match if attribute exists */
327                 struct stat statbuf;
328
329                 if (stat(file, &statbuf) == 0)
330                         return 1;
331         }
332         return 0;
333 }
334
335 static int attr_filtered(const char *path)
336 {
337         struct name_entry *loop_name;
338
339         /* skip devices matching the listed sysfs attributes */
340         list_for_each_entry(loop_name, &filter_attr_nomatch_list, node)
341                 if (attr_match(path, loop_name->name))
342                         return 1;
343
344         /* skip devices not matching the listed sysfs attributes */
345         if (!list_empty(&filter_attr_match_list)) {
346                 list_for_each_entry(loop_name, &filter_attr_match_list, node)
347                         if (attr_match(path, loop_name->name))
348                                 return 0;
349                 return 1;
350         }
351         return 0;
352 }
353
354 enum scan_type {
355         SCAN_DEVICES,
356         SCAN_SUBSYSTEM,
357 };
358
359 static void scan_subsystem(struct udev *udev, const char *subsys, enum scan_type scan)
360 {
361         char base[PATH_SIZE];
362         DIR *dir;
363         struct dirent *dent;
364         const char *subdir;
365
366         if (scan == SCAN_DEVICES)
367                 subdir = "/devices";
368         else if (scan == SCAN_SUBSYSTEM)
369                 subdir = "/drivers";
370         else
371                 return;
372
373         strlcpy(base, udev_get_sys_path(udev), sizeof(base));
374         strlcat(base, "/", sizeof(base));
375         strlcat(base, subsys, sizeof(base));
376
377         dir = opendir(base);
378         if (dir != NULL) {
379                 for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
380                         char dirname[PATH_SIZE];
381                         DIR *dir2;
382                         struct dirent *dent2;
383
384                         if (dent->d_name[0] == '.')
385                                 continue;
386
387                         if (scan == SCAN_DEVICES)
388                                 if (subsystem_filtered(dent->d_name))
389                                         continue;
390
391                         strlcpy(dirname, base, sizeof(dirname));
392                         strlcat(dirname, "/", sizeof(dirname));
393                         strlcat(dirname, dent->d_name, sizeof(dirname));
394
395                         if (scan == SCAN_SUBSYSTEM) {
396                                 if (attr_filtered(dirname))
397                                         continue;
398                                 if (!subsystem_filtered("subsystem"))
399                                         device_list_insert(udev, dirname);
400                                 if (subsystem_filtered("drivers"))
401                                         continue;
402                         }
403
404                         strlcat(dirname, subdir, sizeof(dirname));
405
406                         /* look for devices/drivers */
407                         dir2 = opendir(dirname);
408                         if (dir2 != NULL) {
409                                 for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
410                                         char dirname2[PATH_SIZE];
411
412                                         if (dent2->d_name[0] == '.')
413                                                 continue;
414
415                                         strlcpy(dirname2, dirname, sizeof(dirname2));
416                                         strlcat(dirname2, "/", sizeof(dirname2));
417                                         strlcat(dirname2, dent2->d_name, sizeof(dirname2));
418                                         if (attr_filtered(dirname2))
419                                                 continue;
420                                         device_list_insert(udev, dirname2);
421                                 }
422                                 closedir(dir2);
423                         }
424                 }
425                 closedir(dir);
426         }
427 }
428
429 static void scan_block(struct udev *udev)
430 {
431         char base[PATH_SIZE];
432         DIR *dir;
433         struct dirent *dent;
434
435         if (subsystem_filtered("block"))
436                 return;
437
438         strlcpy(base, udev_get_sys_path(udev), sizeof(base));
439         strlcat(base, "/block", sizeof(base));
440
441         dir = opendir(base);
442         if (dir != NULL) {
443                 for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
444                         char dirname[PATH_SIZE];
445                         DIR *dir2;
446                         struct dirent *dent2;
447
448                         if (dent->d_name[0] == '.')
449                                 continue;
450
451                         strlcpy(dirname, base, sizeof(dirname));
452                         strlcat(dirname, "/", sizeof(dirname));
453                         strlcat(dirname, dent->d_name, sizeof(dirname));
454                         if (attr_filtered(dirname))
455                                 continue;
456                         if (device_list_insert(udev, dirname) != 0)
457                                 continue;
458
459                         /* look for partitions */
460                         dir2 = opendir(dirname);
461                         if (dir2 != NULL) {
462                                 for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
463                                         char dirname2[PATH_SIZE];
464
465                                         if (dent2->d_name[0] == '.')
466                                                 continue;
467
468                                         if (!strcmp(dent2->d_name,"device"))
469                                                 continue;
470
471                                         strlcpy(dirname2, dirname, sizeof(dirname2));
472                                         strlcat(dirname2, "/", sizeof(dirname2));
473                                         strlcat(dirname2, dent2->d_name, sizeof(dirname2));
474                                         if (attr_filtered(dirname2))
475                                                 continue;
476                                         device_list_insert(udev, dirname2);
477                                 }
478                                 closedir(dir2);
479                         }
480                 }
481                 closedir(dir);
482         }
483 }
484
485 static void scan_class(struct udev *udev)
486 {
487         char base[PATH_SIZE];
488         DIR *dir;
489         struct dirent *dent;
490
491         strlcpy(base, udev_get_sys_path(udev), sizeof(base));
492         strlcat(base, "/class", sizeof(base));
493
494         dir = opendir(base);
495         if (dir != NULL) {
496                 for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
497                         char dirname[PATH_SIZE];
498                         DIR *dir2;
499                         struct dirent *dent2;
500
501                         if (dent->d_name[0] == '.')
502                                 continue;
503
504                         if (subsystem_filtered(dent->d_name))
505                                 continue;
506
507                         strlcpy(dirname, base, sizeof(dirname));
508                         strlcat(dirname, "/", sizeof(dirname));
509                         strlcat(dirname, dent->d_name, sizeof(dirname));
510                         dir2 = opendir(dirname);
511                         if (dir2 != NULL) {
512                                 for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) {
513                                         char dirname2[PATH_SIZE];
514
515                                         if (dent2->d_name[0] == '.')
516                                                 continue;
517
518                                         if (!strcmp(dent2->d_name, "device"))
519                                                 continue;
520
521                                         strlcpy(dirname2, dirname, sizeof(dirname2));
522                                         strlcat(dirname2, "/", sizeof(dirname2));
523                                         strlcat(dirname2, dent2->d_name, sizeof(dirname2));
524                                         if (attr_filtered(dirname2))
525                                                 continue;
526                                         device_list_insert(udev, dirname2);
527                                 }
528                                 closedir(dir2);
529                         }
530                 }
531                 closedir(dir);
532         }
533 }
534
535 static void scan_failed(struct udev *udev)
536 {
537         char base[PATH_SIZE];
538         DIR *dir;
539         struct dirent *dent;
540
541         strlcpy(base, udev_get_dev_path(udev), sizeof(base));
542         strlcat(base, "/.udev/failed", sizeof(base));
543
544         dir = opendir(base);
545         if (dir != NULL) {
546                 for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
547                         char device[PATH_SIZE];
548                         size_t start;
549
550                         if (dent->d_name[0] == '.')
551                                 continue;
552
553                         start = strlcpy(device, udev_get_sys_path(udev), sizeof(device));
554                         if(start >= sizeof(device))
555                                 start = sizeof(device) - 1;
556                         strlcat(device, dent->d_name, sizeof(device));
557                         path_decode(&device[start]);
558                         device_list_insert(udev, device);
559                 }
560                 closedir(dir);
561         }
562 }
563
564 int udevadm_trigger(struct udev *udev, int argc, char *argv[])
565 {
566         int failed = 0;
567         const char *sockpath = NULL;
568         int option;
569         const char *action = "add";
570         const char *env = NULL;
571         static const struct option options[] = {
572                 { "verbose", 0, NULL, 'v' },
573                 { "dry-run", 0, NULL, 'n' },
574                 { "retry-failed", 0, NULL, 'F' },
575                 { "socket", 1, NULL, 'o' },
576                 { "help", 0, NULL, 'h' },
577                 { "action", 1, NULL, 'c' },
578                 { "subsystem-match", 1, NULL, 's' },
579                 { "subsystem-nomatch", 1, NULL, 'S' },
580                 { "attr-match", 1, NULL, 'a' },
581                 { "attr-nomatch", 1, NULL, 'A' },
582                 { "env", 1, NULL, 'e' },
583                 {}
584         };
585
586         dbg(udev, "version %s\n", VERSION);
587
588         while (1) {
589                 option = getopt_long(argc, argv, "vnFo:hce::s:S:a:A:", options, NULL);
590                 if (option == -1)
591                         break;
592
593                 switch (option) {
594                 case 'v':
595                         verbose = 1;
596                         break;
597                 case 'n':
598                         dry_run = 1;
599                         break;
600                 case 'F':
601                         failed = 1;
602                         break;
603                 case 'o':
604                         sockpath = optarg;
605                         break;
606                 case 'c':
607                         action = optarg;
608                         break;
609                 case 'e':
610                         if (strchr(optarg, '=') != NULL)
611                                 env = optarg;
612                         break;
613                 case 's':
614                         name_list_add(udev, &filter_subsystem_match_list, optarg, 0);
615                         break;
616                 case 'S':
617                         name_list_add(udev, &filter_subsystem_nomatch_list, optarg, 0);
618                         break;
619                 case 'a':
620                         name_list_add(udev, &filter_attr_match_list, optarg, 0);
621                         break;
622                 case 'A':
623                         name_list_add(udev, &filter_attr_nomatch_list, optarg, 0);
624                         break;
625                 case 'h':
626                         printf("Usage: udevadm trigger OPTIONS\n"
627                                "  --verbose                       print the list of devices while running\n"
628                                "  --dry-run                       do not actually trigger the events\n"
629                                "  --retry-failed                  trigger only the events which have been\n"
630                                "                                  marked as failed during a previous run\n"
631                                "  --socket=<socket path>          pass events to socket instead of triggering kernel events\n"
632                                "  --env=<KEY>=<value>             pass an additional key (works only with --socket=)\n"
633                                "  --subsystem-match=<subsystem>   trigger devices from a matching subystem\n"
634                                "  --subsystem-nomatch=<subsystem> exclude devices from a matching subystem\n"
635                                "  --attr-match=<file[=<value>]>   trigger devices with a matching sysfs\n"
636                                "                                  attribute\n"
637                                "  --attr-nomatch=<file[=<value>]> exclude devices with a matching sysfs\n"
638                                "                                  attribute\n"
639                                "  --help                          print this text\n"
640                                "\n");
641                         goto exit;
642                 default:
643                         goto exit;
644                 }
645         }
646
647         if (sockpath != NULL) {
648                 struct stat stats;
649
650                 sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
651                 memset(&saddr, 0x00, sizeof(struct sockaddr_un));
652                 saddr.sun_family = AF_LOCAL;
653                 if (sockpath[0] == '@') {
654                         /* abstract namespace socket requested */
655                         strlcpy(&saddr.sun_path[1], &sockpath[1], sizeof(saddr.sun_path)-1);
656                         saddrlen = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(&saddr.sun_path[1]);
657                 } else if (stat(sockpath, &stats) == 0 && S_ISSOCK(stats.st_mode)) {
658                         /* existing socket file */
659                         strlcpy(saddr.sun_path, sockpath, sizeof(saddr.sun_path));
660                         saddrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path);
661                 } else {
662                         /* no socket file, assume abstract namespace socket */
663                         strlcpy(&saddr.sun_path[1], sockpath, sizeof(saddr.sun_path)-1);
664                         saddrlen = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(&saddr.sun_path[1]);
665                 }
666         } else if (env != NULL) {
667                 fprintf(stderr, "error: --env= only valid with --socket= option\n");
668                 goto exit;
669         }
670
671         if (failed) {
672                 scan_failed(udev);
673                 exec_list(udev, action, env);
674         } else {
675                 char base[PATH_SIZE];
676                 struct stat statbuf;
677
678                 /* if we have /sys/subsystem, forget all the old stuff */
679                 strlcpy(base, udev_get_sys_path(udev), sizeof(base));
680                 strlcat(base, "/subsystem", sizeof(base));
681                 if (stat(base, &statbuf) == 0) {
682                         scan_subsystem(udev, "subsystem", SCAN_SUBSYSTEM);
683                         exec_list(udev, action, env);
684                         scan_subsystem(udev, "subsystem", SCAN_DEVICES);
685                         exec_list(udev, action, env);
686                 } else {
687                         scan_subsystem(udev, "bus", SCAN_SUBSYSTEM);
688                         exec_list(udev, action, env);
689                         scan_subsystem(udev, "bus", SCAN_DEVICES);
690                         scan_class(udev);
691
692                         /* scan "block" if it isn't a "class" */
693                         strlcpy(base, udev_get_sys_path(udev), sizeof(base));
694                         strlcat(base, "/class/block", sizeof(base));
695                         if (stat(base, &statbuf) != 0)
696                                 scan_block(udev);
697                         exec_list(udev, action, env);
698                 }
699         }
700
701 exit:
702         name_list_cleanup(udev, &filter_subsystem_match_list);
703         name_list_cleanup(udev, &filter_subsystem_nomatch_list);
704         name_list_cleanup(udev, &filter_attr_match_list);
705         name_list_cleanup(udev, &filter_attr_nomatch_list);
706
707         if (sock >= 0)
708                 close(sock);
709         return 0;
710 }