c - reading from stdin after execl() bash return an eio(Input/output error) -


the following code can act expected if executed shell.

but if set program user's shell , ssh host execute program shell, read(0, &buf123, 1); return eio(input/output error):

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #include <regex.h> #include <curl/curl.h> #include <readline/readline.h>  int main() {     char *shell = "/bin/bash";      pid_t child;     if ((child = fork()) < 0) {         perror("vfork");         return;     }     if (child == 0) {         execl(shell, shell + 5, "-c", "exec /bin/bash --login", null);         perror("execl");         return;     }     wait(null);      char buf123[1024];     read(0, &buf123, 1);     printf("::%s::\n", buf123);  } 

but if change execl(bash) non-interactive bash execl(bash -c "id") or other program rather bash, read(0, &buf123, 1); success.

so reproduce error, 2 conditions need met:

1. execvl() interactive bash(system() can reproduce error)  2. run user's shell using ssh 

could me figure out why , how avoid this?

the following strace result:

wait4(-1, null, 0, null)                = 2 --- sigchld {si_signo=sigchld, si_code=cld_exited, si_pid=2, si_status=0, si_utime=0, si_stime=0} --- read(0, 0x7fff7a4c8cb0, 1)              = -1 eio (input/output error) fstat(1, {st_mode=s_ifchr|0620, st_rdev=makedev(136, 1), ...}) = 0 mmap(null, 4096, prot_read|prot_write, map_private|map_anonymous, -1, 0) = 0x7fcd281f3000 write(1, "::xv\37(\315\177::\n", 11)    = 11 exit_group(11)                          = ? +++ exited 11 +++ 

thanks in advance!

i happens because sub-shell login interactive shell , took control on terminal (set session control terminal). process disconnected terminal , cannot read on anymore.

of course if use non interactive shell, don't need control on terminal leaving process.

read posix terminal, sessions , processes group.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -