TextMate is a graphical text editor for OS X 10.7+
修订版 | 0808712630c891592e8b5789f51b4cc992731342 (tree) |
---|---|
时间 | 2012-08-24 03:25:17 |
作者 | Allan Odgaard <git@abet...> |
Commiter | Allan Odgaard |
Use |O_CLOEXEC when possible
This avoids having to do a fcntl(fd, F_SETFD, FD_CLOEXEC) to set the “close on exec” flag.
@@ -209,13 +209,10 @@ namespace document | ||
209 | 209 | void watch_server_t::observe (watch_info_t& info, size_t client_id) |
210 | 210 | { |
211 | 211 | info.path_watched = existing_parent(info.path); |
212 | - info.fd = open(info.path_watched.c_str(), O_EVTONLY, 0); | |
213 | - if(info.fd == -1) | |
212 | + info.fd = open(info.path_watched.c_str(), O_EVTONLY|O_CLOEXEC, 0); | |
213 | + if(info.fd == -1) // TODO we need to actually handle this error @allan | |
214 | 214 | fprintf(stderr, "error observing path, open(\"%s\"): %s\n", info.path_watched.c_str(), strerror(errno)); |
215 | 215 | |
216 | - // TODO we need to actually handle this error @allan | |
217 | - fcntl(info.fd, F_SETFD, 1); | |
218 | - | |
219 | 216 | struct kevent changeList; |
220 | 217 | struct timespec timeout = { }; |
221 | 218 | EV_SET(&changeList, info.fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, NOTE_DELETE | NOTE_WRITE | NOTE_RENAME | NOTE_ATTRIB, 0, (void*)client_id); |
@@ -161,7 +161,7 @@ struct track_paths_t | ||
161 | 161 | private: |
162 | 162 | static int open_file (std::string const& path, bool* exists) |
163 | 163 | { |
164 | - int fd = open(path.c_str(), O_EVTONLY/*|O_CLOEXEC*/, 0); | |
164 | + int fd = open(path.c_str(), O_EVTONLY|O_CLOEXEC, 0); | |
165 | 165 | return fd == -1 && errno == ENOENT ? (*exists = false), open_file(path::parent(path), exists) : fd; |
166 | 166 | } |
167 | 167 |