1

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 ;)

Nenonymo
  • 11
  • 2
  • As you mention `ssh`, a pipe cannot be used to communicate between machines (unless, perhaps, you are using some sort of SSH-mounted file system). You need to use sockets for communication over the network. – chepner May 05 '21 at 13:59
  • What does "distant" mean, in the phrase "a distant directory"? – Joseph Sible-Reinstate Monica May 05 '21 at 17:07
  • It means a directory (in this case, a directory in the `home` of the user) of another user on the same computer or a user on another computer of the same network. (like `[user]@localhost` or `[user]@[local-ip]` if we are refering to the ssh command) @joseph – Nenonymo May 05 '21 at 20:57

0 Answers0