示例#1
0
Status dir_watch_Add(const OsPath& path, PDirWatch& dirWatch)
{
	char resolved[PATH_MAX + 1];

	// init already failed; don't try again or complain	
	if(initialized == -1)
		return ERR::FAIL;	// NOWARN

	if(!initialized)
	{
		errno = 0;
		if((inotifyfd = inotify_init()) < 0) 
		{
			// Check for error ?
			int err = errno;
			initialized = -1;
			LOGERROR("Error initializing inotify file descriptor; hotloading will be disabled, errno=%d", err);
			errno = err;
			return StatusFromErrno();	// NOWARN
		}

		errno = 0;
		int ret = pthread_create(&g_event_loop_thread, NULL, &inotify_event_loop, NULL);
		if (ret != 0)
		{
			initialized = -1;
			LOGERROR("Error creating inotify event loop thread; hotloading will be disabled, err=%d", ret);
			errno = ret;
			return StatusFromErrno();	// NOWARN
		}

		initialized = 1;
		atexit(inotify_deinit);
	}

	PDirWatch tmpDirWatch(new DirWatch);
	errno = 0;
	int wd = inotify_add_watch(inotifyfd, realpath(OsString(path).c_str(), resolved), IN_CREATE | IN_DELETE | IN_CLOSE_WRITE);
	if (wd < 0)
		WARN_RETURN(StatusFromErrno());

	dirWatch.swap(tmpDirWatch);
	dirWatch->path = path;
	dirWatch->reqnum = wd;
	g_paths.insert(std::make_pair(wd, dirWatch));

	return INFO::OK;
}
示例#2
0
Status dir_watch_Add(const OsPath& path, PDirWatch& dirWatch)
{
  PDirWatch tmpDirWatch(new DirWatch);
  dirWatch.swap(tmpDirWatch);
  dirWatch->path = path;
  dirWatch->reqnum = 0;
  g_Paths.push_back( *dirWatch );

  bool  alreadyInsideRootPath = false;
  for ( DirWatchMap::iterator it = g_RootPaths.begin() ; it != g_RootPaths.end(); ++it)
  {
    if ( path_is_subpath( path.string().c_str(), it->path.string().c_str() ) )
      alreadyInsideRootPath = true;
  }

  if ( !alreadyInsideRootPath )
  {
    DeleteEventStream();
    g_RootPaths.push_back( *dirWatch );
  }

	return INFO::OK;
}