diff options
author | Jean-Baptiste Queru <jbq@google.com> | 2013-04-01 14:41:51 -0700 |
---|---|---|
committer | Jean-Baptiste Queru <jbq@google.com> | 2013-04-01 14:41:51 -0700 |
commit | 2bd2b7c2623d4266384e890271869efc044aabff (patch) | |
tree | 0b31f50e55975b6354ed458314e17b4441bb4e17 /native | |
parent | 1d526b16d476792ca7ce47616d55833115e8d6ab (diff) | |
download | idea-2bd2b7c2623d4266384e890271869efc044aabff.tar.gz |
Snapshot ee98b298267d0e09d2cd2f0731b6480a56dd48e7 from master branch of git://git.jetbrains.org/idea/community.git
Change-Id: I4515f72af131fdea9fc6905a4dc0fe9532409a81
Diffstat (limited to 'native')
-rw-r--r-- | native/WinLauncher/WinLauncher/WinLauncher.cpp | 9 | ||||
-rw-r--r-- | native/WinLauncher/WinLauncher/WinLauncher.vcxproj | 8 | ||||
-rw-r--r-- | native/fsNotifier/linux/fsnotifier.h | 6 | ||||
-rw-r--r-- | native/fsNotifier/linux/inotify.c | 9 | ||||
-rw-r--r-- | native/fsNotifier/linux/main.c | 88 | ||||
-rw-r--r-- | native/fsNotifier/linux/util.c | 9 |
6 files changed, 89 insertions, 40 deletions
diff --git a/native/WinLauncher/WinLauncher/WinLauncher.cpp b/native/WinLauncher/WinLauncher/WinLauncher.cpp index 8c1fa3f0a858..0d4cf2154176 100644 --- a/native/WinLauncher/WinLauncher/WinLauncher.cpp +++ b/native/WinLauncher/WinLauncher/WinLauncher.cpp @@ -124,8 +124,8 @@ bool FindJVMInEnvVar(const char* envVarName, bool& result) else { char buf[_MAX_PATH]; - sprintf_s(buf, "The environment variable %s (with the value of %s) does not point to a valid JVM installation", - envVarValue, jvmPath); + sprintf_s(buf, "The environment variable %s (with the value of %s) does not point to a valid JVM installation.", + envVarName, envVarValue); MessageBoxA(NULL, buf, "Error Launching IntelliJ Platform", MB_OK); result = false; } @@ -553,7 +553,6 @@ bool CheckSingleInstance() { hFileMapping = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, FILE_MAPPING_SIZE, mappingName.c_str()); - hSingleInstanceWatcherThread = CreateThread(NULL, 0, SingleInstanceThread, NULL, 0, NULL); return true; } else @@ -704,6 +703,9 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, if (!LoadVMOptions()) return 1; if (!LoadJVMLibrary()) return 1; if (!CreateJVM()) return 1; + + hSingleInstanceWatcherThread = CreateThread(NULL, 0, SingleInstanceThread, NULL, 0, NULL); + if (!RunMainClass()) return 1; jvm->DestroyJavaVM(); @@ -716,3 +718,4 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, return 0; } +
\ No newline at end of file diff --git a/native/WinLauncher/WinLauncher/WinLauncher.vcxproj b/native/WinLauncher/WinLauncher/WinLauncher.vcxproj index 6656ec535a2a..598b5bf49298 100644 --- a/native/WinLauncher/WinLauncher/WinLauncher.vcxproj +++ b/native/WinLauncher/WinLauncher/WinLauncher.vcxproj @@ -64,19 +64,19 @@ <PropertyGroup Label="UserMacros" /> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <LinkIncremental>true</LinkIncremental> - <IncludePath>C:\Java\jdk1.6.0_41\include;C:\Java\jdk1.6.0_41\include\win32;$(IncludePath)</IncludePath> + <IncludePath>C:\Java\jdk1.6.0_43\include;C:\Java\jdk1.6.0_43\include\win32;$(IncludePath)</IncludePath> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <LinkIncremental>true</LinkIncremental> - <IncludePath>C:\Java\jdk1.6.0_37\include;C:\Java\jdk1.6.0_37\include\win32;$(IncludePath)</IncludePath> + <IncludePath>C:\Java\jdk1.6.0_43\include;C:\Java\jdk1.6.0_43\include\win32;$(IncludePath)</IncludePath> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <LinkIncremental>false</LinkIncremental> - <IncludePath>C:\Java\jdk1.6.0_41\include;C:\Java\jdk1.6.0_41\include\win32;$(IncludePath)</IncludePath> + <IncludePath>C:\Java\jdk1.6.0_43\include;C:\Java\jdk1.6.0_43\include\win32;$(IncludePath)</IncludePath> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <LinkIncremental>false</LinkIncremental> - <IncludePath>C:\Java\jdk1.6.0_37\include;C:\Java\jdk1.6.0_37\include\win32;$(IncludePath)</IncludePath> + <IncludePath>C:\Java\jdk1.6.0_43\include;C:\Java\jdk1.6.0_43\include\win32;$(IncludePath)</IncludePath> </PropertyGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ClCompile> diff --git a/native/fsNotifier/linux/fsnotifier.h b/native/fsNotifier/linux/fsnotifier.h index 0140d6be8102..0bcfaa5f9644 100644 --- a/native/fsNotifier/linux/fsnotifier.h +++ b/native/fsNotifier/linux/fsnotifier.h @@ -32,7 +32,7 @@ void message(MSG id); // logging void userlog(int priority, const char* format, ...); -#define CHECK_NULL(p, r) if (p == NULL) { userlog(LOG_ERR, "out of memory"); return r; } +#define CHECK_NULL(p, r) if (p == NULL) { userlog(LOG_ERR, "out of memory"); return r; } // variable-length array @@ -46,6 +46,7 @@ void array_put(array* a, int index, void* element); void* array_get(array* a, int index); void array_delete(array* a); void array_delete_vs_data(array* a); +void array_delete_data(array* a); // poor man's hash table @@ -61,7 +62,8 @@ void table_delete(table* t); enum { ERR_IGNORE = -1, ERR_CONTINUE = -2, - ERR_ABORT = -3 + ERR_ABORT = -3, + ERR_MISSING = -4 }; bool init_inotify(); diff --git a/native/fsNotifier/linux/inotify.c b/native/fsNotifier/linux/inotify.c index 8570d032e782..cf2b33bd6384 100644 --- a/native/fsNotifier/linux/inotify.c +++ b/native/fsNotifier/linux/inotify.c @@ -113,7 +113,7 @@ inline int get_inotify_fd() { } -#define EVENT_MASK IN_MODIFY | IN_ATTRIB | IN_CREATE | IN_DELETE | IN_MOVE | IN_DELETE_SELF +#define EVENT_MASK IN_MODIFY | IN_ATTRIB | IN_CREATE | IN_DELETE | IN_MOVE | IN_DELETE_SELF | IN_MOVE_SELF static int add_watch(const char* path, watch_node* parent) { int wd = inotify_add_watch(inotify_fd, path, EVENT_MASK); @@ -301,7 +301,7 @@ int watch(const char* root, array* mounts) { return ERR_IGNORE; } else if (errno == ENOENT) { - return ERR_CONTINUE; + return ERR_MISSING; } userlog(LOG_ERR, "stat(%s): %s", root, strerror(errno)); return ERR_ABORT; @@ -342,14 +342,14 @@ static bool process_inotify_event(struct inotify_event* event) { strcat(path, event->name); } - if (is_dir && ((event->mask & IN_CREATE) == IN_CREATE || (event->mask & IN_MOVED_TO) == IN_MOVED_TO)) { + if (is_dir && event->mask & (IN_CREATE | IN_MOVED_TO)) { int result = walk_tree(path, node, true, NULL); if (result < 0 && result != ERR_IGNORE && result != ERR_CONTINUE) { return false; } } - if (is_dir && ((event->mask & IN_DELETE) == IN_DELETE || (event->mask & IN_MOVED_FROM) == IN_MOVED_FROM)) { + if (is_dir && event->mask & (IN_DELETE | IN_MOVED_FROM)) { for (int i=0; i<array_size(node->kids); i++) { watch_node* kid = array_get(node->kids, i); if (kid != NULL && strcmp(kid->name, path) == 0) { @@ -363,6 +363,7 @@ static bool process_inotify_event(struct inotify_event* event) { if (callback != NULL) { (*callback)(path, event->mask); } + return true; } diff --git a/native/fsNotifier/linux/main.c b/native/fsNotifier/linux/main.c index 27372e35acc1..91fa1ae8396c 100644 --- a/native/fsNotifier/linux/main.c +++ b/native/fsNotifier/linux/main.c @@ -25,6 +25,7 @@ #include <string.h> #include <sys/inotify.h> #include <sys/select.h> +#include <sys/stat.h> #include <syslog.h> #include <unistd.h> @@ -56,9 +57,13 @@ "The current <b>inotify</b>(7) watch limit is too low. " \ "<a href=\"http://confluence.jetbrains.net/display/IDEADEV/Inotify+Watches+Limit\">More details.</a>\n" +#define MISSING_ROOT_TIMEOUT 1 + +#define UNFLATTEN(root) (root[0] == '|' ? root + 1 : root) + typedef struct { - char* name; - int id; + char* path; + int id; // negative value means missing root } watch_root; static array* roots = NULL; @@ -76,6 +81,8 @@ static array* unwatchable_mounts(); static void inotify_callback(char* path, int event); static void report_event(char* event, char* path); static void output(const char* format, ...); +static void check_missing_roots(); +static void check_root_removal(char*); int main(int argc, char** argv) { @@ -208,13 +215,16 @@ static void main_loop() { int input_fd = fileno(stdin), inotify_fd = get_inotify_fd(); int nfds = (inotify_fd > input_fd ? inotify_fd : input_fd) + 1; fd_set rfds; + struct timeval timeout; bool go_on = true; while (go_on) { FD_ZERO(&rfds); FD_SET(input_fd, &rfds); FD_SET(inotify_fd, &rfds); - if (select(nfds, &rfds, NULL, NULL, NULL) < 0) { + timeout = (struct timeval){MISSING_ROOT_TIMEOUT, 0}; + + if (select(nfds, &rfds, NULL, NULL, &timeout) < 0) { userlog(LOG_ERR, "select: %s", strerror(errno)); go_on = false; } @@ -224,6 +234,9 @@ static void main_loop() { else if (FD_ISSET(inotify_fd, &rfds)) { go_on = process_inotify_input(); } + else { + check_missing_roots(); + } } } @@ -311,9 +324,9 @@ static bool update_roots(array* new_roots) { static void unregister_roots() { watch_root* root; while ((root = array_pop(roots)) != NULL) { - userlog(LOG_INFO, "unregistering root: %s", root->name); + userlog(LOG_INFO, "unregistering root: %s", root->path); unwatch(root->id); - free(root->name); + free(root->path); free(root); }; } @@ -322,12 +335,11 @@ static void unregister_roots() { static bool register_roots(array* new_roots, array* unwatchable, array* mounts) { for (int i=0; i<array_size(new_roots); i++) { char* new_root = array_get(new_roots, i); - char* unflattened = new_root; - if (unflattened[0] == '|') ++unflattened; + char* unflattened = UNFLATTEN(new_root); userlog(LOG_INFO, "registering root: %s", new_root); if (unflattened[0] != '/') { - userlog(LOG_WARNING, " ... not valid, skipped"); + userlog(LOG_WARNING, "invalid root: %s", new_root); continue; } @@ -357,12 +369,12 @@ static bool register_roots(array* new_roots, array* unwatchable, array* mounts) int id = watch(new_root, inner_mounts); array_delete(inner_mounts); - if (id >= 0) { + if (id >= 0 || id == ERR_MISSING) { watch_root* root = malloc(sizeof(watch_root)); CHECK_NULL(root, false); root->id = id; - root->name = strdup(new_root); - CHECK_NULL(root->name, false); + root->path = strdup(new_root); + CHECK_NULL(root->path, false); CHECK_NULL(array_push(roots, root), false); } else if (id == ERR_ABORT) { @@ -380,7 +392,8 @@ static bool register_roots(array* new_roots, array* unwatchable, array* mounts) static bool is_watchable(const char* fs) { // don't watch special and network filesystems return !(strncmp(fs, "dev", 3) == 0 || strcmp(fs, "proc") == 0 || strcmp(fs, "sysfs") == 0 || strcmp(fs, MNTTYPE_SWAP) == 0 || - strncmp(fs, "fuse", 4) == 0 || strcmp(fs, "cifs") == 0 || strcmp(fs, MNTTYPE_NFS) == 0); + (strncmp(fs, "fuse", 4) == 0 && strcmp(fs, "fuseblk") != 0) || + strcmp(fs, "cifs") == 0 || strcmp(fs, MNTTYPE_NFS) == 0); } static array* unwatchable_mounts() { @@ -407,31 +420,25 @@ static array* unwatchable_mounts() { static void inotify_callback(char* path, int event) { - if (event & IN_CREATE || event & IN_MOVED_TO) { + if (event & (IN_CREATE | IN_MOVED_TO)) { report_event("CREATE", path); report_event("CHANGE", path); - return; } - - if (event & IN_MODIFY) { + else if (event & IN_MODIFY) { report_event("CHANGE", path); - return; } - - if (event & IN_ATTRIB) { + else if (event & IN_ATTRIB) { report_event("STATS", path); - return; } - - if (event & IN_DELETE || event & IN_MOVED_FROM) { + else if (event & (IN_DELETE | IN_MOVED_FROM)) { report_event("DELETE", path); - return; } - - if (event & IN_UNMOUNT) { + if (event & (IN_DELETE_SELF | IN_MOVE_SELF)) { + check_root_removal(path); + } + else if (event & IN_UNMOUNT) { output("RESET\n"); userlog(LOG_DEBUG, "RESET"); - return; } } @@ -466,3 +473,32 @@ static void output(const char* format, ...) { fflush(stdout); } + + +static void check_missing_roots() { + struct stat st; + for (int i=0; i<array_size(roots); i++) { + watch_root* root = array_get(roots, i); + if (root->id < 0) { + char* unflattened = UNFLATTEN(root->path); + if (stat(unflattened, &st) == 0) { + root->id = watch(root->path, NULL); + userlog(LOG_INFO, "root restored: %s\n", root->path); + report_event("CREATE", unflattened); + report_event("CHANGE", unflattened); + } + } + } +} + +static void check_root_removal(char* path) { + for (int i=0; i<array_size(roots); i++) { + watch_root* root = array_get(roots, i); + if (root->id >= 0 && strcmp(path, UNFLATTEN(root->path)) == 0) { + unwatch(root->id); + root->id = -1; + userlog(LOG_INFO, "root deleted: %s\n", root->path); + report_event("DELETE", path); + } + } +} diff --git a/native/fsNotifier/linux/util.c b/native/fsNotifier/linux/util.c index 179b3105a422..854a48c7da6f 100644 --- a/native/fsNotifier/linux/util.c +++ b/native/fsNotifier/linux/util.c @@ -108,12 +108,19 @@ void array_delete(array* a) { void array_delete_vs_data(array* a) { if (a != NULL) { + array_delete_data(a); + array_delete(a); + } +} + +void array_delete_data(array* a) { + if (a != NULL) { for (int i=0; i<a->size; i++) { if (a->data[i] != NULL) { free(a->data[i]); } } - array_delete(a); + a->size = 0; } } |