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

📄 acucntrl.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
		fprintf(stderr, "on write in %s: %s",			_PATH_UTMP, sys_errlist[errno]);}	/* poke process 1 and wait for it to do its thing */pokeinit(device, uname, enable)char *uname, *device; int enable;{	struct utmp utmp;	register int i;	post(device, uname);	/* poke init */	if (kill(1, SIGHUP)) {		fprintf(stderr,		    "Cannot send hangup to init process: %s\n",			sys_errlist[errno]);		(void)settys(resettty);		(void)setmodem(device, resetmodem);		exit(1);	}	if (enable)		return;	/* wait till init has responded, clearing the utmp entry */	i = 100;	do {		sleep(1);		if (lseek(etcutmp, utmploc, 0) < 0)			fprintf(stderr, "On lseek in %s: %s",				_PATH_UTMP, sys_errlist[errno]);		if (read(etcutmp, (char *)&utmp, sizeof utmp) < 0)			fprintf(stderr, "On read from %s: %s",				_PATH_UTMP, sys_errlist[errno]);	} while (utmp.ut_name[0] != '\0' && --i > 0);}#ifdef BSD4_3/* identify terminal line in ttys */opnttys(device)char *device;{	register int  ndevice; 	register char *p;	char *index();	char linebuf[BUFSIZ];	ttysfile = NULL;	do {		if (ttysfile != NULL) {			fclose(ttysfile);			sleep(5);		}		ttysfile = fopen(Etcttys, "r");		if(ttysfile == NULL) {			fprintf(stderr, "Cannot open %s: %s\n", Etcttys,				sys_errlist[errno]);			exit(1);		}	} while (flock(fileno(ttysfile), LOCK_NB|LOCK_EX) < 0);	nttysfile = fopen(NEtcttys, "w");	if(nttysfile == NULL) {		fprintf(stderr, "Cannot open %s: %s\n", Etcttys,			sys_errlist[errno]);		exit(1);	}	ndevice = strlen(device);#ifndef BRL4_2	utmploc = sizeof(utmp);#else BRL4_2	utmploc = 0;#endif BRL4_2	while(fgets(linebuf, sizeof(linebuf) - 1, ttysfile) != NULL) {		if(strncmp(device, linebuf, ndevice) == 0)			return;		ttyslnbeg += strlen(linebuf);		if (linebuf[0] != '#' && linebuf[0] != '\0')			utmploc += sizeof(utmp);		if (fputs(linebuf, nttysfile) == NULL) {			fprintf(stderr, "On %s write: %s\n",				Etcttys, sys_errlist[errno]);			exit(1);		}			}	fprintf(stderr, "%s not found in %s\n", device, Etcttys);	exit(1);}/* modify appropriate line in _PATH_TTYS to turn on/off the device */settys(enable)int enable;{	register char *cp, *cp2;	char lbuf[BUFSIZ];	int i;	char c1, c2;	(void) fseek(ttysfile, ttyslnbeg, 0);	if(fgets(lbuf, BUFSIZ, ttysfile) == NULL) {		fprintf(stderr, "On %s read: %s\n",			Etcttys, sys_errlist[errno]);		exit(1);	}	/* format is now */	/* ttyd0 std.100 dialup on secure # comment */	/* except, 2nd item may have embedded spaces inside quotes, Hubert */	cp = lbuf;	for (i=0;*cp && i<3;i++) {		if (*cp == '"') {			cp++;			while (*cp && *cp != '"')				cp++;			if (*cp != '\0')				cp++;		}else {			while (*cp && *cp != ' ' && *cp != '\t')				cp++;		}		while (*cp && (*cp == ' ' || *cp == '\t'))			cp++;	}	if (*cp == '\0') {		fprintf(stderr,"Badly formatted line in %s:\n%s",		    _PATH_TTYS, lbuf);		exit(1);	}	c1 = *--cp;	*cp++ = '\0';	cp2 = cp;	while (*cp && *cp != ' ' && *cp != '\t' && *cp != '\n')		cp++;	if (*cp == '\0') {		fprintf(stderr,"Badly formatted line in %s:\n%s",		    _PATH_TTYS, lbuf);		exit(1);	}	c2 = *cp;	*cp++ = '\0';	while (*cp && (*cp == ' ' || *cp == '\t'))		cp++;	resettty = strcmp("on", cp2) != 0;	fprintf(nttysfile,"%s%c%s%c%s", lbuf, c1, enable ? "on" : "off", c2, cp);	if (ferror(nttysfile)) {		fprintf(stderr, "On %s fprintf: %s\n",			NEtcttys, sys_errlist[errno]);		exit(1);	}	while(fgets(lbuf, sizeof(lbuf) - 1, ttysfile) != NULL) {		if (fputs(lbuf, nttysfile) == NULL) {			fprintf(stderr, "On %s write: %s\n",				NEtcttys, sys_errlist[errno]);			exit(1);		}	}			if (enable^resettty)		(void) unlink(NEtcttys);	else {		struct stat statb;		if (stat(Etcttys, &statb) == 0) {			fchmod(fileno(nttysfile) ,statb.st_mode);			fchown(fileno(nttysfile), statb.st_uid, statb.st_gid);		}		(void) rename(NEtcttys, Etcttys);	}	(void) fclose(nttysfile);	(void) fclose(ttysfile);	return enable^resettty;}#else !BSD4_3/* identify terminal line in ttys */opnttys(device)char *device;{	register FILE *ttysfile;	register int  ndevice, lnsiz; 	register char *p;	char *index();	char linebuf[BUFSIZ];	ttysfile = fopen(Etcttys, "r");	if(ttysfile == NULL) {		fprintf(stderr, "Cannot open %s: %s\n", Etcttys,			sys_errlist[errno]);		exit(1);	}	ndevice = strlen(device);	ttyslnbeg = 0;	utmploc = 0;	while(fgets(linebuf, sizeof(linebuf) - 1, ttysfile) != NULL) {		lnsiz = strlen(linebuf);		if ((p = index(linebuf, '\n')) != NULL)			*p = '\0';		if(strncmp(device, &linebuf[2], ndevice) == 0) {			(void)fclose(ttysfile);#ifdef sequent			/* Why is the sequent off by one? */			utmploc += sizeof(utmp);#endif sequent			return;		}		ttyslnbeg += lnsiz;		utmploc += sizeof(utmp);	}	fprintf(stderr, "%s not found in %s\n", device, Etcttys);	exit(1);}/* modify appropriate line in _PATH_TTYS to turn on/off the device */settys(enable)int enable;{	int ittysfil;	char out, in;	ittysfil = open(Etcttys, 2);	if(ittysfil < 0) {		fprintf(stderr, "Cannot open %s for output: %s\n",			Etcttys, sys_errlist[errno]);		exit(1);	}	(void)lseek(ittysfil, ttyslnbeg, 0);	if(read(ittysfil, &in, 1)<0) {		fprintf(stderr, "On %s write: %s\n",			Etcttys, sys_errlist[errno]);		exit(1);	}	resettty = (in == '1');	out = enable ? '1' : '0';	(void)lseek(ittysfil, ttyslnbeg, 0);	if(write(ittysfil, &out, 1)<0) {		fprintf(stderr, "On %s write: %s\n",			Etcttys, sys_errlist[errno]);		exit(1);	}	(void)close(ittysfil);	return(in==out);}#endif !BSD4_3#ifdef sequentsetmodem(ttyline, enable)char *ttyline; int enable;{	char *sysbuf[BUFSIZ];	sprintf(sysbuf,"/etc/ttyconfig /dev/%s -special %s", ttyline,		enable ? "-carrier" : "-nocarrier");	system(sysbuf);}#endif /* sequent */#ifdef vax/* * Excerpted from (June 8, 1983 W.Sebok) * > ttymodem.c - enable/disable modem control for tty lines. * > * > Knows about DZ11s and DH11/DM11s. * > 23.3.83 - TS * > modified to know about DMF's  (hasn't been tested) Nov 8, 1984 - WLS */setmodem(ttyline, enable)char *ttyline; int enable;{	dev_t dev;	int kmem;	int unit, line, nlines, addr, tflags;	int devtype=0;	char cflags; short sflags;#ifdef BSD4_2	int flags;#else	short flags;#endif	struct uba_device *ubinfo;	struct stat statb;	struct cdevsw cdevsw;	if(nl[CDEVSW].n_type == 0) {		fprintf(stderr, "No namelist.\n");		return(-1);	}	if((kmem = open(_PATH_KMEM, 2)) < 0) {		fprintf(stderr, "%s open: %s\n", _PATH_KMEM,		    sys_errlist[errno]);		return(-1);	}	if(stat(ttyline, &statb) < 0) {		fprintf(stderr, "%s stat: %s\n", ttyline, sys_errlist[errno]);		return(-1);	}	if((statb.st_mode&S_IFMT) != S_IFCHR) {		fprintf(stderr, "%s is not a character device.\n",ttyline);		return(-1);	}	dev = statb.st_rdev;	(void)lseek(kmem,		(off_t) &(((struct cdevsw *)NLVALUE(CDEVSW))[major(dev)]),0);	(void)read(kmem, (char *) &cdevsw, sizeof cdevsw);	if((int)(cdevsw.d_open) == NLVALUE(DZOPEN)) {		devtype = DZ11;		unit = minor(dev) / NDZLINE;		line = minor(dev) % NDZLINE;		addr = (int) &(((int *)NLVALUE(DZINFO))[unit]);		(void)lseek(kmem, (off_t) NLVALUE(NDZ11), 0);	} else if((int)(cdevsw.d_open) == NLVALUE(DHOPEN)) {		devtype = DH11;		unit = minor(dev) / NDHLINE;		line = minor(dev) % NDHLINE;		addr = (int) &(((int *)NLVALUE(DHINFO))[unit]);		(void)lseek(kmem, (off_t) NLVALUE(NDH11), 0);	} else if((int)(cdevsw.d_open) == NLVALUE(DMFOPEN)) {		devtype = DMF;		unit = minor(dev) / NDMFLINE;		line = minor(dev) % NDMFLINE;		addr = (int) &(((int *)NLVALUE(DMFINFO))[unit]);		(void)lseek(kmem, (off_t) NLVALUE(NDMF), 0);	} else {		fprintf(stderr, "Device %s (%d/%d) unknown.\n", ttyline,		    major(dev), minor(dev));		return(-1);	}	(void)read(kmem, (char *) &nlines, sizeof nlines);	if(minor(dev) >= nlines) {		fprintf(stderr, "Sub-device %d does not exist (only %d).\n",		    minor(dev), nlines);		return(-1);	}	(void)lseek(kmem, (off_t)addr, 0);	(void)read(kmem, (char *) &ubinfo, sizeof ubinfo);	(void)lseek(kmem, (off_t) &(ubinfo->ui_flags), 0);	(void)read(kmem, (char *) &flags, sizeof flags);	tflags = 1<<line;	resetmodem = ((flags&tflags) == 0);	flags = enable ? (flags & ~tflags) : (flags | tflags);	(void)lseek(kmem, (off_t) &(ubinfo->ui_flags), 0);	(void)write(kmem, (char *) &flags, sizeof flags);	switch(devtype) {		case DZ11:			if((addr = NLVALUE(DZSCAR)) == 0) {				fprintf(stderr, "No dzsoftCAR.\n");				return(-1);			}			cflags = flags;			(void)lseek(kmem, (off_t) &(((char *)addr)[unit]), 0);			(void)write(kmem, (char *) &cflags, sizeof cflags);			break;		case DH11:			if((addr = NLVALUE(DHSCAR)) == 0) {				fprintf(stderr, "No dhsoftCAR.\n");				return(-1);			}			sflags = flags;			(void)lseek(kmem, (off_t) &(((short *)addr)[unit]), 0);			(void)write(kmem, (char *) &sflags, sizeof sflags);			break;		case DMF:			if((addr = NLVALUE(DMFSCAR)) == 0) {				fprintf(stderr, "No dmfsoftCAR.\n");				return(-1);			}			cflags = flags;			(void)lseek(kmem, (off_t) &(((char *)addr)[unit]), 0);			(void)write(kmem, (char *) &cflags, sizeof cflags);			break;		default:			fprintf(stderr, "Unknown device type\n");			return(-1);	}	return(0);}#endif /* vax */prefix(s1, s2)	register char *s1, *s2;{	register char c;	while ((c = *s1++) == *s2++)		if (c == '\0')			return (1);	return (c == '\0');}#else	/* !DIALINOUT */main(){	fprintf(stderr,"acucntrl is not supported on this system\n");}#endif /* !DIALINOUT */

⌨️ 快捷键说明

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