log_error("Conflicting device node '%s' found, link to '%s' will not be created.", slink, node);
return -EOPNOTSUPP;
} else if (S_ISLNK(stats.st_mode)) {
- char buf[PATH_MAX];
- ssize_t len;
-
- len = readlink(slink, buf, sizeof(buf));
- if (len > 0 && len < (ssize_t) sizeof(buf)) {
- buf[len] = '\0';
- if (streq(target, buf)) {
- log_debug("Preserve already existing symlink '%s' to '%s'", slink, target);
- (void) label_fix(slink, LABEL_IGNORE_ENOENT);
- (void) utimensat(AT_FDCWD, slink, NULL, AT_SYMLINK_NOFOLLOW);
- return 0;
- }
+ _cleanup_free_ char *buf = NULL;
+
+ if (readlink_malloc(slink, &buf) >= 0 &&
+ streq(target, buf)) {
+ log_debug("Preserve already existing symlink '%s' to '%s'", slink, target);
+ (void) label_fix(slink, LABEL_IGNORE_ENOENT);
+ (void) utimensat(AT_FDCWD, slink, NULL, AT_SYMLINK_NOFOLLOW);
+ return 0;
}
}
} else {
#include <sys/inotify.h>
#include <unistd.h>
+#include "alloc-util.h"
#include "device-private.h"
#include "dirent-util.h"
+#include "fs-util.h"
#include "mkdir.h"
#include "stdio-util.h"
#include "udev-watch.h"
FOREACH_DIRENT_ALL(ent, dir, break) {
_cleanup_(sd_device_unrefp) sd_device *dev = NULL;
- char device[PATH_MAX];
- ssize_t len;
+ _cleanup_free_ char *device = NULL;
if (ent->d_name[0] == '.')
continue;
- len = readlinkat(dirfd(dir), ent->d_name, device, sizeof(device));
- if (len <= 0) {
- log_error_errno(errno, "Failed to read link '/run/udev/watch.old/%s', ignoring: %m", ent->d_name);
- goto unlink;
- } else if (len >= (ssize_t) sizeof(device)) {
- log_error("Path specified by link '/run/udev/watch.old/%s' is truncated, ignoring.", ent->d_name);
+ r = readlinkat_malloc(dirfd(dir), ent->d_name, &device);
+ if (r < 0) {
+ log_error_errno(r, "Failed to read link '/run/udev/watch.old/%s', ignoring: %m", ent->d_name);
goto unlink;
}
- device[len] = '\0';
r = sd_device_new_from_device_id(&dev, device);
if (r < 0) {
}
int udev_watch_lookup(int wd, sd_device **ret) {
- char filename[STRLEN("/run/udev/watch/") + DECIMAL_STR_MAX(int)], device[PATH_MAX];
- ssize_t len;
+ char filename[STRLEN("/run/udev/watch/") + DECIMAL_STR_MAX(int)];
+ _cleanup_free_ char *device = NULL;
int r;
assert(ret);
return log_error_errno(EINVAL, "Invalid watch handle.");
xsprintf(filename, "/run/udev/watch/%d", wd);
- len = readlink(filename, device, sizeof(device));
- if (len <= 0) {
- if (errno != ENOENT)
+ r = readlink_malloc(filename, &device);
+ if (r < 0) {
+ if (r != -ENOENT)
return log_error_errno(errno, "Failed to read link '%s': %m", filename);
return 0;
- } else if (len >= (ssize_t) sizeof(device))
- return log_error_errno(ENAMETOOLONG, "Path specified by link '%s' is truncated.", filename);
- device[len] = '\0';
+ }
r = sd_device_new_from_device_id(ret, device);
if (r < 0)