⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ns_maint.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
	if (zp->z_type == Z_STUB)		argv[argc++] = "-S";#endif#ifdef DEBUG	if (debug) {		argv[argc++] = "-d";		sprintf(debug_str, "%d", debug);		argv[argc++] = debug_str;		argv[argc++] = "-l";		argv[argc++] = _PATH_XFERDDT;		if (debug > 5) {			argv[argc++] = "-t";			argv[argc++] = _PATH_XFERTRACE;		}	}#endif		if (zp->z_xaddr.s_addr != 0x00000000) {		/* address was specified by the qserial logic, use it */		argv[argc++] = strcpy(argv_ns[argc_ns++],				      inet_ntoa(zp->z_xaddr));	} else {		/*		 * Copy the server ip addresses into argv, after converting		 * to ascii and saving the static inet_ntoa result		 */		for (cnt = 0;  cnt < zp->z_addrcnt;  cnt++) {			struct in_addr a;			a = zp->z_addr[cnt];			if (aIsUs(a)			    && !haveComplained(zp->z_origin,					       (char*)startxfer)) {				syslog(LOG_ERR,				  "attempted to fetch zone %s from self (%s)",				       zp->z_origin, inet_ntoa(a));				continue;			}			argv[argc++] = strcpy(argv_ns[argc_ns++],					      inet_ntoa(a));		}        }	argv[argc] = 0;#ifdef DEBUG#ifdef ECHOARGS	if (debug) {		int i;		for (i = 0; i < argc; i++) 			fprintf(ddt, "Arg %d=%s\n", i, argv[i]);        }#endif /* ECHOARGS */#endif /* DEBUG */#ifdef SYSV#define vfork fork#else	gettime(&tt);	omask = sigblock(sigmask(SIGCHLD));#endif	if ((pid = vfork()) == -1) {		dprintf(1, (ddt, "xfer [v]fork: %d\n", errno));		syslog(LOG_ERR, "xfer [v]fork: %m");#ifndef SYSV		(void) sigsetmask(omask);#endif		zp->z_time = tt.tv_sec + 10;		return;	}	if (pid == 0) {		/* child */		execv(_PATH_XFER, argv);		syslog(LOG_ERR, "can't exec %s: %m", _PATH_XFER);		_exit(XFER_FAIL);	/* avoid duplicate buffer flushes */	}	/* parent */	dprintf(1, (ddt, "started xfer child %d\n", pid));	zp->z_state &= ~Z_NEED_XFER;	zp->z_state |= Z_XFER_RUNNING;	zp->z_xferpid = pid;	xfers_running++;	zp->z_time = tt.tv_sec + MAX_XFER_TIME;#ifndef SYSV	(void) sigsetmask(omask);#endif}#ifdef DEBUGvoidprintzoneinfo(zonenum)int zonenum;{	struct timeval  tt;	struct zoneinfo *zp = &zones[zonenum];	char *ZoneType;	if (!debug)		return;	fprintf(ddt, "printzoneinfo(%d):\n", zonenum);	gettime(&tt);	switch (zp->z_type) {		case Z_PRIMARY: ZoneType = "Primary"; break;		case Z_SECONDARY: ZoneType = "Secondary"; break;#ifdef STUBS		case Z_STUB: ZoneType = "Stub"; break;#endif		case Z_CACHE: ZoneType = "Cache"; break;		default: ZoneType = "Unknown";	}	if (zp->z_origin != NULL && (zp->z_origin[0] == '\0'))		fprintf(ddt,"origin ='.'");	else		fprintf(ddt,"origin ='%s'", zp->z_origin);#ifdef GEN_AXFR	fprintf(ddt,", class = %d", zp->z_class);#endif 	fprintf(ddt,", type = %s", ZoneType);	if (zp->z_source)		fprintf(ddt,", source = %s\n", zp->z_source);	fprintf(ddt,"z_refresh = %ld", zp->z_refresh);	fprintf(ddt,", retry = %ld", zp->z_retry);	fprintf(ddt,", expire = %ld", zp->z_expire);	fprintf(ddt,", minimum = %ld", zp->z_minimum);	fprintf(ddt,", serial = %lu\n", zp->z_serial);	fprintf(ddt,"z_time = %d", zp->z_time);	if (zp->z_time) {		fprintf(ddt,", now time : %d sec", tt.tv_sec);		fprintf(ddt,", time left: %d sec", zp->z_time - tt.tv_sec);	}	fprintf(ddt,"; state %x\n", zp->z_state);}#endif /* DEBUG *//* * remove_zone (htp, zone) -- *     Delete all RR's in the zone "zone" under specified hash table. */voidremove_zone(htp, zone)	register struct hashbuf *htp;	register int zone;{	register struct databuf *dp, *pdp;	register struct namebuf *np, *pnp, *npn;	struct namebuf **npp, **nppend;	nppend = htp->h_tab + htp->h_size;	for (npp = htp->h_tab; npp < nppend; npp++)	    for (pnp = NULL, np = *npp; np != NULL; np = npn) {		for (pdp = NULL, dp = np->n_data; dp != NULL; ) {			if (dp->d_zone == zone)				dp = rm_datum(dp, np, pdp);			else {				pdp = dp;				dp = dp->d_next;			}		}		if (np->n_hash) {			/* call recursively to remove subdomains. */			remove_zone(np->n_hash, zone);			/* if now empty, free it */			if (np->n_hash->h_cnt == 0) {				free((char*)np->n_hash);				np->n_hash = NULL;			}		}		if ((np->n_hash == NULL) && (np->n_data == NULL)) {			npn = rm_name(np, npp, pnp);			htp->h_cnt--;		} else {			npn = np->n_next;			pnp = np;		}	    }}   /* * Abort an xfer that has taken too long. */static voidabortxfer(zp)	register struct zoneinfo *zp;{	kill(zp->z_xferpid, SIGKILL); /* don't trust it at all */	dprintf(1, (ddt, "Killed child %d (zone %s) due to timeout\n",		    zp->z_xferpid, zp->z_origin));	zp->z_time = tt.tv_sec + zp->z_retry;}/* * SIGCHLD signal handler: process exit of xfer's. * (Note: also called when outgoing transfer completes.) */SIG_FNendxfer(){    	register struct zoneinfo *zp;   	int exitstatus, pid, xfers = 0;	int status;	gettime(&tt);#if defined(USE_WAITPID)	while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {#else /* USE_WAITPID */	{		pid = wait(&status);#endif /* USE_WAITPID */		exitstatus = WIFEXITED(status) ?WEXITSTATUS(status) :0;		for (zp = zones; zp < &zones[nzones]; zp++)		    if (zp->z_xferpid == pid) {			xfers++;			xfers_running--;			zp->z_xferpid = 0;			zp->z_state &= ~Z_XFER_RUNNING;			dprintf(1, (ddt,		"\nendxfer: child %d zone %s returned status=%d termsig=%d\n", 				    pid, zp->z_origin, exitstatus,				    WIFSIGNALED(status) ?WTERMSIG(status) :-1				    )				);			if (WIFSIGNALED(status)) {				if (WTERMSIG(status) != SIGKILL) {					syslog(LOG_ERR,					  "named-xfer exited with signal %d\n",					  WTERMSIG(status));					dprintf(1, (ddt,					"\tchild termination with signal %d\n",						    WTERMSIG(status)));				}				zp->z_time = tt.tv_sec + zp->z_retry;			} else switch (exitstatus) {				case XFER_UPTODATE:					markUpToDate(zp);					break;				case XFER_SUCCESS:					zp->z_state |= Z_NEED_RELOAD;					zp->z_state &= ~Z_SYSLOGGED;					needzoneload++;					break;				case XFER_TIMEOUT:					dprintf(1, (ddt,		    "zoneref: Masters for secondary zone %s unreachable\n",						    zp->z_origin));					if ((zp->z_state & Z_SYSLOGGED) == 0) {						zp->z_state |= Z_SYSLOGGED;						syslog(LOG_WARNING,		    "zoneref: Masters for secondary zone %s unreachable",						    zp->z_origin);					}					zp->z_time = tt.tv_sec + zp->z_retry;					break;				default:					if ((zp->z_state & Z_SYSLOGGED) == 0) {						zp->z_state |= Z_SYSLOGGED;						syslog(LOG_ERR,						 "named-xfer for %s exited %d",						    zp->z_origin, exitstatus);					}					/* FALLTHROUGH */				case XFER_FAIL:					zp->z_state |= Z_SYSLOGGED;					zp->z_time = tt.tv_sec + zp->z_retry;					break;			}			break;		}	}	tryxfer();#if defined(SYSV)	(void)signal(SIGCLD, endxfer);#endif}/* * Try to start some xfers */static voidtryxfer(){	struct zoneinfo *zp;	for (zp = zones;	     xfers_deferred != 0		&& xfers_running < MAX_XFERS_RUNNING		&& zp < &zones[nzones];	     zp++) {		if (zp->z_state & Z_NEED_XFER) {			xfers_deferred--;			startxfer(zp);		}	}	sched_maint();}/* * Reload zones whose transfers have completed. */voidloadxfer(){    	register struct zoneinfo *zp;   	gettime(&tt);	for (zp = zones; zp < &zones[nzones]; zp++) {		if (zp->z_state & Z_NEED_RELOAD) {			dprintf(1, (ddt, "loadxfer() '%s'\n",				    zp->z_origin[0] ? zp->z_origin : "."));			zp->z_state &= ~(Z_NEED_RELOAD|Z_AUTH);			remove_zone(hashtab, zp - zones);			if (db_load(zp->z_source, zp->z_origin, zp, 0) == 0)				zp->z_state |= Z_AUTH;			if (zp->z_state & Z_TMP_FILE)				(void) unlink(zp->z_source);		}	}	sched_maint();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -