Mail Archives: cygwin/2009/09/04/18:00:45
--------------090502020603000700030601
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
When running as member of admin group a Cygwin process normally has
root-like privileges. But this fact cannot be checked with 'geteuid() ==
0'. The shell never sets the default root prompt '#', except if the user
is mapped to uid 0 in /etc/passwd.
Is there a generic way to set '#' via /etc/profile ?
The attached patch works for me on Cygwin 1.7., but it relies on a
runtime file write check.
(It also requires ACL support in /tmp and would not work on 1.5).
Is there a better way to do this?
Christian
--------------090502020603000700030601
Content-Type: text/x-patch;
name="set-root-prompt.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="set-root-prompt.patch"
--- /etc/profile.orig 2009-07-13 20:50:01.875000000 +0200
+++ /etc/profile 2009-09-04 23:57:16.578125000 +0200
@@ -84,6 +84,18 @@
# CVSROOT=:pserver:anoncvs AT sources DOT redhat DOT com:/cvs/src
# export CVSROOT
+# Set root prompt if shell can write to readonly file
+# (does only work if /tmp uses ACLs)
+f=/tmp/etc-profile-$$
+echo > "$f"
+chmod a=r "$f"
+if (echo > "$f") 2>/dev/null; then
+ PS1='# '
+else
+ PS1='$ '
+fi
+rm -f "$f"
+
# Shell dependent settings
case "`echo "_$0" | /usr/bin/tr '[:upper:]' '[:lower:]' | /usr/bin/sed -e 's/^_//'`" in
bash | -bash | */bash | \
@@ -93,7 +105,7 @@
export HOSTNAME
# Set a default prompt of: user AT host and current_directory
- PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '
+ PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n'"$PS1"
;;
ksh* | -ksh* | */ksh* | \
ksh*.exe | -ksh*.exe | */ksh*.exe )
@@ -103,12 +115,12 @@
# Set a default prompt of: user AT host and current_directory
PS1='^[]0;${PWD}^G
^[[32m${USER}@${HOSTNAME} ^[[33m${PWD}^[[0m
-$ '
+'"$PS1"
;;
zsh* | -zsh* | */zsh* | \
zsh*.exe | -zsh*.exe | */zsh*.exe )
# Set a default prompt of: user AT host, a command counter, and current_directory
- PS1='(%n@%m)[%h] %~ %% '
+ PS1='(%n@%m)[%h] %~ '"${PS1/$/%%}"
# Set SHELL if not set
if [ ! -z "${ZSH_NAME}" -a -z "${SHELL}" ]; then
@@ -118,8 +130,7 @@
;;
sh | -sh | */sh | \
sh.exe | -sh.exe | */sh.exe )
- # Set a simple prompt
- PS1='$ '
+ # Keep the simple prompt
;;
* )
# Sorry, this shell has no defaults in /etc/profile,
@@ -131,7 +142,6 @@
# Thanks
- PS1='$ '
;;
esac
--------------090502020603000700030601
Content-Type: text/plain; charset=us-ascii
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
--------------090502020603000700030601--
- Raw text -