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