Exemplo n.º 1
0
int
main(int argc, char **argv)
{
	show_memory_totals();

	if (argc == 1) {
		// list areas of all teams
		int32 cookie = 0;
		team_info info;

		while (get_next_team_info(&cookie, &info) >= B_OK)
			list_areas_for_id(info.team);
	} else {
		// list areas for each team ID/name on the command line
		while (--argc) {
			const char *arg = *++argv;
			team_id team = atoi(arg);

			// if atoi returns >0 it's likely it's a number, else take it as string
			if (team > 0)
				list_areas_for_id(team);
			else
				list_areas_for_name(arg);
		}
	}

	return 0;
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
	team_info tinfo;
	int32 cookie = 0;
	int32 i;
	system_info sysinfo;

	// show up some stats first...
	get_system_info(&sysinfo);
	printf("sem: total: %5" B_PRIu32 ", used: %5" B_PRIu32 ", left: %5" B_PRIu32
		"\n\n", sysinfo.max_sems, sysinfo.used_sems,
		sysinfo.max_sems - sysinfo.used_sems);

	if (argc == 1) {
		while (get_next_team_info( &cookie, &tinfo) == B_OK)
			list_sems(&tinfo);

		return 0;
	}

	for (i = 1; i < argc; i++) {
		if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
			fprintf(stderr, "Usage:  %s [-s semid]  [teamid]\n", argv[0]);
			fputs("        List the semaphores allocated by the specified\n",
				stderr);
			fputs("        team, or all teams if none is specified.\n",
				stderr);
			fputs("\n", stderr);
			fputs("        The -s option displays the sem_info data for a\n",
				stderr);
			fputs("        specified semaphore.\n", stderr);
			return 0;
		} else if (strcmp(argv[i], "-s") == 0) {
			if (argc < i + 2)
				printf("-s used without associated sem id\n");
			else {
				sem_id id = atoi(argv[i + 1]);
				sem_info info;
				if (get_sem_info(id, &info) == B_OK) {
					print_header(NULL);
					print_sem_info(&info);
				} else
					printf("semaphore %" B_PRId32 " unknown\n\n", id);

				i++;
			}
		} else {
			team_id team;
			team = atoi(argv[i]);
			if (get_team_info(team, &tinfo) == B_OK)
				list_sems(&tinfo);
			else
				printf("team %" B_PRId32 " unknown\n\n", team);
		}
	}

	return 0;
}
Exemplo n.º 3
0
static void
list_areas_for_name(const char *name)
{
	int32 cookie = 0;
	team_info info;
	while (get_next_team_info(&cookie, &info) >= B_OK) {
		if (strstr(info.args, name) != NULL)
			list_areas_for_id(info.team);
	}
}
Exemplo n.º 4
0
int32 real_find_proc(data *bar) {
    team_info info;
    int32 cookie = 0;
    while (get_next_team_info(&cookie, &info) == B_OK) {
        if ((uint32) info.team == bar->id) {
            strcpy(bar->name, info.args);
            return 1;
        }
    }
    return 0;
}
Exemplo n.º 5
0
int32 killer_thread(void *data)
{
    int32     cookie;
    team_info info;

    kill_thread(main_thread_id);
    allegro_exit();
    cookie = 0;
    get_next_team_info(&cookie, &info);
    kill_team(info.team);

    return 1;
}
Exemplo n.º 6
0
filter_result
MinimizeAllInputFilter::Filter(BMessage* message, BList* _list)
{
	switch (message->what) {
		case B_KEY_DOWN:
		{
			const char* bytes;
			if (message->FindString("bytes", &bytes) != B_OK)
				break;

			int32 modifiers;
			if (message->FindInt32("modifiers", &modifiers) != B_OK)
				break;

			int32 modifiersHeld = modifiers & (B_COMMAND_KEY
				| B_CONTROL_KEY | B_OPTION_KEY | B_MENU_KEY | B_SHIFT_KEY);

			bool minimize;
			if (modifiersHeld == (B_COMMAND_KEY | B_CONTROL_KEY))
				minimize = true;
			else if (modifiersHeld
					== (B_COMMAND_KEY | B_CONTROL_KEY | B_SHIFT_KEY)) {
				minimize = false;
			} else
				break;

			int32 cookie = 0;
			team_info teamInfo;
			while (get_next_team_info(&cookie, &teamInfo) == B_OK) {
				app_info appInfo;
				be_roster->GetRunningAppInfo(teamInfo.team, &appInfo);
				team_id team = appInfo.team;
				be_roster->ActivateApp(team);

				if (be_roster->GetActiveAppInfo(&appInfo) == B_OK
					&& (appInfo.flags & B_BACKGROUND_APP) == 0
					&& strcasecmp(appInfo.signature, kDeskbarSignature) != 0) {
					BRect zoomRect;
					if (minimize)
						do_minimize_team(zoomRect, team, false);
					else
						do_bring_to_front_team(zoomRect, team, false);
				}
			}

			return B_SKIP_MESSAGE;
		}
	}

	return B_DISPATCH_MESSAGE;
}
Exemplo n.º 7
0
/**
* BeOS entropy poll
*/
void BeOS_EntropySource::poll(Entropy_Accumulator& accum)
   {
   system_info info_sys;
   get_system_info(&info_sys);
   accum.add(info_sys, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA);

   key_info info_key; // current state of the keyboard
   get_key_info(&info_key);
   accum.add(info_key, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA);

   team_info info_team;
   int32 cookie_team = 0;

   while(get_next_team_info(&cookie_team, &info_team) == B_OK)
      {
      accum.add(info_team, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA);

      team_id id = info_team.team;
      int32 cookie = 0;

      thread_info info_thr;
      while(get_next_thread_info(id, &cookie, &info_thr) == B_OK)
         accum.add(info_thr, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA);

      cookie = 0;
      image_info info_img;
      while(get_next_image_info(id, &cookie, &info_img) == B_OK)
         accum.add(info_img, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA);

      cookie = 0;
      sem_info info_sem;
      while(get_next_sem_info(id, &cookie, &info_sem) == B_OK)
         accum.add(info_sem, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA);

      cookie = 0;
      area_info info_area;
      while(get_next_area_info(id, &cookie, &info_area) == B_OK)
         accum.add(info_area, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA);

      if(accum.polling_finished())
         break;
      }
   }
