示例#1
0
static void check_for_dhcp_inotify(struct inotify_event *in, time_t now)
{
  struct hostsfile *ah;

  /* ignore emacs backups and dotfiles */
  if (in->len == 0 || 
      in->name[in->len - 1] == '~' ||
      (in->name[0] == '#' && in->name[in->len - 1] == '#') ||
      in->name[0] == '.')
    return;

  for (ah = daemon->inotify_hosts; ah; ah = ah->next)
    if (ah->wd == in->wd)
      {
	size_t lendir = strlen(ah->fname);
	char *path;
	   
	if ((path = whine_malloc(lendir + in->len + 2)))
	  {
	    strcpy(path, ah->fname);
	    strcat(path, "/");
	    strcat(path, in->name);
	    
	    if (option_read_hostsfile(path))
	      {
		/* Propogate the consequences of loading a new dhcp-host */
		dhcp_update_configs(daemon->dhcp_conf);
		lease_update_from_configs(); 
		lease_update_file(now); 
		lease_update_dns(1);
	      }
	    
	    free(path);
	  }
	
	return;
      }
}
示例#2
0
文件: inotify.c 项目: Einheri/wl500g
int inotify_check(time_t now)
{
  int hit = 0;
  struct hostsfile *ah;

  while (1)
    {
      int rc;
      char *p;
      struct resolvc *res;
      struct inotify_event *in;

      while ((rc = read(daemon->inotifyfd, inotify_buffer, INOTIFY_SZ)) == -1 && errno == EINTR);
      
      if (rc <= 0)
	break;
      
      for (p = inotify_buffer; rc - (p - inotify_buffer) >= (int)sizeof(struct inotify_event); p += sizeof(struct inotify_event) + in->len) 
	{
	  in = (struct inotify_event*)p;
	  
	  for (res = daemon->resolv_files; res; res = res->next)
	    if (res->wd == in->wd && in->len != 0 && strcmp(res->file, in->name) == 0)
	      hit = 1;

	  /* ignore emacs backups and dotfiles */
	  if (in->len == 0 || 
	      in->name[in->len - 1] == '~' ||
	      (in->name[0] == '#' && in->name[in->len - 1] == '#') ||
	      in->name[0] == '.')
	    continue;
	  
	  for (ah = daemon->dynamic_dirs; ah; ah = ah->next)
	    if (ah->wd == in->wd)
	      {
		size_t lendir = strlen(ah->fname);
		char *path;
		
		if ((path = whine_malloc(lendir + in->len + 2)))
		  {
		    strcpy(path, ah->fname);
		    strcat(path, "/");
		    strcat(path, in->name);
		     
		    my_syslog(LOG_INFO, _("inotify, new or changed file %s"), path);

		    if (ah->flags & AH_HOSTS)
		      {
			read_hostsfile(path, ah->index, 0, NULL, 0);
#ifdef HAVE_DHCP
			if (daemon->dhcp || daemon->doing_dhcp6) 
			  {
			    /* Propogate the consequences of loading a new dhcp-host */
			    dhcp_update_configs(daemon->dhcp_conf);
			    lease_update_from_configs(); 
			    lease_update_file(now); 
			    lease_update_dns(1);
			  }
#endif
		      }
#ifdef HAVE_DHCP
		    else if (ah->flags & AH_DHCP_HST)
		      {
			if (option_read_dynfile(path, AH_DHCP_HST))
			  {
			    /* Propogate the consequences of loading a new dhcp-host */
			    dhcp_update_configs(daemon->dhcp_conf);
			    lease_update_from_configs(); 
			    lease_update_file(now); 
			    lease_update_dns(1);
			  }
		      }
		    else if (ah->flags & AH_DHCP_OPT)
		      option_read_dynfile(path, AH_DHCP_OPT);
#endif
		    
		    free(path);
		  }
	      }
	}
    }
  return hit;
}