Gentoo Archives: gentoo-dev

From: Steve Long <slong@××××××××××××××××××.uk>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] Re: eselect_zenity: alpha eselect GUI
Date: Thu, 08 Nov 2007 18:22:06
Message-Id: fgvju5$lck$1@ger.gmane.org
In Reply to: Re: [gentoo-dev] eselect_zenity: alpha eselect GUI by Ciaran McCreesh
1 Ciaran McCreesh wrote:
2
3 > if [[ ${UID} -ne 0 ]]; then
4 >
5 > We've always told people not to do that. Capabilities required by
6 > eselect modules should be tested by attempting to perform the action,
7 > not by some arbitrary query done on UIDs or groups. Being UID 0 doesn't
8 > mean you're allowed to do something, and not being UID 0 doesn't mean
9 > you're not allowed to do something.
10 >
11 I've always used EUID for the root check, eg:
12 if ((EUID)); then
13 echo "You must be root to run this script" >&2
14 exit 1
15 fi
16
17 This won't get round capabilities (so error status should still be checked
18 and the script bail with appropriate output, if it can't do something it's
19 supposed to) but it's sufficient for root privilege check, and is better
20 than UID which requires login as root. This doesn't, of course, deal with
21 non-root users, eg where users in group portage are allowed to carry out a
22 task.
23
24 You can check for that kind of thing with a writeable test, eg:
25 [[ -w $PORTDIR ]] || die 'Write access to portage dir required"
26 While none of this stops you from needing to check errors, it does make it
27 nicer for users, imo, if scripts check early on for broader permissions
28 where it's appropriate.
29
30 Wrt signalling die, the correct way for a script to terminate on signal is
31 something like this code, taken from a SIG_INT handler:
32 trap INT
33 kill -INT $$
34 This ensures the parent process is correctly notified. So IOW just kill self
35 with the appropriate signal, ensuring any traps are cleared.
36
37
38 --
39 gentoo-dev@g.o mailing list

Replies

Subject Author
Re: [gentoo-dev] Re: eselect_zenity: alpha eselect GUI Ciaran McCreesh <ciaran.mccreesh@×××××××××××××.uk>