Task #4078
openUse popen in ndn_application
0%
Description
Currently we use cmd. Then we use a shell command to get the pid - which is unreliable.
But Popen needs to be run with correct HOME environment, otherwise NLSR can't connect with NFD.
Popen does not seem to work correctly for cluster, even when HOME environment is passed:
out = self.node.popen("printenv").stdout.read()
env = {}
for elem in out.split("\n"):
if elem != "":
tmp=elem.split("=")
env[tmp[0]] = tmp[1]
env["HOME"] = self.node.homeFolder
self.popen = self.node.popen(command.split(), env=env)
So maybe for now keep using cmd for cluster:
https://gerrit.named-data.net/#/c/3870/3/ndn/ndn_application.py
Updated by Junxiao Shi over 7 years ago
mnndn has used popen for years.
The trick is passing privateDirs
to mininet.node.Host
constructor, so that $HOME
can keep its default value of /root
and does not need to be overridden.
Updated by Ashlesh Gawande over 7 years ago
- Related to Task #3051: Investigate Mininet's per-host private directories feature for NFD socket file added
Updated by Junxiao Shi over 6 years ago
Popen does not seem to work correctly for cluster, even when HOME environment is passed:
Mininet Cluster Edition implements RemoteMixin._popen as follows:
def _popen( self, cmd, sudo=True, tt=True, **params):
if self.isRemote:
if sudo:
cmd = [ 'sudo', '-E' ] + cmd
if tt:
cmd = self.sshcmd + cmd
else:
# Hack: remove -tt
sshcmd = list( self.sshcmd )
sshcmd.remove( '-tt' )
cmd = sshcmd + cmd
else:
if self.user and not sudo:
# Drop privileges
cmd = [ 'sudo', '-E', '-u', self.user ] + cmd
popen = super( RemoteMixin, self )._popen( cmd, **params )
return popen
When you pass env
to node.popen
, the environment variables apply to "ssh" process, but the remote command (such as /usr/bin/nfd
) does not receive them.
You could set environment variables in the command line before passing them to node.popen
, but it's better to patch RemoteMixin._popen
with this feature and send a pull request.