diff --git a/NeoVimServer/main.m b/NeoVimServer/main.m index 9a8c319a..6df55e77 100644 --- a/NeoVimServer/main.m +++ b/NeoVimServer/main.m @@ -5,9 +5,6 @@ @import Foundation; -#import -#import - #import "NeoVimServer.h" #import "server_globals.h" #import "Logging.h" @@ -15,35 +12,33 @@ NeoVimServer *_neovim_server; +CFRunLoopRef _mainRunLoop; -// Ensure that no parent-less NeoVimServer processes are left when the main app crashes. -// From http://mac-os-x.10953.n7.nabble.com/Ensure-NSTask-terminates-when-parent-application-does-td31477.html -static void observe_parent_termination(void *arg) { - pid_t ppid = getppid(); // get parent pid +void observe_parent_termination() { + pid_t parentPID = getppid(); - int kq = kqueue(); - if (kq != -1) { - struct kevent procEvent; // wait for parent to exit - EV_SET( - &procEvent, // kevent - ppid, // ident - EVFILT_PROC, // filter - EV_ADD, // flags - NOTE_EXIT, // fflags - 0, // data - 0 // udata - ); + dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); + dispatch_source_t source = dispatch_source_create( + DISPATCH_SOURCE_TYPE_PROC, (uintptr_t) parentPID, DISPATCH_PROC_EXIT, queue + ); - kevent(kq, &procEvent, 1, &procEvent, 1, 0); + if (source == NULL) { + WLOG("No parent process monitoring..."); + return; } - ILOG("Exiting NeoVimServer: Parent terminated."); - exit(0); + dispatch_source_set_event_handler(source, ^{ + WLOG("Exiting neovim server due to parent termination."); + quit_neovim(); + dispatch_source_cancel(source); + }); + + dispatch_resume(source); } int main(int argc, const char *argv[]) { - uv_thread_t parent_observer_thread; - uv_thread_create(&parent_observer_thread, observe_parent_termination, NULL); + _mainRunLoop = CFRunLoopGetCurrent(); + observe_parent_termination(); @autoreleasepool { NSArray *arguments = [NSProcessInfo processInfo].arguments; @@ -58,5 +53,7 @@ int main(int argc, const char *argv[]) { } CFRunLoopRun(); + + DLOG("NeoVimServer returning."); return 0; } diff --git a/NeoVimServer/server_globals.h b/NeoVimServer/server_globals.h index 23090dfe..ee275500 100644 --- a/NeoVimServer/server_globals.h +++ b/NeoVimServer/server_globals.h @@ -9,6 +9,7 @@ @class NeoVimServer; extern NeoVimServer *_neovim_server; +extern CFRunLoopRef _mainRunLoop; extern void start_neovim(); extern void quit_neovim(); diff --git a/NeoVimServer/server_ui.m b/NeoVimServer/server_ui.m index 336f51ad..d4f61443 100644 --- a/NeoVimServer/server_ui.m +++ b/NeoVimServer/server_ui.m @@ -119,9 +119,7 @@ static void run_neovim(void *arg __unused) { char *argv[1]; argv[0] = "nvim"; - int returnCode = nvim_main(1, argv); - - NSLog(@"neovim's main returned with code: %d\n", returnCode); + nvim_main(1, argv); } static void set_ui_size(UIBridgeData *bridge, int width, int height) { @@ -519,7 +517,7 @@ void start_neovim() { void quit_neovim() { DLOG("NeoVimServer exiting..."); - exit(0); + CFRunLoopStop(_mainRunLoop); } #pragma mark Functions for neovim's main loop diff --git a/OutlineViewTest/Info.plist b/OutlineViewTest/Info.plist index 0108ced7..894d552b 100644 --- a/OutlineViewTest/Info.plist +++ b/OutlineViewTest/Info.plist @@ -17,9 +17,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.12.5 + SNAPSHOT-160 CFBundleVersion - 159 + 160 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright diff --git a/SwiftNeoVim/Info.plist b/SwiftNeoVim/Info.plist index 3d0749cc..a5f38481 100644 --- a/SwiftNeoVim/Info.plist +++ b/SwiftNeoVim/Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.12.5 + SNAPSHOT-160 CFBundleSignature ???? CFBundleVersion - 159 + 160 NSHumanReadableCopyright Copyright © 2016 Tae Won Ha. All rights reserved. NSPrincipalClass diff --git a/SwiftNeoVimTests/Info.plist b/SwiftNeoVimTests/Info.plist index 27b62a70..b4212c66 100644 --- a/SwiftNeoVimTests/Info.plist +++ b/SwiftNeoVimTests/Info.plist @@ -15,10 +15,10 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 0.12.5 + SNAPSHOT-160 CFBundleSignature ???? CFBundleVersion - 159 + 160 diff --git a/VimR-Workspace-Demo/Info.plist b/VimR-Workspace-Demo/Info.plist index 299f1e79..d0f5f798 100644 --- a/VimR-Workspace-Demo/Info.plist +++ b/VimR-Workspace-Demo/Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.12.5 + SNAPSHOT-160 CFBundleSignature ???? CFBundleVersion - 159 + 160 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright diff --git a/VimR.xcodeproj/project.pbxproj b/VimR.xcodeproj/project.pbxproj index 1823bd53..d2d7717c 100644 --- a/VimR.xcodeproj/project.pbxproj +++ b/VimR.xcodeproj/project.pbxproj @@ -1411,7 +1411,7 @@ COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 159; + DYLIB_CURRENT_VERSION = 160; DYLIB_INSTALL_NAME_BASE = "@rpath"; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -1435,7 +1435,7 @@ COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 159; + DYLIB_CURRENT_VERSION = 160; DYLIB_INSTALL_NAME_BASE = "@rpath"; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -1627,7 +1627,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 159; + CURRENT_PROJECT_VERSION = 160; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -1677,7 +1677,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 159; + CURRENT_PROJECT_VERSION = 160; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; diff --git a/VimR/Info.plist b/VimR/Info.plist index 590171dd..5d95c6da 100644 --- a/VimR/Info.plist +++ b/VimR/Info.plist @@ -36,7 +36,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.12.5 + SNAPSHOT-160 CFBundleSignature ???? CFBundleURLTypes @@ -53,7 +53,7 @@ CFBundleVersion - 159 + 160 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright diff --git a/VimRTests/Info.plist b/VimRTests/Info.plist index 27b62a70..b4212c66 100644 --- a/VimRTests/Info.plist +++ b/VimRTests/Info.plist @@ -15,10 +15,10 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 0.12.5 + SNAPSHOT-160 CFBundleSignature ???? CFBundleVersion - 159 + 160 diff --git a/appcast_snapshot.xml b/appcast_snapshot.xml index f1893492..030be748 100644 --- a/appcast_snapshot.xml +++ b/appcast_snapshot.xml @@ -7,22 +7,22 @@ Most recent changes with links to updates for VimR. en - SNAPSHOT-158 + SNAPSHOT-160 -
  • GH-376: Bugfix, cf. GH-376
  • +
  • GH-339: First draft of markdown previewer. Please report issues in GH-339 https://github.com/qvacua/vimr/issues/339.
  • ]]>
    - https://github.com/qvacua/vimr/releases/tag/snapshot/158 + https://github.com/qvacua/vimr/releases/tag/snapshot/160 - 2017-01-07T20:29:50.456369 + 2017-01-08T16:18:48.294323 10.10.0 -