chiark / gitweb /
do not skip /dev/{disk,char}/M:m removal when the device node is already gone
[elogind.git] / udev / udev-builtin.c
1 /*
2  * Copyright (C) 2007-2009 Kay Sievers <kay.sievers@vrfy.org>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include <unistd.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <stddef.h>
22 #include <string.h>
23 #include <errno.h>
24 #include <getopt.h>
25
26 #include "udev.h"
27
28 static const struct udev_builtin *builtins[] = {
29         [UDEV_BUILTIN_PATH_ID] = &udev_builtin_path_id,
30         [UDEV_BUILTIN_USB_ID] = &udev_builtin_usb_id,
31         [UDEV_BUILTIN_INPUT_ID] = &udev_builtin_input_id,
32 };
33
34 int udev_builtin_list(struct udev *udev)
35 {
36         unsigned int i;
37
38         for (i = 0; i < ARRAY_SIZE(builtins); i++)
39                 fprintf(stderr, "  %-12s %s\n", builtins[i]->name, builtins[i]->help);
40         return 0;
41 }
42
43 const char *udev_builtin_name(enum udev_builtin_cmd cmd)
44 {
45         return builtins[cmd]->name;
46 }
47
48 enum udev_builtin_cmd udev_builtin_lookup(const char *name)
49 {
50         enum udev_builtin_cmd i;
51
52         for (i = 0; i < ARRAY_SIZE(builtins); i++)
53                 if (strcmp(builtins[i]->name, name) == 0)
54                         return i;
55         return UDEV_BUILTIN_MAX;
56 }
57
58 int udev_builtin_run(struct udev_device *dev, enum udev_builtin_cmd cmd, bool test)
59 {
60         return builtins[cmd]->cmd(dev, test);
61 }
62
63 int udev_builtin_add_property(struct udev_device *dev, bool test, const char *key, const char *val, ...)
64 {
65         struct udev_list_entry *entry;
66
67         entry = udev_device_add_property(dev, key, val);
68         /* store in db, skip private keys */
69         if (key[0] != '.')
70                 udev_list_entry_set_num(entry, true);
71
72         info(udev_device_get_udev(dev), "%s=%s\n", key, val);
73         if (test)
74                 printf("%s=%s\n", key, val);
75         return 0;
76 }