1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-29 16:56:40 +03:00
vimr/NeoVimServer/main.m

63 lines
1.7 KiB
Mathematica
Raw Normal View History

/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
2016-10-22 18:25:43 +03:00
@import Foundation;
#import <sys/event.h>
#import <uv.h>
#import "NeoVimServer.h"
#import "server_globals.h"
2016-08-13 00:45:56 +03:00
#import "Logging.h"
#import "CocoaCategories.h"
NeoVimServer *_neovim_server;
2016-10-22 18:25:43 +03:00
// 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
2016-07-17 16:59:01 +03:00
static void observe_parent_termination(void *arg) {
pid_t ppid = getppid(); // get parent pid
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
);
kevent(kq, &procEvent, 1, &procEvent, 1, 0);
}
2016-10-22 18:25:43 +03:00
ILOG("Exiting NeoVimServer: Parent terminated.");
exit(0);
}
int main(int argc, const char *argv[]) {
uv_thread_t parent_observer_thread;
2016-07-17 16:59:01 +03:00
uv_thread_create(&parent_observer_thread, observe_parent_termination, NULL);
@autoreleasepool {
NSArray<NSString *> *arguments = [NSProcessInfo processInfo].arguments;
2016-07-10 15:43:26 +03:00
NSString *remoteServerName = arguments[1];
NSString *localServerName = arguments[2];
2016-07-10 15:43:26 +03:00
_neovim_server = [[NeoVimServer alloc] initWithLocalServerName:localServerName remoteServerName:remoteServerName];
DLOG("Started neovim server '%s' and connected it with the remote agent '%s'.",
localServerName.cstr, remoteServerName.cstr);
[_neovim_server notifyReadiness];
}
2016-07-10 14:51:00 +03:00
CFRunLoopRun();
return 0;
}