File: not-root

package info (click to toggle)
cssc 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 11,368 kB
  • sloc: cpp: 39,446; ansic: 17,403; sh: 11,328; python: 3,923; makefile: 1,929; perl: 342; awk: 15; sed: 15
file content (33 lines) | stat: -rw-r--r-- 763 bytes parent folder | download | duplicates (4)
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
# Hey, Emacs!  This is a -*- sh -*- script.
#
# The test suite fails if run by root, because when you are root,
# "test -w foo" returns 0 even for read-only files because root can
# write to them.
#
# The test suite depends on being able to accurately detect a readonly file.

# Execute in a subshell so that we can use "trap ... 0" and 
# ensure that the temporary file is removed before we reach 
# the end of this file.

(
f=/tmp/foo.$$.tmp
# Use rm and echo rather than risking a missing "touch".
rm -f $f ; echo > $f

# Remove temporary file on exit.
trap "rm -f $f" 0


chmod 400 $f
if test -f $f
then
	if test -w $f
	then
		miscarry "Please do not run the suite as root" 
	fi
else
	miscarry "Could not create $f (or buggy test(1))"
fi
unset f
) || exit $?