On Wed, 15.06.11 13:20, William Douglas ([email protected]) wrote:
> Ah right, I was only thinking of getting /proc/kmsg working =P.
> I have updated accordingly below.
Almost there now:
> +_sd_hidden_ int sd_is_special(int fd, const char *path) {
> + struct stat st_fd;
> +
> + if (fd < 0)
> + return -EINVAL;
> +
> + if (fstat(fd, &st_fd) < 0)
> + return -errno;
> +
> + if (!S_ISREG(st_fd.st_mode) || !S_ISCHR(st_fd.st_mode))
> + return 0;
> +
> + if (path) {
> + struct stat st_path;
> +
> + if (stat(path, &st_path) < 0) {
> +
> + if (errno == ENOENT || errno == ENOTDIR)
> + return 0;
> +
> + return -errno;
> + }
> +
> + if (S_ISREG(st_fd.st_mode))
> + return
> + st_path.st_dev == st_fd.st_dev &&
> + st_path.st_ino == st_fd.st_ino;
> + else
> + return st_path.st_rdev == st_fd.st_rdev;
if st_path refers to a normal file, but st_fd to a device node, then
you are accessing st_path.st_rdev which might not be initialized. Since
st_rdev is specific to device nodes you need to verify the type of
st_path, too.
Lennart
--
Lennart Poettering - Red Hat, Inc.
_______________________________________________
systemd-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/systemd-devel