For a project I need to open a file (in fact a named pipe) with os.open().
Here is the situation:
I have a process that creates two names pipe on a first machine (lets call them pipeCS and pipeSC). Each pipe goes in one direction (pipeCS = client->server and pipeSC = server->client).
Then we have a fork() and the first subprocess is replaced by a ssh process (with os.execvp("ssh -e none -l [uname] [adress] [file]", [args]
)
On the client side, I open the two pipes with:
pcs_c = os.open("pipeCS", os.O_WRONLY|os.O_CREAT) #pipe client->server
psc_c = os.open("pipeSC", os.O_RDONLY|os.O_CREAT) #pipe server->client
And on the server side, I also want to open theses pipes with something like:
pcs_s = os.open("pipeCS", os.O_RDONLY|os.O_CREAT) #pipe client->server
psc_s = os.open("pipeSC", os.O_WRONLY|os.O_CREAT) #pipe server->client
It's really important to open them with os.open(), because I need the I/O of the pipes to be blocking and to be able to use (os.write(fd, [data])
). Could you tell me how to open the named pipes (which are on the client side) on the server side ?
Here is my code if you want to see the context :
elif dic['ssh']: #client side of the code
os.mkfifo("pipeCS") #client -> server
os.mkfifo("pipeSC") #server -> client
pcs_c = os.open("pipeCS", os.O_WRONLY|os.O_CREAT) #pipe client->server clientSide, write
psc_c = os.open("pipeSC", os.O_RDONLY|os.O_CREAT) #pipe server->client clientSide, read
pid = os.fork()
if pid == 0:
#code sender
sender.send_local(src, dic, pcs_c, psc_c)
else:
#replace the client subprocess with the server process
os.execvp("ssh -e none -l distant localhost -- ./[file] --server", [])
elif dic['--server']: #server side of the code
pcs_s = os.open("[something to open [user]@[machine]:pipeCS]", os.O_RDONLY|os.O_CREAT) #pipe client->server
psc_s = os.open("[something to open [user]@[machine]:pipeSC]", os.O_WRONLY|os.O_CREAT) #pipe server->client
server.server_ssh(dic, pcs_s, psc_s)
Thank you for your attention ;)