udevd.c revision 225cb03bd851adc6d269b13bdf2b1bfded2b96b9
71092d70af35567dd154d3de2ce04ce62e157a7cLennart Poettering/*
9f26fa2217bcad38a6a92a06a598f6c3a3d1b18eKay Sievers * Copyright (C) 2004-2006 Kay Sievers <kay.sievers@vrfy.org>
9f26fa2217bcad38a6a92a06a598f6c3a3d1b18eKay Sievers * Copyright (C) 2004 Chris Friesen <chris_friesen@sympatico.ca>
6db01ccb784c924d883c020996da05469aee8ebdKay Sievers *
6db01ccb784c924d883c020996da05469aee8ebdKay Sievers * This program is free software; you can redistribute it and/or modify it
d086fe4e085d216652b70e575e59302810035989Kay Sievers * under the terms of the GNU General Public License as published by the
d086fe4e085d216652b70e575e59302810035989Kay Sievers * Free Software Foundation version 2 of the License.
d086fe4e085d216652b70e575e59302810035989Kay Sievers *
d086fe4e085d216652b70e575e59302810035989Kay Sievers * This program is distributed in the hope that it will be useful, but
d086fe4e085d216652b70e575e59302810035989Kay Sievers * WITHOUT ANY WARRANTY; without even the implied warranty of
d086fe4e085d216652b70e575e59302810035989Kay Sievers * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9cb48731b29f508178731b45b0643c816800c05eKay Sievers * General Public License for more details.
9cb48731b29f508178731b45b0643c816800c05eKay Sievers *
9cb48731b29f508178731b45b0643c816800c05eKay Sievers * You should have received a copy of the GNU General Public License along
9cb48731b29f508178731b45b0643c816800c05eKay Sievers * with this program; if not, write to the Free Software Foundation, Inc.,
9cb48731b29f508178731b45b0643c816800c05eKay Sievers * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
9cb48731b29f508178731b45b0643c816800c05eKay Sievers *
9cb48731b29f508178731b45b0643c816800c05eKay Sievers */
9cb48731b29f508178731b45b0643c816800c05eKay Sievers
7c66aeba0f28cb82027d6015405ed71afa3b6059Kay Sievers#include <stddef.h>
7c66aeba0f28cb82027d6015405ed71afa3b6059Kay Sievers#include <signal.h>
c904f64d84db8c4eebedf210ba10893f19ba05edLennart Poettering#include <unistd.h>
c904f64d84db8c4eebedf210ba10893f19ba05edLennart Poettering#include <errno.h>
05677bb78079c3fa0283101aac2c07581f4873f1Lennart Poettering#include <stdio.h>
73090dc815390f4fca4e3ed8a7e1d3806605daaaLennart Poettering#include <stdlib.h>
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers#include <string.h>
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers#include <ctype.h>
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers#include <dirent.h>
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers#include <fcntl.h>
9a36607584bbd1d78775353e022a51794b4e27b1Lennart Poettering#include <syslog.h>
9a36607584bbd1d78775353e022a51794b4e27b1Lennart Poettering#include <time.h>
a40593a0d0d740efa387e35411e1e456a6c5aba7Lennart Poettering#include <getopt.h>
20ffc4c4a9226b0e45cc02ad9c0108981626c0bbKay Sievers#include <sys/select.h>
871206d340ed6119b31daeb8b13c8ef5ccf25501Kay Sievers#include <sys/wait.h>
871206d340ed6119b31daeb8b13c8ef5ccf25501Kay Sievers#include <sys/types.h>
871206d340ed6119b31daeb8b13c8ef5ccf25501Kay Sievers#include <sys/socket.h>
825c6fe5eb362437aa46faa52b683a62eede9a13Lennart Poettering#include <sys/un.h>
825c6fe5eb362437aa46faa52b683a62eede9a13Lennart Poettering#include <sys/stat.h>
825c6fe5eb362437aa46faa52b683a62eede9a13Lennart Poettering#include <sys/ioctl.h>
825c6fe5eb362437aa46faa52b683a62eede9a13Lennart Poettering#include <linux/types.h>
825c6fe5eb362437aa46faa52b683a62eede9a13Lennart Poettering#include <linux/netlink.h>
825c6fe5eb362437aa46faa52b683a62eede9a13Lennart Poettering
825c6fe5eb362437aa46faa52b683a62eede9a13Lennart Poettering#include "udev.h"
825c6fe5eb362437aa46faa52b683a62eede9a13Lennart Poettering#include "udev_rules.h"
825c6fe5eb362437aa46faa52b683a62eede9a13Lennart Poettering#include "udevd.h"
825c6fe5eb362437aa46faa52b683a62eede9a13Lennart Poettering#include "udev_selinux.h"
825c6fe5eb362437aa46faa52b683a62eede9a13Lennart Poettering
825c6fe5eb362437aa46faa52b683a62eede9a13Lennart Poetteringstatic int debug_trace;
e146e4516b9ea9907852e7ad609de39dca9e8769Kay Sieversstatic int verbose;
e146e4516b9ea9907852e7ad609de39dca9e8769Kay Sievers
e146e4516b9ea9907852e7ad609de39dca9e8769Kay Sieversstatic struct udev_rules rules;
e146e4516b9ea9907852e7ad609de39dca9e8769Kay Sieversstatic int udevd_sock = -1;
e146e4516b9ea9907852e7ad609de39dca9e8769Kay Sieversstatic int uevent_netlink_sock = -1;
71092d70af35567dd154d3de2ce04ce62e157a7cLennart Poetteringstatic int inotify_fd = -1;
dcfc4b2e5c1af6375488c00bdc6fb8122f86c4d7Lennart Poetteringstatic pid_t sid;
424a19f8a2061c6b058283228734010b2fa24db4Lennart Poettering
424a19f8a2061c6b058283228734010b2fa24db4Lennart Poetteringstatic int signal_pipe[2] = {-1, -1};
424a19f8a2061c6b058283228734010b2fa24db4Lennart Poetteringstatic volatile int sigchilds_waiting;
424a19f8a2061c6b058283228734010b2fa24db4Lennart Poetteringstatic volatile int udev_exit;
67f3c40265471056d1e532c6d6e36a521b0a780aLennart Poetteringstatic volatile int reload_config;
67f3c40265471056d1e532c6d6e36a521b0a780aLennart Poetteringstatic int run_exec_q;
a1cccad1fe88ddd6943e18af97cf7f466296970fLennart Poetteringstatic int stop_exec_q;
a1cccad1fe88ddd6943e18af97cf7f466296970fLennart Poetteringstatic int max_childs;
a1cccad1fe88ddd6943e18af97cf7f466296970fLennart Poetteringstatic int max_childs_running;
a1cccad1fe88ddd6943e18af97cf7f466296970fLennart Poetteringstatic char udev_log[32];
a1cccad1fe88ddd6943e18af97cf7f466296970fLennart Poettering
a1cccad1fe88ddd6943e18af97cf7f466296970fLennart Poetteringstatic LIST_HEAD(exec_list);
a1cccad1fe88ddd6943e18af97cf7f466296970fLennart Poetteringstatic LIST_HEAD(running_list);
a1cccad1fe88ddd6943e18af97cf7f466296970fLennart Poettering
a1cccad1fe88ddd6943e18af97cf7f466296970fLennart Poettering
a1cccad1fe88ddd6943e18af97cf7f466296970fLennart Poettering#ifdef USE_LOG
a1cccad1fe88ddd6943e18af97cf7f466296970fLennart Poetteringvoid log_message(int priority, const char *format, ...)
a8b10efaec5005b8e4fcc2bebdf86993ad14993dLennart Poettering{
a8b10efaec5005b8e4fcc2bebdf86993ad14993dLennart Poettering va_list args;
8556879e0d14925ce897875c6c264368e2d048c2Lennart Poettering
8556879e0d14925ce897875c6c264368e2d048c2Lennart Poettering if (priority > udev_log_priority)
8556879e0d14925ce897875c6c264368e2d048c2Lennart Poettering return;
8556879e0d14925ce897875c6c264368e2d048c2Lennart Poettering
8556879e0d14925ce897875c6c264368e2d048c2Lennart Poettering va_start(args, format);
8556879e0d14925ce897875c6c264368e2d048c2Lennart Poettering if (verbose) {
8556879e0d14925ce897875c6c264368e2d048c2Lennart Poettering printf("[%d] ", (int) getpid());
8556879e0d14925ce897875c6c264368e2d048c2Lennart Poettering vprintf(format, args);
8556879e0d14925ce897875c6c264368e2d048c2Lennart Poettering printf("\n");
8556879e0d14925ce897875c6c264368e2d048c2Lennart Poettering } else
8556879e0d14925ce897875c6c264368e2d048c2Lennart Poettering vsyslog(priority, format, args);
8556879e0d14925ce897875c6c264368e2d048c2Lennart Poettering va_end(args);
4a30847b9d71e0381948d68279c8f775b9de7850Lennart Poettering}
4a30847b9d71e0381948d68279c8f775b9de7850Lennart Poettering
b5b46d599524341ddd7407e5dff1021af8ff5089Lennart Poettering#endif
b5b46d599524341ddd7407e5dff1021af8ff5089Lennart Poettering
802840582c71e9679637a4631866ce2d179f03c5Lennart Poetteringstatic void asmlinkage udev_event_sig_handler(int signum)
802840582c71e9679637a4631866ce2d179f03c5Lennart Poettering{
5e8b28838e493b59628322b69580097ef7dd9384Lennart Poettering if (signum == SIGALRM)
5e8b28838e493b59628322b69580097ef7dd9384Lennart Poettering exit(1);
5e8b28838e493b59628322b69580097ef7dd9384Lennart Poettering}
5e8b28838e493b59628322b69580097ef7dd9384Lennart Poettering
d87be9b0af81a6e07d4fb3028e45c4409100dc26Lennart Poetteringstatic int udev_event_process(struct udevd_uevent_msg *msg)
d87be9b0af81a6e07d4fb3028e45c4409100dc26Lennart Poettering{
438bacd18e0b8766c5add47f28b04876272daa97Lennart Poettering struct sigaction act;
438bacd18e0b8766c5add47f28b04876272daa97Lennart Poettering struct udevice *udev;
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering int i;
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering int retval;
d87be9b0af81a6e07d4fb3028e45c4409100dc26Lennart Poettering
d87be9b0af81a6e07d4fb3028e45c4409100dc26Lennart Poettering /* set signal handlers */
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering memset(&act, 0x00, sizeof(act));
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering act.sa_handler = (void (*)(int)) udev_event_sig_handler;
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering sigemptyset (&act.sa_mask);
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering act.sa_flags = 0;
cb7ed9dfca647198bce95f503552710eae22da37Lennart Poettering sigaction(SIGALRM, &act, NULL);
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering /* reset to default */
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering act.sa_handler = SIG_DFL;
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering sigaction(SIGINT, &act, NULL);
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering sigaction(SIGTERM, &act, NULL);
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering sigaction(SIGCHLD, &act, NULL);
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering sigaction(SIGHUP, &act, NULL);
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering /* trigger timeout to prevent hanging processes */
a6e87e90ede66815989ba2db92a07102a69906feLennart Poettering alarm(UDEV_ALARM_TIMEOUT);
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering /* reconstruct event environment from message */
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering for (i = 0; msg->envp[i]; i++)
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering putenv(msg->envp[i]);
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering udev = udev_device_init(NULL);
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering if (udev == NULL)
1946b0bd55b356ea25bd747cb338a4b31fabeecfLennart Poettering return -1;
1946b0bd55b356ea25bd747cb338a4b31fabeecfLennart Poettering strlcpy(udev->action, msg->action, sizeof(udev->action));
cde9cb343ae101660dd36992cae730b63c7cd617Lennart Poettering sysfs_device_set_values(udev->dev, msg->devpath, msg->subsystem, msg->driver);
877d54e9b09e093c2102f519a84e2a52637ae035Lennart Poettering udev->devpath_old = msg->devpath_old;
38a60d7112d33ffd596b23e8df53d75a7c09e71bLennart Poettering udev->devt = msg->devt;
38a60d7112d33ffd596b23e8df53d75a7c09e71bLennart Poettering
c0d6e764d107a81a6439c41edbe92790623ed7deLennart Poettering retval = udev_device_event(&rules, udev);
c0d6e764d107a81a6439c41edbe92790623ed7deLennart Poettering
c0ca7aeec963207b6fa5ee39bd204cb26cba4023Lennart Poettering /* run programs collected by RUN-key*/
c0ca7aeec963207b6fa5ee39bd204cb26cba4023Lennart Poettering if (retval == 0 && !udev->ignore_device && udev_run)
c0ca7aeec963207b6fa5ee39bd204cb26cba4023Lennart Poettering retval = udev_rules_run(udev);
c0ca7aeec963207b6fa5ee39bd204cb26cba4023Lennart Poettering
d8b78264a5245307babbf5af8e39d6d4a1ae095fLennart Poettering udev_device_cleanup(udev);
d8b78264a5245307babbf5af8e39d6d4a1ae095fLennart Poettering return retval;
d8b78264a5245307babbf5af8e39d6d4a1ae095fLennart Poettering}
d8b78264a5245307babbf5af8e39d6d4a1ae095fLennart Poettering
50b3e64e27d1e73b84f96359f9f38dd497cb9b59Lennart Poetteringenum event_state {
50b3e64e27d1e73b84f96359f9f38dd497cb9b59Lennart Poettering EVENT_QUEUED,
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poettering EVENT_FINISHED,
7560fffcd2531786b9c1ca657667a43e90331326Lennart Poettering EVENT_FAILED,
5a7e959984788cf89719dec31999409b63bb802bLennart Poettering};
5a7e959984788cf89719dec31999409b63bb802bLennart Poettering
68f160039eb78fe122cfe0d4c49695ae91f6f0d1Lennart Poetteringstatic void export_event_state(struct udevd_uevent_msg *msg, enum event_state state)
0790b9fed42eefc4e22dbbe2337cba9713b7848cLennart Poettering{
5a7e959984788cf89719dec31999409b63bb802bLennart Poettering char filename[PATH_SIZE];
5a7e959984788cf89719dec31999409b63bb802bLennart Poettering char filename_failed[PATH_SIZE];
68f160039eb78fe122cfe0d4c49695ae91f6f0d1Lennart Poettering size_t start;
68f160039eb78fe122cfe0d4c49695ae91f6f0d1Lennart Poettering
68f160039eb78fe122cfe0d4c49695ae91f6f0d1Lennart Poettering /* location of queue file */
68f160039eb78fe122cfe0d4c49695ae91f6f0d1Lennart Poettering snprintf(filename, sizeof(filename), "%s/"EVENT_QUEUE_DIR"/%llu", udev_root, msg->seqnum);
68f160039eb78fe122cfe0d4c49695ae91f6f0d1Lennart Poettering
68f160039eb78fe122cfe0d4c49695ae91f6f0d1Lennart Poettering /* location of failed file */
0790b9fed42eefc4e22dbbe2337cba9713b7848cLennart Poettering strlcpy(filename_failed, udev_root, sizeof(filename_failed));
68f160039eb78fe122cfe0d4c49695ae91f6f0d1Lennart Poettering strlcat(filename_failed, "/", sizeof(filename_failed));
df1c8f6ac8a45913104b5eeb44f4574689fedd50Lennart Poettering start = strlcat(filename_failed, EVENT_FAILED_DIR"/", sizeof(filename_failed));
5aea932fd54db835b77709ddeba30732648aae53Lennart Poettering strlcat(filename_failed, msg->devpath, sizeof(filename_failed));
5aea932fd54db835b77709ddeba30732648aae53Lennart Poettering path_encode(&filename_failed[start], sizeof(filename_failed) - start);
918943c75fbd9dee87ff396de3a7c63a8d228433Lennart Poettering
918943c75fbd9dee87ff396de3a7c63a8d228433Lennart Poettering switch (state) {
fd4d89b2c0b31da01d134301e30916931ae3c7d9Lennart Poettering case EVENT_QUEUED:
fd4d89b2c0b31da01d134301e30916931ae3c7d9Lennart Poettering unlink(filename_failed);
8230e26dc954a40d8c9dbc8ddd9376117021f9d2Lennart Poettering delete_path(filename_failed);
8230e26dc954a40d8c9dbc8ddd9376117021f9d2Lennart Poettering
dcfc4b2e5c1af6375488c00bdc6fb8122f86c4d7Lennart Poettering create_path(filename);
dcfc4b2e5c1af6375488c00bdc6fb8122f86c4d7Lennart Poettering symlink(msg->devpath, filename);
dcfc4b2e5c1af6375488c00bdc6fb8122f86c4d7Lennart Poettering break;
dcfc4b2e5c1af6375488c00bdc6fb8122f86c4d7Lennart Poettering case EVENT_FINISHED:
4d9909c93e9c58789c71b34555a1908307c6849eLennart Poettering if (msg->devpath_old != NULL) {
4d9909c93e9c58789c71b34555a1908307c6849eLennart Poettering /* "move" event - rename failed file to current name, do not delete failed */
7212a8a99ee863698f5feaa00abb4b99f3996a1aLennart Poettering char filename_failed_old[PATH_SIZE];
7212a8a99ee863698f5feaa00abb4b99f3996a1aLennart Poettering
47ae7201b1df43bd3da83a19e38483b0e5694c99Lennart Poettering strlcpy(filename_failed_old, udev_root, sizeof(filename_failed_old));
47ae7201b1df43bd3da83a19e38483b0e5694c99Lennart Poettering strlcat(filename_failed_old, "/", sizeof(filename_failed_old));
941e990db1f2682abaa2966b1c48602901d0c599Lennart Poettering start = strlcat(filename_failed_old, EVENT_FAILED_DIR"/", sizeof(filename_failed_old));
941e990db1f2682abaa2966b1c48602901d0c599Lennart Poettering strlcat(filename_failed_old, msg->devpath_old, sizeof(filename_failed_old));
decab96090593d617bfd576cb68253a6e082309bLennart Poettering path_encode(&filename_failed_old[start], sizeof(filename) - start);
decab96090593d617bfd576cb68253a6e082309bLennart Poettering
919a7f39e6aa4a93b8348ec2586e313c40f49e52Lennart Poettering if (rename(filename_failed_old, filename_failed) == 0)
919a7f39e6aa4a93b8348ec2586e313c40f49e52Lennart Poettering info("renamed devpath, moved failed state of '%s' to %s'",
88a6c5894c9d3f85d63b87b040c130366b4006ceKay Sievers msg->devpath_old, msg->devpath);
8351ceaea9480d9c2979aa2ff0f4982cfdfef58dLennart Poettering } else {
6a7353684b65f0107cbdfa0a16ab7717ba257b61Lennart Poettering unlink(filename_failed);
6a7353684b65f0107cbdfa0a16ab7717ba257b61Lennart Poettering delete_path(filename_failed);
6b78f9b4354010f8af2fe48c783ffd52b2db8f57Lennart Poettering }
6b78f9b4354010f8af2fe48c783ffd52b2db8f57Lennart Poettering
9f8d29834ba97052403e50ec9b358c0470fa4cebLennart Poettering unlink(filename);
9f8d29834ba97052403e50ec9b358c0470fa4cebLennart Poettering delete_path(filename);
9f8d29834ba97052403e50ec9b358c0470fa4cebLennart Poettering break;
9f8d29834ba97052403e50ec9b358c0470fa4cebLennart Poettering case EVENT_FAILED:
68f160039eb78fe122cfe0d4c49695ae91f6f0d1Lennart Poettering /* move failed event to the failed directory */
68f160039eb78fe122cfe0d4c49695ae91f6f0d1Lennart Poettering create_path(filename_failed);
b7def684941808600c344f0be7a2b9fcdda97e0fLennart Poettering rename(filename, filename_failed);
b7def684941808600c344f0be7a2b9fcdda97e0fLennart Poettering
c66d36e5b5ae81f3c5297d6dacadc13c88c530f6Lennart Poettering /* clean up possibly empty queue directory */
c66d36e5b5ae81f3c5297d6dacadc13c88c530f6Lennart Poettering delete_path(filename);
c66d36e5b5ae81f3c5297d6dacadc13c88c530f6Lennart Poettering break;
c66d36e5b5ae81f3c5297d6dacadc13c88c530f6Lennart Poettering }
c66d36e5b5ae81f3c5297d6dacadc13c88c530f6Lennart Poettering
c66d36e5b5ae81f3c5297d6dacadc13c88c530f6Lennart Poettering return;
be0aa78406c73a6625308dc0672b5ff27ec6f9a8Lennart Poettering}
be0aa78406c73a6625308dc0672b5ff27ec6f9a8Lennart Poettering
461b1822321d6be0d7fd8be29bf3b4993ebd1b85Lennart Poetteringstatic void msg_queue_delete(struct udevd_uevent_msg *msg)
461b1822321d6be0d7fd8be29bf3b4993ebd1b85Lennart Poettering{
9946996cda11a18b44d82344676e5a0e96339408Lennart Poettering list_del(&msg->node);
9946996cda11a18b44d82344676e5a0e96339408Lennart Poettering
9946996cda11a18b44d82344676e5a0e96339408Lennart Poettering /* mark as failed, if "add" event returns non-zero */
d1970645411ea1cc083ea1668e0d446252dc1505Lennart Poettering if (msg->exitstatus && strcmp(msg->action, "add") == 0)
d1970645411ea1cc083ea1668e0d446252dc1505Lennart Poettering export_event_state(msg, EVENT_FAILED);
b4efdf97203ddf781c17f77be84cc61516a077d2Lennart Poettering else
b4efdf97203ddf781c17f77be84cc61516a077d2Lennart Poettering export_event_state(msg, EVENT_FINISHED);
b4efdf97203ddf781c17f77be84cc61516a077d2Lennart Poettering
3471bedc005fab03f40b99bf6599645330adcd9eLennart Poettering free(msg);
3471bedc005fab03f40b99bf6599645330adcd9eLennart Poettering}
5231084b479455e6cc892ec3c37c9f599c5bea58Lennart Poettering
5231084b479455e6cc892ec3c37c9f599c5bea58Lennart Poetteringstatic void udev_event_run(struct udevd_uevent_msg *msg)
eeb875144e5a80d0521461a139f13fc8014d77d8Lennart Poettering{
eeb875144e5a80d0521461a139f13fc8014d77d8Lennart Poettering pid_t pid;
a32f224aafaf47d3489a730259a47ef45781193eLennart Poettering int retval;
a32f224aafaf47d3489a730259a47ef45781193eLennart Poettering
a32f224aafaf47d3489a730259a47ef45781193eLennart Poettering pid = fork();
a32f224aafaf47d3489a730259a47ef45781193eLennart Poettering switch (pid) {
a32f224aafaf47d3489a730259a47ef45781193eLennart Poettering case 0:
a32f224aafaf47d3489a730259a47ef45781193eLennart Poettering /* child */
347e1b6df028ebb1589146c167add8d37a3d4244Kay Sievers close(uevent_netlink_sock);
347e1b6df028ebb1589146c167add8d37a3d4244Kay Sievers close(udevd_sock);
347e1b6df028ebb1589146c167add8d37a3d4244Kay Sievers if (inotify_fd >= 0)
347e1b6df028ebb1589146c167add8d37a3d4244Kay Sievers close(inotify_fd);
347e1b6df028ebb1589146c167add8d37a3d4244Kay Sievers close(signal_pipe[READ_END]);
347e1b6df028ebb1589146c167add8d37a3d4244Kay Sievers close(signal_pipe[WRITE_END]);
347e1b6df028ebb1589146c167add8d37a3d4244Kay Sievers logging_close();
347e1b6df028ebb1589146c167add8d37a3d4244Kay Sievers
347e1b6df028ebb1589146c167add8d37a3d4244Kay Sievers logging_init("udevd-event");
347e1b6df028ebb1589146c167add8d37a3d4244Kay Sievers setpriority(PRIO_PROCESS, 0, UDEV_PRIORITY);
347e1b6df028ebb1589146c167add8d37a3d4244Kay Sievers
347e1b6df028ebb1589146c167add8d37a3d4244Kay Sievers retval = udev_event_process(msg);
347e1b6df028ebb1589146c167add8d37a3d4244Kay Sievers info("seq %llu finished with %i", msg->seqnum, retval);
347e1b6df028ebb1589146c167add8d37a3d4244Kay Sievers
166503dada92d7ca3570a653e07a51ed826b7c8aLennart Poettering logging_close();
59cea26a349cfa8db906b520dac72563dd773ff2Lennart Poettering if (retval)
35eb6b124ebdf82bd77aad6e44962a9a039c4d33Lennart Poettering exit(1);
9473414219330b9febc1d0712bbf49ad74cf962fLennart Poettering exit(0);
f1a8e221ecacea23883df57951e291a910463948Lennart Poettering case -1:
24f3a374b9588a6e409ba58b40bdd684050decf3Lennart Poettering err("fork of child failed: %s", strerror(errno));
24f3a374b9588a6e409ba58b40bdd684050decf3Lennart Poettering msg_queue_delete(msg);
99add6fd0b8f4307ed79256e25f38da318e795c4Lennart Poettering break;
24f3a374b9588a6e409ba58b40bdd684050decf3Lennart Poettering default:
069cfc85f876bb6966cb5a9bbe0235f5064622cdLennart Poettering /* get SIGCHLD in main loop */
069cfc85f876bb6966cb5a9bbe0235f5064622cdLennart Poettering info("seq %llu forked, pid [%d], '%s' '%s', %ld seconds old",
7b63bde1ed0d4f30c799c9b4737fa926465929f9Lennart Poettering msg->seqnum, pid, msg->action, msg->subsystem, time(NULL) - msg->queue_time);
7b63bde1ed0d4f30c799c9b4737fa926465929f9Lennart Poettering msg->pid = pid;
5b40d33761376354116a8cddb9b9fbdb6c4727d6Lennart Poettering }
5b40d33761376354116a8cddb9b9fbdb6c4727d6Lennart Poettering}
f7f21d33db5dfe88dc8175c61dada44013347729Lennart Poettering
f7f21d33db5dfe88dc8175c61dada44013347729Lennart Poetteringstatic void msg_queue_insert(struct udevd_uevent_msg *msg)
27b5482cc08b7fac1b6b15d980d42ae04f3ae1caLennart Poettering{
27b5482cc08b7fac1b6b15d980d42ae04f3ae1caLennart Poettering char filename[PATH_SIZE];
27b5482cc08b7fac1b6b15d980d42ae04f3ae1caLennart Poettering int fd;
27b5482cc08b7fac1b6b15d980d42ae04f3ae1caLennart Poettering
b86fa936ce36976cd6a96034cf14ea267695bcb2Lennart Poettering msg->queue_time = time(NULL);
b86fa936ce36976cd6a96034cf14ea267695bcb2Lennart Poettering
a26336da875a6657d404d1e44b86ae067c34b110Kay Sievers strlcpy(filename, udev_root, sizeof(filename));
a26336da875a6657d404d1e44b86ae067c34b110Kay Sievers strlcat(filename, "/" EVENT_SEQNUM, sizeof(filename));
e85647f73e235c2a6ea412cb8d841e092c373501Lennart Poettering fd = open(filename, O_WRONLY|O_TRUNC|O_CREAT, 0644);
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering if (fd >= 0) {
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering char str[32];
14038c2e83001abfbcdc3f9f2402189a9b3d2f0cLennart Poettering int len;
14038c2e83001abfbcdc3f9f2402189a9b3d2f0cLennart Poettering
465349c06d994dd2cc6b6fc4109ac0b9952d500aLennart Poettering len = sprintf(str, "%llu\n", msg->seqnum);
465349c06d994dd2cc6b6fc4109ac0b9952d500aLennart Poettering write(fd, str, len);
465349c06d994dd2cc6b6fc4109ac0b9952d500aLennart Poettering close(fd);
465349c06d994dd2cc6b6fc4109ac0b9952d500aLennart Poettering }
465349c06d994dd2cc6b6fc4109ac0b9952d500aLennart Poettering
465349c06d994dd2cc6b6fc4109ac0b9952d500aLennart Poettering export_event_state(msg, EVENT_QUEUED);
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering info("seq %llu queued, '%s' '%s'", msg->seqnum, msg->action, msg->subsystem);
d889a2069a87e4617b32ddbdeace5a53a12c699dLennart Poettering
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering /* run one event after the other in debug mode */
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering if (debug_trace) {
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering list_add_tail(&msg->node, &running_list);
eecd1362f7f4de432483b5d77c56726c3621a83aLennart Poettering udev_event_run(msg);
06dab8e18aebf822392c7ca66c5bf3c1200fdec8Lennart Poettering waitpid(msg->pid, NULL, 0);
06dab8e18aebf822392c7ca66c5bf3c1200fdec8Lennart Poettering msg_queue_delete(msg);
7e2668c6fd5720ae4d2d55eb8a062739687516afLennart Poettering return;
7e2668c6fd5720ae4d2d55eb8a062739687516afLennart Poettering }
e85647f73e235c2a6ea412cb8d841e092c373501Lennart Poettering
e85647f73e235c2a6ea412cb8d841e092c373501Lennart Poettering /* run all events with a timeout set immediately */
e01a15b71e18bf2008aec7e75041ffa42eb80b80Kay Sievers if (msg->timeout != 0) {
a888b352eb53b07daa24fa859ceeb254336b293dLennart Poettering list_add_tail(&msg->node, &running_list);
3b2d5b02ae231f1d3eb0d96eb980155d7797304eLennart Poettering udev_event_run(msg);
3b2d5b02ae231f1d3eb0d96eb980155d7797304eLennart Poettering return;
0f0dbc46ccf5aaaf3131446d0a4d78bc97a37295Lennart Poettering }
0f0dbc46ccf5aaaf3131446d0a4d78bc97a37295Lennart Poettering
3d9a412243035beeaaf3465a62065444a5adf21cLennart Poettering list_add_tail(&msg->node, &exec_list);
3d9a412243035beeaaf3465a62065444a5adf21cLennart Poettering run_exec_q = 1;
20ffc4c4a9226b0e45cc02ad9c0108981626c0bbKay Sievers}
f25626edf4c39bb9409cb165e6ce9551dd130661Lennart Poettering
a0a3844815b0f346dba03f41245c620f432e462fLennart Poetteringstatic int mem_size_mb(void)
a0a3844815b0f346dba03f41245c620f432e462fLennart Poettering{
9efaf380a7c7fa16f44b1aa15b967e99f331203aLennart Poettering FILE* f;
9efaf380a7c7fa16f44b1aa15b967e99f331203aLennart Poettering char buf[4096];
4ee717820208a4c8e92383d0dbefa401827fab38Kay Sievers long int memsize = -1;
4ee717820208a4c8e92383d0dbefa401827fab38Kay Sievers
5ba2dc259f3cdd8fddef68cfd28380a32534e49aKay Sievers f = fopen("/proc/meminfo", "r");
5ba2dc259f3cdd8fddef68cfd28380a32534e49aKay Sievers if (f == NULL)
5ba2dc259f3cdd8fddef68cfd28380a32534e49aKay Sievers return -1;
5ba2dc259f3cdd8fddef68cfd28380a32534e49aKay Sievers
20ffc4c4a9226b0e45cc02ad9c0108981626c0bbKay Sievers while (fgets(buf, sizeof(buf), f) != NULL) {
762f91fa600b3b2887e3b088cd700216a85e3c81Kay Sievers long int value;
762f91fa600b3b2887e3b088cd700216a85e3c81Kay Sievers
762f91fa600b3b2887e3b088cd700216a85e3c81Kay Sievers if (sscanf(buf, "MemTotal: %ld kB", &value) == 1) {
762f91fa600b3b2887e3b088cd700216a85e3c81Kay Sievers memsize = value / 1024;
b45f770f0049fbdf3f6c9db0ab11deeff4ccd86dKay Sievers break;
b8217b7bd5fd171916a095b150fad4c3a37f5a41Kay Sievers }
b45f770f0049fbdf3f6c9db0ab11deeff4ccd86dKay Sievers }
b45f770f0049fbdf3f6c9db0ab11deeff4ccd86dKay Sievers
b45f770f0049fbdf3f6c9db0ab11deeff4ccd86dKay Sievers fclose(f);
b8217b7bd5fd171916a095b150fad4c3a37f5a41Kay Sievers return memsize;
08f23fd29c9df9c8b4e874933eb39711f069754bLennart Poettering}
08f23fd29c9df9c8b4e874933eb39711f069754bLennart Poettering
18b754d345ecb0b15e369978aaffa72e9814b86aKay Sieversstatic int cpu_count(void)
068665b6fd9839f27bcace7e8f56c0baa6935272Lennart Poettering{
231931ffba1bca9d8759bbd6f797e56f8c6971faLennart Poettering FILE* f;
231931ffba1bca9d8759bbd6f797e56f8c6971faLennart Poettering char buf[4096];
169c4f65131fbc7bcb51e7d5487a715cdcd0e0ebLennart Poettering int count = 0;
169c4f65131fbc7bcb51e7d5487a715cdcd0e0ebLennart Poettering
bd08f2422491169e92dc0899d5ba848fcae4c15cLennart Poettering f = fopen("/proc/stat", "r");
bd08f2422491169e92dc0899d5ba848fcae4c15cLennart Poettering if (f == NULL)
fb0864e7b9c6d26269ccea6ec5c0fd921c029781Lennart Poettering return -1;
fb0864e7b9c6d26269ccea6ec5c0fd921c029781Lennart Poettering
18da49531e4c6b31bd2439b4d738dc1bb9660af1Lennart Poettering while (fgets(buf, sizeof(buf), f) != NULL) {
18da49531e4c6b31bd2439b4d738dc1bb9660af1Lennart Poettering if (strncmp(buf, "cpu", 3) == 0 && isdigit(buf[3]))
9586cdfab6a2638078702b7fea7e16b3a71899e2Lennart Poettering count++;
9586cdfab6a2638078702b7fea7e16b3a71899e2Lennart Poettering }
9586cdfab6a2638078702b7fea7e16b3a71899e2Lennart Poettering
9586cdfab6a2638078702b7fea7e16b3a71899e2Lennart Poettering fclose(f);
7f110ff9b8828b477e87de7b28c708cf69a3d008Lennart Poettering if (count == 0)
7f110ff9b8828b477e87de7b28c708cf69a3d008Lennart Poettering return -1;
101f077676e9fbe1a66c8b2dc4864a8d7a94c372Lennart Poettering return count;
101f077676e9fbe1a66c8b2dc4864a8d7a94c372Lennart Poettering}
f7f964eb3625e4cca7f16377fa12aa7a760243e7Lennart Poettering
f7f964eb3625e4cca7f16377fa12aa7a760243e7Lennart Poetteringstatic int running_processes(void)
144f0fc0c8a5e2f6b72179e2b5fb992474da24adLennart Poettering{
d0e5a33374cee92962af33dfc03873e470b014f6Lennart Poettering FILE* f;
d0e5a33374cee92962af33dfc03873e470b014f6Lennart Poettering char buf[4096];
d0e5a33374cee92962af33dfc03873e470b014f6Lennart Poettering int running = -1;
d0e5a33374cee92962af33dfc03873e470b014f6Lennart Poettering
d0e5a33374cee92962af33dfc03873e470b014f6Lennart Poettering f = fopen("/proc/stat", "r");
15e9fbd851c15ecaad4888932584f37dcd26111aLennart Poettering if (f == NULL)
15e9fbd851c15ecaad4888932584f37dcd26111aLennart Poettering return -1;
53ed2eeb2e709a6c0d152d7bdf2d9a4b9f997a16Lennart Poettering
53ed2eeb2e709a6c0d152d7bdf2d9a4b9f997a16Lennart Poettering while (fgets(buf, sizeof(buf), f) != NULL) {
680a1dbc354b2f437b4e06e27d4c43217977efdfLennart Poettering int value;
680a1dbc354b2f437b4e06e27d4c43217977efdfLennart Poettering
a6e87e90ede66815989ba2db92a07102a69906feLennart Poettering if (sscanf(buf, "procs_running %u", &value) == 1) {
88f89a9b6d25dfcb89691727c8cdaf01f4090b72Lennart Poettering running = value;
7e64c73a93cdcc7068280f3e3ba8adbd6c6f8f84Lennart Poettering break;
7e64c73a93cdcc7068280f3e3ba8adbd6c6f8f84Lennart Poettering }
c4aa65e7147dc742886edf25593e10466b02fc3aLennart Poettering }
7e64c73a93cdcc7068280f3e3ba8adbd6c6f8f84Lennart Poettering
a558d00381291afd6a81f7df07269fe76eeae556Lennart Poettering fclose(f);
a558d00381291afd6a81f7df07269fe76eeae556Lennart Poettering return running;
a558d00381291afd6a81f7df07269fe76eeae556Lennart Poettering}
a558d00381291afd6a81f7df07269fe76eeae556Lennart Poettering
a558d00381291afd6a81f7df07269fe76eeae556Lennart Poettering/* return the number of process es in our session, count only until limit */
a558d00381291afd6a81f7df07269fe76eeae556Lennart Poetteringstatic int running_processes_in_session(pid_t session, int limit)
a558d00381291afd6a81f7df07269fe76eeae556Lennart Poettering{
a558d00381291afd6a81f7df07269fe76eeae556Lennart Poettering DIR *dir;
05aa9edde0f9f4077b8120389c93cb0134eda9c5Lennart Poettering struct dirent *dent;
05aa9edde0f9f4077b8120389c93cb0134eda9c5Lennart Poettering int running = 0;
62f21ec91ad8e7e24079962f4df066b0094fe68dLennart Poettering
62f21ec91ad8e7e24079962f4df066b0094fe68dLennart Poettering dir = opendir("/proc");
f7357f59c3d4de8080fa78f8aa5fa6dbf1afc8dcLennart Poettering if (!dir)
62f21ec91ad8e7e24079962f4df066b0094fe68dLennart Poettering return -1;
87a8baa35d6d65ac3b58ae8e26e338e67f8ae8edLennart Poettering
87a8baa35d6d65ac3b58ae8e26e338e67f8ae8edLennart Poettering /* read process info from /proc */
87a8baa35d6d65ac3b58ae8e26e338e67f8ae8edLennart Poettering for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
87a8baa35d6d65ac3b58ae8e26e338e67f8ae8edLennart Poettering int f;
5ba081b0fb02380cee4c2ff5bc7e05f869eb8415Lennart Poettering char procdir[64];
5ba081b0fb02380cee4c2ff5bc7e05f869eb8415Lennart Poettering char line[256];
b3fa47e0819b08ea32e69e19e6d88ce2daca069dLennart Poettering const char *pos;
b3fa47e0819b08ea32e69e19e6d88ce2daca069dLennart Poettering char state;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering pid_t ppid, pgrp, sess;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering int len;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering if (!isdigit(dent->d_name[0]))
4cbd9ecf45f64c3a9acc99d473fbf3be3687ae24Lennart Poettering continue;
4cbd9ecf45f64c3a9acc99d473fbf3be3687ae24Lennart Poettering
b011116d1829bde044a638cbabfb070a7e0e8fa7Kay Sievers snprintf(procdir, sizeof(procdir), "/proc/%s/stat", dent->d_name);
b011116d1829bde044a638cbabfb070a7e0e8fa7Kay Sievers procdir[sizeof(procdir)-1] = '\0';
7d441ddb5ca090b5a97f58ac4b4d97b3e84fa81eLennart Poettering
65c0cf7108ae3537a357c74b4586a783baba82f9Lennart Poettering f = open(procdir, O_RDONLY);
65c0cf7108ae3537a357c74b4586a783baba82f9Lennart Poettering if (f == -1)
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers continue;
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers len = read(f, line, sizeof(line)-1);
a2f5666d06fe8233025738047115bb9e3959df3eLennart Poettering close(f);
a2f5666d06fe8233025738047115bb9e3959df3eLennart Poettering
ad740100d108282d0244d5739d4dcc86fe4c5fdeLennart Poettering if (len <= 0)
ad740100d108282d0244d5739d4dcc86fe4c5fdeLennart Poettering continue;
c821bd28c2ecce8d35248d61949fe1c0c3030b6cLennart Poettering else
c821bd28c2ecce8d35248d61949fe1c0c3030b6cLennart Poettering line[len] = '\0';
de6c78f8795743894431a099d26ec562a8acf3dfLennart Poettering
7d441ddb5ca090b5a97f58ac4b4d97b3e84fa81eLennart Poettering /* skip ugly program name */
14e639ae7a1dbf156273ce697d30fbc6c6594209Lennart Poettering pos = strrchr(line, ')') + 2;
14e639ae7a1dbf156273ce697d30fbc6c6594209Lennart Poettering if (pos == NULL)
ff01d048b4c1455241c894cf7982662c9d28fd34Lennart Poettering continue;
ff01d048b4c1455241c894cf7982662c9d28fd34Lennart Poettering
d3c7d7dd77b2b72315164b672462825cef6c0f9aKay Sievers if (sscanf(pos, "%c %d %d %d ", &state, &ppid, &pgrp, &sess) != 4)
72b9ed828bd22f3ddd74b6853c183eebf006d6d8Lennart Poettering continue;
1d6702e8d3877c0bebf3ac817dc45ff72f5ecfa9Lennart Poettering
1d6702e8d3877c0bebf3ac817dc45ff72f5ecfa9Lennart Poettering /* count only processes in our session */
1d6702e8d3877c0bebf3ac817dc45ff72f5ecfa9Lennart Poettering if (sess != session)
71092d70af35567dd154d3de2ce04ce62e157a7cLennart Poettering continue;
71092d70af35567dd154d3de2ce04ce62e157a7cLennart Poettering
71092d70af35567dd154d3de2ce04ce62e157a7cLennart Poettering /* count only running, no sleeping processes */
0a55b298d930543c8065bb9e708dd112562b1736Lennart Poettering if (state != 'R')
97f73ffb04947acf0a5854e3a7bdbb7a0105f6faLennart Poettering continue;
97f73ffb04947acf0a5854e3a7bdbb7a0105f6faLennart Poettering
85f248b26653f5322c26735661d63d4e8460c30eLennart Poettering running++;
85f248b26653f5322c26735661d63d4e8460c30eLennart Poettering if (limit > 0 && running >= limit)
1258097cd3cdbc5dd3d264850119e553a29c5068Lennart Poettering break;
1258097cd3cdbc5dd3d264850119e553a29c5068Lennart Poettering }
1258097cd3cdbc5dd3d264850119e553a29c5068Lennart Poettering closedir(dir);
a4c279f87451186b8beb1b8cc21c7cad561ecf4bLennart Poettering
a4c279f87451186b8beb1b8cc21c7cad561ecf4bLennart Poettering return running;
d3fc81bd6a5a046b22600ac1204df220c93d2c15Lennart Poettering}
d3fc81bd6a5a046b22600ac1204df220c93d2c15Lennart Poettering
d3fc81bd6a5a046b22600ac1204df220c93d2c15Lennart Poetteringstatic int compare_devpath(const char *running, const char *waiting)
d3fc81bd6a5a046b22600ac1204df220c93d2c15Lennart Poettering{
7c697168102cb64c5cb65a542959684014da99c7Lennart Poettering int i;
253ee27a0c7a410d27d490bb79ea97caed6a2b68Lennart Poettering
71092d70af35567dd154d3de2ce04ce62e157a7cLennart Poettering for (i = 0; i < PATH_SIZE; i++) {
8d0e38a2b966799af884e78a54fd6a2dffa44788Lennart Poettering /* identical device event found */
f28f1daf754a9a07de90e6fc4ada581bf5de677dLennart Poettering if (running[i] == '\0' && waiting[i] == '\0')
f28f1daf754a9a07de90e6fc4ada581bf5de677dLennart Poettering return 1;
f28f1daf754a9a07de90e6fc4ada581bf5de677dLennart Poettering
f28f1daf754a9a07de90e6fc4ada581bf5de677dLennart Poettering /* parent device event found */
88a07670cfa974a605c7c7b520b8a3135fce37f9Lennart Poettering if (running[i] == '\0' && waiting[i] == '/')
88a07670cfa974a605c7c7b520b8a3135fce37f9Lennart Poettering return 2;
88a07670cfa974a605c7c7b520b8a3135fce37f9Lennart Poettering
916abb21d0a6653e0187b91591e492026886b0a4Lennart Poettering /* child device event found */
916abb21d0a6653e0187b91591e492026886b0a4Lennart Poettering if (running[i] == '/' && waiting[i] == '\0')
71092d70af35567dd154d3de2ce04ce62e157a7cLennart Poettering return 3;
916abb21d0a6653e0187b91591e492026886b0a4Lennart Poettering
b23de6af893c11da4286bc416455cd0926d1532eLennart Poettering /* no matching event */
b23de6af893c11da4286bc416455cd0926d1532eLennart Poettering if (running[i] != waiting[i])
21bdae12e11ae20460715475d8a0c991f15464acLennart Poettering break;
21bdae12e11ae20460715475d8a0c991f15464acLennart Poettering }
9534ce54858c67363b841cdbdc315140437bfdb4Lennart Poettering
9534ce54858c67363b841cdbdc315140437bfdb4Lennart Poettering return 0;
68c7d001f4117f0c3d0a4582e32cbb03ae5fac57Lennart Poettering}
68c7d001f4117f0c3d0a4582e32cbb03ae5fac57Lennart Poettering
68c7d001f4117f0c3d0a4582e32cbb03ae5fac57Lennart Poettering/* lookup event for identical, parent, child, or physical device */
7a2a0b907b5cc60f5d9a871997d7d6e7f62bf4d8Lennart Poetteringstatic int devpath_busy(struct udevd_uevent_msg *msg, int limit)
253ee27a0c7a410d27d490bb79ea97caed6a2b68Lennart Poettering{
5d0fcd7c8d29340ac9425c309e8ac436a9af699cLennart Poettering struct udevd_uevent_msg *loop_msg;
5d0fcd7c8d29340ac9425c309e8ac436a9af699cLennart Poettering int childs_count = 0;
acb14d318b84bda00d1e666d7dab6794d5bbeb3fLennart Poettering
8bbabc447b1d913bd21faf97c7b17d20d315d2b4Lennart Poettering /* check exec-queue which may still contain delayed events we depend on */
8bbabc447b1d913bd21faf97c7b17d20d315d2b4Lennart Poettering list_for_each_entry(loop_msg, &exec_list, node) {
abdf7993161a2762df6887fdb5a5f0f4f5da24cfLennart Poettering /* skip ourself and all later events */
73090dc815390f4fca4e3ed8a7e1d3806605daaaLennart Poettering if (loop_msg->seqnum >= msg->seqnum)
44143309dd0b37d61d7d842ca58f01a65646ec71Kay Sievers break;
3d57c6ab801f4437f12948e29589e3d00c3ad9dbLennart Poettering
b9a2a36b519ccd79c4198e7dda4e657d597a14adLennart Poettering /* check our old name */
b9a2a36b519ccd79c4198e7dda4e657d597a14adLennart Poettering if (msg->devpath_old != NULL)
ba1a55152c50dfbcd3d4a64353b95f4a2f37985eLennart Poettering if (strcmp(loop_msg->devpath , msg->devpath_old) == 0)
9408a2d295a312a5472345090e28e0502570494bLennart Poettering return 2;
71092d70af35567dd154d3de2ce04ce62e157a7cLennart Poettering
3f7a8c4e9f1d3ce48919e24eb2c9d56dd6fd88d8Kay Sievers /* check identical, parent, or child device event */
f9276855a1d270b6c3f857cdaf2c4b49920c2228Lennart Poettering if (compare_devpath(loop_msg->devpath, msg->devpath) != 0) {
f9276855a1d270b6c3f857cdaf2c4b49920c2228Lennart Poettering dbg("%llu, device event still pending %llu (%s)",
260abb780a135e4cae8c10715c7e85675efc345aLennart Poettering msg->seqnum, loop_msg->seqnum, loop_msg->devpath);
260abb780a135e4cae8c10715c7e85675efc345aLennart Poettering return 3;
260abb780a135e4cae8c10715c7e85675efc345aLennart Poettering }
2791a8f8dc8764a9247cdba3562bd4c04010f144Lennart Poettering
a8f11321c209830a35edd0357e8def5d4437d854Lennart Poettering /* check physical device event (special case of parent) */
a8f11321c209830a35edd0357e8def5d4437d854Lennart Poettering if (msg->physdevpath && msg->action && strcmp(msg->action, "add") == 0)
21bdae12e11ae20460715475d8a0c991f15464acLennart Poettering if (compare_devpath(loop_msg->devpath, msg->physdevpath) != 0) {
21bdae12e11ae20460715475d8a0c991f15464acLennart Poettering dbg("%llu, physical device event still pending %llu (%s)",
c32e0c40f7e706e3ebcd101187d5ced96f083491Lennart Poettering msg->seqnum, loop_msg->seqnum, loop_msg->devpath);
c32e0c40f7e706e3ebcd101187d5ced96f083491Lennart Poettering return 4;
Error!

 

There was an error!

null

java.lang.NullPointerException