Beispiel #1
0
/* Uptime comparison. */
static int
tcmp(const void *a1, const void *a2)
{
	return (rflg * (
		(ISDOWN(HS(a2)) ? HS(a2)->hs_wd.wd_recvtime - now
		    : HS(a2)->hs_wd.wd_sendtime - HS(a2)->hs_wd.wd_boottime)
		-
		(ISDOWN(HS(a1)) ? HS(a1)->hs_wd.wd_recvtime - now
		    : HS(a1)->hs_wd.wd_sendtime - HS(a1)->hs_wd.wd_boottime)
	));
}
Beispiel #2
0
/* Number of users comparison. */
static int
ucmp(const void *a1, const void *a2)
{
	if (ISDOWN(HS(a1)))
		if (ISDOWN(HS(a2)))
			return (tcmp(a1, a2));
		else
			return (rflg);
	else if (ISDOWN(HS(a2)))
		return (-rflg);
	else
		return (rflg * (HS(a2)->hs_nusers - HS(a1)->hs_nusers));
}
Beispiel #3
0
/* Load average comparison. */
static int
lcmp(const void *a1, const void *a2)
{
	if (ISDOWN(HS(a1)))
		if (ISDOWN(HS(a2)))
			return (tcmp(a1, a2));
		else
			return (rflg);
	else if (ISDOWN(HS(a2)))
		return (-rflg);
	else
		return (rflg *
		   (HS(a2)->hs_wd.wd_loadav[0] - HS(a1)->hs_wd.wd_loadav[0]));
}
Beispiel #4
0
static Boolean any_user_input(void)
/*****************************************************************************
 * I'm not sure this is the best way to do this, but...
 ****************************************************************************/
{
    wait_wndo_input(ANY_INPUT);
    return (ISDOWN(MBPEN|MBRIGHT) || JSTHIT(KEYHIT));
}
Beispiel #5
0
static Errcode get_sep_source_colors(Sep_cb *sep)
{
int color;
Errcode err;
SHORT ogrid;

	if ((sep->p.ctable = pj_malloc(COLORS)) == NULL)
		return(Err_no_memory);
	save_undo();
	if (vs.sep_box)
	{
		if((err = get_rub_rect(&sep->p.rect)) < 0)
			goto error;
		if((err = rub_rect_in_place(&sep->p.rect)) < 0)
			goto error;
	}
	else
	{
		sep->p.rect.x = sep->p.rect.y = 0;
		sep->p.rect.width = vb.pencel->width;
		sep->p.rect.height = vb.pencel->height;
	}

	if (vs.sep_rgb	== 2)	/* range */
	{
		sep->p.ccount = cluster_count();
		pj_copy_bytes(cluster_bundle(), sep->p.ctable, sep->p.ccount);
		return(Success);
	}

	ogrid = vs.use_grid;
	vs.use_grid = FALSE;

	for (;;)	/* gather up a table while pen down of colors under cursor */
	{
		color = pj_get_dot(vb.pencel,icb.mx,icb.my);
		if (!in_cnums(color, sep->p.ctable, sep->p.ccount) )
			sep->p.ctable[sep->p.ccount++] = color;
		wait_any_input();
		if (!ISDOWN(MBPEN))
			break;
	}
	vs.use_grid = ogrid;
	err = Success;
error:
	return(err);
}
Beispiel #6
0
static void
ruptime(const char *host, int aflg, int (*cmp)(const void *, const void *))
{
	struct hs *hsp;
	struct whod *wd;
	struct whoent *we;
	struct dirent *dp;
	const char *hostname;
	int fd, i, maxloadav;
	size_t hspace;
	ssize_t cc;

	rewinddir(dirp);
	hsp = NULL;
	maxloadav = -1;
	(void)time(&now);
	for (nhosts = hspace = 0; (dp = readdir(dirp)) != NULL;) {
		if (dp->d_ino == 0 || strncmp(dp->d_name, "whod.", 5) != 0)
			continue;
		if ((fd = open(dp->d_name, O_RDONLY, 0)) < 0) {
			warn("%s", dp->d_name);
			continue;
		}

		if (nhosts == hspace) {
			if ((hs =
			    realloc(hs, (hspace += 40) * sizeof(*hs))) == NULL)
				err(1, NULL);
			hsp = hs + nhosts;
		}

		wd = &hsp->hs_wd;
		cc = read(fd, wd, sizeof(*wd));
		(void)close(fd);
		if (cc < (ssize_t)WHDRSIZE)
			continue;

		if (host != NULL) {
			hostname = wd->wd_hostname;
			if (strcasecmp(hostname, host) != 0)
				continue;
		}
		if (LEFTEARTH(wd->wd_recvtime))
			continue;

		for (i = 0; i < 2; i++)
			if (wd->wd_loadav[i] > maxloadav)
				maxloadav = wd->wd_loadav[i];

		for (hsp->hs_nusers = 0, we = &wd->wd_we[0];
		    (char *)(we + 1) <= (char *)wd + cc; we++)
			if (aflg || we->we_idle < 3600)
				++hsp->hs_nusers;
		++hsp;
		++nhosts;
	}
	if (nhosts == 0) {
		if (host == NULL)
			errx(1, "no hosts in %s", _PATH_RWHODIR);
		else
			warnx("host %s not in %s", host, _PATH_RWHODIR);
	}

	qsort(hs, nhosts, sizeof(hs[0]), cmp);
	for (i = 0; i < (int)nhosts; i++) {
		hsp = &hs[i];
		wd = &hsp->hs_wd;
		if (ISDOWN(hsp)) {
			(void)printf("%-25.25s%s\n", wd->wd_hostname,
			    interval(now - hsp->hs_wd.wd_recvtime, "down"));
			continue;
		}
		(void)printf(
		    "%-25.25s%s,  %4d user%s  load %*.2f, %*.2f, %*.2f\n",
		    wd->wd_hostname,
		    interval((time_t)wd->wd_sendtime -
		        (time_t)wd->wd_boottime, "  up"),
		    hsp->hs_nusers,
		    hsp->hs_nusers == 1 ? ", " : "s,",
		    maxloadav >= 1000 ? 5 : 4,
		        wd->wd_loadav[0] / 100.0,
		    maxloadav >= 1000 ? 5 : 4,
		        wd->wd_loadav[1] / 100.0,
		    maxloadav >= 1000 ? 5 : 4,
		        wd->wd_loadav[2] / 100.0);
	}
	free(hs);
	hs = NULL;
}
Beispiel #7
0
/*************
 * DESCRIPTION:   divide OCTREE-object in eight children:
 *                - if depth < maxdepth
 *                - if at least one object is in actual OCTREE-object
 * INPUT:         octree            pointer to OCTREE-object
 *                depth             current depth of octree
 *                maxOctreeDepth    maximum depth of octree
 * OUTPUT:        none
 *************/