Exemplo n.º 8
0
status_t
system_shutdown(bool reboot)
{
	int32 cookie = 0;
	team_info info;
	
	// Now shutdown all system services!
	// TODO: Once we are sure we can shutdown the system on all hardware
	// checking reboot may not be necessary anymore.
	if (reboot) {
		while (get_next_team_info(&cookie, &info) == B_OK) {
			if (info.team == B_SYSTEM_TEAM)
				continue;
			kill_team(info.team);
		}
	}
	
	sync();

	return arch_cpu_shutdown(reboot);
}
Exemplo n.º 9
0
void
MemoryBarMenu::Pulse()
{
	system_info	sinfo;
	get_system_info(&sinfo);
	int committedMemory = int(sinfo.used_pages * B_PAGE_SIZE / 1024);
	int cachedMemory = int(sinfo.cached_pages * B_PAGE_SIZE / 1024);
	Window()->BeginViewTransaction();

	// create the list of items to remove, for their team is gone. Update the old teams.
	int lastRecycle = 0;
	int firstRecycle = 0;
	int	k;
	MemoryBarMenuItem* item;
	int	total = 0;
	for (k = 1; (item = (MemoryBarMenuItem*)ItemAt(k)) != NULL; k++) {
		int m = item->UpdateSituation(committedMemory);
		if (m < 0) {
			if (lastRecycle == fRecycleCount) {
				fRecycleCount += EXTRA;
				fRecycleList = (MRecycleItem*)realloc(fRecycleList,
					sizeof(MRecycleItem) * fRecycleCount);
			}
			fRecycleList[lastRecycle].index = k;
			fRecycleList[lastRecycle++].item = item;
		} else {
			if (lastRecycle > 0) {
				RemoveItems(fRecycleList[0].index, lastRecycle, true);
				k -= lastRecycle;
				lastRecycle = 0;
			}
			total += m;
		}
	}

	// Look new teams that have appeared. Create an item for them, or recycle from the list.
	int32 cookie = 0;
	info_pack infos;
	item = NULL;
	while (get_next_team_info(&cookie, &infos.team_info) == B_OK) {
		int	j = 0;
		while (j < fTeamCount && infos.team_info.team != fTeamList[j]) {
			j++;
		}

		if (infos.team_info.team != fTeamList[j]) {
			// new team
			team_info info;
			j = 0;
			while (j < fTeamCount && fTeamList[j] != -1) {
				if (get_team_info(fTeamList[j], &info) != B_OK)
					fTeamList[j] = -1;
				else
					j++;
			}

			if (j == fTeamCount) {
				fTeamCount += 10;
				fTeamList = (team_id*)realloc(fTeamList, sizeof(team_id) * fTeamCount);
			}

			fTeamList[j] = infos.team_info.team;
			if (!get_team_name_and_icon(infos, true)) {
				// the team is already gone!
				delete infos.team_icon;
				fTeamList[j] = -1;
			} else {
				if (!item && firstRecycle < lastRecycle)
					item = fRecycleList[firstRecycle++].item;

				if (item)
					item->Reset(infos.team_name, infos.team_info.team, infos.team_icon, true);
				else {
					AddItem(item = new MemoryBarMenuItem(infos.team_name,
						infos.team_info.team, infos.team_icon, true, NULL));
				}

				int m = item->UpdateSituation(committedMemory);
				if (m >= 0) {
					total += m;
					item = NULL;
				} else
					fTeamList[j] = -1;
			}
		}
	}

	if (item) {
		RemoveItem(item);
		delete item;
	}

	// Delete the items that haven't been recycled.
	if (firstRecycle < lastRecycle) {
		RemoveItems(IndexOf(fRecycleList[firstRecycle].item),
			lastRecycle - firstRecycle, true);
	}

	fLastTotalTime = system_time();
	KernelMemoryBarMenuItem	*kernelItem;
	if ((kernelItem = (KernelMemoryBarMenuItem*)ItemAt(0)) != NULL)
		kernelItem->UpdateSituation(committedMemory, cachedMemory);

	Window()->EndViewTransaction();
	Window()->Flush();
}
Exemplo n.º 10
0
void
TeamMonitorWindow::UpdateList()
{
	bool changed = false;

	for (int32 i = 0; i < fListView->CountItems(); i++) {
		TeamListItem* item = dynamic_cast<TeamListItem*>(fListView->ItemAt(i));
		if (item != NULL)
			item->SetFound(false);
	}

	int32 cookie = 0;
	team_info info;
	while (get_next_team_info(&cookie, &info) == B_OK) {
		if (info.team <=16)
			continue;

		bool found = false;
		for (int32 i = 0; i < fListView->CountItems(); i++) {
			TeamListItem* item
				= dynamic_cast<TeamListItem*>(fListView->ItemAt(i));
			if (item != NULL && item->GetInfo()->team == info.team) {
				item->SetFound(true);
				found = true;
			}
		}

		if (!found) {
			TeamListItem* item = new TeamListItem(info);

			fListView->AddItem(item,
				item->IsSystemServer() ? fListView->CountItems() : 0);
			item->SetFound(true);
			changed = true;
		}
	}

	for (int32 i = fListView->CountItems() - 1; i >= 0; i--) {
		TeamListItem* item = dynamic_cast<TeamListItem*>(fListView->ItemAt(i));
		if (item != NULL && !item->Found()) {
			if (item == fDescriptionView->Item()) {
				fDescriptionView->SetItem(NULL);
				fKillButton->SetEnabled(false);
				fQuitButton->SetEnabled(false);
			}

			delete fListView->RemoveItem(i);
			changed = true;
		}
	}

	if (changed)
		fListView->Invalidate();

	bool desktopRunning = be_roster->IsRunning(kTrackerSignature)
		&& be_roster->IsRunning(kDeskbarSignature);
	if (!desktopRunning && fRestartButton->IsHidden()) {
		fRestartButton->Show();
		SetDefaultButton(fRestartButton);
		fRestartButton->Parent()->Layout(true);
	}

	fRestartButton->SetEnabled(!desktopRunning);
}
Exemplo n.º 11
0
void MainWindow::UpdateTeams()
{
	ThreadItem *thread_item;
	TeamItem   *team_item;

	DisableUpdates();

	if (!team_items_list)
		team_items_list = new Hashtable;

	app_info inf;
	thread_info thinf;
	int32 th_cookie, te_cookie;
	int32 i;

	team_info teinf;

	te_cookie = 0;

	iteration = (iteration + 1) % 2;

	total_CPU_diff = 0;
	int idle_CPU_diff = 0;

	for (i = 0; get_next_team_info(&te_cookie, &teinf) == B_NO_ERROR; i++) {
		if (!(team_item = (TeamItem *)team_items_list->get(teinf.team))) {
			team_item = new TeamItem(&teinf);
			team_item->refreshed = iteration;
			team_items_list->put(teinf.team, team_item);
			teamView->AddRow(team_item);

			team_item->CPU_diff = 0;
			for (th_cookie = 0; get_next_thread_info(team_item->team, &th_cookie, &thinf) == B_OK;) {
				thread_item = new ThreadItem(&thinf);
				thread_item->refreshed = iteration;
				team_item->thread_items_list->put(thinf.thread, thread_item);
				teamView->AddRow(thread_item, team_item);
				if (teinf.team != 1 || strncmp(thinf.name, "idle thread ", 12) != 0) {
					team_item->CPU_diff += thread_item->CPU_diff;
				} else
					idle_CPU_diff += thread_item->CPU_diff;
			}
		}
		// update team
		else {
			team_item->update(&teinf);
			team_item->refreshed = iteration;

			team_item->CPU_diff = 0;
			for (th_cookie = 0; get_next_thread_info(team_item->team, &th_cookie, &thinf) == B_OK;) {
				if (!(thread_item = (ThreadItem *)team_item->thread_items_list->get(thinf.thread))) {
					thread_item = new ThreadItem(&thinf);
					thread_item->refreshed = iteration;
					team_item->thread_items_list->put(thinf.thread, thread_item);
					teamView->AddRow(thread_item, team_item);
				}
				// update thread
				else {
					thread_item->update(&thinf);
					thread_item->refreshed = iteration;
				}
				if (teinf.team != 1 || strncmp(thinf.name, "idle thread ", 12) != 0) {
					team_item->CPU_diff += thread_item->CPU_diff;
				} else
					idle_CPU_diff += thread_item->CPU_diff;
			}

		}
		total_CPU_diff += team_item->CPU_diff;
		if (total_CPU_diff < 0) printf("Error. CPU diff out of bounds\n");
	}
	total_CPU_diff += idle_CPU_diff;

	// division by zero && overflow handling
	if (total_CPU_diff <= 0) total_CPU_diff = 1;

	RemoveList.MakeEmpty();
	teamView->FullListDoForEach(postlistproc, (void *)this);
	RemoveProcessItems(&RemoveList);

	EnableUpdates();
}
Exemplo n.º 12
0
int
main()
{
	team_info teamInfo;
	int32 cookie = 0;
	while (get_next_team_info(&cookie, &teamInfo) == B_OK) {
		if (!strncmp(teamInfo.args, "/boot/beos/", 11)) {
			// this is a system component and not worth to investigate
			continue;
		}

		thread_info threadInfo;
		int32 threadCookie = 0;
		while (get_next_thread_info(teamInfo.team, &threadCookie, &threadInfo)
				== B_OK) {
			// search for the roster thread
			if (!strcmp(threadInfo.name, "_roster_thread_")) {
				port_id port = find_port("antares-test:roster");
				port_info portInfo;
				if (get_port_info(port, &portInfo) == B_OK
					&& portInfo.team == teamInfo.team) {
					puts("The Antares Registrar is already running.");
					return 0;
				}
			}
		}
	}

	// the Antares registrar doesn't seem to run yet, change this

	BPath currentPath(".");

	BQuery query;
	query.SetPredicate("name==test_registrar");

	// search on current volume only
	dev_t device = dev_for_path(".");
	BVolume volume(device);

	query.SetVolume(&volume);
	query.Fetch();

	entry_ref ref;
	while (query.GetNextRef(&ref) == B_OK) {
		BPath path(&ref);
		if (path.InitCheck() != B_OK)
			continue;

		const char* registrarPath = path.Path();
		const char* generatedPath = strstr(registrarPath, "generated");
		if (generatedPath == NULL)
			continue;

		if (!strncmp(currentPath.Path(), registrarPath, generatedPath - registrarPath)) {
			// gotcha!
			const char* args[] = { registrarPath, NULL };
			thread_id thread = load_image(1, args, (const char**)environ);
			if (thread < B_OK) {
				fprintf(stderr, "%s: Could not start the registrar: %s\n",
					__progname, strerror(thread));
				return -1;
			}

			resume_thread(thread);
			return 0;
		}
	}

	fprintf(stderr, "%s: Could not find the Antares Registrar.\n"
		"    (This tool only works when used in the Antares tree, but maybe\n"
		"    the registrar just needs to be built.)\n",
		__progname);
	return -1;
}
Exemplo n.º 13
0
status_t
thread_popup(void *arg)
{
	Tpopup_param* param = (Tpopup_param*) arg;
	int32 mcookie, hcookie;
	unsigned long m;
	long h;
	BMenuItem* item;
	bool top = param->top;

	system_info systemInfo;
	get_system_info(&systemInfo);
	info_pack* infos = new info_pack[systemInfo.used_teams];
	// TODO: this doesn't necessarily get all teams
	for (m = 0, mcookie = 0; m < systemInfo.used_teams; m++) {
		infos[m].team_icon = NULL;
		infos[m].team_name[0] = 0;
		infos[m].thread_info = NULL;
		if (get_next_team_info(&mcookie, &infos[m].team_info) == B_OK) {
			infos[m].thread_info = new thread_info[infos[m].team_info.thread_count];
			for (h = 0, hcookie = 0; h < infos[m].team_info.thread_count; h++) {
				if (get_next_thread_info(infos[m].team_info.team, &hcookie,
						&infos[m].thread_info[h]) != B_OK)
					infos[m].thread_info[h].thread = -1;
			}
			get_team_name_and_icon(infos[m], true);
		} else {
			systemInfo.used_teams = m;
			infos[m].team_info.team = -1;
		}
	}

	BPopUpMenu* popup = new BPopUpMenu("Global Popup", false, false);
	popup->SetFont(be_plain_font);

	// Quit section
	BMenu* QuitPopup = new QuitMenu(B_TRANSLATE("Quit an application"),
	infos, systemInfo.used_teams);
	QuitPopup->SetFont(be_plain_font);
	popup->AddItem(QuitPopup);

	// Memory Usage section
	MemoryBarMenu* MemoryPopup = new MemoryBarMenu(B_TRANSLATE("Memory usage"),
	infos, systemInfo);
	int64 committedMemory = (int64)systemInfo.used_pages * B_PAGE_SIZE / 1024;
	for (m = 0; m < systemInfo.used_teams; m++) {
		if (infos[m].team_info.team >= 0) {
			MemoryBarMenuItem* memoryItem =
				new MemoryBarMenuItem(infos[m].team_name,
					infos[m].team_info.team, infos[m].team_icon, false, NULL);
			MemoryPopup->AddItem(memoryItem);
			memoryItem->UpdateSituation(committedMemory);
		}
	}

	addtopbottom(MemoryPopup);

	// CPU Load section
	TeamBarMenu* CPUPopup = new TeamBarMenu(B_TRANSLATE("Threads and CPU "
	"usage"), infos, systemInfo.used_teams);
	for (m = 0; m < systemInfo.used_teams; m++) {
		if (infos[m].team_info.team >= 0) {
			ThreadBarMenu* TeamPopup = new ThreadBarMenu(infos[m].team_name,
				infos[m].team_info.team, infos[m].team_info.thread_count);
			BMessage* kill_team = new BMessage('KlTm');
			kill_team->AddInt32("team", infos[m].team_info.team);
			TeamBarMenuItem* item = new TeamBarMenuItem(TeamPopup, kill_team,
				infos[m].team_info.team, infos[m].team_icon, false);
			item->SetTarget(gPCView);
			CPUPopup->AddItem(item);
		}
	}

	addtopbottom(CPUPopup);
	addtopbottom(new BSeparatorItem());

	// CPU on/off section
	if (gCPUcount > 1) {
		for (unsigned int i = 0; i < gCPUcount; i++) {
			char item_name[32];
			sprintf (item_name, B_TRANSLATE("Processor %d"), i + 1);
			BMessage* m = new BMessage ('CPU ');
			m->AddInt32 ("cpu", i);
			item = new IconMenuItem (gPCView->fProcessorIcon, item_name, m);
			if (_kern_cpu_enabled(i))
				item->SetMarked (true);
			item->SetTarget(gPCView);
			addtopbottom(item);
		}
		addtopbottom (new BSeparatorItem ());
	}

	// Scheduler modes
	static const char* schedulerModes[] = { B_TRANSLATE_MARK("Low latency"),
		B_TRANSLATE_MARK("Power saving") };
	unsigned int modesCount = sizeof(schedulerModes) / sizeof(const char*);
	int32 currentMode = get_scheduler_mode();
	for (unsigned int i = 0; i < modesCount; i++) {
		BMessage* m = new BMessage('Schd');
		m->AddInt32("mode", i);
		item = new BMenuItem(B_TRANSLATE(schedulerModes[i]), m);
		if ((uint32)currentMode == i)
			item->SetMarked(true);
		item->SetTarget(gPCView);
		addtopbottom(item);
	}
	addtopbottom(new BSeparatorItem());

	if (!be_roster->IsRunning(kTrackerSig)) {
		item = new IconMenuItem(gPCView->fTrackerIcon,
		B_TRANSLATE("Restart Tracker"), new BMessage('Trac'));
		item->SetTarget(gPCView);
		addtopbottom(item);
	}
	if (!be_roster->IsRunning(kDeskbarSig)) {
		item = new IconMenuItem(gPCView->fDeskbarIcon,
		B_TRANSLATE("Restart Deskbar"), new BMessage('Dbar'));
		item->SetTarget(gPCView);
		addtopbottom(item);
	}

	item = new IconMenuItem(gPCView->fTerminalIcon,
	B_TRANSLATE("New Terminal"), new BMessage('Term'));
	item->SetTarget(gPCView);
	addtopbottom(item);

	addtopbottom(new BSeparatorItem());

	bool showLiveInDeskbarItem = gInDeskbar;
	if (!showLiveInDeskbarItem) {
		int32 cookie = 0;
		image_info info;
		while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) {
			if (info.type == B_APP_IMAGE) {
				// only show the Live in Deskbar item if a) we're running in
				// deskbar itself, or b) we're running in PC's team.
				if (strstr(info.name, "ProcessController") != NULL) {
					showLiveInDeskbarItem = true;
					break;
				}
			}
		}
	}

	if (showLiveInDeskbarItem && be_roster->IsRunning(kDeskbarSig)) {
		item = new BMenuItem(B_TRANSLATE("Live in the Deskbar"),
			new BMessage('AlDb'));
		BDeskbar deskbar;
		item->SetMarked(gInDeskbar || deskbar.HasItem(kDeskbarItemName));
		item->SetTarget(gPCView);
		addtopbottom(item);
		addtopbottom(new BSeparatorItem ());
	}


	item = new IconMenuItem(gPCView->fProcessControllerIcon,
	B_TRANSLATE("About ProcessController" B_UTF8_ELLIPSIS),
		new BMessage(B_ABOUT_REQUESTED));
	item->SetTarget(gPCView);
	addtopbottom(item);

	param->where.x -= 5;
	param->where.y -= 8;
	popup->Go(param->where, true, true, param->clickToOpenRect);

	delete popup;
	for (m = 0; m < systemInfo.used_teams; m++) {
		if (infos[m].team_info.team >= 0) {
			delete[] infos[m].thread_info;
			delete infos[m].team_icon;
		}
	}
	delete[] infos;
	delete param;
	atomic_add (&gPopupFlag, -1);
	gPopupThreadID = 0;

	return B_OK;
}
Exemplo n.º 14
0
void slowPoll( void )
	{
	RANDOM_STATE randomState;
	BYTE buffer[ RANDOM_BUFSIZE + 8 ];
	key_info keyInfo;
	team_info teami;
	thread_info threadi;
	area_info areai;
	port_info porti;
	sem_info semi;
	image_info imagei;
	double temperature;
	int32 devID, cookie;
	int fd, value;

	if( ( fd = open( "/dev/urandom", O_RDONLY ) ) >= 0 )
		{
		MESSAGE_DATA msgData;
		BYTE buffer[ ( DEVRANDOM_BITS / 8 ) + 8 ];
		static const int quality = 100;

		/* Read data from /dev/urandom, which won't block (although the
		   quality of the noise is lesser). */
		read( fd, buffer, DEVRANDOM_BITS / 8 );
		setMessageData( &msgData, buffer, DEVRANDOM_BITS / 8 );
		krnlSendMessage( SYSTEM_OBJECT_HANDLE, IMESSAGE_SETATTRIBUTE_S,
						 &msgData, CRYPT_IATTRIBUTE_ENTROPY );
		zeroise( buffer, DEVRANDOM_BITS / 8 );
		close( fd );

		krnlSendMessage( SYSTEM_OBJECT_HANDLE, IMESSAGE_SETATTRIBUTE,
						 ( MESSAGE_CAST ) &quality,
						 CRYPT_IATTRIBUTE_ENTROPY_QUALITY );
		return;
		}

	initRandomData( randomState, buffer, RANDOM_BUFSIZE );

	/* Get the state of all keys on the keyboard and various other
	   system states */
#if 0	/* See comment at start */
	if( get_key_info( &keyInfo ) == B_NO_ERROR )
		addRandomData( randomState, &keyInfo, sizeof( key_info ) );
#endif /* 0 */
	value = is_computer_on();	/* Returns 1 if computer is on */
	addRandomValue( randomState, value );
	temperature = is_computer_on_fire();	/* MB temp.if on fire */
	addRandomData( randomState, &temperature, sizeof( double ) );

	/* Get information on all running teams (thread groups, ie applications).
	   This returns the team ID, number of threads, images, and areas,
	   debugger port and thread ID, program args, and uid and gid */
	cookie = 0;
	while( get_next_team_info( &cookie, &teami ) == B_NO_ERROR )
		addRandomData( randomState, &teami, sizeof( teami ) );

	/* Get information on all running threads.  This returns the thread ID,
	   team ID, thread name and state (eg running, suspended, asleep,
	   blocked), the thread priority, elapsed user and kernel time, and
	   thread stack information */
	cookie = 0;
	while( get_next_thread_info( 0, &cookie, &threadi ) == B_NO_ERROR )
		{
		addRandomValue( randomState, has_data( threadi.thread ) );
		addRandomData( randomState, &threadi, sizeof( threadi ) );
		}

	/* Get information on all memory areas (chunks of virtual memory).  This
	   returns the area ID, name, size, locking scheme and protection bits,
	   ID of the owning team, start address, number of resident bytes, copy-
	   on-write count, an number of pages swapped in and out */
	cookie = 0;
	while( get_next_area_info( 0, &cookie, &areai ) == B_NO_ERROR )
		addRandomData( randomState, &areai, sizeof( areai ) );

	/* Get information on all message ports.  This returns the port ID, ID of
	   the owning team, message queue length, number of messages in the
	   queue, and total number of messages processed */
	cookie = 0;
	while( get_next_port_info( 0, &cookie, &porti ) == B_NO_ERROR )
		addRandomData( randomState, &porti, sizeof( porti ) );

	/* Get information on all semaphores.  This returns the semaphore and
	   owning team ID, the name, thread count, and the ID of the last thread
	   which acquired the semaphore */
	cookie = 0;
	while( get_next_sem_info( 0, &cookie, &semi ) == B_NO_ERROR )
		addRandomData( randomState, &semi, sizeof( semi ) );

	/* Get information on all images (code blocks, eg applications, shared
	   libraries, and add-on images (DLL's on steroids).  This returns the
	   image ID and type (app, library, or add-on), the order in which the
	   image was loaded compared to other images, the address of the init
	   and shutdown routines, the device and node where the image lives,
	   and the image text and data sizes) */
	cookie = 0;
	while( get_next_image_info( 0, &cookie, &imagei ) == B_NO_ERROR )
		addRandomData( randomState, &imagei, sizeof( imagei ) );

	/* Get information on all storage devices.  This returns the device
	   number, root inode, various device parameters such as I/O block size,
	   and the number of free and used blocks and inodes */
	devID = 0;
	while( next_dev( &devID ) >= 0 )
		{
		fs_info fsInfo;

		if( fs_stat_dev( devID, &fsInfo ) == B_NO_ERROR )
			addRandomData( randomState, &fsInfo, sizeof( fs_info ) );
		}

	/* Flush any remaining data through */
	endRandomData( randomState, 100 );
	}
