]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/udev/udev-builtin.c
libudev: udev_device_read_db - drop unused argument
[thirdparty/systemd.git] / src / udev / udev-builtin.c
CommitLineData
c3cfed0d
KS
1/***
2 This file is part of systemd.
3
4 Copyright 2007-2012 Kay Sievers <kay@vrfy.org>
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18***/
d7867b31 19
d7867b31 20#include <stdio.h>
d7867b31 21#include <string.h>
d7867b31
KS
22#include <getopt.h>
23
24#include "udev.h"
25
7781e063
KS
26static bool initialized;
27
d7867b31 28static const struct udev_builtin *builtins[] = {
f553b3b1 29#ifdef HAVE_BLKID
912541b0 30 [UDEV_BUILTIN_BLKID] = &udev_builtin_blkid,
f553b3b1 31#endif
0bb91b50 32 [UDEV_BUILTIN_BTRFS] = &udev_builtin_btrfs,
796b06c2 33 [UDEV_BUILTIN_HWDB] = &udev_builtin_hwdb,
912541b0 34 [UDEV_BUILTIN_INPUT_ID] = &udev_builtin_input_id,
9d7d42bc 35 [UDEV_BUILTIN_KEYBOARD] = &udev_builtin_keyboard,
e3043162 36#ifdef HAVE_KMOD
912541b0 37 [UDEV_BUILTIN_KMOD] = &udev_builtin_kmod,
e3043162 38#endif
a660c63c 39 [UDEV_BUILTIN_NET_ID] = &udev_builtin_net_id,
0b99c9f8 40 [UDEV_BUILTIN_NET_LINK] = &udev_builtin_net_setup_link,
912541b0 41 [UDEV_BUILTIN_PATH_ID] = &udev_builtin_path_id,
912541b0 42 [UDEV_BUILTIN_USB_ID] = &udev_builtin_usb_id,
83cd6b75
KS
43#ifdef HAVE_ACL
44 [UDEV_BUILTIN_UACCESS] = &udev_builtin_uaccess,
45#endif
d7867b31
KS
46};
47
9ec6e95b 48void udev_builtin_init(struct udev *udev) {
912541b0 49 unsigned int i;
912541b0 50
7781e063 51 if (initialized)
4af113f9 52 return;
7781e063 53
4af113f9
KS
54 for (i = 0; i < ELEMENTSOF(builtins); i++)
55 if (builtins[i]->init)
56 builtins[i]->init(udev);
7781e063
KS
57
58 initialized = true;
aa29418a
KS
59}
60
9ec6e95b 61void udev_builtin_exit(struct udev *udev) {
912541b0 62 unsigned int i;
aa29418a 63
7781e063
KS
64 if (!initialized)
65 return;
66
8fef0ff2 67 for (i = 0; i < ELEMENTSOF(builtins); i++)
912541b0
KS
68 if (builtins[i]->exit)
69 builtins[i]->exit(udev);
7781e063
KS
70
71 initialized = false;
aa29418a
KS
72}
73
9ec6e95b 74bool udev_builtin_validate(struct udev *udev) {
912541b0 75 unsigned int i;
912541b0 76
8fef0ff2 77 for (i = 0; i < ELEMENTSOF(builtins); i++)
4af113f9
KS
78 if (builtins[i]->validate && builtins[i]->validate(udev))
79 return true;
80 return false;
4f1795cc
KS
81}
82
9ec6e95b 83void udev_builtin_list(struct udev *udev) {
912541b0 84 unsigned int i;
d7867b31 85
8fef0ff2 86 for (i = 0; i < ELEMENTSOF(builtins); i++)
5ac0162c 87 fprintf(stderr, " %-14s %s\n", builtins[i]->name, builtins[i]->help);
d7867b31
KS
88}
89
9ec6e95b 90const char *udev_builtin_name(enum udev_builtin_cmd cmd) {
912541b0 91 return builtins[cmd]->name;
d7867b31
KS
92}
93
9ec6e95b 94bool udev_builtin_run_once(enum udev_builtin_cmd cmd) {
912541b0 95 return builtins[cmd]->run_once;
81dadce5
KS
96}
97
9ec6e95b 98enum udev_builtin_cmd udev_builtin_lookup(const char *command) {
912541b0
KS
99 char name[UTIL_PATH_SIZE];
100 enum udev_builtin_cmd i;
101 char *pos;
102
d5a89d7d 103 strscpy(name, sizeof(name), command);
912541b0
KS
104 pos = strchr(name, ' ');
105 if (pos)
106 pos[0] = '\0';
8fef0ff2 107 for (i = 0; i < ELEMENTSOF(builtins); i++)
090be865 108 if (streq(builtins[i]->name, name))
912541b0
KS
109 return i;
110 return UDEV_BUILTIN_MAX;
d7867b31
KS
111}
112
9ec6e95b 113int udev_builtin_run(struct udev_device *dev, enum udev_builtin_cmd cmd, const char *command, bool test) {
912541b0
KS
114 char arg[UTIL_PATH_SIZE];
115 int argc;
116 char *argv[128];
117
e5f2783e
KS
118 /* we need '0' here to reset the internal state */
119 optind = 0;
d5a89d7d 120 strscpy(arg, sizeof(arg), command);
912541b0
KS
121 udev_build_argv(udev_device_get_udev(dev), arg, &argc, argv);
122 return builtins[cmd]->cmd(dev, argc, argv, test);
d7867b31
KS
123}
124
9ec6e95b 125int udev_builtin_add_property(struct udev_device *dev, bool test, const char *key, const char *val) {
912541b0 126 struct udev_list_entry *entry;
d7867b31 127
912541b0
KS
128 entry = udev_device_add_property(dev, key, val);
129 /* store in db, skip private keys */
130 if (key[0] != '.')
131 udev_list_entry_set_num(entry, true);
d7867b31 132
912541b0
KS
133 if (test)
134 printf("%s=%s\n", key, val);
135 return 0;
d7867b31 136}