1 /* Copyright 2012-present Facebook, Inc. 2 * Licensed under the Apache License, Version 2.0 */ 3 4 #ifndef WATCHMAN_H 5 #define WATCHMAN_H 6 7 #include "watchman_system.h" 8 9 #include "thirdparty/jansson/jansson.h" 10 #include "watchman_hash.h" 11 #include "watchman_ignore.h" 12 #include "watchman_stream.h" 13 #include "watchman_string.h" 14 15 struct watchman_file; 16 struct watchman_dir; 17 struct watchman_root; 18 struct watchman_pending_fs; 19 struct watchman_trigger_command; 20 typedef struct watchman_root w_root_t; 21 22 #include "watchman_clockspec.h" 23 #include "watchman_pending.h" 24 #include "watchman_dir.h" 25 #include "watchman_watcher.h" 26 #include "watchman_opendir.h" 27 #include "watchman_file.h" 28 29 #define WATCHMAN_IO_BUF_SIZE 1048576 30 #define WATCHMAN_BATCH_LIMIT (16*1024) 31 32 #include "watchman_root.h" 33 #include "watchman_pdu.h" 34 #include "watchman_perf.h" 35 #include "watchman_query.h" 36 #include "watchman_client.h" 37 38 #include "watchman_cmd.h" 39 #include "watchman_config.h" 40 #include "watchman_trigger.h" 41 42 // Returns the name of the filesystem for the specified path 43 w_string w_fstype(const char *path); 44 45 extern char *poisoned_reason; 46 47 #ifndef _WIN32 w_path_exists(const char * path)48static inline bool w_path_exists(const char *path) { 49 return access(path, F_OK) == 0; 50 } 51 #else 52 bool w_path_exists(const char *path); 53 #endif 54 55 /* We leverage the fact that our aligned pointers will never set the LSB of a 56 * pointer value. We can use the LSB to indicate whether kqueue entries are 57 * dirs or files */ 58 #define SET_DIR_BIT(dir) ((void*)(((intptr_t)dir) | 0x1)) 59 #define IS_DIR_BIT_SET(dir) ((((intptr_t)dir) & 0x1) == 0x1) 60 #define DECODE_DIR(dir) ((void*)(((intptr_t)dir) & ~0x1)) 61 62 bool w_is_stopping(void); 63 64 void w_request_shutdown(void); 65 66 #include "watchman_time.h" 67 68 extern const char *watchman_tmp_dir; 69 extern char *watchman_state_file; 70 extern int dont_save_state; 71 void w_state_shutdown(void); 72 void w_state_save(void); 73 bool w_state_load(void); 74 bool w_root_save_state(json_ref& state); 75 bool w_root_load_state(const json_ref& state); 76 json_ref w_root_watch_list_to_json(void); 77 78 #include "FileDescriptor.h" 79 80 #ifdef __APPLE__ 81 watchman::FileDescriptor w_get_listener_socket_from_launchd(); 82 #endif 83 void w_listener_prep_inetd(); 84 bool w_start_listener(const char *socket_path); 85 void w_check_my_sock(void); 86 87 #include "watchman_getopt.h" 88 89 #ifdef HAVE_SYS_SIGLIST 90 # define w_strsignal(val) sys_siglist[(val)] 91 #else 92 # define w_strsignal(val) strsignal((val)) 93 #endif 94 95 const char *get_sock_name(void); 96 97 #ifndef _WIN32 98 /** 99 * Gets the group struct for the given group name. The return value may point 100 * to a static area so it should be used immediately and not passed to free(3). 101 * 102 * Returns null on failure. 103 */ 104 const struct group *w_get_group(const char *group_name); 105 #endif // ndef WIN32 106 107 void w_ioprio_set_low(void); 108 void w_ioprio_set_normal(void); 109 110 struct flag_map { 111 uint32_t value; 112 const char *label; 113 }; 114 void w_expand_flags(const struct flag_map *fmap, uint32_t flags, 115 char *buf, size_t len); 116 117 #endif 118 119 /* vim:ts=2:sw=2:et: 120 */ 121