mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
Use O_CLOEXEC when possible
This avoids having to do a fcntl(fd, F_SETFD, FD_CLOEXEC) to set the “close on exec” flag.
This commit is contained in:
@@ -209,13 +209,10 @@ namespace document
|
||||
void watch_server_t::observe (watch_info_t& info, size_t client_id)
|
||||
{
|
||||
info.path_watched = existing_parent(info.path);
|
||||
info.fd = open(info.path_watched.c_str(), O_EVTONLY, 0);
|
||||
if(info.fd == -1)
|
||||
info.fd = open(info.path_watched.c_str(), O_EVTONLY|O_CLOEXEC, 0);
|
||||
if(info.fd == -1) // TODO we need to actually handle this error @allan
|
||||
fprintf(stderr, "error observing path, open(\"%s\"): %s\n", info.path_watched.c_str(), strerror(errno));
|
||||
|
||||
// TODO we need to actually handle this error @allan
|
||||
fcntl(info.fd, F_SETFD, 1);
|
||||
|
||||
struct kevent changeList;
|
||||
struct timespec timeout = { };
|
||||
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
|
||||
private:
|
||||
static int open_file (std::string const& path, bool* exists)
|
||||
{
|
||||
int fd = open(path.c_str(), O_EVTONLY/*|O_CLOEXEC*/, 0);
|
||||
int fd = open(path.c_str(), O_EVTONLY|O_CLOEXEC, 0);
|
||||
return fd == -1 && errno == ENOENT ? (*exists = false), open_file(path::parent(path), exists) : fd;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user