[systemd-commits] src/libudev src/udev
Kay Sievers
kay at kemper.freedesktop.org
Fri Jul 13 15:39:52 PDT 2012
src/libudev/libudev-private.h | 1 +
src/libudev/libudev-util.c | 25 +++++++++++++++++++++++++
src/udev/udev-event.c | 9 +--------
src/udev/udevd.c | 14 ++------------
4 files changed, 29 insertions(+), 20 deletions(-)
New commits:
commit c6eefe366470e1cf6c94f52dd923dc822eb5d027
Author: Kay Sievers <kay at vrfy.org>
Date: Sat Jul 14 00:32:47 2012 +0200
udev: avoid creating /dev/kmsg with fopen() to support CONFIG_PRINTK=n
diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h
index 4eb4a59..bc58424 100644
--- a/src/libudev/libudev-private.h
+++ b/src/libudev/libudev-private.h
@@ -173,4 +173,5 @@ int util_resolve_subsys_kernel(struct udev *udev, const char *string,
char *result, size_t maxsize, int read_value);
unsigned long long ts_usec(const struct timespec *ts);
unsigned long long now_usec(void);
+ssize_t print_kmsg(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
#endif
diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c
index 8e6d5b6..e2fb449 100644
--- a/src/libudev/libudev-util.c
+++ b/src/libudev/libudev-util.c
@@ -727,3 +727,28 @@ unsigned long long now_usec(void)
return 0;
return ts_usec(&ts);
}
+
+ssize_t print_kmsg(const char *fmt, ...)
+{
+ int fd;
+ va_list ap;
+ char text[1024];
+ ssize_t len;
+ ssize_t ret;
+
+ fd = open("/dev/kmsg", O_WRONLY|O_NOCTTY|O_CLOEXEC);
+ if (fd < 0)
+ return -errno;
+
+ len = snprintf(text, sizeof(text), "<30>systemd-udevd[%u]: ", getpid());
+
+ va_start(ap, fmt);
+ len += vsnprintf(text + len, sizeof(text) - len, fmt, ap);
+ va_end(ap);
+
+ ret = write(fd, text, len);
+ if (ret < 0)
+ ret = -errno;
+ close(fd);
+ return ret;
+}
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
index 46e579d..d5dd1f3 100644
--- a/src/udev/udev-event.c
+++ b/src/udev/udev-event.c
@@ -767,14 +767,7 @@ static int rename_netif(struct udev_event *event)
util_strscpy(ifr.ifr_newname, IFNAMSIZ, event->name);
err = ioctl(sk, SIOCSIFNAME, &ifr);
if (err >= 0) {
- FILE *f;
-
- f = fopen("/dev/kmsg", "we");
- if (f != NULL) {
- fprintf(f, "<30>systemd-udevd[%u]: renamed network interface %s to %s\n",
- getpid(), ifr.ifr_name, ifr.ifr_newname);
- fclose(f);
- }
+ print_kmsg("renamed network interface %s to %s", ifr.ifr_name, ifr.ifr_newname);
} else {
err = -errno;
log_error("error changing net interface name %s to %s: %m\n", ifr.ifr_name, ifr.ifr_newname);
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index ee78b39..a028c9c 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -891,7 +891,6 @@ static int mem_size_mb(void)
static int convert_db(struct udev *udev)
{
char filename[UTIL_PATH_SIZE];
- FILE *f;
struct udev_enumerate *udev_enumerate;
struct udev_list_entry *list_entry;
@@ -907,11 +906,7 @@ static int convert_db(struct udev *udev)
if (access(filename, F_OK) < 0)
return 0;
- f = fopen("/dev/kmsg", "we");
- if (f != NULL) {
- fprintf(f, "<30>systemd-udevd[%u]: converting old udev database\n", getpid());
- fclose(f);
- }
+ print_kmsg("converting old udev database\n");
udev_enumerate = udev_enumerate_new(udev);
if (udev_enumerate == NULL)
@@ -1058,7 +1053,6 @@ static void kernel_cmdline_options(struct udev *udev)
int main(int argc, char *argv[])
{
struct udev *udev;
- FILE *f;
sigset_t mask;
int daemonize = false;
int resolve_names = 1;
@@ -1265,11 +1259,7 @@ int main(int argc, char *argv[])
sd_notify(1, "READY=1");
}
- f = fopen("/dev/kmsg", "we");
- if (f != NULL) {
- fprintf(f, "<30>systemd-udevd[%u]: starting version " VERSION "\n", getpid());
- fclose(f);
- }
+ print_kmsg("starting version " VERSION "\n");
if (!debug) {
int fd;
More information about the systemd-commits
mailing list