]> git.ipfire.org Git - thirdparty/systemd.git/blame - udev/udev-builtin-kmod.c
autogen.sh: moce CFLAGS from to configure.ac; print common ./configure options
[thirdparty/systemd.git] / udev / udev-builtin-kmod.c
CommitLineData
81dadce5 1/*
aa29418a 2 * load kernel modules
81dadce5
KS
3 *
4 * Copyright (C) 2011 Kay Sievers <kay.sievers@vrfy.org>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <stdio.h>
21#include <stdlib.h>
22#include <stdarg.h>
23#include <unistd.h>
24#include <string.h>
25#include <errno.h>
26#include <fcntl.h>
27#include <sys/stat.h>
06316d9f 28#include <sys/wait.h>
81dadce5
KS
29
30#include "udev.h"
31
e216e514 32static int builtin_kmod(struct udev_device *dev, int argc, char *argv[], bool test)
81dadce5 33{
e216e514 34 struct udev *udev = udev_device_get_udev(dev);
06316d9f
KS
35 pid_t pid;
36 char *m[5];
e216e514
KS
37
38 if (argc < 3) {
39 err(udev, "missing command + argument\n");
40 return EXIT_FAILURE;
41 }
42
06316d9f
KS
43 err(udev, "'%s' the module '%s' (%i)\n", argv[1], argv[2], argc);
44
45 m[0] = "/sbin/modprobe";
46 m[1] = "-bv";
47 m[1] = argv[2];
48 m[2] = argv[3];
49 m[3] = NULL;
50
51 pid = fork();
52 switch(pid) {
53 case 0:
54 execv(m[0], m);
55 _exit(1);
56 case -1:
57 return EXIT_FAILURE;
58 default:
59 waitpid(pid, NULL, 0);
60 }
61
81dadce5
KS
62 return EXIT_SUCCESS;
63}
64
aa29418a
KS
65static int builtin_kmod_load(struct udev *udev)
66{
e216e514 67 info(udev, "load module index\n");
aa29418a
KS
68 return 0;
69}
70
71static int builtin_kmod_unload(struct udev *udev)
72{
e216e514 73 info(udev, "unload module index\n");
aa29418a
KS
74 return 0;
75}
76
81dadce5
KS
77const struct udev_builtin udev_builtin_kmod = {
78 .name = "kmod",
79 .cmd = builtin_kmod,
aa29418a
KS
80 .load = builtin_kmod_load,
81 .unload = builtin_kmod_unload,
81dadce5
KS
82 .help = "kernel module loader",
83 .run_once = false,
84};