aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-07-04 19:48:26 +0300
committerZyX <kp-pav@yandex.ru>2017-07-04 19:58:02 +0300
commit7109f63e3cf70ffc4581f3dfb6132632413e4817 (patch)
treed3bf1bf85d8bf96e3398770701504754c73fecdf
parent28f6bd822b26ae92701ca553d29693d35864753f (diff)
downloadrneovim-7109f63e3cf70ffc4581f3dfb6132632413e4817.tar.gz
rneovim-7109f63e3cf70ffc4581f3dfb6132632413e4817.tar.bz2
rneovim-7109f63e3cf70ffc4581f3dfb6132632413e4817.zip
main: Flush file in place of closing it, also do error reporting
Apparently on travis OS X systems it crashes when cleaning up streams with stdout closed: (lldb) bt all * thread #1: tid = 0x0000, 0x00007fff8703df06 libsystem_kernel.dylib`__pthread_kill + 10, stop reason = signal SIGSTOP * frame #0: 0x00007fff8703df06 libsystem_kernel.dylib`__pthread_kill + 10 frame #1: 0x00007fff93a764ec libsystem_pthread.dylib`pthread_kill + 90 frame #2: 0x00007fff97c056df libsystem_c.dylib`abort + 129 frame #3: 0x00007fff97bccdd8 libsystem_c.dylib`__assert_rtn + 321 frame #4: 0x0000000107a4e106 nvim`uv__close(fd=<unavailable>) + 102 at core.c:521 frame #5: 0x0000000107a5307d nvim`uv__loop_close(loop=0x00007fff5847c018) + 77 at loop.c:118 frame #6: 0x0000000107a4d149 nvim`uv_loop_close(loop=0x00007fff5847c018) + 57 at uv-common.c:626 frame #7: 0x000000010783e5bc nvim`stream_set_blocking(fd=0, blocking=true) + 204 at stream.c:34 frame #8: 0x000000010795d66b nvim`mch_exit(r=0) + 91 at os_unix.c:147 frame #9: 0x00000001078d5663 nvim`command_line_scan(parmp=0x00007fff5847c760) + 1779 at main.c:787 frame #10: 0x00000001078d4393 nvim`main(argc=2, argv=0x00007fff5847c898) + 163 at main.c:249 frame #11: 0x00007fff8cdd65ad libdyld.dylib`start + 1 frame #12: 0x00007fff8cdd65ad libdyld.dylib`start + 1
-rw-r--r--src/nvim/main.c5
-rw-r--r--src/nvim/os/fileio.c15
2 files changed, 16 insertions, 4 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c
index f55f876608..7dcf00c26b 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -783,7 +783,10 @@ static void command_line_scan(mparm_T *parmp)
msgpack_rpc_from_object(md, p);
msgpack_packer_free(p);
- file_close(&fp, false);
+ const int ff_ret = file_flush(&fp);
+ if (ff_ret < 0) {
+ msgpack_file_write_error(ff_ret);
+ }
mch_exit(0);
} else if (STRICMP(argv[0] + argv_idx, "headless") == 0) {
parmp->headless = true;
diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c
index 0ed0ae87e3..5d68473982 100644
--- a/src/nvim/os/fileio.c
+++ b/src/nvim/os/fileio.c
@@ -400,9 +400,18 @@ int msgpack_file_write(void *data, const char *buf, size_t len)
assert(len < PTRDIFF_MAX);
const ptrdiff_t written_bytes = file_write((FileDescriptor *)data, buf, len);
if (written_bytes < 0) {
- emsgf(_("E5420: Failed to write to file: %s"),
- os_strerror((int)written_bytes));
- return -1;
+ return msgpack_file_write_error((int)written_bytes);
}
return 0;
}
+
+/// Print error which occurs when failing to write msgpack data
+///
+/// @param[in] error Error code of the error to print.
+///
+/// @return -1 (error return for msgpack_packer callbacks).
+int msgpack_file_write_error(const int error)
+{
+ emsgf(_("E5420: Failed to write to file: %s"), os_strerror(error));
+ return -1;
+}