| 110 | Process::Process( int pid ) : mPID( pid ) {} |
| 111 | |
| 112 | static void execshell( const char* cmd, const char* const* args, std::string workingDirectory, |
| 113 | const std::unordered_map<std::string, std::string>& env ) { |
| 114 | const struct passwd* pw; |
| 115 | const char* sh; |
| 116 | |
| 117 | errno = 0; |
| 118 | if ( ( pw = getpwuid( getuid() ) ) == NULL ) { |
| 119 | if ( errno ) { |
| 120 | fprintf( stderr, "getpwuid: %s\n", strerror( errno ) ); |
| 121 | _exit( 1 ); |
| 122 | } else { |
| 123 | fprintf( stderr, "who are you?\n" ); |
| 124 | _exit( 1 ); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | if ( ( sh = getenv( "SHELL" ) ) == NULL ) |
| 129 | sh = ( pw->pw_shell[0] ) ? pw->pw_shell : cmd; |
| 130 | |
| 131 | if ( workingDirectory.empty() ) |
| 132 | workingDirectory = pw->pw_dir; |
| 133 | |
| 134 | FileSystem::changeWorkingDirectory( workingDirectory ); |
| 135 | |
| 136 | unsetenv( "COLUMNS" ); |
| 137 | unsetenv( "LINES" ); |
| 138 | unsetenv( "TERMCAP" ); |
| 139 | setenv( "LOGNAME", pw->pw_name, 1 ); |
| 140 | setenv( "USER", pw->pw_name, 1 ); |
| 141 | setenv( "SHELL", sh, 1 ); |
| 142 | setenv( "HOME", pw->pw_dir, 1 ); |
| 143 | setenv( "TERM", "xterm-256color", 1 ); |
| 144 | setenv( "TERM_PROGRAM", "eterm", 1 ); |
| 145 | setenv( "TERM_PROGRAM_VERSION", EE::Version::getVersionName( false ).c_str(), 1 ); |
| 146 | setenv( "COLORTERM", "24bit", 1 ); |
| 147 | |
| 148 | for ( const auto& e : env ) |
| 149 | setenv( e.first.c_str(), e.second.c_str(), 1 ); |
| 150 | |
| 151 | signal( SIGCHLD, SIG_DFL ); |
| 152 | signal( SIGHUP, SIG_DFL ); |
| 153 | signal( SIGINT, SIG_DFL ); |
| 154 | signal( SIGQUIT, SIG_DFL ); |
| 155 | signal( SIGTERM, SIG_DFL ); |
| 156 | signal( SIGALRM, SIG_DFL ); |
| 157 | |
| 158 | execvp( cmd, (char* const*)args ); |
| 159 | _exit( 1 ); |
| 160 | } |
| 161 | |
| 162 | std::unique_ptr<Process> Process::createWithPipe( const std::string& /*program*/, |
| 163 | const std::vector<std::string>& /*args*/, |
no test coverage detected