bool process_iterator_t::next_process(wcstring *out_str, pid_t *out_pid) { wcstring cmd; pid_t pid = 0; while (cmd.empty()) { wcstring name; if (! dir || ! wreaddir(dir, name)) break; if (!iswnumeric(name.c_str())) continue; wcstring path = wcstring(L"/proc/") + name; struct stat buf; if (wstat(path, &buf)) continue; if (buf.st_uid != getuid()) continue; /* remember the pid */ pid = fish_wcstoi(name.c_str(), NULL, 10); /* the 'cmdline' file exists, it should contain the commandline */ FILE *cmdfile; if ((cmdfile=wfopen(path + L"/cmdline", "r"))) { wcstring full_command_line; signal_block(); fgetws2(&full_command_line, cmdfile); signal_unblock(); /* The command line needs to be escaped */ cmd = tok_first(full_command_line.c_str()); } #ifdef SunOS else if ((cmdfile=wfopen(path + L"/psinfo", "r"))) { psinfo_t info; if (fread(&info, sizeof(info), 1, cmdfile)) { /* The filename is unescaped */ cmd = str2wcstring(info.pr_fname); } } #endif if (cmdfile) fclose(cmdfile); } bool result = ! cmd.empty(); if (result) { *out_str = cmd; *out_pid = pid; } return result; }
/// Various things we need to initialize at run-time that don't really fit any of the other init /// routines. static void misc_init() { #ifdef OS_IS_CYGWIN // MS Windows tty devices do not currently have either a read or write timestamp. Those // respective fields of `struct stat` are always the current time. Which means we can't // use them. So we assume no external program has written to the terminal behind our // back. This makes multiline promptusable. See issue #2859 and // https://github.com/Microsoft/BashOnWindows/issues/545 has_working_tty_timestamps = false; #else // This covers preview builds of Windows Subsystem for Linux (WSL). FILE *procsyskosrel; if ((procsyskosrel = wfopen(L"/proc/sys/kernel/osrelease", "r"))) { wcstring osrelease; fgetws2(&osrelease, procsyskosrel); if (osrelease.find(L"3.4.0-Microsoft") != wcstring::npos) { has_working_tty_timestamps = false; } } if (procsyskosrel) { fclose(procsyskosrel); } #endif // OS_IS_MS_WINDOWS }