Exemple #1
0
void SdfRenderer::polygon(QDomElement &element)
{
	parsestyle(element);
	// FIXME: init points array here
	QPoint *points = NULL;
	int n = element.attribute("n").toInt();
	if (!element.isNull())
	{
		points = getpoints(element, n);
	}
	if (points != NULL)
	{
//		painter->drawConvexPolygon(points, n);
		delete[] points;
	}
	defaultstyle();
}
Exemple #2
0
int
main(int argc, char **argv)
{
	int ch, col, ktrlen, size;
	pid_t do_pid = -1;
	void *m;
	int trpoints = ALL_POINTS;
	char *cp;

	(void) setlocale(LC_CTYPE, "");

	while ((ch = getopt(argc,argv,"f:djlm:np:RTt:")) != -1)
		switch((char)ch) {
		case 'f':
			tracefile = optarg;
			break;
		case 'j':
			fixedformat = 1;
			break;
		case 'd':
			decimal = 1;
			break;
		case 'l':
			tail = 1;
			break;
		case 'm':
			maxdata = atoi(optarg);
			break;
		case 'n':
			fancy = 0;
			break;
		case 'p':
			do_pid = strtoul(optarg, &cp, 0);
			if (*cp != 0)
				errx(1,"invalid number %s", optarg);
			break;
		case 'R':
			timestamp = 2;	/* relative timestamp */
			break;
		case 'T':
			timestamp = 1;
			break;
		case 't':
			trpoints = getpoints(optarg);
			if (trpoints < 0)
				errx(1, "unknown trace point in %s", optarg);
			break;
		default:
			usage();
		}

	if (argc > optind)
		usage();

	m = (void *)malloc(size = 1025);
	if (m == NULL)
		errx(1, "%s", strerror(ENOMEM));
	if (!freopen(tracefile, "r", stdin))
		err(1, "%s", tracefile);
	while (fread_tail(&ktr_header, sizeof(struct ktr_header), 1)) {
		if (trpoints & (1 << ktr_header.ktr_type) &&
		    (do_pid == -1 || ktr_header.ktr_pid == do_pid))
			col = dumpheader(&ktr_header);
		else
			col = -1;
		if ((ktrlen = ktr_header.ktr_len) < 0)
			errx(1, "bogus length 0x%x", ktrlen);
		if (ktrlen > size) {
			m = (void *)realloc(m, ktrlen+1);
			if (m == NULL)
				errx(1, "%s", strerror(ENOMEM));
			size = ktrlen;
		}
		if (ktrlen && fread_tail(m, ktrlen, 1) == 0)
			errx(1, "data too short");
		if ((trpoints & (1<<ktr_header.ktr_type)) == 0)
			continue;
		if (col == -1)
			continue;
		switch (ktr_header.ktr_type) {
		case KTR_SYSCALL:
			ktrsyscall((struct ktr_syscall *)m);
			break;
		case KTR_SYSRET:
			ktrsysret((struct ktr_sysret *)m);
			break;
		case KTR_NAMEI:
			ktrnamei(m, ktrlen);
			break;
		case KTR_GENIO:
			ktrgenio((struct ktr_genio *)m, ktrlen);
			break;
		case KTR_PSIG:
			ktrpsig((struct ktr_psig *)m);
			break;
		case KTR_CSW:
			ktrcsw((struct ktr_csw *)m);
			break;
		case KTR_USER:
			ktruser(ktrlen, m);
			break;
		}
		if (tail)
			(void)fflush(stdout);
	}
	exit(0);
}
Exemple #3
0
int
main(int argc, char *argv[])
{
	int append, ch, fd, inherit, ops, trpoints;
	const char *tracefile;
	mode_t omask;
	struct stat sb;

	append = ops = inherit = 0;
	trpoints = DEF_POINTS;
	tracefile = def_tracefile;
	while ((ch = getopt(argc,argv,"aCcdf:g:ip:t:")) != -1)
		switch((char)ch) {
		case 'a':
			append = 1;
			break;
		case 'C':
			set_pid_clear("1", CLEARALL);
			break;
		case 'c':
			set_pid_clear(NULL, CLEAR);
			break;
		case 'd':
			ops |= KTRFLAG_DESCEND;
			break;
		case 'f':
			tracefile = optarg;
			break;
		case 'g':
			set_pid_clear(optarg, NOTSET);
			pid = -pid;
			break;
		case 'i':
			inherit = 1;
			break;
		case 'p':
			set_pid_clear(optarg, NOTSET);
			break;
		case 't':
			trpoints = getpoints(optarg);
			if (trpoints < 0) {
				warnx("unknown facility in %s", optarg);
				usage();
			}
			break;
		default:
			usage();
		}

	argv += optind;
	argc -= optind;

	/* must have either -[Cc], a pid or a command */
	if (clear == NOTSET && pid == 0 && argc == 0)
		usage();
	/* can't have both a pid and a command */
	/* (note that -C sets pid to 1) */
	if (pid != 0 && argc > 0) {
		usage();
	}

	if (inherit)
		trpoints |= KTRFAC_INHERIT;

	(void)signal(SIGSYS, no_ktrace);
	if (clear != NOTSET) {
		if (clear == CLEARALL) {
			ops = KTROP_CLEAR | KTRFLAG_DESCEND;
			trpoints = ALL_POINTS;
		} else {
			ops |= pid ? KTROP_CLEAR : KTROP_CLEARFILE;
		}
		if (ktrace(tracefile, ops, trpoints, pid) < 0)
			err(1, "%s", tracefile);
		exit(0);
	}

	omask = umask(S_IRWXG|S_IRWXO);
	if (append) {
		if ((fd = open(tracefile, O_CREAT | O_WRONLY | O_NONBLOCK,
		    DEFFILEMODE)) < 0)
			err(1, "%s", tracefile);
		if (fstat(fd, &sb) != 0 || sb.st_uid != getuid())
			errx(1, "refuse to append to %s not owned by you",
			    tracefile);
		if (!(S_ISREG(sb.st_mode)))
			errx(1, "%s not regular file", tracefile);
	} else {
		if (unlink(tracefile) == -1 && errno != ENOENT)
			err(1, "unlink %s", tracefile);
		if ((fd = open(tracefile, O_CREAT | O_EXCL | O_WRONLY,
		    DEFFILEMODE)) < 0)
			err(1, "%s", tracefile);
	}
	(void)umask(omask);
	(void)close(fd);

	trpoints |= PROC_ABI_POINTS;

	if (argc > 0) { 
		if (ktrace(tracefile, ops, trpoints, getpid()) < 0)
			err(1, "%s", tracefile);
		execvp(*argv, argv);
		err(1, "exec of '%s' failed", *argv);
	}
	if (ktrace(tracefile, ops, trpoints, pid) < 0)
		err(1, "%s", tracefile);
	exit(0);
}
Exemple #4
0
int
main(int argc, char *argv[])
{
	enum { NOTSET, CLEAR, CLEARALL } clear;
	int append, ch, fd, inherit, ops, pidset, trpoints;
	pid_t pid;
	char *tracefile, *tracespec;
	mode_t omask;
	struct stat sb;

	is_ltrace = strcmp(__progname, "ltrace") == 0;

	clear = NOTSET;
	append = ops = pidset = inherit = pid = 0;
	trpoints = is_ltrace ? KTRFAC_USER : DEF_POINTS;
	tracefile = DEF_TRACEFILE;
	tracespec = NULL;

	if (is_ltrace) {
		while ((ch = getopt(argc, argv, "af:it:u:")) != -1)
			switch ((char)ch) {
			case 'a':
				append = 1;
				break;
			case 'f':
				tracefile = optarg;
				break;
			case 'i':
				inherit = 1;
				break;
			case 't':
				trpoints = getpoints(optarg);
				if (trpoints < 0) {
					warnx("unknown facility in %s", optarg);
					usage();
				}
				break;
			case 'u':
				tracespec = optarg;
				break;
			default:
				usage();
			}
	} else {
		while ((ch = getopt(argc, argv, "aBCcdf:g:ip:t:")) != -1)
			switch ((char)ch) {
			case 'a':
				append = 1;
				break;
			case 'B':
				putenv("LD_BIND_NOW=");
				break;
			case 'C':
				clear = CLEARALL;
				pidset = 1;
				break;
			case 'c':
				clear = CLEAR;
				break;
			case 'd':
				ops |= KTRFLAG_DESCEND;
				break;
			case 'f':
				tracefile = optarg;
				break;
			case 'g':
				pid = -rpid(optarg);
				pidset = 1;
				break;
			case 'i':
				inherit = 1;
				break;
			case 'p':
				pid = rpid(optarg);
				pidset = 1;
				break;
			case 't':
				trpoints = getpoints(optarg);
				if (trpoints < 0) {
					warnx("unknown facility in %s", optarg);
					usage();
				}
				break;
			default:
				usage();
			}
	}

	argv += optind;
	argc -= optind;
	
	if ((pidset && *argv) || (!pidset && !*argv && clear != CLEAR))
		usage();

	if (inherit)
		trpoints |= KTRFAC_INHERIT;

	(void)signal(SIGSYS, no_ktrace);
	if (clear != NOTSET) {
		if (clear == CLEARALL) {
			ops = KTROP_CLEAR | KTRFLAG_DESCEND;
			trpoints = ALL_POINTS;
			pid = 1;
		} else
			ops |= pid ? KTROP_CLEAR : KTROP_CLEARFILE;

		if (ktrace(tracefile, ops, trpoints, pid) < 0) {
			if (errno == ESRCH)
				err(1, "%d", pid);
			err(1, "%s", tracefile);
		}
		exit(0);
	}

	omask = umask(S_IRWXG|S_IRWXO);
	if (append) {
		if ((fd = open(tracefile, O_CREAT | O_WRONLY, DEFFILEMODE)) < 0)
			err(1, "%s", tracefile);
		if (fstat(fd, &sb) != 0 || sb.st_uid != getuid())
			errx(1, "Refuse to append to %s: not owned by you.",
			    tracefile);
	} else {
		if (unlink(tracefile) == -1 && errno != ENOENT)
			err(1, "unlink %s", tracefile);
		if ((fd = open(tracefile, O_CREAT | O_EXCL | O_WRONLY,
		    DEFFILEMODE)) < 0)
			err(1, "%s", tracefile);
	}
	(void)umask(omask);
	(void)close(fd);

	if (*argv) { 
		if (is_ltrace) {
			if (setenv("LD_TRACE_PLT", inherit ? "i" : "", 1) < 0)
				err(1, "setenv(LD_TRACE_PLT)");
			if (tracespec &&
			    setenv("LD_TRACE_PLTSPEC", tracespec, 1) < 0)
				err(1, "setenv(LD_TRACE_PLTSPEC)");
		}
		if (ktrace(tracefile, ops, trpoints, getpid()) < 0)
			err(1, "%s", tracefile);
		execvp(argv[0], &argv[0]);
		err(1, "exec of '%s' failed", argv[0]);
	}
	else if (ktrace(tracefile, ops, trpoints, pid) < 0) {
		if (errno == ESRCH)
			err(1, "%d", pid);
		err(1, "%s", tracefile);
	}
	exit(0);
}