Repository navigation
Closed
Labels
Description
This looks like a bug to me:
Lines 1032 to 1076 in eac4207
| pid = fork(); | |
| if (pid == -1) { | |
| perror("failed to fork"); | |
| close(sockpair[1]); | |
| return -1; | |
| } else if (pid == 0) { | |
| int devnull; | |
| devnull = open("/dev/null", O_WRONLY); | |
| if (dup2(sockpair[1], 0) == -1 || dup2(sockpair[1], 1) == -1) { | |
| perror("failed to redirect input/output"); | |
| _exit(1); | |
| } | |
| if (!sshfs.foreground && devnull != -1) | |
| dup2(devnull, 2); | |
| close(devnull); | |
| close(sockpair[0]); | |
| close(sockpair[1]); | |
| switch (fork()) { | |
| case -1: | |
| perror("failed to fork"); | |
| _exit(1); | |
| case 0: | |
| break; | |
| default: | |
| _exit(0); | |
| } | |
| chdir("/"); | |
| if (sshfs.password_stdin) { | |
| int sfd; | |
| setsid(); | |
| sfd = open(ptyname, O_RDWR); | |
| if (sfd == -1) { | |
| perror(ptyname); | |
| _exit(1); | |
| } | |
| close(sfd); | |
| close(sshfs.ptyslavefd); | |
| close(sshfs.ptyfd); | |
| } |
Why isn't setsid() called after the first fork()? By leaving it open daemonized process can still get at least SIGINT, which wasn't intended for it.
How to reproduce:
mkdir ~/sshfs-tstvim- (in vim)
:!sshfs server: ~/tst - (in vim)
:!readand hit CTRL-C
~/tst gets unmounted, which shouldn't happen.
Moving setsid() should be enough to fix this.
Activity
Nikratio commentedon Aug 11, 2018
Thanks for the report! Yes, setsid() should come right after the first fork (at least according to Kerrisk, 2010). Could you provide a patch/pull request?
Nikratio commentedon Aug 11, 2018
(note that I haven't looked at the actual code. Please make sure that reading the password from stdin still works after this change)
xaizek commentedon Aug 11, 2018
No, sorry, building seems to require too much of additional software, I tried to install some, but then it wanted more and more...
jose1711 commentedon Aug 11, 2018
i moved
setsid()right after fork like thisit works fine in vim but sshfs is unable to read password from stdin (when ssh key is not in place):
xaizek commentedon Aug 11, 2018
Thanks @jose1711. Realized that I can test this on older version which doesn't require installing anything, but has the same issue. Apparently reading input doesn't work unless final process is a session leader. It seems to work if
setsid()is just moved out aboveif-statement, just to call it unconditionally.jose1711 commentedon Aug 11, 2018
@xaizek can you please fork and make a testing branch? i am trying to move
setsid()places but sshfs still does not ask for the password. thank youxaizek commentedon Aug 11, 2018
Just make it look something like this:
sshfs.password_stdinis set on-o password_stdin, so I do:If I do
sshfs server: /tmp/mtpoint, I do get password request but via some pinentry program with and without changes to the source code.Do you get password prompt if
setsid()is left where it is?jose1711 commentedon Aug 11, 2018
with
setsid()right belowchdir("/");the behaviour is as follows:There's no prompt for password or console or in pinentry program.
Sending password via stdin works
With original sourcecode i am getting prompted on console and password is accepted.
xaizek commentedon Aug 11, 2018
From
man ssh:That's probably why I get pinentry.
Since it's
sshprocess which needs a terminal, it's the one that should detach from it afterwards, but it doesn't have such option. Maybe there is no fix for this issue then.