Exemplo n.º 15
0
Arquivo: ps.c Projeto: DonCN/haiku
int
main(int argc, char** argv)
{
	team_info teamInfo;
	int32 teamCookie = 0;
	system_info systemInfo;
	bool printSystemInfo = false;
	bool printThreads = false;
	bool printHeader = true;
	bool printSemaphoreInfo = false;
	bool customizeColumns = false;
	// match this in team name
	char* string_to_match;

	int c;

	while ((c = getopt(argc, argv, "-ihaso:")) != EOF) {
		switch (c) {
			case 'i':
				printSystemInfo = true;
				break;
			case 'h':
				printf( "usage: ps [-hais] [-o columns list] [team]\n"
						"-h : show help\n"
						"-i : show system info\n"
						"-s : show semaphore info\n"
						"-o : display team info associated with the list\n"
						"-a : show threads too (by default only teams are "
							"displayed)\n");
				return 0;
				break;
			case 'a':
				printThreads = true;
				break;
			case 's':
				printSemaphoreInfo = true;
				break;
			case 'o':
				if (!customizeColumns)
					ColumnsCount = 0;
				customizeColumns = true;
				/* fallthrough */
			case 1:
			{
				size_t i = 0;
				if (c == 1 && !customizeColumns)
					break;
				for (i = 0; i < sizeof(Infos) / sizeof(Infos[0]); i++)
					if (strcmp(optarg, Infos[i].name) == 0
							&& ColumnsCount < maxColumns) {
						Columns[ColumnsCount++] = i;
						continue;
					}
				break;
			}
		}
	}

	// TODO: parse command line
	// Possible command line options:
	//      -t  pstree like output

	if (argc == 2 && (printSystemInfo || printThreads))
		string_to_match = NULL;
	else
		string_to_match = (argc >= 2 && !customizeColumns)
			? argv[argc - 1] : NULL;

	if (!string_to_match) {
		while (get_next_team_info(&teamCookie, &teamInfo) >= B_OK) {
			printTeamInfo(&teamInfo, printHeader);
			printHeader = false;
			if (printThreads) {
				printf("\n%-37s %5s %8s %4s %8s %8s\n", "Thread", "Id", \
					"State", "Prio", "UTime", "KTime");
				printTeamThreads(&teamInfo, printSemaphoreInfo);
				printf("----------------------------------------------" \
					"-----------------------------\n");
				printHeader = true;
			}
		}
	} else {
		while (get_next_team_info(&teamCookie, &teamInfo) >= B_OK) {
			char* p = teamInfo.args;
			if ((p = strchr(p, ' ')))
				*p = '\0'; /* remove arguments, keep only argv[0] */
			p = strrchr(teamInfo.args, '/'); /* forget the path */
			if (p == NULL)
				p = teamInfo.args;
			if (strstr(p, string_to_match) == NULL)
				continue;
			printTeamInfo(&teamInfo, true);
			printf("\n%-37s %5s %8s %4s %8s %8s\n", "Thread", "Id", "State", \
				"Prio", "UTime", "KTime");
			printTeamThreads(&teamInfo, printSemaphoreInfo);
		}
	}

	if (printSystemInfo) {
		// system stats
		get_system_info(&systemInfo);
		printf("\nSystem Info\n");
		printf("%" B_PRIu32 "k (%" B_PRIu32 " bytes) total memory\n",
			(systemInfo.max_pages * B_PAGE_SIZE / 1024),
			(systemInfo.max_pages * B_PAGE_SIZE));
		printf("%" B_PRIu32 "k (%" B_PRIu32 " bytes) currently committed\n",
			(systemInfo.used_pages * B_PAGE_SIZE / 1024),
			(systemInfo.used_pages * B_PAGE_SIZE));
		printf("%" B_PRIu32 "k (%" B_PRIu32 " bytes) currently available\n",
			(systemInfo.max_pages - systemInfo.used_pages) * B_PAGE_SIZE / 1024,
			(systemInfo.max_pages - systemInfo.used_pages) * B_PAGE_SIZE);
		printf("%2.1f%% memory utilisation\n",
			(float)100 * systemInfo.used_pages / systemInfo.max_pages);
	}
	return 0;
}
Exemplo n.º 16
0
int
main(int argc, char* argv[])
{
	team_info teamInfo;
	int32 cookie = 0;
	while (get_next_team_info(&cookie, &teamInfo) == B_OK) {
		if (!strncmp(teamInfo.args, "/boot/beos/", 11)
			|| !strncmp(teamInfo.args, "/boot/system/", 13)) {
			// this is a system component and not worth to investigate
			continue;
		}

		thread_info threadInfo;
		int32 threadCookie = 0;
		while (get_next_thread_info(teamInfo.team, &threadCookie, &threadInfo)
				== B_OK) {
			// search for the roster thread
			if (!strcmp(threadInfo.name, "_roster_thread_")) {
				port_id port = find_port("haiku-test:roster");
				port_info portInfo;
				if (get_port_info(port, &portInfo) == B_OK
					&& portInfo.team == teamInfo.team) {
					puts("The Haiku Registrar is already running.");
					return 0;
				}
			}
		}
	}

	// the Haiku registrar doesn't seem to run yet, change this

	BPath currentPath(".");

	BQuery query;
	query.SetPredicate("name==test_registrar");

	// search on current volume only
	dev_t device = dev_for_path(".");
	BVolume volume(device);

	query.SetVolume(&volume);
	query.Fetch();

	entry_ref ref;
	while (query.GetNextRef(&ref) == B_OK) {
		BPath path(&ref);
		if (path.InitCheck() != B_OK)
			continue;

		const char* registrarPath = path.Path();
		const char* generatedPath = strstr(registrarPath, "generated");
		if (generatedPath == NULL)
			continue;

		if (!strncmp(currentPath.Path(), registrarPath, generatedPath - registrarPath)) {
			// gotcha!
			if (launch_registrar(registrarPath) == B_OK)
				return 0;
		}
	}

	// As a fallback (maybe the volume does not support queries for example)
	// try to find the test_registrar in the current folder...
	BString registrarPath(argv[0]);
	registrarPath.RemoveLast(__progname);
	registrarPath.Append("test_registrar");
	if (launch_registrar(registrarPath.String()) == B_OK)
		return 0;

	fprintf(stderr, "%s: Could not find the Haiku Registrar.\n"
		"    (This tool only works when used in the Haiku tree, but maybe\n"
		"    the registrar just needs to be built.)\n",
		__progname);
	return -1;
}
Exemplo n.º 17
0
int
main(int argc, char **argv)
{
	const char *pattern = NULL;
	dev_t device = -1;
	ino_t node = -1;
	int32 id = -1;
	info_mode mode = kList;
	bool brief = false;

	// parse arguments

	if (argc == 2) {
		// filter output
		if (isdigit(argv[1][0]))
			id = atol(argv[1]);
		else if (argv[1][0] == '-')
			usage(!strcmp(argv[1], "--help"));
		else
			pattern = argv[1];
	} else if (argc > 2) {
		if (!strcmp(argv[1], "-d") || !strcmp(argv[1], "-D")) {
			// filter by device usage
			device = dev_for_path(argv[2]);
			if (device < 0) {
				fprintf(stderr, "%s: could not find device: %s\n", __progname,
					strerror(errno));
				return 1;
			}
			mode = kFilterDevice;
			if (argv[1][1] == 'D')
				brief = true;
		} else if (!strcmp(argv[1], "-f") || !strcmp(argv[1], "-F")) {
			// filter by file usage
			struct stat stat;
			if (::stat(argv[2], &stat) < 0) {
				fprintf(stderr, "%s: could not open file: %s\n", __progname,
					strerror(errno));
				return 1;
			}
			device = stat.st_dev;
			node = stat.st_ino;
			mode = kFilterFile;
			if (argv[1][1] == 'F')
				brief = true;
		} else
			usage(true);
	}

	// do the job!

	team_info info;
	int32 cookie = 0;

	while (get_next_team_info(&cookie, &info) == B_OK) {
		switch (mode) {
			case kList:
				if ((id != -1 && id != info.team)
					|| (pattern != NULL && !strstr(info.args, pattern)))
					continue;
				print_fds(info);
				break;

			case kFilterDevice:
				filter_device(info, device, brief);
				break;
			case kFilterFile:
				filter_file(info, device, node, brief);
				break;
		}
	}

	return 0;
}
Exemplo n.º 18
0
long
thread_popup(void *arg)
{
	Tpopup_param* param = (Tpopup_param*) arg;
	int32 mcookie, hcookie;
	long m, h;
	BMenuItem* item;
	bool top = param->top;

	system_info systemInfo;
	get_system_info(&systemInfo);
	info_pack* infos = new info_pack[systemInfo.used_teams];
	// TODO: this doesn't necessarily get all teams
	for (m = 0, mcookie = 0; m < systemInfo.used_teams; m++) {
		infos[m].team_icon = NULL;
		infos[m].team_name[0] = 0;
		infos[m].thread_info = NULL;
		if (get_next_team_info(&mcookie, &infos[m].team_info) == B_OK) {
			infos[m].thread_info = new thread_info[infos[m].team_info.thread_count];
			for (h = 0, hcookie = 0; h < infos[m].team_info.thread_count; h++) {
				if (get_next_thread_info(infos[m].team_info.team, &hcookie,
						&infos[m].thread_info[h]) != B_OK)
					infos[m].thread_info[h].thread = -1;
			}
			get_team_name_and_icon(infos[m], true);
		} else {
			systemInfo.used_teams = m;
			infos[m].team_info.team = -1;
		}
	}

	BPopUpMenu* popup = new BPopUpMenu("Global Popup", false, false);
	popup->SetFont(be_plain_font);

	// Quit section
	BMenu* QuitPopup = new QuitMenu(B_TRANSLATE("Quit an application"),
	infos, systemInfo.used_teams);
	QuitPopup->SetFont(be_plain_font);
	popup->AddItem(QuitPopup);

	// Memory Usage section
	MemoryBarMenu* MemoryPopup = new MemoryBarMenu(B_TRANSLATE("Memory usage"),
	infos, systemInfo);
	int commitedMemory = int(systemInfo.used_pages * B_PAGE_SIZE / 1024);
	for (m = 0; m < systemInfo.used_teams; m++) {
		if (infos[m].team_info.team >= 0) {
			MemoryBarMenuItem* memoryItem =
				new MemoryBarMenuItem(infos[m].team_name,
					infos[m].team_info.team, infos[m].team_icon, false, NULL);
			MemoryPopup->AddItem(memoryItem);
			memoryItem->UpdateSituation(commitedMemory);
		}
	}

	addtopbottom(MemoryPopup);

	// CPU Load section
	TeamBarMenu* CPUPopup = new TeamBarMenu(B_TRANSLATE("Threads and CPU "
	"usage"), infos, systemInfo.used_teams);
	for (m = 0; m < systemInfo.used_teams; m++) {
		if (infos[m].team_info.team >= 0) {
			ThreadBarMenu* TeamPopup = new ThreadBarMenu(infos[m].team_name,
				infos[m].team_info.team, infos[m].team_info.thread_count);
			BMessage* kill_team = new BMessage('KlTm');
			kill_team->AddInt32("team", infos[m].team_info.team);
			TeamBarMenuItem* item = new TeamBarMenuItem(TeamPopup, kill_team,
				infos[m].team_info.team, infos[m].team_icon, false);
			item->SetTarget(gPCView);
			CPUPopup->AddItem(item);
		}
	}

	addtopbottom(CPUPopup);
	addtopbottom(new BSeparatorItem());

	// CPU on/off section
	if (gCPUcount > 1) {
		for (int i = 0; i < gCPUcount; i++) {
			char item_name[32];
			sprintf (item_name, B_TRANSLATE("Processor %d"), i + 1);
			BMessage* m = new BMessage ('CPU ');
			m->AddInt32 ("cpu", i);
			item = new IconMenuItem (gPCView->fProcessorIcon, item_name, m);
			if (_kern_cpu_enabled(i))
				item->SetMarked (true);
			item->SetTarget(gPCView);
			addtopbottom(item);
		}
		addtopbottom (new BSeparatorItem ());
	}

	if (!be_roster->IsRunning(kTrackerSig)) {
		item = new IconMenuItem(gPCView->fTrackerIcon,
		B_TRANSLATE("Restart Tracker"), new BMessage('Trac'));
		item->SetTarget(gPCView);
		addtopbottom(item);
	}
	if (!be_roster->IsRunning(kDeskbarSig)) {
		item = new IconMenuItem(gPCView->fDeskbarIcon,
		B_TRANSLATE("Restart Deskbar"), new BMessage('Dbar'));
		item->SetTarget(gPCView);
		addtopbottom(item);
	}

	item = new IconMenuItem(gPCView->fTerminalIcon,
	B_TRANSLATE("New Terminal"), new BMessage('Term'));
	item->SetTarget(gPCView);
	addtopbottom(item);

	addtopbottom(new BSeparatorItem());

	if (be_roster->IsRunning(kDeskbarSig)) {
		item = new BMenuItem(B_TRANSLATE("Live in the Deskbar"),
		new BMessage('AlDb'));
		BDeskbar deskbar;
		item->SetMarked(gInDeskbar || deskbar.HasItem(kDeskbarItemName));
		item->SetTarget(gPCView);
		addtopbottom(item);
		addtopbottom(new BSeparatorItem ());
	}

	item = new IconMenuItem(gPCView->fProcessControllerIcon,
	B_TRANSLATE("About ProcessController"B_UTF8_ELLIPSIS),
		new BMessage(B_ABOUT_REQUESTED));
	item->SetTarget(gPCView);
	addtopbottom(item);

	param->where.x -= 5;
	param->where.y -= 8;
	popup->Go(param->where, true, true, param->clickToOpenRect);

	delete popup;
	for (m = 0; m < systemInfo.used_teams; m++) {
		if (infos[m].team_info.team >= 0) {
			delete[] infos[m].thread_info;
			delete infos[m].team_icon;
		}
	}
	delete[] infos;
	delete param;
	atomic_add (&gPopupFlag, -1);
	gPopupThreadID = 0;

	return B_OK;
}