aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os
Commit message (Collapse)AuthorAge
...
* | | IO: let 'fsync' option control more casesJustin M. Keyes2018-04-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Vim has the 'swapsync' option which we removed in 62d137ce0969. Instead let 'fsync' control swapfile-fsync. These cases ALWAYS force fsync (ignoring 'fsync' option): - Idle (CursorHold). - Exit caused by deadly signal. - SIGPWR signal. - Explicit :preserve command.
* | | Merge #8276 'startup: Make -s - read from stdin'Justin M. Keyes2018-04-17
|\ \ \
| * | | win: Fix reading from stdinb-r-o-c-k2018-04-14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Reading from stdin on Windows is fixed in the same way as it was in #8267. * The file_read function was returning without filling the destination buffer when it was called with a non-blocking file descriptor.
| * | | Merge branch 'master' into s-dash-stdinb-r-o-c-k2018-04-14
| |\ \ \
| * \ \ \ Merge branch 'master' into s-dash-stdinZyX2017-12-03
| |\ \ \ \
| * | | | | os/fileio: Fix QB failureZyX2017-03-19
| | | | | |
| * | | | | fileio,main: Do not restart syscall at EAGAIN when reading for -sZyX2017-03-19
| | | | | |
| * | | | | getchar: Use fileio instead of fdopenZyX2017-03-19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: as fileio is cached and reads blocks this is going to wait until either EOF or reading enough characters to fill rbuffer. This is not good when reading user input from stdin as script.
| * | | | | main: Temporary fix assertion errorZyX2017-03-19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This variant uses `fdopen()` which is not standard, but it fixes problem on my system. In next commit `scriptin` will use `FileDescriptor*` from os/fileio in place of `FILE*`.
* | | | | | Merge #6272 'stdpath()'Justin M. Keyes2018-04-15
|\ \ \ \ \ \ | |_|_|/ / / |/| | | | |
| * | | | | eval: Add stdpath() method (#5297)Christian Höltje2018-03-29
| | |_|/ / | |/| | | | | | | | | | | | | | | | | | | | | | | Adds the :stdpath method for fetching XDG standard directories. Fixes #5297
* | | | | os/shell: use msg functions instead of screen when throttlingBjörn Linse2018-04-09
| | | | |
* | | | | os/shell: remove dead calls to screen functionsBjörn Linse2018-04-09
| | | | |
* | | | | build/OpenBSD: need -lpthread -lc++abi for LuaJIT (#8215)Utkarsh Anand2018-04-02
|/ / / /
* | | | lintJames McCoy2018-03-29
| | | |
* | | | build/NetBSD: use kinfo_proc2; undef uint64_t (#8197)Utkarsh Anand2018-03-29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | closes #8196 For historical reasons, uint64_t and friends are defined both as typedefs and macros. Some platforms that do that define the macros as identity (#define uint64_t uint64_t), others like NetBSD define to the backing type (#define uint64_t __uint64_t). This is normally transparent, except when multiple levels of macro expansions are used inconsistently.
* | | | refactor/rename: path_is_absolute()Justin M. Keyes2018-03-24
| | | |
* | | | Merge #8107 'jobs: separate process-group'Justin M. Keyes2018-03-18
|\ \ \ \
| * | | | API: nvim_get_proc()Justin M. Keyes2018-03-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | TODO: "exepath" field (win32: QueryFullProcessImageName()) On unix-likes `ps` is used because the platform-specific APIs are a nightmare. For reference, below is a (incomplete) attempt: diff --git a/src/nvim/os/process.c b/src/nvim/os/process.c index 09769925aca5..99afbbf290c1 100644 --- a/src/nvim/os/process.c +++ b/src/nvim/os/process.c @@ -208,3 +210,60 @@ int os_proc_children(int ppid, int **proc_list, size_t *proc_count) return 0; } +/// Gets various properties of the process identified by `pid`. +/// +/// @param pid Process to inspect. +/// @return Map of process properties, empty on error. +Dictionary os_proc_info(int pid) +{ + Dictionary pinfo = ARRAY_DICT_INIT; +#ifdef WIN32 + +#elif defined(__APPLE__) + char buf[PROC_PIDPATHINFO_MAXSIZE]; + if (proc_pidpath(pid, buf, sizeof(buf))) { + name = getName(buf); + PUT(pinfo, "exepath", STRING_OBJ(cstr_to_string(buf))); + return name; + } else { + ILOG("proc_pidpath() failed for pid: %d", pid); + } +#elif defined(BSD) +# if defined(__FreeBSD__) +# define KP_COMM(o) o.ki_comm +# else +# define KP_COMM(o) o.p_comm +# endif + struct kinfo_proc *proc = kinfo_getproc(pid); + if (proc) { + PUT(pinfo, "name", cstr_to_string(KP_COMM(proc))); + xfree(proc); + } else { + ILOG("kinfo_getproc() failed for pid: %d", pid); + } + +#elif defined(__linux__) + char fname[256] = { 0 }; + char buf[MAXPATHL]; + snprintf(fname, sizeof(fname), "/proc/%d/comm", pid); + FILE *fp = fopen(fname, "r"); + // FileDescriptor *f = file_open_new(&error, fname, kFileReadOnly, 0); + // ptrdiff_t file_read(FileDescriptor *const fp, char *const ret_buf, + // const size_t size) + if (fp == NULL) { + ILOG("fopen() of /proc/%d/comm failed", pid); + } else { + size_t n = fread(buf, sizeof(char), sizeof(buf) - 1, fp); + if (n == 0) { + WLOG("fread() of /proc/%d/comm failed", pid); + } else { + size_t end = MIN(sizeof(buf) - 1, n); + end = (end > 0 && buf[end - 1] == '\n') ? end - 1 : end; + buf[end] = '\0'; + PUT(pinfo, "name", STRING_OBJ(cstr_to_string(buf))); + } + } + fclose(fp); +#endif + return pinfo; +}
| * | | | win: nvim_get_proc_children()Justin M. Keyes2018-03-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | TODO: Raymond Chen explains[1] racy behavior of the CreateToolhelp32Snapshot approach. Better approach: > create a job object and put process P in it. Then call > QueryInformationJobObject with JobObjectBasicProcessIdList to get the > list of child processes. [1] "Why is CreateToolhelp32Snapshot returning incorrect parent process IDs all of a sudden?" https://blogs.msdn.microsoft.com/oldnewthing/20150403-00/?p=44313
| * | | | nvim_get_proc_children: fallback to shellJustin M. Keyes2018-03-16
| | | | | | | | | | | | | | | | | | | | | | | | | /proc/…/children may be unavailable because of an unset kernel option. Fallback to `pgrep` invoked in a shell.
| * | | | API: nvim_get_proc_children()Justin M. Keyes2018-03-16
| | | | | | | | | | | | | | | | | | | | ref https://github.com/libuv/libuv/pull/836
| * | | | win: os_proc_tree_kill()Justin M. Keyes2018-03-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | XXX: comment at https://stackoverflow.com/q/1173342 : > Windows recycles PIDs quite fast, you have to be extra careful not > to kill unrelated processes. These APIs will report PPIDs for long > dead processes whose PIDs may have been recycled. Check the parent > start date to make sure it is related to the processes you spawned.
| * | | | jobs: child proc must have a separate process-groupJustin M. Keyes2018-03-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | UV_PROCESS_DETACHED compels libuv:uv__process_child_init() to call setsid() in the child just after fork(). That ensures the process and its descendants are grouped in a separate session (and process group). The following jobstart() call correctly groups `sh` and `sleep` in a new session (and process-group), where `sh` is the "session leader" (and process-group leader): :call jobstart(['sh','-c','sleep 60']) SESN PGRP PID PPID Command 30383 30383 30383 3620 │ ├─ -bash 30383 31432 31432 30383 │ │ └─ nvim -u NORC 30383 31432 31433 30383 │ │ ├─ nvim -u NORC 8105 8105 8105 31432 │ │ └─ sh -c sleep 60 8105 8105 8106 8105 │ │ └─ sleep 60 closes #6530 ref: https://stackoverflow.com/q/1046933 ref: https://unix.stackexchange.com/a/404065 Helped-by: Marco Hinz <mh.codebro+github@gmail.com> Discussion ------------------------------------------------------------------------ On my linux box before this patch, the termclose_spec.lua:'kills job trapping SIGTERM' test indirectly causes cmake/busted to wait for 60s. That's because the test spawns a `sleep 60` descendant process which hangs around even after nvim exits: nvim killed the parent PID, but not PGID (process-group), so the grandchild "reparented" to init (PID 1). Session contains processes (and process-groups) which are logically part of the same "login session". Process-group is a set of logically/informally-related processes within a session; for example, shells assign a process group to each "job". Session IDs and PGIDs both have type pid_t (like PIDs). These OS-level mechanisms are, as usual, legacy accidents whose purpose is upheld by convention and folklore. We can use session-level grouping (setsid), or we could use process-group-level grouping (setpgid). Vim uses setsid() if available, otherwise setpgid(0,0). Windows ------------------------------------------------------------------------ UV_PROCESS_DETACHED on win32 sets CREATE_NEW_PROCESS_GROUP flag. But uv_kill() does not kill the process-group: https://github.com/nodejs/node/issues/3617 Ideas: - Set UV_PROCESS_DETACHED (CREATE_NEW_PROCESS_GROUP), then call GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pid) - Maybe won't work because MSDN says "Only processes that share the same console as the calling process receive the signal." https://docs.microsoft.com/en-us/windows/console/generateconsolectrlevent But CREATE_NEW_PROCESS_GROUP creates a new console ... ref https://stackoverflow.com/q/1453520 - Group processes within a "job". libuv does that *globally* for non-detached processes: uv__init_global_job_handle. - Iterate through CreateToolhelp32Snapshot(). - https://stackoverflow.com/q/1173342 - Vim does this, see terminate_all()
* | | | | build/MSVC: fix "C4005: RGB: macro redefinition"Justin M. Keyes2018-03-18
|/ / / /
* | | | Add missing PVS headers to new filesJames McCoy2018-03-11
| | | |
* | | | build/msvc: Remove confusing commentb-r-o-c-k2018-03-04
| | | |
* | | | build/msvc: Fix standard IO file number definitionsb-r-o-c-k2018-02-28
| | | | | | | | | | | | | | | | With MSVC, STDOUT_FILENO and STDERR_FILENO are defined as function calls instead of constants, meaning they can't be assigned to enum values. The enum was only used in one file, so it has been removed. A definition for STDIN_FILENO has been added that is consistent with the other two definitions.
* | | | build/msvc: Move include into unix_defs.hb-r-o-c-k2018-02-28
| | | |
* | | | build/msvc: Add mode_t typedef to win_defs.hb-r-o-c-k2018-02-28
| | | |
* | | | shell: handle split-up UTF-8 sequencesBjörn Linse2018-02-10
| | | |
* | | | shell: support bellBjörn Linse2018-02-10
| | | |
* | | | lint, minor cleanupJustin M. Keyes2018-02-07
| | | |
* | | | shell: use msg_outtrans_len_attr for :!cmdBjörn Linse2018-02-05
| | | | | | | | | | | | | | | | fixes #7830 and #7788
* | | | os_system(): do not set up input stream for empty string #7951Justin M. Keyes2018-02-01
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Test failure: test/functional/eval/system_spec.lua: "works with an empty string" E5677: Error writing input to shell-command: EPIPE ref https://github.com/neovim/neovim/pull/6558#issuecomment-361061035 ref #6554
* | | | Merge #7863 'mingw64: fix gcc warnings'Justin M. Keyes2018-01-20
|\ \ \ \
| * | | | Fix warning: multi-line comment [-Wcomment] use `:341,355s/: ↵George Zhao2018-01-19
| | | | | | | | | | | | | | | | | | | | \zs.*/\=string(submatch(0))`
| * | | | Fix warning, read/write have unsigned int count on windows.George Zhao2018-01-19
| | | | |
| * | | | Fix warning about NULL compareGeorge Zhao2018-01-18
| | | | |
| * | | | Fix warning about conversion on mingw64George Zhao2018-01-18
|/ / / /
* | | | os/input.c: parse keycodes in non-string context #7411lePerdu2018-01-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | cb02137dfac7 had two mistakes, of the same nature: trans_special() must be invoked with in_string=false unless the parsing context is a VimL string. replace_termcodes() and input_enqueue() are low-level mechanisms where VimL strings do not exist. keymap.c: adjust double-quote case to satisfy keymap_spec.lua closes #7410
* | | | os/fileio: Fix some flag names in file_* functions documentationZyX2018-01-14
| | | |
* | | | vim-patch:8.0.0074Michael Schupikov2017-12-15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: Cannot make Vim fail on an internal error. Solution: Add IEMSG() and IEMSG2(). (Domenique Pelle) Avoid reporting an internal error without mentioning where. https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f Signed-off-by: Michael Schupikov <michael@schupikov.de>
* | | | pty_process_unix: _exit() on execvp() failureJustin M. Keyes2017-12-13
| | | | | | | | | | | | | | | | | | | | Mostly cargo-culting based on a reading of the manpages, interwebs, and the Vim source.
* | | | mac: Set $LANG based on the system localeJames McCoy2017-12-10
| |/ / |/| | | | | | | | | | | | | | | | | | | | | | | Unix's typical locale-related environment variables aren't always set appropriately on a Mac. Instead of relying on them, query the locale information using Mac specific APIs and then set $LANG appropriately for the rest of nvim. Closes #5873
* | | Use defined(BSD) check when defining OPEN_CHR_FILESJames McCoy2017-11-28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rather than enumerate predefines for all BSD systems, just rely on the fact that they all "#define BSD" in sys/param.h. Debian's GNU/kFreeBSD still requires its own check, since it isn't using the BSD userspace. References: OpenBSD - https://github.com/openbsd/src/blob/210ebf9df0460bbdad02da9bbd5d859b61f57462/sys/sys/param.h#L40 FreeBSD - https://github.com/freebsd/freebsd/blob/f5d95e1f8d32db4ccccfd5ad9cecb21ed07a695d/sys/sys/param.h#L43 NetBSD - https://github.com/NetBSD/src/blob/ea620980793cf2011e5424f4a537b0488e3ffb4d/sys/sys/param.h#L49 DragonFlyBSD - https://github.com/DragonFlyBSD/DragonFlyBSD/blob/94ecf1295bb42b59772448d58ff40dd75c4a3ef8/sys/sys/param.h#L41 vim-patch:8.0.1357
* | | input: only change mode of input fd if there is an input fdBjörn Linse2017-11-25
| | |
* | | tui: job-control: use saved termios for pty jobsJustin M. Keyes2017-11-25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On startup, if running in a terminal, save the termios properties. Use the saved termios for `:terminal` and `jobstart()` pty jobs. This won't affect nvim spawned outside of a terminal. questions: - This affects `:terminal` and `jobstart({'pty':v:true})`. Should we be more conservative for `jobstart({'pty':v:true})` (e.g. pass NULL to forkpty() and let the OS defaults prevail)? - Note: `iutf8` would not be set in that case.
* | | channels: generalize jobclose()Björn Linse2017-11-25
| | |
* | | channels: allow bytes sockets and stdio, and buffered bytes outputBjörn Linse2017-11-24
| | |