aboutsummaryrefslogtreecommitdiff
path: root/util-linux/mdev.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-09-07 23:22:08 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-09-07 23:22:08 +0000
commit8d89bed8401bfbca9c5ef18f201439b3502e733b (patch)
treeb5db7bd373d32b4891610cd2c58f6307d4808447 /util-linux/mdev.c
parentee9deb863e089e1b607cc5771123257c3223bea0 (diff)
downloadbusybox-w32-8d89bed8401bfbca9c5ef18f201439b3502e733b.tar.gz
busybox-w32-8d89bed8401bfbca9c5ef18f201439b3502e733b.tar.bz2
busybox-w32-8d89bed8401bfbca9c5ef18f201439b3502e733b.zip
watchdog: add -T option
function old new delta watchdog_main 159 219 +60 mdev: support match by major,minor. See bug 4714. +100 bytes.
Diffstat (limited to 'util-linux/mdev.c')
-rw-r--r--util-linux/mdev.c55
1 files changed, 26 insertions, 29 deletions
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index d0d010382..5ac801555 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -59,8 +59,7 @@ static void make_device(char *path, int delete)
59 int major, minor, type, len; 59 int major, minor, type, len;
60 int mode = 0660; 60 int mode = 0660;
61#if ENABLE_FEATURE_MDEV_CONF 61#if ENABLE_FEATURE_MDEV_CONF
62 uid_t uid = 0; 62 struct bb_uidgid_t ugid = { 0, 0 };
63 gid_t gid = 0;
64 parser_t *parser; 63 parser_t *parser;
65 char *tokens[5]; 64 char *tokens[5];
66#endif 65#endif
@@ -78,9 +77,10 @@ static void make_device(char *path, int delete)
78 77
79 /* Try to read major/minor string. Note that the kernel puts \n after 78 /* Try to read major/minor string. Note that the kernel puts \n after
80 * the data, so we don't need to worry about null terminating the string 79 * the data, so we don't need to worry about null terminating the string
81 * because sscanf() will stop at the first nondigit, which \n is. We 80 * because sscanf() will stop at the first nondigit, which \n is.
82 * also depend on path having writeable space after it. 81 * We also depend on path having writeable space after it.
83 */ 82 */
83 major = -1;
84 if (!delete) { 84 if (!delete) {
85 strcpy(dev_maj_min, "/dev"); 85 strcpy(dev_maj_min, "/dev");
86 len = open_read_close(path, dev_maj_min + 1, 64); 86 len = open_read_close(path, dev_maj_min + 1, 64);
@@ -90,6 +90,8 @@ static void make_device(char *path, int delete)
90 return; 90 return;
91 /* no "dev" file, so just try to run script */ 91 /* no "dev" file, so just try to run script */
92 *dev_maj_min = '\0'; 92 *dev_maj_min = '\0';
93 } else if (sscanf(dev_maj_min, "%u:%u", &major, &minor) != 2) {
94 major = -1;
93 } 95 }
94 } 96 }
95 97
@@ -113,8 +115,23 @@ static void make_device(char *path, int delete)
113 115
114 /* Fields: regex uid:gid mode [alias] [cmd] */ 116 /* Fields: regex uid:gid mode [alias] [cmd] */
115 117
116 /* 1st field: regex to match this device */ 118 /* 1st field: @<numeric maj,min>... */
117 { 119 if (tokens[0][0] == '@') {
120 /* @major,minor[-last] */
121 /* (useful when name is ambiguous:
122 * "/sys/class/usb/lp0" and
123 * "/sys/class/printer/lp0") */
124 int cmaj, cmin0, cmin1, sc;
125 if (major < 0)
126 continue; /* no dev, no match */
127 sc = sscanf(tokens[0], "@%u,%u-%u", &cmaj, &cmin0, &cmin1);
128 if (sc < 1 || major != cmaj
129 || (sc == 2 && minor != cmin0)
130 || (sc == 3 && (minor < cmin0 || minor > cmin1))
131 ) {
132 continue; /* no match */
133 }
134 } else { /* ... or regex to match device name */
118 regex_t match; 135 regex_t match;
119 int result; 136 int result;
120 137
@@ -144,27 +161,7 @@ static void make_device(char *path, int delete)
144 * after parsing the rest of fields */ 161 * after parsing the rest of fields */
145 162
146 /* 2nd field: uid:gid - device ownership */ 163 /* 2nd field: uid:gid - device ownership */
147 { 164 parse_chown_usergroup_or_die(&ugid, tokens[1]);
148 struct passwd *pass;
149 struct group *grp;
150 char *str_uid = tokens[1];
151 char *str_gid = strchrnul(str_uid, ':');
152
153 if (*str_gid)
154 *str_gid++ = '\0';
155 /* Parse UID */
156 pass = getpwnam(str_uid);
157 if (pass)
158 uid = pass->pw_uid;
159 else
160 uid = strtoul(str_uid, NULL, 10);
161 /* Parse GID */
162 grp = getgrnam(str_gid);
163 if (grp)
164 gid = grp->gr_gid;
165 else
166 gid = strtoul(str_gid, NULL, 10);
167 }
168 165
169 /* 3rd field: mode - device permissions */ 166 /* 3rd field: mode - device permissions */
170 mode = strtoul(tokens[2], NULL, 8); 167 mode = strtoul(tokens[2], NULL, 8);
@@ -243,7 +240,7 @@ static void make_device(char *path, int delete)
243 config_close(parser); 240 config_close(parser);
244#endif /* ENABLE_FEATURE_MDEV_CONF */ 241#endif /* ENABLE_FEATURE_MDEV_CONF */
245 242
246 if (!delete && sscanf(dev_maj_min, "%u:%u", &major, &minor) == 2) { 243 if (!delete && major >= 0) {
247 244
248 if (ENABLE_FEATURE_MDEV_RENAME) 245 if (ENABLE_FEATURE_MDEV_RENAME)
249 unlink(device_name); 246 unlink(device_name);
@@ -255,7 +252,7 @@ static void make_device(char *path, int delete)
255 symlink(device_name, "root"); 252 symlink(device_name, "root");
256 253
257#if ENABLE_FEATURE_MDEV_CONF 254#if ENABLE_FEATURE_MDEV_CONF
258 chown(device_name, uid, gid); 255 chown(device_name, ugid.uid, ugid.gid);
259 256
260#if ENABLE_FEATURE_MDEV_RENAME 257#if ENABLE_FEATURE_MDEV_RENAME
261 if (alias) { 258 if (alias) {