Exemplo n.º 1
0
static void
cleanup(int ustatus __unused)
{
	int error, status;
	pid_t pid, waitres;
	const char *myargs[5];

	err_set_exit(NULL);
	myargs[0] = "rm";
	myargs[1] = "-rf";
	myargs[2] = "--";
	myargs[3] = dir;
	myargs[4] = NULL;
	error = posix_spawnp(&pid, myargs[0], NULL, NULL,
	    __DECONST(char **, myargs), environ);
	if (error != 0)
		warn("posix_spawnp rm");
	else {
		waitres = waitpid(pid, &status, 0);
		if (waitres != pid)
			warnx("waitpid rm failed");
		else if (status != 0)
			warnx("rm failed");
	}
}
Exemplo n.º 2
0
int
main(int argc, char *argv[])
{
	int fd;

	if (!mkdtemp(dir))
		err(2, "mkdtemp");

	err_set_exit(cleanup);

	fd = open(dir, O_DIRECTORY | O_RDONLY);
	if (fd == -1)
		err(2, "open %s", dir);

	if (mkdirat(fd, "d1", 0777) == -1)
		err(2, "mkdirat d1");

	if (symlinkat(dir, fd, "d1/looper") == -1)
		err(2, "symlinkat looper");

	ftwflags = FTW_PHYS;
	if (nftw(dir, cb, 10, ftwflags) == -1)
		err(2, "nftw FTW_PHYS");
	ftwflags = FTW_PHYS | FTW_DEPTH;
	if (nftw(dir, cb, 10, ftwflags) == -1)
		err(2, "nftw FTW_PHYS | FTW_DEPTH");
	ftwflags = 0;
	if (nftw(dir, cb, 10, ftwflags) == -1)
		err(2, "nftw 0");
	ftwflags = FTW_DEPTH;
	if (nftw(dir, cb, 10, ftwflags) == -1)
		err(2, "nftw FTW_DEPTH");

	close(fd);

	printf("PASS nftw()\n");

	cleanup(failures != 0);

	return (failures != 0);
}
Exemplo n.º 3
0
int main(int argc, char **argv) {
        int i;

	if (argc != 2) {
		printf("usage!\n");
		exit(1);
	}

	printf("testing err_set_file\n");
	err_set_file(stdout);
	printf("testing err_set_exit\n");
	err_set_exit(custom_exit);

	errno = ENOMEM;

	printf("testing warn and vwarn\n");
	warn("\ttest of %s", "warn");
	printf("testing warnx and vwarnx\n");
	warnx("\ttest of warnx");

	i = atoi(argv[1]);
	switch (i) {
	case 0:
		printf("testing err and verr\n");
		err(1, "\ttest of %s", "err");
		break;

	case 1:
		printf("testing errx and verrx\n");
		errx(2, "\ttest of %s", "verrx"); /* bogus */
		break;

	default:
		printf("unknown case: %d\n", i);
		exit(1);
	}
	return 0;
}
Exemplo n.º 4
0
int
main(int argc, char **argv)
{
	int arg, addr, ch, fd;
	int dao = 0, eject = 0, fixate = 0, list = 0, multi = 0, preemp = 0;
	int nogap = 0, speed = 4 * 177, test_write = 0, force = 0;
	int block_size = 0, block_type = 0, cdopen = 0, dvdrw = 0;
	const char *dev, *env_speed;

	if (feature_present("ata_cam")) {
		errx(1, "\nATA_CAM option is enabled in kernel.\n"
		    "Install the sysutils/cdrtools port and use cdrecord instead.\n\n"
		    "Please refer to:\n"
		    "http://www.freebsd.org/doc/handbook/creating-cds.html#CDRECORD");
	}

	if ((dev = getenv("CDROM")) == NULL)
		dev = "/dev/acd0";

	env_speed = getenv("BURNCD_SPEED");

	while ((ch = getopt(argc, argv, "def:Flmnpqs:tv")) != -1) {
		switch (ch) {
		case 'd':
			dao = 1;
			break;

		case 'e':
			eject = 1;
			break;

		case 'f':
			dev = optarg;
			break;

		case 'F':
			force = 1;
			break;

		case 'l':
			list = 1;
			break;

		case 'm':
			multi = 1;
			break;

		case 'n':
			nogap = 1;
			break;

		case 'p':
			preemp = 1;
			break;

		case 'q':
			quiet = 1;
			break;

		case 's':
			env_speed = optarg;
			break;

		case 't':
			test_write = 1;
			break;

		case 'v':
			verbose = 1;
			break;

		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	if (env_speed == NULL)
		;
	else if (strcasecmp("max", env_speed) == 0)
		speed = CDR_MAX_SPEED;
	else
		speed = atoi(env_speed) * 177;
	if (speed <= 0)
		errx(EX_USAGE, "Invalid speed: %s", env_speed);

	if (argc == 0)
		usage();

	if ((fd = open(dev, O_RDWR, 0)) < 0)
		err(EX_NOINPUT, "open(%s)", dev);

	if (ioctl(fd, CDRIOCGETBLOCKSIZE, &saved_block_size) < 0)
		err(EX_IOERR, "ioctl(CDRIOCGETBLOCKSIZE)");

	if (ioctl(fd, CDRIOCWRITESPEED, &speed) < 0)
		err(EX_IOERR, "ioctl(CDRIOCWRITESPEED)");

	global_fd_for_cleanup = fd;
	err_set_exit(cleanup);
	signal(SIGHUP, cleanup_signal);
	signal(SIGINT, cleanup_signal);
	signal(SIGTERM, cleanup_signal);

	for (arg = 0; arg < argc; arg++) {
		if (!strcasecmp(argv[arg], "fixate")) {
			fixate = 1;
			continue;
		}
		if (!strcasecmp(argv[arg], "eject")) {
			eject = 1;
			break;
		}
		if (!strcasecmp(argv[arg], "msinfo")) {
			struct ioc_read_toc_single_entry entry;
			struct ioc_toc_header header;

			if (ioctl(fd, CDIOREADTOCHEADER, &header) < 0)
				err(EX_IOERR, "ioctl(CDIOREADTOCHEADER)");
			bzero(&entry, sizeof(struct ioc_read_toc_single_entry));
			entry.address_format = CD_LBA_FORMAT;
			entry.track = header.ending_track;
			if (ioctl(fd, CDIOREADTOCENTRY, &entry) < 0)
				err(EX_IOERR, "ioctl(CDIOREADTOCENTRY)");
			if (ioctl(fd, CDRIOCNEXTWRITEABLEADDR, &addr) < 0)
				err(EX_IOERR, "ioctl(CDRIOCNEXTWRITEABLEADDR)");
			fprintf(stdout, "%d,%d\n",
				ntohl(entry.entry.addr.lba), addr);

			break;
		}
		if ((!strcasecmp(argv[arg], "erase") ||
		     !strcasecmp(argv[arg], "blank")) && !test_write) {
			int blank, pct, last = 0;

			if (!strcasecmp(argv[arg], "erase"))
				blank = CDR_B_ALL;
			else
				blank = CDR_B_MIN;
			if (!quiet)
				fprintf(stderr, "%sing CD, please wait..\r",
					blank == CDR_B_ALL ? "eras" : "blank");

			if (ioctl(fd, CDRIOCBLANK, &blank) < 0)
				err(EX_IOERR, "ioctl(CDRIOCBLANK)");
			while (1) {
				sleep(1);
				if (ioctl(fd, CDRIOCGETPROGRESS, &pct) == -1)
					err(EX_IOERR,"ioctl(CDRIOGETPROGRESS)");
				if (pct > 0 && !quiet)
					fprintf(stderr,
						"%sing CD - %d %% done     \r",
						blank == CDR_B_ALL ?
						"eras" : "blank", pct);
				if (pct == 100 || (pct == 0 && last > 90))
					break;
				last = pct;
			}
			if (!quiet)
				printf("\n");
			continue;
		}
		if (!strcasecmp(argv[arg], "format") && !test_write) {
			if (arg + 1 < argc &&
				(!strcasecmp(argv[arg + 1], "dvd+rw") ||
				!strcasecmp(argv[arg + 1], "dvd-rw")))
				do_format(fd, force, argv[arg + 1]);
			else
				errx(EX_NOINPUT, "format media type invalid");
			arg++;
			continue;
		}
		if (!strcasecmp(argv[arg], "audio") || !strcasecmp(argv[arg], "raw")) {
			block_type = CDR_DB_RAW;
			block_size = 2352;
			continue;
		}
		if (!strcasecmp(argv[arg], "data") || !strcasecmp(argv[arg], "mode1")) {
			block_type = CDR_DB_ROM_MODE1;
			block_size = 2048;
			continue;
		}
		if (!strcasecmp(argv[arg], "mode2")) {
			block_type = CDR_DB_ROM_MODE2;
			block_size = 2336;
			continue;
		}
		if (!strcasecmp(argv[arg], "xamode1")) {
			block_type = CDR_DB_XA_MODE1;
			block_size = 2048;
			continue;
		}
		if (!strcasecmp(argv[arg], "xamode2")) {
			block_type = CDR_DB_XA_MODE2_F2;
			block_size = 2324;
			continue;
		}
		if (!strcasecmp(argv[arg], "vcd")) {
			block_type = CDR_DB_XA_MODE2_F2;
			block_size = 2352;
			dao = 1;
			nogap = 1;
			continue;
		}
		if (!strcasecmp(argv[arg], "dvdrw")) {
			block_type = CDR_DB_ROM_MODE1;
			block_size = 2048;
			dvdrw = 1;
			continue;
		}

		if (!block_size)
			errx(EX_NOINPUT, "no data format selected");
		if (list) {
			char file_buf[MAXPATHLEN + 1], *eol;
			FILE *fp;

			if ((fp = fopen(argv[arg], "r")) == NULL)
				err(EX_NOINPUT, "fopen(%s)", argv[arg]);

			while (fgets(file_buf, sizeof(file_buf), fp) != NULL) {
				if (*file_buf == '#' || *file_buf == '\n')
					continue;
				if ((eol = strchr(file_buf, '\n')))
					*eol = '\0';
				add_track(file_buf, block_size, block_type, nogap);
			}
			if (feof(fp))
				fclose(fp);
			else
				err(EX_IOERR, "fgets(%s)", file_buf);
		}
		else
			add_track(argv[arg], block_size, block_type, nogap);
	}
	if (notracks) {
		if (dvdrw && notracks > 1)
			errx(EX_USAGE, "DVD's only have 1 track");
		if (ioctl(fd, CDIOCSTART, 0) < 0)
			err(EX_IOERR, "ioctl(CDIOCSTART)");
		if (!cdopen) {
			if (ioctl(fd, CDRIOCINITWRITER, &test_write) < 0)
				err(EX_IOERR, "ioctl(CDRIOCINITWRITER)");
			cdopen = 1;
		}
		if (dao)
			do_DAO(fd, test_write, multi);
		else
			do_TAO(fd, test_write, preemp, dvdrw);
	}
	if (!test_write && fixate && !dao && !dvdrw) {
		if (!quiet)
			fprintf(stderr, "fixating CD, please wait..\n");
		if (ioctl(fd, CDRIOCFIXATE, &multi) < 0)
			err(EX_IOERR, "ioctl(CDRIOCFIXATE)");
	}

	if (ioctl(fd, CDRIOCSETBLOCKSIZE, &saved_block_size) < 0) {
		err_set_exit(NULL);
		err(EX_IOERR, "ioctl(CDRIOCSETBLOCKSIZE)");
	}

	if (eject)
		if (ioctl(fd, CDIOCEJECT) < 0)
			err(EX_IOERR, "ioctl(CDIOCEJECT)");

	signal(SIGHUP, SIG_DFL);
	signal(SIGINT, SIG_DFL);
	signal(SIGTERM, SIG_DFL);
	close(fd);
	exit(EX_OK);
}