|
23 | 23 | import subprocess |
24 | 24 | import re |
25 | 25 | import time |
| 26 | +import tempfile |
26 | 27 | try: |
27 | 28 | import ipaddress |
28 | 29 | except ImportError, ex: |
@@ -188,20 +189,52 @@ def startShell(self, node, noOverridePrompt=False): |
188 | 189 |
|
189 | 190 | shell = os.path.realpath(os.path.abspath(os.environ['SHELL'])) |
190 | 191 |
|
191 | | - if os.path.basename(shell) == 'bash' and not noOverridePrompt: |
192 | | - promptOverride = [ '-c', '''exec $SHELL --rcfile <(cat ~/.bashrc; echo '[ "$SN_NO_OVERRIDE_PROMPT" ] || PS1="\e[1m[\$SN_NODE_NAME]\e[0m $PS1"')''' ] |
193 | | - else: |
194 | | - promptOverride = [ ] |
| 192 | + user = os.environ['SUDO_USER'] |
| 193 | + userId = int(os.environ['SUDO_UID']) |
| 194 | + |
| 195 | + nodeEnv = {} |
| 196 | + node.setEnvironVars(nodeEnv) |
| 197 | + |
| 198 | + promptOverrideRCFile = None |
| 199 | + |
| 200 | + try: |
| 201 | + |
| 202 | + cmd = [ 'sudo', '-u', user, '--preserve-env=' + ','.join(nodeEnv.keys()), shell ] |
| 203 | + |
| 204 | + if os.path.basename(shell) == 'bash' and not noOverridePrompt: |
| 205 | + promptOverrideRCFile = tempfile.NamedTemporaryFile() |
| 206 | + |
| 207 | + promptOverrideRCFile.write(''': |
| 208 | +if test -f /etc/bash.bashrc; then |
| 209 | + . /etc/bash.bashrc |
| 210 | +fi |
| 211 | +if test -f ${HOME}/.bashrc; then |
| 212 | + . ${HOME}/.bashrc |
| 213 | +fi |
| 214 | +if [ `tput colors` -gt 0 ]; then |
| 215 | + PS1="\[\e[36m\][\$SN_NODE_NAME] \[\e[0m\]$PS1" |
| 216 | +else |
| 217 | + PS1="[\$SN_NODE_NAME] $PS1" |
| 218 | +fi |
| 219 | +''') |
195 | 220 |
|
196 | | - cmd = [ 'su', ] + promptOverride + [ os.environ['SUDO_USER'] ] |
| 221 | + promptOverrideRCFile.flush() |
| 222 | + |
| 223 | + os.fchown(promptOverrideRCFile.fileno(), userId, userId) |
| 224 | + |
| 225 | + cmd += [ '--rcfile', promptOverrideRCFile.name ] |
197 | 226 |
|
198 | | - if not node.isHostNode: |
199 | | - cmd = [ 'ip', 'netns', 'exec', node.nsName ] + cmd |
| 227 | + if not node.isHostNode: |
| 228 | + cmd = [ 'ip', 'netns', 'exec', node.nsName ] + cmd |
| 229 | + |
| 230 | + cmdEnv = os.environ.copy() |
| 231 | + cmdEnv.update(nodeEnv) |
200 | 232 |
|
201 | | - cmdEnv = os.environ.copy() |
202 | | - node.setEnvironVars(cmdEnv) |
203 | | - |
204 | | - subprocess.call(cmd, env=cmdEnv) |
| 233 | + subprocess.call(cmd, env=cmdEnv) |
| 234 | + |
| 235 | + finally: |
| 236 | + if promptOverrideRCFile != None: |
| 237 | + promptOverrideRCFile.close() |
205 | 238 |
|
206 | 239 | def clearAll(self): |
207 | 240 | verifyRoot() |
@@ -1277,11 +1310,11 @@ def setEnvironVars(self, environ): |
1277 | 1310 | weaveConfig = '--node-id %016X ' % self.weaveNodeId |
1278 | 1311 | weaveConfig += '--fabric-id %016X ' % self.weaveFabricId |
1279 | 1312 | if self.wifiInterface: |
1280 | | - weaveConfig += '--default-subnet 1 ' |
| 1313 | + weaveConfig += '--subnet 1 ' |
1281 | 1314 | elif self.threadInterface: |
1282 | | - weaveConfig += '--default-subnet 6 ' |
| 1315 | + weaveConfig += '--subnet 6 ' |
1283 | 1316 | elif self.legacyInterface: |
1284 | | - weaveConfig += '--default-subnet 2 ' |
| 1317 | + weaveConfig += '--subnet 2 ' |
1285 | 1318 | if self.useLwIP: |
1286 | 1319 | weaveConfig += self.getLwIPConfig() |
1287 | 1320 | environ['WEAVE_CONFIG'] = weaveConfig |
|
0 commit comments