예제 #1
0
/*
 *	Main program.
 *	Write a wtmp entry and reboot cq. halt.
 */
int main(int argc, char **argv)
{
	int do_sync = 1;
	int do_hard = 0;
	int do_ifdown = 0;
	int c;

	/*
	 *	Get flags
	 */
	while((c = getopt(argc, argv, ":ifn:")) != EOF) {
		switch(c) {
			case 'n':
				do_sync = 0;
				break;
			case 'f':
				do_hard = 1;
				break;
			case 'i':
				do_ifdown = 1;
				break;
			default:
				usage();
		}
	 }
	if (argc == optind) usage();

	if (geteuid() != 0) {
		fprintf(stderr, "%s: must be superuser.\n", progname);
		exit(1);
	}

	(void)chdir("/");

	if (!do_hard ) {
		/*
		 *	See if we are in runlevel 0 or 6.
		 */
		c = get_runlevel();
		if (c != '0' && c != '6')
			do_shutdown(argv[optind]);
	}

	if (do_sync) {
		sync();
		sleep(2);
	}

	if (do_ifdown)
		(void)ifdown();

    (void)hdflush();

    syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
            LINUX_REBOOT_CMD_RESTART2, argv[optind]);

	return 0;
}
예제 #2
0
파일: rhcopy.c 프로젝트: Pizookies/Radiance
void
addholo(			/* add a holodeck file */
	char	*hdf
)
{
	int	fd;
					/* open the holodeck for reading */
	openholo(hdf, 0);
	fd = hdlist[noutsects]->fd;	/* remember the file handle */
	while (hdlist[noutsects] != NULL) {	/* load each section */
							/* clump the beams */
		clumpbeams(hdlist[noutsects], 0, BKBSIZE*1024, addclump);
		hddone(hdlist[noutsects]);		/* free the section */
	}
	close(fd);			/* close input file */
	hdflush(NULL);			/* flush output */
}
예제 #3
0
파일: rhcopy.c 프로젝트: Pizookies/Radiance
void
addpicz(		/* add a picture + depth-buffer */
	char	*pcf,
	char	*zbf
)
{
	FILE	*pfp;
	int	zfd;
	COLR	*cscn;
	float	*zscn;
	struct phead	phd;
	int	eshft;
	double	emult;
	RESOLU	prs;
	RREAL	vl[2];
	FVECT	ro, rd;
	double	aftd;
	COLOR	ctmp;
	int	j;
	register int	i;
				/* open files */
	if ((pfp = fopen(pcf, "r")) == NULL) {
		sprintf(errmsg, "cannot open picture file \"%s\"", pcf);
		error(SYSTEM, pcf);
	}
	if ((zfd = open(zbf, O_RDONLY)) < 0) {
		sprintf(errmsg, "cannot open depth file \"%s\"", zbf);
		error(SYSTEM, pcf);
	}
				/* load picture header */
	phd.vw = stdview;
	phd.expos = 1.0;
	phd.badfmt = phd.gotview = phd.altprims = 0;
	if (getheader(pfp, picheadline, &phd) < 0 ||
			phd.badfmt || !fgetsresolu(&prs, pfp)) {
		sprintf(errmsg, "bad format for picture file \"%s\"", pcf);
		error(USER, errmsg);
	}
	if (!phd.gotview || setview(&phd.vw) != NULL) {
		sprintf(errmsg, "missing/illegal view in picture \"%s\"",
				pcf);
		error(USER, errmsg);
	}
	if (phd.altprims) {
		sprintf(errmsg, "ignoring primary values in picture \"%s\"",
				pcf);
		error(WARNING, errmsg);
	}
				/* figure out what to do about exposure */
	if ((phd.expos < 0.99) | (phd.expos > 1.01)) {
		emult = -log(phd.expos)/log(2.);
		eshft = emult >= 0. ? emult+.5 : emult-.5;
		emult -= (double)eshft;
		if ((emult <= 0.01) & (emult >= -0.01))
			emult = -1.;
		else {
			emult = 1./phd.expos;
			eshft = 0;
		}
	} else {
		emult = -1.;
		eshft = 0;
	}
				/* allocate buffers */
	cscn = (COLR *)malloc(scanlen(&prs)*sizeof(COLR));
	zscn = (float *)malloc(scanlen(&prs)*sizeof(float));
	if ((cscn == NULL) | (zscn == NULL))
		error(SYSTEM, "out of memory in addpicz");
				/* read and process each scanline */
	for (j = 0; j < numscans(&prs); j++) {
		i = scanlen(&prs);			/* read colrs */
		if (freadcolrs(cscn, i, pfp) < 0) {
			sprintf(errmsg, "error reading picture \"%s\"", pcf);
			error(USER, errmsg);
		}
		if (eshft)				/* shift exposure */
			shiftcolrs(cscn, i, eshft);
		i *= sizeof(float);			/* read depth */
		if (read(zfd, (char *)zscn, i) != i) {
			sprintf(errmsg, "error reading depth file \"%s\"", zbf);
			error(USER, errmsg);
		}
		for (i = scanlen(&prs); i--; ) {	/* do each pixel */
			pix2loc(vl, &prs, i, j);
			aftd = viewray(ro, rd, &phd.vw, vl[0], vl[1]);
			if (aftd < -FTINY)
				continue;		/* off view */
			if (aftd > FTINY && zscn[i] > aftd)
				continue;		/* aft clipped */
			if (emult > 0.) {		/* whatta pain */
				colr_color(ctmp, cscn[i]);
				scalecolor(ctmp, emult);
				setcolr(cscn[i], colval(ctmp,RED),
					colval(ctmp,GRN), colval(ctmp,BLU));
			}
			addray(ro, rd, (double)zscn[i], cscn[i]);
		}
	}
				/* write output and free beams */
	hdflush(NULL);
				/* clean up */
	free((void *)cscn);
	free((void *)zscn);
	fclose(pfp);
	close(zfd);
}