X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev%2Fudevd.c;h=4000d37e80f596b8a9d5499965b0d3ed73c3b225;hp=d64beef3a9b29fdfc02765d7da21eb6affe1cf0d;hb=ee137da3897d154e0c62b03ea7ef3c3359753adc;hpb=17fcfb5972977b6a3aedca6ad2aa8d1fbfbc761d
diff --git a/udev/udevd.c b/udev/udevd.c
index d64beef3a..4000d37e8 100644
--- a/udev/udevd.c
+++ b/udev/udevd.c
@@ -16,8 +16,6 @@
* along with this program. If not, see .
*/
-#include "config.h"
-
#include
#include
#include
@@ -266,7 +264,7 @@ static void udev_event_run(struct udevd_uevent_msg *msg)
exit(1);
exit(0);
case -1:
- err(msg->udev, "fork of child failed: %s\n", strerror(errno));
+ err(msg->udev, "fork of child failed: %m\n");
msg_queue_delete(msg);
break;
default:
@@ -621,7 +619,7 @@ static struct udevd_uevent_msg *get_netlink_msg(struct udev *udev)
size = recv(uevent_netlink_sock, &buffer, sizeof(buffer), 0);
if (size < 0) {
if (errno != EINTR)
- err(udev, "unable to receive kernel netlink message: %s\n", strerror(errno));
+ err(udev, "unable to receive kernel netlink message: %m\n");
return NULL;
}
@@ -731,7 +729,7 @@ static int init_uevent_netlink_sock(struct udev *udev)
uevent_netlink_sock = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);
if (uevent_netlink_sock == -1) {
- err(udev, "error getting socket: %s\n", strerror(errno));
+ err(udev, "error getting socket: %m\n");
return -1;
}
@@ -740,7 +738,7 @@ static int init_uevent_netlink_sock(struct udev *udev)
retval = bind(uevent_netlink_sock, (struct sockaddr *) &snl, sizeof(struct sockaddr_nl));
if (retval < 0) {
- err(udev, "bind failed: %s\n", strerror(errno));
+ err(udev, "bind failed: %m\n");
close(uevent_netlink_sock);
uevent_netlink_sock = -1;
return -1;
@@ -786,11 +784,11 @@ int main(int argc, char *argv[])
const char *value;
int daemonize = 0;
static const struct option options[] = {
- { "daemon", 0, NULL, 'd' },
- { "debug-trace", 0, NULL, 't' },
- { "debug", 0, NULL, 'D' },
- { "help", 0, NULL, 'h' },
- { "version", 0, NULL, 'V' },
+ { "daemon", no_argument, NULL, 'd' },
+ { "debug-trace", no_argument, NULL, 't' },
+ { "debug", no_argument, NULL, 'D' },
+ { "help", no_argument, NULL, 'h' },
+ { "version", no_argument, NULL, 'V' },
{}
};
int rc = 1;
@@ -803,6 +801,7 @@ int main(int argc, char *argv[])
logging_init("udevd");
udev_set_log_fn(udev, log_fn);
dbg(udev, "version %s\n", VERSION);
+ selinux_init(udev);
while (1) {
int option;
@@ -878,29 +877,29 @@ int main(int argc, char *argv[])
retval = pipe(signal_pipe);
if (retval < 0) {
- err(udev, "error getting pipes: %s\n", strerror(errno));
+ err(udev, "error getting pipes: %m\n");
goto exit;
}
retval = fcntl(signal_pipe[READ_END], F_GETFL, 0);
if (retval < 0) {
- err(udev, "error fcntl on read pipe: %s\n", strerror(errno));
+ err(udev, "error fcntl on read pipe: %m\n");
goto exit;
}
retval = fcntl(signal_pipe[READ_END], F_SETFL, retval | O_NONBLOCK);
if (retval < 0) {
- err(udev, "error fcntl on read pipe: %s\n", strerror(errno));
+ err(udev, "error fcntl on read pipe: %m\n");
goto exit;
}
retval = fcntl(signal_pipe[WRITE_END], F_GETFL, 0);
if (retval < 0) {
- err(udev, "error fcntl on write pipe: %s\n", strerror(errno));
+ err(udev, "error fcntl on write pipe: %m\n");
goto exit;
}
retval = fcntl(signal_pipe[WRITE_END], F_SETFL, retval | O_NONBLOCK);
if (retval < 0) {
- err(udev, "error fcntl on write pipe: %s\n", strerror(errno));
+ err(udev, "error fcntl on write pipe: %m\n");
goto exit;
}
@@ -919,7 +918,7 @@ int main(int argc, char *argv[])
dbg(udev, "daemonized fork running\n");
break;
case -1:
- err(udev, "fork of daemon failed: %s\n", strerror(errno));
+ err(udev, "fork of daemon failed: %m\n");
rc = 4;
goto exit;
default:
@@ -947,7 +946,7 @@ int main(int argc, char *argv[])
/* OOM_DISABLE == -17 */
fd = open("/proc/self/oom_adj", O_RDWR);
if (fd < 0)
- err(udev, "error disabling OOM: %s\n", strerror(errno));
+ err(udev, "error disabling OOM: %m\n");
else {
write(fd, "-17", 3);
close(fd);
@@ -955,9 +954,21 @@ int main(int argc, char *argv[])
fd = open("/dev/kmsg", O_WRONLY);
if (fd > 0) {
- const char *str = "<6>udevd version " VERSION " started\n";
-
- write(fd, str, strlen(str));
+ const char *ver_str = "<6>udev: starting version " VERSION "\n";
+ char path[UTIL_PATH_SIZE];
+ struct stat statbuf;
+
+ write(fd, ver_str, strlen(ver_str));
+ util_strlcpy(path, udev_get_sys_path(udev), sizeof(path));
+ util_strlcat(path, "/class/mem/null", sizeof(path));
+ if (lstat(path, &statbuf) == 0) {
+ if (S_ISDIR(statbuf.st_mode)) {
+ const char *depr_str = "<6>udev: deprecated sysfs layout "
+ "(CONFIG_SYSFS_DEPRECATED) is unsupported\n";
+
+ write(fd, depr_str, strlen(depr_str));
+ }
+ }
close(fd);
}
@@ -994,7 +1005,7 @@ int main(int argc, char *argv[])
} else if (errno == ENOSYS)
err(udev, "the kernel does not support inotify, udevd can't monitor rules file changes\n");
else
- err(udev, "inotify_init failed: %s\n", strerror(errno));
+ err(udev, "inotify_init failed: %m\n");
/* maximum limit of forked childs */
value = getenv("UDEVD_MAX_CHILDS");
@@ -1037,7 +1048,7 @@ int main(int argc, char *argv[])
fdcount = select(maxfd+1, &readfds, NULL, NULL, NULL);
if (fdcount < 0) {
if (errno != EINTR)
- err(udev, "error in select: %s\n", strerror(errno));
+ err(udev, "error in select: %m\n");
continue;
}
@@ -1115,6 +1126,8 @@ exit:
if (uevent_netlink_sock >= 0)
close(uevent_netlink_sock);
+ selinux_exit(udev);
+ udev_unref(udev);
logging_close();
return rc;
}