execve(“/bin/sh”, 0, 0); in a pipe

后端 未结 3 747
广开言路
广开言路 2021-02-14 10:25

I have the following example program:

#include 

int
main(int argc, char ** argv){
    char buf[100];

    printf(\"Please enter your name: \");
          


        
3条回答
  •  心在旅途
    2021-02-14 11:23

    Not 100% sure of this (the precise shell being used and the OS might throw these answers a bit; I believe that FreeBSD uses GNU bash by default as /bin/sh?), but

    • sh may be detecting that its input is not a tty.

    or

    • Your version of sh might go into non-interactive mode like that also if called as sh, expecting login will prepend a - onto argv[0] for it. Setting up execve ("/bin/sh", { "-sh", NULL}, NULL) might convince it that it's being run as a login shell.

提交回复
热议问题