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