]> git.ipfire.org Git - thirdparty/util-linux.git/blob - tests/ts/mount/rlimit
2eaeb501bee8d5cd64ea4b552a33e7e948f430d2
[thirdparty/util-linux.git] / tests / ts / mount / rlimit
1 #!/bin/bash
2
3 #
4 # Copyright (C) 2007 Karel Zak <kzak@redhat.com>
5 #
6 # This file is part of util-linux.
7 #
8 # This file is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This file is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18
19 #
20 # The /etc/mtab file should not be modified if RLIMIT_FSIZE (ulimit -f)
21 # is too low, otherwise the file could be corrupted (incomplete write).
22 # The [u]mount(8) has to block SIGXFSZ and check if all writes and fflush
23 # calls are successful.
24 #
25
26 TS_TOPDIR="${0%/*}/../.."
27 TS_DESC="rlimit-fsize"
28
29 . $TS_TOPDIR/functions.sh
30 ts_init "$*"
31
32 ts_check_test_command "$TS_CMD_MOUNT"
33 ts_check_test_command "$TS_CMD_UMOUNT"
34 ts_check_prog "mkfs.ext3"
35
36 ts_skip_nonroot
37 ts_check_losetup
38
39 [ -L /etc/mtab ] && ts_skip "mtab is symlink"
40 [ "$(stat --format '%s' /etc/mtab)" -gt "1024" ] || ts_skip "mtab is too small"
41
42 set -o pipefail
43
44 function mtab_checksum()
45 {
46 md5sum /etc/mtab | awk '{printf $1}'
47 }
48
49 DEVICE=$(ts_device_init)
50 [ "$?" == 0 ] || ts_die "Cannot init device"
51
52 mkfs.ext3 $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE" $DEVICE
53
54
55 ts_init_subtest "mount"
56 OLD_SUM=$(mtab_checksum)
57 [ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT
58 (
59 ulimit -f 1
60 $TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT
61 ) &> /dev/null
62 NEW_SUM=$(mtab_checksum)
63 [ $NEW_SUM = $OLD_SUM ] && echo "OK: mtab unmodified by mount" >> $TS_OUTPUT
64 ts_is_mounted $DEVICE || ts_die "Cannot find $DEVICE in /proc/mounts"
65 $TS_CMD_UMOUNT $TS_MOUNTPOINT &> /dev/null
66 ts_is_mounted $DEVICE && ts_die "$DEVICE is still mounted"
67 ts_finalize_subtest
68
69
70 ts_init_subtest "umount"
71 [ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT
72 $TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT &> /dev/null
73 ts_is_mounted $DEVICE || ts_die "Cannot find $DEVICE in /proc/mounts"
74 OLD_SUM=$(mtab_checksum)
75 (
76 ulimit -f 1
77 $TS_CMD_UMOUNT $TS_MOUNTPOINT &> /dev/null
78 ) &> /dev/null
79 NEW_SUM=$(mtab_checksum)
80 [ $NEW_SUM = $OLD_SUM ] && echo "OK: mtab unmodified by umount" >> $TS_OUTPUT
81 if ts_is_mounted $DEVICE; then
82 echo "FAIL: $DEVICE is still mounted" >> $TS_OUTPUT
83 $TS_CMD_UMOUNT $TS_MOUNTPOINT &> /dev/null
84 else
85 # repair /etc/mtab
86 $TS_CMD_UMOUNT --fake $TS_MOUNTPOINT &> /dev/null
87 fi
88 ts_finalize_subtest
89
90
91 ts_device_deinit $DEVICE
92 ts_log "Success"
93 ts_finalize