openssl: bump to 3.0.3
[kiss-trunc88.git] / smdev / patches / scan_all.patch
blob3d319dde822fe158b9b2363b3f805fe3c242b4ea
1 From 6d5a094b85a1a148647744eb327593d6aef9a822 Mon Sep 17 00:00:00 2001
2 From: Platon Ryzhikov <ihummer63@yandex.ru>
3 Date: Mon, 18 May 2020 16:58:10 +0300
4 Subject: [PATCH] Scan all /sys to find uevents, they may contain info about
5 modules even if they don't describe devices
7 ---
8 smdev.c | 127 ++++++++++++++++++++++++++++----------------------------
9 1 file changed, 64 insertions(+), 63 deletions(-)
11 diff --git a/smdev.c b/smdev.c
12 index b774908..ff35df2 100644
13 --- a/smdev.c
14 +++ b/smdev.c
15 @@ -85,7 +85,7 @@ main(int argc, char *argv[])
17 umask(0);
18 if (sflag) {
19 - recurse("/sys/devices", populatedev);
20 + recurse("/sys", populatedev);
21 } else {
22 if (dohotplug() < 0)
23 eprintf("Environment not set up correctly for hotplugging\n");
24 @@ -126,14 +126,14 @@ dohotplug(void)
25 action = getenv("ACTION");
26 devpath = getenv("DEVPATH");
27 devname = getenv("DEVNAME");
28 - if (!minor || !major || !action || !devpath || !devname)
29 + if (!action || !devpath)
30 return -1;
32 - ev.minor = estrtol(minor, 10);
33 - ev.major = estrtol(major, 10);
34 + ev.minor = minor?estrtol(minor, 10):-1;
35 + ev.major = major?estrtol(major, 10):-1;
36 ev.action = mapaction(action);
37 ev.devpath = devpath;
38 - ev.devname = devname;
39 + ev.devname = devname?devname:".";
40 return doevent(&ev);
43 @@ -249,12 +249,14 @@ removedev(struct event *ev)
44 if (rule->path && rule->path[0] == '!')
45 return 0;
47 - /* Delete device node */
48 - unlink(rpath.path);
49 - /* Delete symlink */
50 - if (rule->path && rule->path[0] == '>') {
51 - snprintf(buf, sizeof(buf), "/dev/%s", ev->devname);
52 - unlink(buf);
53 + if (ev->major >= 0 && ev->minor >= 0 && ev->devname) {
54 + /* Delete device node */
55 + unlink(rpath.path);
56 + /* Delete symlink */
57 + if (rule->path && rule->path[0] == '>') {
58 + snprintf(buf, sizeof(buf), "/dev/%s", ev->devname);
59 + unlink(buf);
60 + }
62 return 0;
64 @@ -276,58 +278,59 @@ createdev(struct event *ev)
65 if (rule->path && rule->path[0] == '!')
66 goto runrule;
68 - snprintf(buf, sizeof(buf), "%d:%d", ev->major, ev->minor);
69 - if ((type = devtype(buf)) < 0)
70 - return -1;
72 - /* Parse path and create the directory tree */
73 - parsepath(rule, &rpath, ev->devname);
74 - if (!(dirc = strdup(rpath.path)))
75 - eprintf("strdup:");
76 - strlcpy(buf, dirname(dirc), sizeof(buf));
77 - free(dirc);
78 - umask(022);
79 - if (mkpath(buf, 0755) < 0)
80 - eprintf("mkdir %s:", buf);
81 - umask(0);
82 + if (ev->major >= 0 && ev->minor >= 0 && ev->devname) {
83 + snprintf(buf, sizeof(buf), "%d:%d", ev->major, ev->minor);
84 + if ((type = devtype(buf)) < 0)
85 + return -1;
87 - if (mknod(rpath.path, rule->mode | type,
88 - makedev(ev->major, ev->minor)) < 0 &&
89 - errno != EEXIST)
90 - eprintf("mknod %s:", rpath.path);
92 - errno = 0;
93 - pw = getpwnam(rule->user);
94 - if (!pw) {
95 - if (errno)
96 - eprintf("getpwnam %s:", rule->user);
97 - else
98 - eprintf("getpwnam %s: no such user\n",
99 - rule->user);
101 + /* Parse path and create the directory tree */
102 + parsepath(rule, &rpath, ev->devname);
103 + if (!(dirc = strdup(rpath.path)))
104 + eprintf("strdup:");
105 + strlcpy(buf, dirname(dirc), sizeof(buf));
106 + free(dirc);
107 + umask(022);
108 + if (mkpath(buf, 0755) < 0)
109 + eprintf("mkdir %s:", buf);
110 + umask(0);
112 + if (mknod(rpath.path, rule->mode | type,
113 + makedev(ev->major, ev->minor)) < 0 &&
114 + errno != EEXIST)
115 + eprintf("mknod %s:", rpath.path);
117 + errno = 0;
118 + pw = getpwnam(rule->user);
119 + if (!pw) {
120 + if (errno)
121 + eprintf("getpwnam %s:", rule->user);
122 + else
123 + eprintf("getpwnam %s: no such user\n",
124 + rule->user);
127 - errno = 0;
128 - gr = getgrnam(rule->group);
129 - if (!gr) {
130 - if (errno)
131 - eprintf("getgrnam %s:", rule->group);
132 - else
133 - eprintf("getgrnam %s: no such group\n",
134 - rule->group);
136 + errno = 0;
137 + gr = getgrnam(rule->group);
138 + if (!gr) {
139 + if (errno)
140 + eprintf("getgrnam %s:", rule->group);
141 + else
142 + eprintf("getgrnam %s: no such group\n",
143 + rule->group);
146 - if (chown(rpath.path, pw->pw_uid, gr->gr_gid) < 0)
147 - eprintf("chown %s:", rpath.path);
148 + if (chown(rpath.path, pw->pw_uid, gr->gr_gid) < 0)
149 + eprintf("chown %s:", rpath.path);
151 - if (chmod(rpath.path, rule->mode) < 0)
152 - eprintf("chmod %s:", rpath.path);
153 + if (chmod(rpath.path, rule->mode) < 0)
154 + eprintf("chmod %s:", rpath.path);
156 - if (rule->path && rule->path[0] == '>') {
157 - /* ev->devname is the original device name */
158 - snprintf(buf, sizeof(buf), "/dev/%s", ev->devname);
159 - symlink(rpath.path, buf);
160 + if (rule->path && rule->path[0] == '>') {
161 + /* ev->devname is the original device name */
162 + snprintf(buf, sizeof(buf), "/dev/%s", ev->devname);
163 + symlink(rpath.path, buf);
167 runrule:
168 if(rule->cmd) {
169 if (chdir("/dev") < 0)
170 @@ -389,12 +392,10 @@ populatedev(const char *path)
171 char *cwd;
173 recurse(path, populatedev);
174 - if (strcmp(path, "dev") == 0) {
175 - cwd = agetcwd();
176 - if (!craftev(cwd))
177 - dohotplug();
178 - free(cwd);
180 + cwd = agetcwd();
181 + if (!craftev(cwd))
182 + dohotplug();
183 + free(cwd);
186 static int
188 2.26.2