Merge lp:~elopio/snappy/sudo_path into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Leo Arias
Status: Merged
Merge reported by: Leo Arias
Merged at revision: not available
Proposed branch: lp:~elopio/snappy/sudo_path
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 23 lines (+11/-0)
1 file modified
_integration-tests/reboot-wrapper (+11/-0)
To merge this branch: bzr merge lp:~elopio/snappy/sudo_path
Reviewer Review Type Date Requested Status
Sergio Schvezov Needs Information
Federico Gimenez continuous-integration Pending
Review via email: mp+269252@code.launchpad.net

Commit message

Added a sudo wrapper that preserves the user path.

To post a comment you must log in.
lp:~elopio/snappy/sudo_path updated
642. By Leo Arias

Make the file writable.

643. By Leo Arias

Fixed the path.

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

Have you tried something like
Maybe expand PATH using os.ExpandEnv
cmd := exec.Command("/bin/sh", "-c", "sudo env PATH=$PATH ...")

review: Needs Information
Revision history for this message
Leo Arias (elopio) wrote :

That works. The problem with that approach is that we would have to do the same for every sudo call.
We could write a helper called ExecSudoCommand, if you prefer that.

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

Oh, I'll leave it to your preference, we used to have run_with and run in phablet-test-run, made it easy to get it at a first glance.

I you prefer this, you have my ack to self approve though ;-)

Revision history for this message
Leo Arias (elopio) wrote :

I hate both ways. mvo found this, so maybe he'll have a preference.

Revision history for this message
Leo Arias (elopio) wrote :
Revision history for this message
Leo Arias (elopio) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '_integration-tests/reboot-wrapper'
2--- _integration-tests/reboot-wrapper 2015-07-08 08:41:35 +0000
3+++ _integration-tests/reboot-wrapper 2015-08-26 18:43:10 +0000
4@@ -21,8 +21,19 @@
5 TEST=$1
6 NEEDS_REBOOT=/tmp/needs-reboot
7
8+# We export the tests bin path so the snappy binary that might be compiled from
9+# the branch is found.
10 export PATH=$(pwd)/_integration-tests/bin:$PATH
11
12+# XXX sudo does not preserve the user PATH. A nicer way to solve this would be
13+# to use an alias, but go exec.Command sets the full binary path.
14+cat > $(pwd)/_integration-tests/bin/sudo <<EOF
15+#!/bin/bash
16+/usr/bin/sudo env PATH=$PATH "\$@"
17+EOF
18+
19+chmod +x $(pwd)/_integration-tests/bin/sudo
20+
21 # shift to remove the test binary name (first argument) and be able to pass the rest
22 # of them to it
23 shift

Subscribers

People subscribed via source and target branches