EA-46653 (abort on FSEvent stream creation failure)

This commit is contained in:
Roman Shevchenko
2013-06-05 15:30:56 +04:00
parent 743a276525
commit 6a262c84fe
3 changed files with 21 additions and 20 deletions

Binary file not shown.

View File

@@ -68,24 +68,9 @@ static void callback(ConstFSEventStreamRef streamRef,
}
static void * EventProcessingThread(void *data) {
CFStringRef path = CFSTR("/");
CFArrayRef pathsToWatch = CFArrayCreate(NULL, (const void **)&path, 1, NULL);
void *callbackInfo = NULL;
CFAbsoluteTime latency = 0.3; // Latency in seconds
FSEventStreamRef stream = FSEventStreamCreate(
NULL,
&callback,
callbackInfo,
pathsToWatch,
kFSEventStreamEventIdSinceNow,
latency,
kFSEventStreamCreateFlagNoDefer
);
FSEventStreamRef stream = (FSEventStreamRef) data;
FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
FSEventStreamStart(stream);
CFRunLoopRun();
return NULL;
}
@@ -169,13 +154,29 @@ int main(const int argc, const char* argv[]) {
return 1;
}
pthread_t threadId;
if (pthread_create(&threadId, NULL, EventProcessingThread, NULL) != 0) {
// Give up if cannot create a thread.
CFStringRef path = CFSTR("/");
CFArrayRef pathsToWatch = CFArrayCreate(NULL, (const void **)&path, 1, NULL);
CFAbsoluteTime latency = 0.3; // Latency in seconds
FSEventStreamRef stream = FSEventStreamCreate(
NULL,
&callback,
NULL,
pathsToWatch,
kFSEventStreamEventIdSinceNow,
latency,
kFSEventStreamCreateFlagNoDefer
);
if (stream == NULL) {
printf("GIVEUP\n");
return 2;
}
pthread_t threadId;
if (pthread_create(&threadId, NULL, EventProcessingThread, stream) != 0) {
printf("GIVEUP\n");
return 3;
}
while (TRUE) {
fscanf(stdin, "%s", command);
if (strcmp(command, "EXIT") == 0 || feof(stdin)) break;

View File

@@ -1,3 +1,3 @@
#!/bin/sh
# Clang can be downloaded from from http://llvm.org/releases/download.html or found in XCode 4+
# Clang can be downloaded from http://llvm.org/releases/download.html or found in XCode 4+
clang -arch i386 -mmacosx-version-min=10.5 -framework CoreServices -o fsnotifier fsnotifier.c