static void DivideOctree(OCTREE *octree, const WORD depth, WORD maxOctreeDepth)
{
	WORD direction;
	VECTOR mid;
	VOXEL voxel, newvoxel;
	OBJECT *object;
	CONTENT *content, *help, *old;

	content = octree->content;
	if(!content)
		return;
	if(!content->next)
		return;

	if(depth < maxOctreeDepth)
	{
		voxel = octree->voxel;
		mid.x = 0.5f * (voxel.min.x+voxel.max.x);
		mid.y = 0.5f * (voxel.min.y+voxel.max.y);
		mid.z = 0.5f * (voxel.min.z+voxel.max.z);
		for(direction = LEFTDOWNBACK; direction <= RIGHTUPFRONT; direction++)
		{
			newvoxel.min.x = ISLEFT(direction) ? voxel.min.x : mid.x;
			newvoxel.min.y = ISDOWN(direction) ? voxel.min.y : mid.y;
			newvoxel.min.z = ISBACK(direction) ? voxel.min.z : mid.z;
			newvoxel.max.x = ISLEFT(direction) ? mid.x : voxel.max.x;
			newvoxel.max.y = ISDOWN(direction) ? mid.y : voxel.max.y;
			newvoxel.max.z = ISBACK(direction) ? mid.z : voxel.max.z;
			octree->child[direction] =
				AllocateOctree(octree, direction, &newvoxel);
			if(octree->child[direction])
			{
				content = NULL;
				help = octree->content;
				while(help)
				{
					object = help->object;
					if(!((object->voxel.min.x > newvoxel.max.x) ||
						(object->voxel.max.x < newvoxel.min.x) ||
						(object->voxel.min.y > newvoxel.max.y) ||
						(object->voxel.max.y < newvoxel.min.y) ||
						(object->voxel.min.z > newvoxel.max.z) ||
						(object->voxel.max.z < newvoxel.min.z)))
					{
						old = content;
						content = AllocateContent(old, object);
						if(content)
						{
							help = help->next;
						}
						else
						{
							FreeContentList(old);
							help = NULL;
						}
					}
					else
					{
						help = help->next;
					}
				}
				octree->child[direction]->content = content;
				DivideOctree(octree->child[direction], depth+1, maxOctreeDepth);
			}
		}
		octree->direction |= HASCHILDREN;
		FreeContentList(octree->content);
		octree->content = NULL;
	}
}
Beispiel #8
0
int
main(int argc, char *argv[])
{
	struct dirent *dp;
	struct hs *hsp = NULL;
	struct whod *wd;
	struct whoent *we;
	DIR *dirp;
	size_t hspace;
	int aflg, ch, fd, maxloadav;
	char buf[sizeof(struct whod)];
	int (*cmp)(const void *, const void *);
	u_int cc, i;

	aflg = 0;
	cmp = hscmp;
	while ((ch = getopt(argc, argv, "alrut")) != -1)
		switch (ch) {
		case 'a':
			aflg = 1;
			break;
		case 'l':
			cmp = lcmp;
			break;
		case 'r':
			rflg = -1;
			break;
		case 't':
			cmp = tcmp;
			break;
		case 'u':
			cmp = ucmp;
			break;
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if (argc != 0)
		usage();

	if (chdir(_PATH_RWHODIR) || (dirp = opendir(".")) == NULL)
		err(1, "%s", _PATH_RWHODIR);

	maxloadav = -1;
	for (nhosts = hspace = 0; (dp = readdir(dirp)) != NULL;) {
		if (dp->d_ino == 0 || strncmp(dp->d_name, "whod.", 5))
			continue;
		if ((fd = open(dp->d_name, O_RDONLY, 0)) < 0) {
			warn("%s", dp->d_name);
			continue;
		}
		cc = read(fd, buf, sizeof(struct whod));
		(void)close(fd);

		if (cc < WHDRSIZE)
			continue;
		if (LEFTEARTH(((struct whod *)buf)->wd_recvtime))
			continue;
		if (nhosts == hspace) {
			hspace += 40;
			if ((hs = realloc(hs, hspace * sizeof(*hs))) == NULL)
				err(1, NULL);
			hsp = hs + nhosts;
		}

		if ((hsp->hs_wd = malloc((size_t)WHDRSIZE)) == NULL)
			err(1, NULL);
		memmove(hsp->hs_wd, buf, (size_t)WHDRSIZE);

		for (wd = (struct whod *)buf, i = 0; i < 2; ++i)
			if (wd->wd_loadav[i] > maxloadav)
				maxloadav = wd->wd_loadav[i];

		for (hsp->hs_nusers = 0,
		    we = (struct whoent *)(buf + cc); --we >= wd->wd_we;)
			if (aflg || we->we_idle < 3600)
				++hsp->hs_nusers;
		++hsp;
		++nhosts;
	}
	if (nhosts == 0)
		errx(1, "no hosts in %s", _PATH_RWHODIR);

	(void)time(&now);
	qsort(hs, nhosts, sizeof(hs[0]), cmp);
	for (i = 0; i < nhosts; i++) {
		hsp = &hs[i];
		if (ISDOWN(hsp)) {
			(void)printf("%-12.12s%s\n", hsp->hs_wd->wd_hostname,
			    interval(now - hsp->hs_wd->wd_recvtime, "down"));
			continue;
		}
		(void)printf(
		    "%-12.12s%s,  %4d user%s  load %*.2f, %*.2f, %*.2f\n",
		    hsp->hs_wd->wd_hostname,
		    interval((time_t)hsp->hs_wd->wd_sendtime -
			(time_t)hsp->hs_wd->wd_boottime, "  up"),
		    hsp->hs_nusers,
		    hsp->hs_nusers == 1 ? ", " : "s,",
		    maxloadav >= 1000 ? 5 : 4,
			hsp->hs_wd->wd_loadav[0] / 100.0,
		    maxloadav >= 1000 ? 5 : 4,
		        hsp->hs_wd->wd_loadav[1] / 100.0,
		    maxloadav >= 1000 ? 5 : 4,
		        hsp->hs_wd->wd_loadav[2] / 100.0);
	}
	exit(0);
}