diff options
author | Kay Sievers <kay@vrfy.org> | 2012-07-14 00:32:47 +0200 |
---|---|---|
committer | Kay Sievers <kay@vrfy.org> | 2012-07-14 00:33:59 +0200 |
commit | c6eefe366470e1cf6c94f52dd923dc822eb5d027 (patch) | |
tree | 119a52b2b185274f6890acc9d4f89de8a6b4b54d /src/libudev | |
parent | 95694951a0905dd748c6902268b15e3a56632da2 (diff) |
udev: avoid creating /dev/kmsg with fopen() to support CONFIG_PRINTK=n
Diffstat (limited to 'src/libudev')
-rw-r--r-- | src/libudev/libudev-private.h | 1 | ||||
-rw-r--r-- | src/libudev/libudev-util.c | 25 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h index 4eb4a598e0..bc58424636 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 8e6d5b621d..e2fb449d64 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; +} |