-/*
- * libudev - interface to udev device information
- *
- * Copyright (C) 2008-2011 Kay Sievers <kay.sievers@vrfy.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- */
+/***
+ This file is part of systemd.
+
+ Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
#include <stdio.h>
#include <stdlib.h>
/**
* SECTION:libudev-util
* @short_description: utils
+ *
+ * Utilities useful when dealing with devices and device node names.
*/
int util_delete_path(struct udev *udev, const char *path)
if (pw != NULL)
return pw->pw_uid;
if (errno == 0 || errno == ENOENT || errno == ESRCH)
- err(udev, "specified user '%s' unknown\n", user);
+ udev_err(udev, "specified user '%s' unknown\n", user);
else
- err(udev, "error resolving user '%s': %m\n", user);
+ udev_err(udev, "error resolving user '%s': %m\n", user);
return 0;
}
buflen *= 2;
continue;
} else if (errno == 0 || errno == ENOENT || errno == ESRCH) {
- err(udev, "specified group '%s' unknown\n", group);
+ udev_err(udev, "specified group '%s' unknown\n", group);
} else {
- err(udev, "error resolving group '%s': %m\n", group);
+ udev_err(udev, "error resolving group '%s': %m\n", group);
}
break;
}
util_strscpy(result, maxsize, val);
else
result[0] = '\0';
- dbg(udev, "value '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result);
+ udev_dbg(udev, "value '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result);
} else {
size_t l;
char *s;
l = util_strpcpyl(&s, maxsize, udev_device_get_syspath(dev), NULL);
if (attr != NULL)
util_strpcpyl(&s, l, "/", attr, NULL);
- dbg(udev, "path '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result);
+ udev_dbg(udev, "path '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result);
}
udev_device_unref(dev);
return 0;
return j;
}
-size_t util_path_decode(char *s)
-{
- size_t i, j;
-
- for (i = 0, j = 0; s[i] != '\0'; j++) {
- if (memcmp(&s[i], "\\x2f", 4) == 0) {
- s[j] = '/';
- i += 4;
- } else if (memcmp(&s[i], "\\x5c", 4) == 0) {
- s[j] = '\\';
- i += 4;
- } else {
- s[j] = s[i];
- i++;
- }
- }
- s[j] = '\0';
- return j;
-}
-
void util_remove_trailing_chars(char *path, char c)
{
size_t len;
return bits;
}
-#define USEC_PER_SEC 1000000ULL
-#define NSEC_PER_USEC 1000ULL
-unsigned long long ts_usec(const struct timespec *ts)
+ssize_t print_kmsg(const char *fmt, ...)
{
- return (unsigned long long) ts->tv_sec * USEC_PER_SEC +
- (unsigned long long) ts->tv_nsec / NSEC_PER_USEC;
-}
+ int fd;
+ va_list ap;
+ char text[1024];
+ ssize_t len;
+ ssize_t ret;
-unsigned long long now_usec(void)
-{
- struct timespec ts;
+ fd = open("/dev/kmsg", O_WRONLY|O_NOCTTY|O_CLOEXEC);
+ if (fd < 0)
+ return -errno;
- if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
- return 0;
- return ts_usec(&ts);
+ 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;
}