[PATCH] Stop searching for information in none files. libparted/arch/linux.c: Ingore all files that don't begin with "/". tests/Makefile.am: include the new test file. tests/t7100-unnecessary-stats.sh: new test file.

Joel Granados Moreno jgranado at redhat.com
Fri Nov 7 16:54:30 UTC 2008


Signed-off-by: Joel Granados Moreno <jgranado at redhat.com>
---
 libparted/arch/linux.c           |    2 +
 tests/Makefile.am                |    1 +
 tests/t7100-unnecessary-stats.sh |   70 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 73 insertions(+), 0 deletions(-)
 create mode 100755 tests/t7100-unnecessary-stats.sh

diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 83e24c8..8734ab7 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2107,6 +2107,8 @@ _mount_table_search (const char* file_name, dev_t dev)
                 return 0;
         while (fgets (line, 512, file)) {
                 junk = sscanf (line, "%s", part_name);
+                if (part_name[0] != '/')
+                        continue;
                 if (stat (part_name, &part_stat) == 0) {
                         if (part_stat.st_rdev == dev) {
                                 fclose (file);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1c8c753..b5619b9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,6 +15,7 @@ TESTS = \
   t5000-tags.sh \
   t6000-dm.sh \
   t7000-scripting.sh \
+  t7100-unnecessary-stats.sh \
   t8000-loop.sh
 
 EXTRA_DIST = \
diff --git a/tests/t7100-unnecessary-stats.sh b/tests/t7100-unnecessary-stats.sh
new file mode 100755
index 0000000..a10cf56
--- /dev/null
+++ b/tests/t7100-unnecessary-stats.sh
@@ -0,0 +1,70 @@
+#!/bin/sh
+
+# Copyright (C) 2008 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program 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 General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Its ok for parted to search for files that don't exist.  Its not ok
+# when parted searches for things that are not a file.  With this in
+# mind we check for some strings that might be searched for for one
+# reason or another.
+test_description='Make sure parted is not searching for none files.'
+
+priviledges_required_=1
+device_mapper_required_=1
+
+: ${srcdir=.}
+. $srcdir/test-lib.sh
+
+test "x$ENABLE_DEVICE_MAPPER" = xyes ||
+  {
+    say "skipping $0: no device-mapper support"
+    test_done
+    exit
+  }
+
+linear_=linear0
+stracef="$(pwd)/partedstrace"
+
+cleanup_(){
+    kpartx -d $DM_DEV_DIR/mapper/"$linear_"
+    dmsetup remove $linear_
+    test -n "$lbd" && losetup -d "$lbd"
+    rm -f "$lbdf" "$stracef"
+}
+
+test_expect_success \
+    "setup: create loop devices" \
+    'lbdf=$(pwd)/lbdf && lbd=$(loop_setup_ "$lbdf")'
+
+test_expect_success \
+    "setup: create linear mapping" \
+    'dmsetup create $linear_ --table="0 1000 linear $lbd 0" > /dev/null 2>&1 &&
+     dev="$DM_DEV_DIR"/mapper/"$linear_"'
+
+test_expect_success \
+    "setup: create a partition" \
+    'parted -s "$dev" mklabel gpt > /dev/null 2>&1 &&
+     parted -s "$dev" mkpart primary ext2 18K 100K > /dev/null 2>&1 &&
+     kpartx -a "$dev" > /dev/null 2>&1'
+
+test_expect_success \
+    "Capturing the output of 'strace parted -s dev print free'" \
+    'strace -o "$stracef" parted -s "$dev" print free > /dev/null 2>&1'
+
+test_expect_failure \
+    "Searching for traces of unwanted strings in the temporary strace file" \
+    'cat "$stracef" | grep "stat(\"[^\/|^\.]" > /dev/null 2>&1'
+
+test_done
-- 
1.5.6.5


------=_Part_74160_672907434.1226412908896--



More information about the parted-devel mailing list