daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
bd1529
From 8ee1cc626f616a2022d641a464fbde9108dd8ad9 Mon Sep 17 00:00:00 2001
bd1529
From: Martin Wilck <mwilck@suse.com>
bd1529
Date: Tue, 24 Apr 2018 10:50:24 +0200
bd1529
Subject: [PATCH] test/udev-test.pl: test correctness of symlink targets
bd1529
bd1529
Test if symlinks are created correctly by comparing the symlink
bd1529
targets to the devnode path. This implies (for the symlink) that
bd1529
major/minor numbers and permissions are correct, as we have tested
bd1529
that on the devnode already.
bd1529
bd1529
(cherry picked from commit 997683c8f152e1c139a7ce537de81a0aeae4627f)
bd1529
bd1529
Related: #1642728
bd1529
---
bd1529
 test/udev-test.pl | 23 ++++++++++++++++++-----
bd1529
 1 file changed, 18 insertions(+), 5 deletions(-)
bd1529
bd1529
diff --git a/test/udev-test.pl b/test/udev-test.pl
bd1529
index aa9a8dc2ff..2e3089c5e0 100755
bd1529
--- a/test/udev-test.pl
bd1529
+++ b/test/udev-test.pl
bd1529
@@ -22,6 +22,7 @@ use POSIX qw(WIFEXITED WEXITSTATUS);
bd1529
 use IPC::SysV qw(IPC_PRIVATE S_IRUSR S_IWUSR IPC_CREAT);
bd1529
 use IPC::Semaphore;
bd1529
 use Time::HiRes qw(usleep);
bd1529
+use Cwd qw(getcwd abs_path);
bd1529
 
bd1529
 my $udev_bin            = "./test-udev";
bd1529
 my $valgrind            = 0;
bd1529
@@ -2243,14 +2244,26 @@ sub check_add {
bd1529
 
bd1529
         my $devnode = check_devnode($device);
bd1529
 
bd1529
-        print "device \'$device->{devpath}\' expecting node/link \'$device->{exp_name}\'\n";
bd1529
         return if (!defined($device->{exp_name}));
bd1529
 
bd1529
-        if ((-e "$udev_dev/$device->{exp_name}") ||
bd1529
-            (-l "$udev_dev/$device->{exp_name}")) {
bd1529
-                print "add $device->{devpath}:         ok\n";
bd1529
+        my @st = lstat("$udev_dev/$device->{exp_name}");
bd1529
+        if (-l _) {
bd1529
+                my $cwd = getcwd();
bd1529
+                my $dir = "$udev_dev/$device->{exp_name}";
bd1529
+                $dir =~ s!/[^/]*$!!;
bd1529
+                my $tgt = readlink("$udev_dev/$device->{exp_name}");
bd1529
+                $tgt = abs_path("$dir/$tgt");
bd1529
+                $tgt =~ s!^$cwd/!!;
bd1529
+
bd1529
+                if ($tgt ne $devnode) {
bd1529
+                        print "symlink $device->{exp_name}:         error, found -> $tgt\n";
bd1529
+                        $error++;
bd1529
+                        system("tree", "$udev_dev");
bd1529
+                } else {
bd1529
+                        print "symlink $device->{exp_name}:         ok\n";
bd1529
+                }
bd1529
         } else {
bd1529
-                print "add  $device->{devpath}:         error";
bd1529
+                print "symlink $device->{exp_name}:         error";
bd1529
                 if ($device->{exp_add_error}) {
bd1529
                         print " as expected\n";
bd1529
                 } else {