-
Notifications
You must be signed in to change notification settings - Fork 0
/
udev.c
67 lines (57 loc) · 1.92 KB
/
udev.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* hajimete - A simple Linux system starter.
* udev helper functions
* Copyright © 2009 Calvin Walton <calvin.walton@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "udev.h"
#include "exec.h"
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
int udev_init(void)
{
int err;
printf("Please wait while I initialize your devices...\n");
printf("Starting udevd.\n");
err = exec_run_wait("/sbin/start-stop-daemon", "/sbin/start-stop-daemon", "--start", "--exec", "/sbin/udevd", "--", "--daemon", (char *) NULL);
if (err) {
printf("Failed to start udevd\n");
return -1;
}
printf("Triggering events.\n");
err = exec_run_wait("/sbin/udevadm", "/sbin/udevadm", "--debug", "trigger", (char *) NULL);
if (err) {
printf("Failed to trigger udev events\n");
return -1;
}
printf("Waiting for the events to propagate.\n");
exec_run_wait("/sbin/udevadm", "/sbin/udevadm", "--debug", "settle", "--timeout=0", (char *) NULL);
printf("You should now have all your device nodes.\n");
return 0;
}
int udev_kill(void)
{
int err;
printf("Stopping udevd.\n");
err = exec_run_wait("/sbin/start-stop-daemon", "/sbin/start-stop-daemon", "--stop", "--exec", "/sbin/udevd", (char *) NULL);
if (err) {
printf("Failed to stop udevd\n");
return -1;
}
return 0;
}