Skip to contentSkip to conversation

ceph_common.sh: Do not sudo to root unless needed

PATCH Applied Jim Schutt 2 participants 3 messages Sep 14, 2011 – Sep 19, 2011

lore
Share & tools
lore

Jim Schutt

author
#0 lore raw

PATCH 1/1 ceph_common.sh: Do not sudo to root unless needed

Using do_root_cmd() doesn't really need to sudo to root if you're already root.

Commit 71dc75bdafe62a098c0493ad62f2d0d2a6ca7946 causes a regression:
when system "foo" has a sudoers config that requires a tty, init-ceph now fails like this:
sudo: sorry, you must have a tty to run sudo

when it is invoked by root with something like this:
ssh foo /etc/init.d/init-ceph start

---
 src/ceph_common.sh |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
src/ceph_common.sh +6 -1
index adb8783..1da42bd 100644
@@ -97,7 +97,12 @@ do_root_cmd() {
     if [ -z "$ssh" ]; then
 	[ $verbose -eq 1 ] && echo "--- $host# $1"
 	ulimit -c unlimited
-	sudo bash -c "$1" || { echo "failed: '$1'" ; exit 1; }
+	whoami=`whoami`
+	if [ "$whoami" = "root" ]; then
+	    bash -c "$1" || { echo "failed: '$1'" ; exit 1; }
+	else
+	    sudo bash -c "$1" || { echo "failed: '$1'" ; exit 1; }
+	fi
     else
 	[ $verbose -eq 1 ] && echo "--- $rootssh $2 \"cd $sshdir ; ulimit -c unlimited ; $1\""
 	$rootssh $2 "cd $sshdir ; ulimit -c unlimited ; $1" || { echo "failed: '$rootssh $1'" ; exit 1; }
Signature · 1 line
1.7.1
#1 lore raw
Quoted 8 lines · Jim Schutt

Using do_root_cmd() doesn't really need to sudo to root if you're already root.

Commit 71dc75bdafe62a098c0493ad62f2d0d2a6ca7946 causes a regression:
when system "foo" has a sudoers config that requires a tty, init-ceph now fails like this:
 sudo: sorry, you must have a tty to run sudo

Quoted 4 lines

when it is invoked by root with something like this:
  ssh foo /etc/init.d/init-ceph start

Applied as d64237a6a555944d6d35676490bc4fb7c7db965d, thank you.

(It seems I screwed up the author field in the commit, sorry about that. I don't want to force push just to fix that; Signed-off-by gives you credit anyway.)
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#2 lore raw
Quoted 12 lines · Tommi Virtanen
Quoted 11 lines · Jim Schutt

Using do_root_cmd() doesn't really need to sudo to root if you're already root.

Commit 71dc75bdafe62a098c0493ad62f2d0d2a6ca7946 causes a regression:
when system "foo" has a sudoers config that requires a tty, init-ceph now fails like this:
sudo: sorry, you must have a tty to run sudo

when it is invoked by root with something like this:
ssh foo /etc/init.d/init-ceph start

Quoted 9 lines
Quoted 1 line

Applied as d64237a6a555944d6d35676490bc4fb7c7db965d, thank you.

(It seems I screwed up the author field in the commit, sorry about that. I don't want to force push just to fix that; Signed-off-by gives you credit anyway.)

No problem - thanks for taking a look.

-- Jim