udev-event.c revision cdae488a3fbca5a61b3f8ea0651730cfa2da9cb0
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering * Copyright (C) 2003-2009 Kay Sievers <kay.sievers@vrfy.org>
3e2147858f21943d5f4a781c60f33ac22c6096edKay Sievers * This program is free software: you can redistribute it and/or modify
3e2147858f21943d5f4a781c60f33ac22c6096edKay Sievers * it under the terms of the GNU General Public License as published by
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering * the Free Software Foundation, either version 2 of the License, or
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering * (at your option) any later version.
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering * This program is distributed in the hope that it will be useful,
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering * but WITHOUT ANY WARRANTY; without even the implied warranty of
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering * GNU General Public License for more details.
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering * You should have received a copy of the GNU General Public License
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering * along with this program. If not, see <http://www.gnu.org/licenses/>.
907dd1953b7517534d646f5b2777780020c896e2Kay Sieversstruct udev_event *udev_event_new(struct udev_device *dev)
0e3b0a95cc57cf8c51b20b5b94af7e51c5e424f3Jan Alexander Steffens (heftig) event->udev = udev_device_get_udev(dev);
0e3b0a95cc57cf8c51b20b5b94af7e51c5e424f3Jan Alexander Steffens (heftig) udev_list_init(&event->run_list);
0e3b0a95cc57cf8c51b20b5b94af7e51c5e424f3Jan Alexander Steffens (heftig) dbg(event->udev, "allocated event %p\n", event);
0e3b0a95cc57cf8c51b20b5b94af7e51c5e424f3Jan Alexander Steffens (heftig)void udev_event_unref(struct udev_event *event)
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering udev_list_cleanup_entries(event->udev, &event->run_list);
f15515b5e6a9ebe95c938cc670df6e576fcf9176Filipe Brandenburgersize_t udev_event_apply_format(struct udev_event *event, const char *src, char *dest, size_t size)
2f96919bcdd0978164c801b21e053fb3b31e8bacFilipe Brandenburger static const struct subst_map {
1c7dde3e475978c569a982d65fd86d4b4e3caad8Bastien Nocera { .name = "tempnode", .fmt = 'N', .type = SUBST_TEMP_NODE },
e9da3678fcfc774b325dc1eaa054d0e00028a1fcLennart Poettering { .name = "attr", .fmt = 's', .type = SUBST_ATTR },
e9da3678fcfc774b325dc1eaa054d0e00028a1fcLennart Poettering { .name = "sysfs", .fmt = 's', .type = SUBST_ATTR },
e9da3678fcfc774b325dc1eaa054d0e00028a1fcLennart Poettering { .name = "env", .fmt = 'E', .type = SUBST_ENV },
3ce4fad8f548db9edb19869ea540e3192d2123f4Kay Sievers { .name = "kernel", .fmt = 'k', .type = SUBST_KERNEL },
f975e971accc4d50c73ae53167db3df7a7099cf2Lennart Poettering { .name = "number", .fmt = 'n', .type = SUBST_KERNEL_NUMBER },
e9da3678fcfc774b325dc1eaa054d0e00028a1fcLennart Poettering { .name = "driver", .fmt = 'd', .type = SUBST_DRIVER },
3e2147858f21943d5f4a781c60f33ac22c6096edKay Sievers { .name = "devpath", .fmt = 'p', .type = SUBST_DEVPATH },
92ec4495f76a7a2a6c31f5bb2a5240f78dcfe1d2Javier Jardón { .name = "id", .fmt = 'b', .type = SUBST_ID },
2d0efdf1af5ff77441228854343c61d42a89840cSamuli Suominen { .name = "major", .fmt = 'M', .type = SUBST_MAJOR },
2d0efdf1af5ff77441228854343c61d42a89840cSamuli Suominen { .name = "minor", .fmt = 'm', .type = SUBST_MINOR },
b51fc639f01ee6194af3e7e944a79accce474fe1Dave Reisner { .name = "result", .fmt = 'c', .type = SUBST_RESULT },
dd5ae4c36c89da5dbe8d1628939b26c00db98753Przemyslaw Kedzierski { .name = "parent", .fmt = 'P', .type = SUBST_PARENT },
dd5ae4c36c89da5dbe8d1628939b26c00db98753Przemyslaw Kedzierski { .name = "name", .fmt = 'D', .type = SUBST_NAME },
2d0efdf1af5ff77441228854343c61d42a89840cSamuli Suominen { .name = "links", .fmt = 'L', .type = SUBST_LINKS },
96ede2601f27cd5fe52eed96b873bef55cd0ce23Lennart Poettering { .name = "root", .fmt = 'r', .type = SUBST_ROOT },
2d0efdf1af5ff77441228854343c61d42a89840cSamuli Suominen { .name = "sys", .fmt = 'S', .type = SUBST_SYS },
4acbce79798347cddf1e1d42e9be571e0a041873Zbigniew Jędrzejewski-Szmek enum subst_type type = SUBST_UNKNOWN;
b62cfcea00862ccbf0e5e297f8a339f70987edefMichael Biebl /* substitute named variable */
b62cfcea00862ccbf0e5e297f8a339f70987edefMichael Biebl unsigned int i;
732bfe09aeffc3cd78b80ee9e20c9c3babd944d6Zbigniew Jędrzejewski-Szmek for (i = 0; i < ARRAY_SIZE(map); i++) {
732bfe09aeffc3cd78b80ee9e20c9c3babd944d6Zbigniew Jędrzejewski-Szmek if (strncmp(&from[1], map[i].name, strlen(map[i].name)) == 0) {
732bfe09aeffc3cd78b80ee9e20c9c3babd944d6Zbigniew Jędrzejewski-Szmek dbg(event->udev, "will substitute format name '%s'\n", map[i].name);
ae0ceefc2f432bc1068889fcff53d929eca8a3c4Zbigniew Jędrzejewski-Szmek /* substitute format char */
ae0ceefc2f432bc1068889fcff53d929eca8a3c4Zbigniew Jędrzejewski-Szmek for (i = 0; i < ARRAY_SIZE(map); i++) {
ae0ceefc2f432bc1068889fcff53d929eca8a3c4Zbigniew Jędrzejewski-Szmek dbg(event->udev, "will substitute format char '%c'\n", map[i].fmt);
be1a67d9d63bfdd4a5f8ba9cfc804030f10f5833Lennart Poettering /* copy char */
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering /* extract possible $format{attr} */
8dc31a63981267f257583ef82ceb79859ff243f8Daniel Mack unsigned int i;
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering err(event->udev, "missing closing brace for format '%s'\n", src);
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering if (i >= sizeof(attrbuf))
9b85fc6a89386582bfe792dba881800b0a093839Gustavo Sverzut Barbieri l = util_strpcpy(&s, l, udev_device_get_devpath(dev));
9b85fc6a89386582bfe792dba881800b0a093839Gustavo Sverzut Barbieri dbg(event->udev, "substitute devpath '%s'\n", udev_device_get_devpath(dev));
2a4d1ec1520c926b0160efe14142634e164ddc30Cristian Rodríguez l = util_strpcpy(&s, l, udev_device_get_sysname(dev));
c1663b9daf5a43425e54bbe3daf6b10e64578f80Lennart Poettering dbg(event->udev, "substitute kernel name '%s'\n", udev_device_get_sysname(dev));
a01a4517e16c532fbd5203fbfe2571255e2cd312Filipe Brandenburger if (udev_device_get_sysnum(dev) == NULL)
a01a4517e16c532fbd5203fbfe2571255e2cd312Filipe Brandenburger l = util_strpcpy(&s, l, udev_device_get_sysnum(dev));
a01a4517e16c532fbd5203fbfe2571255e2cd312Filipe Brandenburger dbg(event->udev, "substitute kernel number '%s'\n", udev_device_get_sysnum(dev));
a01a4517e16c532fbd5203fbfe2571255e2cd312Filipe Brandenburger l = util_strpcpy(&s, l, udev_device_get_sysname(event->dev_parent));
a01a4517e16c532fbd5203fbfe2571255e2cd312Filipe Brandenburger dbg(event->udev, "substitute id '%s'\n", udev_device_get_sysname(event->dev_parent));
b850b06e1efcc7e27cfd785759a3a913ac9ed196Kay Sievers driver = udev_device_get_driver(event->dev_parent);
ae0ceefc2f432bc1068889fcff53d929eca8a3c4Zbigniew Jędrzejewski-Szmek l = util_strpcpy(&s, l, driver);
5a45a93627609451784a04366cfa1150d32611d1Lennart Poettering dbg(event->udev, "substitute driver '%s'\n", driver);
9e7adc3ae1133fa08a468768a490812299fad030Lucas De Marchi sprintf(num, "%d", major(udev_device_get_devnum(dev)));
2b4919a68cf826efbe939291e6dc4f08e824dc41Kay Sievers dbg(event->udev, "substitute major number '%s'\n", num);
2b4919a68cf826efbe939291e6dc4f08e824dc41Kay Sievers sprintf(num, "%d", minor(udev_device_get_devnum(dev)));
2b4919a68cf826efbe939291e6dc4f08e824dc41Kay Sievers dbg(event->udev, "substitute minor number '%s'\n", num);
39c4ead2323b45bbe9866e0f97fd8dcfb8a0bedeZbigniew Jędrzejewski-Szmek if (event->program_result == NULL)
39c4ead2323b45bbe9866e0f97fd8dcfb8a0bedeZbigniew Jędrzejewski-Szmek /* get part part of the result string */
de0671ee7fe465e108f62dcbbbe9366f81dd9e9aZbigniew Jędrzejewski-Szmek dbg(event->udev, "request part #%d of result string\n", i);
de0671ee7fe465e108f62dcbbbe9366f81dd9e9aZbigniew Jędrzejewski-Szmek util_strscpy(result, sizeof(result), event->program_result);
c937e0d5c579863677e0fcb5508517f7714c332dZbigniew Jędrzejewski-Szmek while (cpos[0] != '\0' && !isspace(cpos[0]))
32dcef3ab1eb91ee469c3246ef859578dccd8a45Zbigniew Jędrzejewski-Szmek err(event->udev, "requested part of result string not found\n");
be8737ae386166d2f279767ac87b226204c0de7eFilipe Brandenburger /* %{2+}c copies the whole string from the second part on */
747cf8cdf61cdad068c727e42eac699f2505ae77Zbigniew Jędrzejewski-Szmek dbg(event->udev, "substitute part of result string '%s'\n", tmp);
747cf8cdf61cdad068c727e42eac699f2505ae77Zbigniew Jędrzejewski-Szmek l = util_strpcpy(&s, l, event->program_result);
747cf8cdf61cdad068c727e42eac699f2505ae77Zbigniew Jędrzejewski-Szmek dbg(event->udev, "substitute result string '%s'\n", event->program_result);
7959ff9914a6f3a59dbff95c199bcc540b70ac94Kay Sievers err(event->udev, "missing file parameter for attr\n");
85f19d825e7504676f3a80c78c1d9a7ec35a3b3fMichael Biebl /* try to read the value specified by "[dmi/id]product_name" */
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering if (util_resolve_subsys_kernel(event->udev, attr, vbuf, sizeof(vbuf), 1) == 0)
7959ff9914a6f3a59dbff95c199bcc540b70ac94Kay Sievers /* try to read the attribute the device */
27c64db6dff88ebe9761dfe3b0c073d2a9bf2e41Zbigniew Jędrzejewski-Szmek value = udev_device_get_sysattr_value(event->dev, attr);
e287086b8aa2558356af225a12d9bfea8e7d61caLennart Poettering /* try to read the attribute of the parent device, other matches have selected */
81577dc22887debaf9b19bf1034a2887fb9069c7Zbigniew Jędrzejewski-Szmek if (value == NULL && event->dev_parent != NULL && event->dev_parent != event->dev)
81577dc22887debaf9b19bf1034a2887fb9069c7Zbigniew Jędrzejewski-Szmek value = udev_device_get_sysattr_value(event->dev_parent, attr);
81577dc22887debaf9b19bf1034a2887fb9069c7Zbigniew Jędrzejewski-Szmek /* strip trailing whitespace, and replace unwanted characters */
81577dc22887debaf9b19bf1034a2887fb9069c7Zbigniew Jędrzejewski-Szmek util_strscpy(vbuf, sizeof(vbuf), value);
c4a5ddc9f29cf910fac9d814cd898b4cc2bd79b1Tom Gundersen count = udev_util_replace_chars(vbuf, UDEV_ALLOWED_CHARS_INPUT);
75616a1332aff00d27db713cda3bd93c508a5b59Zbigniew Jędrzejewski-Szmek info(event->udev, "%i character(s) replaced\n" , count);
81577dc22887debaf9b19bf1034a2887fb9069c7Zbigniew Jędrzejewski-Szmek dbg(event->udev, "substitute sysfs value '%s'\n", vbuf);
34f7b9f98facbf3431c6849622104cee992f2b7dLennart Poettering dev_parent = udev_device_get_parent(event->dev);
81577dc22887debaf9b19bf1034a2887fb9069c7Zbigniew Jędrzejewski-Szmek devnode = udev_device_get_devnode(dev_parent);
81577dc22887debaf9b19bf1034a2887fb9069c7Zbigniew Jędrzejewski-Szmek size_t devlen = strlen(udev_get_dev_path(event->udev))+1;
81577dc22887debaf9b19bf1034a2887fb9069c7Zbigniew Jędrzejewski-Szmek l = util_strpcpy(&s, l, &devnode[devlen]);
81577dc22887debaf9b19bf1034a2887fb9069c7Zbigniew Jędrzejewski-Szmek dbg(event->udev, "found parent '%s', got node name '%s'\n",
81577dc22887debaf9b19bf1034a2887fb9069c7Zbigniew Jędrzejewski-Szmek udev_device_get_syspath(dev_parent), &devnode[devlen]);
ac6b760ceedd4b21921b6a682cf1479af3d3024fZbigniew Jędrzejewski-Szmek l = util_strpcpy(&s, l, event->tmp_node);
ac6b760ceedd4b21921b6a682cf1479af3d3024fZbigniew Jędrzejewski-Szmek dbg(event->udev, "tempnode: return earlier created one\n");
ac6b760ceedd4b21921b6a682cf1479af3d3024fZbigniew Jędrzejewski-Szmek devnum = udev_device_get_devnum(dev);
ac6b760ceedd4b21921b6a682cf1479af3d3024fZbigniew Jędrzejewski-Szmek /* lookup kernel provided node */
37161c5148396448921841ae1026b281c7949652Emil Renner Berthing udev_get_dev_path(event->udev), "/", udev_device_get_knodename(dev), NULL);
37161c5148396448921841ae1026b281c7949652Emil Renner Berthing if (stat(filename, &statbuf) == 0 && statbuf.st_rdev == devnum) {
37161c5148396448921841ae1026b281c7949652Emil Renner Berthing dbg(event->udev, "tempnode: return kernel node\n");
37161c5148396448921841ae1026b281c7949652Emil Renner Berthing /* lookup /dev/{char,block}/<maj>:<min> */
37161c5148396448921841ae1026b281c7949652Emil Renner Berthing if (strcmp(udev_device_get_subsystem(dev), "block") == 0)
53e856e16ac37fe30b8bb59153ff69aad0fa9c27Zbigniew Jędrzejewski-Szmek snprintf(filename, sizeof(filename), "%s/%s/%u:%u",
53e856e16ac37fe30b8bb59153ff69aad0fa9c27Zbigniew Jędrzejewski-Szmek udev_get_dev_path(event->udev), devtype,
53e856e16ac37fe30b8bb59153ff69aad0fa9c27Zbigniew Jędrzejewski-Szmek major(udev_device_get_devnum(dev)),
53e856e16ac37fe30b8bb59153ff69aad0fa9c27Zbigniew Jędrzejewski-Szmek minor(udev_device_get_devnum(dev)));
53e856e16ac37fe30b8bb59153ff69aad0fa9c27Zbigniew Jędrzejewski-Szmek if (stat(filename, &statbuf) == 0 && statbuf.st_rdev == devnum) {
53e856e16ac37fe30b8bb59153ff69aad0fa9c27Zbigniew Jędrzejewski-Szmek l = util_strpcpy(&s, l, filename);
53e856e16ac37fe30b8bb59153ff69aad0fa9c27Zbigniew Jędrzejewski-Szmek dbg(event->udev, "tempnode: return maj:min node\n");
6aea6d10f460853111ca8744201ec8dade97de3cThomas H.P. Andersen /* create temporary node */
6aea6d10f460853111ca8744201ec8dade97de3cThomas H.P. Andersen dbg(event->udev, "tempnode: create temp node\n");
6aea6d10f460853111ca8744201ec8dade97de3cThomas H.P. Andersen asprintf(&event->tmp_node, "%s/.tmp-%s-%u:%u",
6aea6d10f460853111ca8744201ec8dade97de3cThomas H.P. Andersen udev_get_dev_path(event->udev), devtype,
6aea6d10f460853111ca8744201ec8dade97de3cThomas H.P. Andersen udev_node_mknod(dev, event->tmp_node, makedev(0, 0), 0600, 0, 0);
6aea6d10f460853111ca8744201ec8dade97de3cThomas H.P. Andersen l = util_strpcpy(&s, l, event->tmp_node);
6aea6d10f460853111ca8744201ec8dade97de3cThomas H.P. Andersen dbg(event->udev, "substitute name '%s'\n", event->name);
6aea6d10f460853111ca8744201ec8dade97de3cThomas H.P. Andersen l = util_strpcpy(&s, l, udev_device_get_sysname(dev));
6aea6d10f460853111ca8744201ec8dade97de3cThomas H.P. Andersen dbg(event->udev, "substitute sysname '%s'\n", udev_device_get_sysname(dev));
6aea6d10f460853111ca8744201ec8dade97de3cThomas H.P. Andersen size_t devlen = strlen(udev_get_dev_path(event->udev))+1;
e30431623a7d871da123cc37055ac49abf2c20eaTom Gundersen list_entry = udev_device_get_devlinks_list_entry(dev);
e2ca86cf78f911a8be51f0224796e24883019139Dave Reisner l = util_strpcpy(&s, l, &udev_list_entry_get_name(list_entry)[devlen]);
a18535d9e138c525d0443ec9f30a90b3e2184686Tom Gundersen udev_list_entry_foreach(list_entry, udev_list_entry_get_next(list_entry))
e2ca86cf78f911a8be51f0224796e24883019139Dave Reisner l = util_strpcpyl(&s, l, " ", &udev_list_entry_get_name(list_entry)[devlen], NULL);
c4955740969d7ba8ba43b024bca1a0a5b56eb8e8Tom Gundersen l = util_strpcpy(&s, l, udev_get_dev_path(event->udev));
e30431623a7d871da123cc37055ac49abf2c20eaTom Gundersen dbg(event->udev, "substitute udev_root '%s'\n", udev_get_dev_path(event->udev));
f553b3b1074151200187df916427a1468186435eAnders Olofsson l = util_strpcpy(&s, l, udev_get_sys_path(event->udev));
d4f5a1f47dbd04f26f2ddf951c97c4cb0ebbbe62David Herrmann dbg(event->udev, "substitute sys_path '%s'\n", udev_get_sys_path(event->udev));
d4f5a1f47dbd04f26f2ddf951c97c4cb0ebbbe62David Herrmann value = udev_device_get_property_value(event->dev, attr);
f553b3b1074151200187df916427a1468186435eAnders Olofsson dbg(event->udev, "substitute env '%s=%s'\n", attr, value);
f553b3b1074151200187df916427a1468186435eAnders Olofsson err(event->udev, "unknown substitution type=%i\n", type);
8d3ae2bd4c9bf9fc2e57f7b3776325a1c750ca30Chris Leech dbg(event->udev, "'%s' -> '%s' (%zu)\n", src, dest, l);
8d3ae2bd4c9bf9fc2e57f7b3776325a1c750ca30Chris Leechstatic void rename_netif_kernel_log(struct ifreq ifr)
c0467cf387548dc98c0254f63553d862b35a84e5Ronny Chevalier fprintf(f, "<6>udev: renamed network interface %s to %s\n",
3e2147858f21943d5f4a781c60f33ac22c6096edKay Sieversstatic int rename_netif(struct udev_event *event)
816115863962548a9a0d9fbfe429c7f8e685beacRoberto Sassu info(event->udev, "changing net interface name from '%s' to '%s'\n",
816115863962548a9a0d9fbfe429c7f8e685beacRoberto Sassu err(event->udev, "error opening socket: %m\n");
591622d7efbc828f00f190d91b6608148b967ff5Lennart Poettering memset(&ifr, 0x00, sizeof(struct ifreq));
591622d7efbc828f00f190d91b6608148b967ff5Lennart Poettering util_strscpy(ifr.ifr_name, IFNAMSIZ, udev_device_get_sysname(dev));
3f8cc098d218525710e5cbad9adf37001d3b6060Jan Engelhardt util_strscpy(ifr.ifr_newname, IFNAMSIZ, event->name);
591622d7efbc828f00f190d91b6608148b967ff5Lennart Poettering /* see if the destination interface name already exists */
591622d7efbc828f00f190d91b6608148b967ff5Lennart Poettering err(event->udev, "error changing netif name %s to %s: %m\n",
eef65bf3ee6f73afa4a5de23ae3a794a279f30c0Michael Scherer /* free our own name, another process may wait for us */
eef65bf3ee6f73afa4a5de23ae3a794a279f30c0Michael Scherer util_strscpyl(ifr.ifr_newname, IFNAMSIZ, udev_device_get_sysname(dev), "_rename", NULL);
eef65bf3ee6f73afa4a5de23ae3a794a279f30c0Michael Scherer err(event->udev, "error changing netif name %s to %s: %m\n",
eef65bf3ee6f73afa4a5de23ae3a794a279f30c0Michael Scherer /* wait 90 seconds for our target to become available */
eef65bf3ee6f73afa4a5de23ae3a794a279f30c0Michael Scherer util_strscpy(ifr.ifr_name, IFNAMSIZ, ifr.ifr_newname);
eef65bf3ee6f73afa4a5de23ae3a794a279f30c0Michael Scherer util_strscpy(ifr.ifr_newname, IFNAMSIZ, event->name);
45df1f2c9a7fee67b37f64ddd00adad5982844faCristian Rodríguez const struct timespec duration = { 0, 1000 * 1000 * 1000 / 20 };
45df1f2c9a7fee67b37f64ddd00adad5982844faCristian Rodríguez err(event->udev, "error changing net interface name %s to %s: %m\n",
45df1f2c9a7fee67b37f64ddd00adad5982844faCristian Rodríguez dbg(event->udev, "wait for netif '%s' to become free, loop=%i\n",
807e17f05e217b474af39503efb9503d81b12596Lennart Poetteringint udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules)
1a2a0ac53bbe724caf41c2bcf22ab9ea32b63d4eZbigniew Jędrzejewski-Szmek struct udev_device *dev = event->dev;
1a2a0ac53bbe724caf41c2bcf22ab9ea32b63d4eZbigniew Jędrzejewski-Szmek if (udev_device_get_sysname_old(dev) != NULL &&
1a2a0ac53bbe724caf41c2bcf22ab9ea32b63d4eZbigniew Jędrzejewski-Szmek strcmp(udev_device_get_sysname_old(dev), udev_device_get_sysname(dev)) != 0) {
1a2a0ac53bbe724caf41c2bcf22ab9ea32b63d4eZbigniew Jędrzejewski-Szmek info(event->udev, "moved database from '%s:%s' to '%s:%s'\n",
1a2a0ac53bbe724caf41c2bcf22ab9ea32b63d4eZbigniew Jędrzejewski-Szmek udev_device_get_subsystem(dev), udev_device_get_sysname_old(dev),
807e17f05e217b474af39503efb9503d81b12596Lennart Poettering udev_device_get_subsystem(dev), udev_device_get_sysname(dev));
edce2aed3aa93b84f7b4c70412bdb665da2977b0Lennart Poettering /* add device node */
edce2aed3aa93b84f7b4c70412bdb665da2977b0Lennart Poettering if (major(udev_device_get_devnum(dev)) != 0 &&
1a2a0ac53bbe724caf41c2bcf22ab9ea32b63d4eZbigniew Jędrzejewski-Szmek (strcmp(udev_device_get_action(dev), "add") == 0 || strcmp(udev_device_get_action(dev), "change") == 0)) {
1a2a0ac53bbe724caf41c2bcf22ab9ea32b63d4eZbigniew Jędrzejewski-Szmek dbg(event->udev, "device node add '%s'\n", udev_device_get_devpath(dev));
1a2a0ac53bbe724caf41c2bcf22ab9ea32b63d4eZbigniew Jędrzejewski-Szmek /* read old database entry */
edce2aed3aa93b84f7b4c70412bdb665da2977b0Lennart Poettering dev_old = udev_device_new_from_syspath(event->udev, udev_device_get_syspath(dev));
8af3cf74df03f7528f9e2605ec7896a5daf0f711Lennart Poettering /* disable watch during event processing */
1a2a0ac53bbe724caf41c2bcf22ab9ea32b63d4eZbigniew Jędrzejewski-Szmek udev_rules_apply_to_event(rules, event);
1a2a0ac53bbe724caf41c2bcf22ab9ea32b63d4eZbigniew Jędrzejewski-Szmek dbg(event->udev, "cleanup temporary device node\n");
8af3cf74df03f7528f9e2605ec7896a5daf0f711Lennart Poettering util_unlink_secure(event->udev, event->tmp_node);
1a2a0ac53bbe724caf41c2bcf22ab9ea32b63d4eZbigniew Jędrzejewski-Szmek if (event->name != NULL && event->name[0] == '\0') {
1a2a0ac53bbe724caf41c2bcf22ab9ea32b63d4eZbigniew Jędrzejewski-Szmek info(event->udev, "device node creation suppressed\n");
1a2a0ac53bbe724caf41c2bcf22ab9ea32b63d4eZbigniew Jędrzejewski-Szmek /* if rule given name disagrees with kernel node name, delete kernel node */
1a2a0ac53bbe724caf41c2bcf22ab9ea32b63d4eZbigniew Jędrzejewski-Szmek if (event->name != NULL && udev_device_get_knodename(dev) != NULL) {
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek if (strcmp(event->name, udev_device_get_knodename(dev)) != 0)
3b1a55e110ab387a8d213581983e20c0a63d7894Zbigniew Jędrzejewski-Szmek /* no rule, use kernel provided name */
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poettering if (udev_device_get_knodename(dev) != NULL) {
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poettering event->name = strdup(udev_device_get_knodename(dev));
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poettering info(event->udev, "no node name set, will use kernel supplied name '%s'\n", event->name);
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poettering event->name = strdup(udev_device_get_sysname(event->dev));
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poettering info(event->udev, "no node name set, will use device name '%s'\n", event->name);
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poettering /* something went wrong */
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poettering err(event->udev, "no node name for '%s'\n", udev_device_get_sysname(event->dev));
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poettering /* set device node name */
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poettering util_strscpyl(filename, sizeof(filename), udev_get_dev_path(event->udev), "/", event->name, NULL);
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poettering /* write current database entry */
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poettering /* remove/update possible left-over symlinks from old database entry */
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poettering udev_node_update_old_links(dev, dev_old);
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poettering /* create new node and symlinks */
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poettering err = udev_node_add(dev, event->mode, event->uid, event->gid);
812cce323db081634f37e4ec6d29f2b9328a3f52Lennart Poettering if (delete_kdevnode && udev_device_get_knodename(dev) != NULL) {
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poettering util_strscpyl(filename, sizeof(filename),
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poettering udev_get_dev_path(event->udev), "/", udev_device_get_knodename(dev), NULL);
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poettering if (stat(filename, &stats) == 0 && stats.st_rdev == udev_device_get_devnum(dev)) {
5b6319dceedd81f3f1ce7eb70ea5defaef43bcecLennart Poettering info(event->udev, "removed kernel created node '%s'\n", filename);
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poettering /* add netif */
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poettering if (strcmp(udev_device_get_subsystem(dev), "net") == 0 && strcmp(udev_device_get_action(dev), "add") == 0) {
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poettering dbg(event->udev, "netif add '%s'\n", udev_device_get_devpath(dev));
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poettering /* look if we want to change the name of the netif */
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poettering if (strcmp(event->name, udev_device_get_sysname(dev)) != 0) {
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poettering info(event->udev, "renamed netif to '%s'\n", event->name);
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poettering /* remember old name */
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poettering udev_device_add_property(dev, "INTERFACE_OLD", udev_device_get_sysname(dev));
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poettering /* now change the devpath, because the kernel device name has changed */
a48a62a1af02aec4473c9deed98dd5b89d210f93Zbigniew Jędrzejewski-Szmek util_strscpy(syspath, sizeof(syspath), udev_device_get_syspath(dev));
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poettering util_strscpy(pos, sizeof(syspath) - (pos - syspath), event->name);
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poettering udev_device_set_syspath(event->dev, syspath);
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poettering udev_device_add_property(dev, "INTERFACE", udev_device_get_sysname(dev));
5eda94dda25bccda928c4b33c790dbe748573a22Lennart Poettering info(event->udev, "changed devpath to '%s'\n", udev_device_get_devpath(dev));
2b3e18de74ca89b374dd4f7a2c30e5731d347841Karol Lewandowski /* remove device node */
2b3e18de74ca89b374dd4f7a2c30e5731d347841Karol Lewandowski if (major(udev_device_get_devnum(dev)) != 0 && strcmp(udev_device_get_action(dev), "remove") == 0) {
2b3e18de74ca89b374dd4f7a2c30e5731d347841Karol Lewandowski /* import database entry and delete it */
d2edfae0f9bdbecf6a8518e2a5bcf06f470e0d9eKay Sievers /* remove watch */
e174dce27173396ed8034c9cfda87eb210365126WaLyong Cho info(event->udev, "'%s' not found in database, using kernel name '%s'\n",
1fab0cbafcb67cff912d0e45de9677135550f924Sangjung Woo udev_device_get_syspath(dev), udev_device_get_knodename(dev));
e174dce27173396ed8034c9cfda87eb210365126WaLyong Cho udev_get_dev_path(event->udev), "/", udev_device_get_knodename(dev), NULL);
e174dce27173396ed8034c9cfda87eb210365126WaLyong Cho info(event->udev, "ignore_remove for '%s'\n", udev_device_get_devnode(dev));
dd5ae4c36c89da5dbe8d1628939b26c00db98753Przemyslaw Kedzierski /* default devices */
dd5ae4c36c89da5dbe8d1628939b26c00db98753Przemyslaw Kedzierski udev_rules_apply_to_event(rules, event);
feb12d3ed2c7f9132c64773c7c41b9e3a608a814Lennart Poettering if (strcmp(udev_device_get_action(dev), "remove") != 0)
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poetteringint udev_event_execute_run(struct udev_event *event, const sigset_t *sigmask)
79e8bde40da4d18c553b64299ebb69f409260df4Olof Johansson udev_list_entry_foreach(list_entry, udev_list_get_entry(&event->run_list)) {
79e8bde40da4d18c553b64299ebb69f409260df4Olof Johansson const char *cmd = udev_list_entry_get_name(list_entry);
79e8bde40da4d18c553b64299ebb69f409260df4Olof Johansson if (strncmp(cmd, "socket:", strlen("socket:")) == 0) {
79e8bde40da4d18c553b64299ebb69f409260df4Olof Johansson monitor = udev_monitor_new_from_socket(event->udev, &cmd[strlen("socket:")]);
79e8bde40da4d18c553b64299ebb69f409260df4Olof Johansson udev_monitor_send_device(monitor, NULL, event->dev);
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poettering udev_event_apply_format(event, cmd, program, sizeof(program));
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poettering envp = udev_device_get_properties_envp(event->dev);
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poettering if (util_run_program(event->udev, program, envp, NULL, 0, NULL, sigmask) != 0) {