]> git.saurik.com Git - apt.git/blame - test/integration/test-no-fds-leaked-to-maintainer-scripts
zh_CN.po: update simplified Chinese translation
[apt.git] / test / integration / test-no-fds-leaked-to-maintainer-scripts
CommitLineData
9fc0b435
DK
1#!/bin/sh
2set -e
3
3abb6a6a
DK
4TESTDIR="$(readlink -f "$(dirname "$0")")"
5. "$TESTDIR/framework"
9fc0b435
DK
6
7setupenvironment
e18f6133 8configarchitecture 'amd64' 'i386'
9fc0b435
DK
9configdpkgnoopchroot
10
299aea92 11setupsimplenativepackage "fdleaks" 'all' '1.0' 'unstable'
9fc0b435
DK
12BUILDDIR="incoming/fdleaks-1.0"
13for script in 'preinst' 'postinst' 'prerm' 'postrm'; do
748a2177
DK
14 cat > ${BUILDDIR}/debian/$script << EOF
15#!/bin/sh
3abb6a6a 16if [ -e '$(pwd)/rootdir/tmp/read_stdin' ]; then
748a2177
DK
17 read line;
18 echo "STDIN: -\$line-"
19fi
20ls -l /proc/self/fd/
21EOF
9fc0b435
DK
22done
23buildpackage "$BUILDDIR" 'unstable' 'main' 'native'
24rm -rf "$BUILDDIR"
25
e18f6133
DK
26PKGNAME='fdleaks:all'
27if ! dpkg-checkbuilddeps -d 'dpkg (>= 1.16.2)' /dev/null >/dev/null 2>&1; then
28 PKGNAME='fdleaks'
29fi
30
9fc0b435
DK
31setupaptarchive
32
299aea92
DK
33rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
34testsuccess aptget install -y fdleaks -qq < /dev/null
9fc0b435 35
e18f6133 36checkfdleak() {
7ec34330 37 msgtest 'Check if fds were not' "leaked: expect $1"
e18f6133
DK
38 if [ "$(grep 'root root' rootdir/tmp/testsuccess.output | wc -l)" = "$1" ]; then
39 msgpass
40 else
41 echo
42 cat rootdir/tmp/testsuccess.output
43 msgfail
44 fi
45}
46checkinstall() {
47 checkfdleak 8
48
49 cp rootdir/tmp/testsuccess.output terminal.output
50 tail -n +3 rootdir/var/log/apt/term.log | head -n -1 > terminal.log
51 testfileequal 'terminal.log' "$(cat terminal.output)"
299aea92 52
e18f6133
DK
53 testequal "startup archives unpack
54install $PKGNAME <none> 1.0
55status half-installed $PKGNAME 1.0
56status unpacked $PKGNAME 1.0
57status unpacked $PKGNAME 1.0
299aea92 58startup packages configure
e18f6133
DK
59configure $PKGNAME 1.0 <none>
60status unpacked $PKGNAME 1.0
61status half-configured $PKGNAME 1.0
b4450f1d 62status installed $PKGNAME 1.0" cut -f 3- -d' ' rootdir/var/log/dpkg.log
e18f6133
DK
63}
64checkinstall
299aea92
DK
65
66rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
67testsuccess aptget purge -y fdleaks -qq
e18f6133
DK
68checkpurge() {
69 checkfdleak 12
70
71 cp rootdir/tmp/testsuccess.output terminal.output
72 tail -n +3 rootdir/var/log/apt/term.log | head -n -1 > terminal.log
73 testfileequal 'terminal.log' "$(cat terminal.output)"
74
28557f94
DK
75 testequal "startup packages remove
76status installed $PKGNAME 1.0
e18f6133
DK
77remove $PKGNAME 1.0 <none>
78status half-configured $PKGNAME 1.0
79status half-installed $PKGNAME 1.0
80status config-files $PKGNAME 1.0
28557f94
DK
81status config-files $PKGNAME 1.0
82startup packages purge
83remove $PKGNAME 1.0 <none>
e18f6133
DK
84purge $PKGNAME 1.0 <none>
85status config-files $PKGNAME 1.0
86status config-files $PKGNAME 1.0
87status config-files $PKGNAME 1.0
88status config-files $PKGNAME 1.0
89status config-files $PKGNAME 1.0
a2a75ff4
DK
90status not-installed $PKGNAME <none>
91startup packages configure" cut -f 3- -d' ' rootdir/var/log/dpkg.log
7ec34330 92 testequalor2 "dpkg-query: no packages found matching ${PKGNAME}" "No packages found matching ${PKGNAME}." dpkg -l "$PKGNAME"
e18f6133
DK
93}
94checkpurge
95
96msgtest 'setsid provided is new enough to support' '-w'
97if dpkg-checkbuilddeps -d 'util-linux (>= 2.24.2-1)' /dev/null >/dev/null 2>&1; then
9fc0b435
DK
98 msgpass
99else
e18f6133
DK
100 msgskip "$(command dpkg -l util-linux)"
101 exit
9fc0b435 102fi
299aea92 103
e18f6133
DK
104rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
105testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" install -y fdleaks -qq < /dev/null
106checkinstall
107
108rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
109testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" purge -y fdleaks -qq
110checkpurge
748a2177
DK
111
112touch rootdir/tmp/read_stdin
113
114rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
115for i in $(seq 1 10); do echo "$i"; done | testsuccess aptget install -y fdleaks -qq
116checkinstall
117testequal '2' grep -c '^STDIN: ' rootdir/var/log/apt/term.log
118
119rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
120yes '' | testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" purge -y fdleaks -qq
121checkpurge
122testequal '3' grep -c '^STDIN: ' rootdir/var/log/apt/term.log