File: 1849

package info (click to toggle)
pcp 7.0.5-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 252,916 kB
  • sloc: ansic: 1,478,844; sh: 177,285; xml: 160,462; cpp: 83,809; python: 24,349; perl: 18,303; yacc: 6,877; lex: 2,864; makefile: 2,694; awk: 165; fortran: 60; java: 52
file content (214 lines) | stat: -rwxr-xr-x 5,086 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/sh
# PCP QA Test No. 1849
# check out __pmCleanMapDir()
#
# non-valgrind variant, see qa/1848 for the valgrind variant
#
# Copyright (c) 2023 Ken McDonell.  All Rights Reserved.
#

if [ $# -eq 0 ]
then
    seq=`basename $0`
    echo "QA output created by $seq"
else
    # use $seq from caller, unless not set
    [ -n "$seq" ] || seq=`basename $0`
    echo "QA output created by `basename $0` $*"
fi

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check


do_valgrind=false
if [ "$1" = "--valgrind" ]
then
    _check_valgrind
    do_valgrind=true
elif which valgrind >/dev/null 2>&1
then
    [ $PCPQA_VALGRIND = both ] || \
        _notrun "valgrind variant qa/1848 will be run"
fi

_cleanup()
{
    cd $here
    $sudo rm -rf $tmp $tmp.*
}

# need sort at end to dodge directory entry order non-determinism
#
_doit()
{
    if $do_valgrind
    then
	_run_valgrind src/cleanmapdir -Dmisc $*
    else
	src/cleanmapdir -Dmisc $* 2>&1
    fi \
    | tee -a $seq_full \
    | _filter \
    | LC_COLLATE=POSIX sort
}

status=0	# success is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15

_filter()
{
    sed \
	-e "s@$tmp@TMP@g" \
	-e "s@TMP/$DEAD1@TMP/DEAD-PID-1@" \
	-e "s@TMP/$DEAD2@TMP/DEAD-PID-2@" \
	-e "s/\([^0-9]\)$DEAD1\([^0-9]\)/\1DEAD-PID-1\2/g" \
	-e "s/\([^0-9]\)$DEAD2\([^0-9]\)/\1DEAD-PID-2\2/g" \
	-e "s/\([^0-9]\)$$\([^0-9]\)/\1QA-TEST-PID\2/g" \
	-e "s/^$$\([^0-9]\)/QA-TEST-PID\1/" \
	-e "s/\([^0-9]\)$$\$/\1QA-TEST-PID/" \
	-e "s/^$$\$/QA-TEST-PID/" \
	-e 's/ uid [0-9][0-9]*\([^0-9]\)/ uid UU\1/g' \
	-e 's/ gid [0-9][0-9]*\([^0-9]\)/ gid GG\1/g' \
	-e '/^\[.* Warning/s//[DATE] Warning/' \
    # end
}

date >/dev/null 2>&1 &
DEAD1=$!
echo "DEAD1=$DEAD1" >>$seq_full
date >/dev/null 2>&1 &
DEAD2=$!
echo "DEAD2=$DEAD2" >>$seq_full

# real QA test starts here

echo
echo "+++ dirname does not exist ..." | tee -a $seq_full
_doit $tmp

echo
echo "+++ dirname is a symlink not a dir ..." | tee -a $seq_full
ln -s /tmp $tmp
_doit $tmp
rm -f $tmp		# refactor-ok

echo
echo "+++ dirname is a regular file not a dir ..." | tee -a $seq_full
touch $tmp
_doit $tmp
rm -rf $tmp		# refactor-ok

echo
echo "+++ no permission to read dirname ..." | tee -a $seq_full
mkdir $tmp
$sudo chgrp `id -gn` $tmp
chmod 333 $tmp
_doit $tmp
chmod 755 $tmp

echo
echo "+++ wrong user for dirname ..." | tee -a $seq_full
$sudo chown pcp $tmp
ls -ld $tmp >>$seq_full
_doit $tmp
$sudo chown `id -un` $tmp

echo
echo "+++ wrong group for dirname ..." | tee -a $seq_full
$sudo chgrp pcp $tmp
ls -ld $tmp >>$seq_full
_doit $tmp
$sudo chgrp `id -gn` $tmp

echo
echo "+++ bad 'PID' file names and CANNOT unlink ..." | tee -a $seq_full
touch $tmp/-1
touch $tmp/0
touch $tmp/foo-bar
touch $tmp/12345678901234567890123456789
touch $tmp/123456mumble
touch $tmp/$$
(cd $tmp; rm -f primary; ln -s $$ primary)
chmod 555 $tmp
_doit $tmp -C primary
ls $tmp | _filter | LC_COLLATE=POSIX sort
chmod 755 $tmp

echo
echo "+++ bad 'PID' file names and CAN unlink ..." | tee -a $seq_full
_doit $tmp -C primary
ls $tmp | _filter | LC_COLLATE=POSIX sort
rm -f $tmp/*		# refactor-ok

echo
echo "+++ PIDs -> no process ..." | tee -a $seq_full
touch $tmp/$DEAD1
touch $tmp/$DEAD2
touch $tmp/$$
(cd $tmp; rm -f primary; ln -s $$ primary)
_doit $tmp -C primary
ls $tmp | _filter | LC_COLLATE=POSIX sort

echo
echo "+++ special not a symlink ..." | tee -a $seq_full
rm -f $tmp/primary		# refactor-ok
touch $tmp/primary
_doit $tmp -C primary
ls $tmp | _filter | LC_COLLATE=POSIX sort
(cd $tmp; rm -f primary; ln -s $$ primary)

echo
echo "+++ special points to a bad 'PID' ..." | tee -a $seq_full
rm -f $tmp/primary $tmp/$$		# refactor-ok
(cd $tmp; rm -f bad; ln -s -- -1 bad)
_doit $tmp -C bad
(cd $tmp; rm -f bad; ln -s 0 bad)
_doit $tmp -C bad
(cd $tmp; rm -f bad; ln -s foo-bar bad)
_doit $tmp -C bad
(cd $tmp; rm -f bad; ln -s 12345678901234567890123456789  bad)
_doit $tmp -C bad
(cd $tmp; rm -f bad; ln -s 123! bad)
_doit $tmp -C bad
(cd $tmp; rm -f bad; ln -s $DEAD1 bad)
_doit $tmp -C bad
ls $tmp | _filter | LC_COLLATE=POSIX sort
(cd $tmp; rm -f $$; touch $$)
(cd $tmp; rm -f primary; ln -s $$ primary)
touch $tmp/$$
(cd $tmp; rm -f bad)

echo
echo "+++ special points somewhere else ..." | tee -a $seq_full
rm -f $tmp/primary		# refactor-ok
echo "--- primary -> /etc/passwd"
(cd $tmp; rm -f primary; ln -s /etc/passwd primary)
_doit $tmp -C primary
echo "--- foo -> ../foo"
(cd $tmp; rm -f foo; ln -s ../foo foo)
_doit $tmp -C foo
echo "--- bar -> ../DEAD1"
(cd $tmp; rm -f foo bar; ln -s ../$DEAD1 bar)
_doit $tmp -C bar
echo "--- bar -> TMP/DEAD1"
(cd $tmp; rm -f bar; ln -s $tmp/$DEAD1 bar)
_doit $tmp -C bar
echo "--- bar -> TMP/QA-TEST-PID"
(cd $tmp; rm -f bar; ln -s $tmp/$$ bar)
_doit $tmp -C bar
ls $tmp | _filter | LC_COLLATE=POSIX sort
(cd $tmp; rm -f primary; ln -s $$ primary)
(cd $tmp; rm -f foo bar)

echo
echo "+++ special -> no process ..." | tee -a $seq_full
(cd $tmp; rm -f primary; ln -s $DEAD1 primary)
_doit $tmp -C primary
ls $tmp | _filter | LC_COLLATE=POSIX sort
(cd $tmp; rm -f primary; ln -s $$ primary)

# success, all done
exit