/src/udev-builtin.c (fff6de377bbeeff7f92a0bb74b77124dd9ac7593) (3937 bytes) (mode 100644) (type blob)
/*
* Copyright (C) 2007-2009 Kay Sievers <kay.sievers@vrfy.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <getopt.h>
#include "udev.h"
static const struct udev_builtin *builtins[] = {
[UDEV_BUILTIN_BLKID] = &udev_builtin_blkid,
[UDEV_BUILTIN_INPUT_ID] = &udev_builtin_input_id,
[UDEV_BUILTIN_KMOD] = &udev_builtin_kmod,
[UDEV_BUILTIN_PATH_ID] = &udev_builtin_path_id,
[UDEV_BUILTIN_PCI_DB] = &udev_builtin_pci_db,
[UDEV_BUILTIN_USB_DB] = &udev_builtin_usb_db,
[UDEV_BUILTIN_USB_ID] = &udev_builtin_usb_id,
};
int udev_builtin_init(struct udev *udev)
{
unsigned int i;
int err = 0;
for (i = 0; i < ARRAY_SIZE(builtins); i++) {
if (builtins[i]->init) {
err = builtins[i]->init(udev);
if (err < 0)
break;
}
}
return err;
}
void udev_builtin_exit(struct udev *udev)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(builtins); i++)
if (builtins[i]->exit)
builtins[i]->exit(udev);
}
bool udev_builtin_validate(struct udev *udev)
{
unsigned int i;
bool change = false;
for (i = 0; i < ARRAY_SIZE(builtins); i++)
if (builtins[i]->validate)
if (builtins[i]->validate(udev))
change = true;
return change;
}
void udev_builtin_list(struct udev *udev)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(builtins); i++)
fprintf(stderr, " %-12s %s\n", builtins[i]->name, builtins[i]->help);
}
const char *udev_builtin_name(enum udev_builtin_cmd cmd)
{
return builtins[cmd]->name;
}
bool udev_builtin_run_once(enum udev_builtin_cmd cmd)
{
return builtins[cmd]->run_once;
}
enum udev_builtin_cmd udev_builtin_lookup(const char *command)
{
char name[UTIL_PATH_SIZE];
enum udev_builtin_cmd i;
char *pos;
util_strscpy(name, sizeof(name), command);
pos = strchr(name, ' ');
if (pos)
pos[0] = '\0';
for (i = 0; i < ARRAY_SIZE(builtins); i++)
if (strcmp(builtins[i]->name, name) == 0)
return i;
return UDEV_BUILTIN_MAX;
}
int udev_builtin_run(struct udev_device *dev, enum udev_builtin_cmd cmd, const char *command, bool test)
{
char arg[UTIL_PATH_SIZE];
int argc;
char *argv[128];
optind = 0;
util_strscpy(arg, sizeof(arg), command);
udev_build_argv(udev_device_get_udev(dev), arg, &argc, argv);
return builtins[cmd]->cmd(dev, argc, argv, test);
}
int udev_builtin_add_property(struct udev_device *dev, bool test, const char *key, const char *val)
{
struct udev_list_entry *entry;
entry = udev_device_add_property(dev, key, val);
/* store in db, skip private keys */
if (key[0] != '.')
udev_list_entry_set_num(entry, true);
info(udev_device_get_udev(dev), "%s=%s\n", key, val);
if (test)
printf("%s=%s\n", key, val);
return 0;
}
Mode |
Type |
Size |
Ref |
File |
100644 |
blob |
18092 |
d159169d1050894d3ea3b98e1c965c4058208fe1 |
COPYING-GPL |
100644 |
blob |
26525 |
d2e31278b0ee6fef16025fe44061062ad9acece4 |
COPYING-LGPL |
100644 |
blob |
6035 |
c1a2782caf56be5ae9fc1dbafe0568a99edbb78b |
README |
100644 |
blob |
14 |
2430e121d55dea637b402ee33da9b2b9d2b7553e |
TODO |
100755 |
blob |
10096 |
e770b37da1d18f6a5f1f255435a538a020467992 |
make |
100644 |
blob |
1340 |
307eda511fd9f87338d1cb44a7a920beee7e9d79 |
make.libudev.sh |
100644 |
blob |
2995 |
850cc113476c3d734d6c63ce5e4b690b73a9a31b |
make.udevd.sh |
040000 |
tree |
- |
1e20d200b76becb71a8bc5bd8d56381c2ed3cd8f |
rules |
040000 |
tree |
- |
6855eb6c4e5205055b820aae4e3b0e26400707d9 |
src |
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"
Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/sylware/mudev
Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/sylware/mudev
Clone this repository using git:
git clone git://git.rocketgit.com/user/sylware/mudev
You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a
merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main