示例#1
0
文件: haiku-nat.c 项目: mariuz/haiku
static void
haiku_init_thread_list(team_debug_info *teamDebugInfo)
{
	thread_info threadInfo;
	int32 cookie = 0;

	// init gdb's thread DB
	init_thread_list();

	while (get_next_thread_info(teamDebugInfo->team, &cookie, &threadInfo)
		== B_OK) {
		if (threadInfo.thread != teamDebugInfo->nub_thread)
			haiku_add_thread(teamDebugInfo, threadInfo.thread);
	}
}
status_t
LocalDebuggerInterface::GetThreadInfos(BObjectList<ThreadInfo>& infos)
{
	thread_info threadInfo;
	int32 cookie = 0;
	while (get_next_thread_info(fTeamID, &cookie, &threadInfo) == B_OK) {
		ThreadInfo* info = new(std::nothrow) ThreadInfo(threadInfo.team,
			threadInfo.thread, threadInfo.name);
		if (info == NULL || !infos.AddItem(info)) {
			delete info;
			return B_NO_MEMORY;
		}
	}

	return B_OK;
}
示例#3
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;
      }
   }
示例#4
0
文件: ps.c 项目: DonCN/haiku
static void
printTeamThreads(team_info* teamInfo, bool printSemaphoreInfo)
{
	const char* threadState;
	int32 threadCookie = 0;
	sem_info semaphoreInfo;
	thread_info threadInfo;

	// Print all info about its threads too
	while (get_next_thread_info(teamInfo->team, &threadCookie, &threadInfo)
		>= B_OK) {
		if (threadInfo.state < B_THREAD_RUNNING
			|| threadInfo.state > B_THREAD_WAITING)
			// This should never happen
			threadState = "???";
		else
			threadState = sStates[threadInfo.state - 1];

		printf("%-37s %5" B_PRId32 " %8s %4" B_PRId32 " %8" B_PRIu64 " %8"
			B_PRId64 " ", threadInfo.name, threadInfo.thread, threadState,
			threadInfo.priority, (threadInfo.user_time / 1000),
			(threadInfo.kernel_time / 1000));

		if (printSemaphoreInfo) {
			if (threadInfo.state == B_THREAD_WAITING && threadInfo.sem != -1) {
				status_t status = get_sem_info(threadInfo.sem, &semaphoreInfo);
				if (status == B_OK) {
					printf("%s(%" B_PRId32 ")\n", semaphoreInfo.name,
						semaphoreInfo.sem);
				} else {
					printf("%s(%" B_PRId32 ")\n", strerror(status),
						threadInfo.sem);
				}
			} else
				puts("");
		} else
			puts("");
	}
}
示例#5
0
int32 VisionApp::ThreadStates(void)
{
	thread_id team(Team());
	int32 cookie(0);
	thread_info info;

	BString buffer;
	int32 t_count(0);

	while (get_next_thread_info(team, &cookie, &info) == B_NO_ERROR) {
		// wake up any threads that're snoozing for their next reconnect run
		if (strstr(info.name, "s>") != NULL) {
			switch (info.state) {
			case B_THREAD_ASLEEP:
				suspend_thread(info.thread);
			// fall through
			case B_THREAD_SUSPENDED:
				resume_thread(info.thread);
				break;
			default:
				break;
			}
		}

		if (fDebugShutdown) {
			buffer += "thread: ";
			buffer << info.thread;
			buffer += " name:  ";
			buffer += info.name;
			buffer += " state: ";

			switch ((int32)info.state) {
			case B_THREAD_RUNNING:
				buffer += "running\n";
				break;

			case B_THREAD_READY:
				buffer += "ready\n";
				break;

			case B_THREAD_RECEIVING:
				buffer += "receiving\n";
				break;

			case B_THREAD_ASLEEP:
				buffer += "asleep\n";
				break;

			case B_THREAD_SUSPENDED:
				buffer += "suspended\n";
				break;

			case B_THREAD_WAITING:
				buffer += "waiting\n";
				break;

			default:
				buffer += "???\n";
			}
		}
		++t_count;
	}

	if (fDebugShutdown && buffer.Length()) {
		printf("%s\n", buffer.String());
#if 0
    BAlert *alert (new BAlert (
      "Too many threads",
      buffer.String(),
      t_count > 1 ? "Damn" : "Cool",
      0,
      0,
      B_WIDTH_AS_USUAL,
      t_count > 1 ? B_STOP_ALERT : B_INFO_ALERT));
      alert->Go();
#endif
	}

	return t_count;
}
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;
}
示例#7
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();
}
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;
}
示例#9
0
void
FolderShaper::WaitForOpeningFolder(const entry_ref * a_ref)	
{
	PRINT(("WaitForOpeningFolder()\n"));

	status_t	status;
//	int32		count = 0;
		
	BMessenger	tracker_messgr(FS_TRACKER_SIGNATURE);
	
//	snooze loop for thread
	PRINT(("## snooze loop for thread ##\n"));
	
	BString thread_name;
	BString ref_name;

	int32	cookie = 0;
	bool 	got_thread = false;
			
	team_id  my_team_id  =	tracker_messgr.Team();
	if (my_team_id != B_NAME_NOT_FOUND)
	{
		thread_info	info;
		
		for (int j = 0; j < 250; j++)
		{
			PRINT(("**************************************\n"));
			cookie = 0;
			
			while (get_next_thread_info(my_team_id, &cookie, &info) == B_OK)
			{
				thread_name	= 	info.name;
				ref_name	=	a_ref->name;
				ref_name.Prepend("w>");
				
				PRINT(("thread: %s\n", thread_name.String()));
				
				if (thread_name == ref_name)
				{
					got_thread = true;
					PRINT(("got thread %s\n", thread_name.String()));
					break;
				}	
			}
			
			if (got_thread)
				break;
			snooze(20000);
		}
	}
	else
	{
		PRINT(("Error: Could not set up BMessenger to Tracker!\n"));
		snooze(1000000);	// if no contact, snooze 1/10 sec
		return;				// then return
	}

//	snooze loop for window (Tr. scripting)
	PRINT(("## snooze loop for Tracker window ##\n"));
	
	bool got_window = false;
	
	for (int j = 0; j < 250; j++)
	{
		PRINT(("**************************************\n"));
		PRINT(("window snooze (%d)\n", j));
		
		if (IsFolderOpen(a_ref))
		{
			PRINT(("Tracker window is open.\n"));
			got_window = true;
			break;
		}
			
		snooze(20000);
	}

	if (! got_window)
	{
		PRINT(("Error: Tracker window did not open even though we snoozed quite some time!\n"));
		snooze(1000000);	// if no contact, snooze 1/10 sec
		return;				// then return
	}
	
//	snooze loop for contents loading
	PRINT(("## snooze loop for window contents ##\n"));

	BMessage	get_win_msg(B_GET_PROPERTY);
	BMessage	reply;
	
	entry_ref 	windowRef;
	BDirectory	window_dir;

	int32		dir_entry_count		=	0;
	int32		window_poses_count	=	0;
		
	int32	win_count = 0;
	for(win_count = 1; win_count < 1000; win_count++)
	{
		get_win_msg.MakeEmpty();
		get_win_msg.what = B_GET_PROPERTY;
		get_win_msg.AddSpecifier("Path");
		get_win_msg.AddSpecifier("Poses");
		get_win_msg.AddSpecifier("Window", win_count);
		
		reply.MakeEmpty();
		if((status = tracker_messgr.SendMessage(&get_win_msg, &reply)) != B_OK)
		{	ErrorMessage("Error: Invalid Reply From Tracker!\n", status);	return; }
	
		if((status = reply.FindRef("result", &windowRef)) != B_OK)
		{	PRINT(("(%ld) Error -- no windowRef: %s)\n", win_count, strerror(status))); }		
		
		if(*a_ref == windowRef)
		{
			PRINT(("That's the window! (win_count: %ld)\n", win_count));
			window_dir.SetTo(&windowRef);
			break;
		}
	}

// snooze loop for matching BDir entry count and BWindow poses count

	BMessage count_msg	(B_COUNT_PROPERTIES);
	count_msg.AddSpecifier("Entry");
	count_msg.AddSpecifier("Poses");
	count_msg.AddSpecifier("Window", win_count);

	dir_entry_count	=	window_dir.CountEntries();

	bool got_match = false;
	for (int j = 0; j < 200; j++)
	{
		PRINT(("**************************************\n"));
		PRINT(("try match (%d)\n", j));

		reply.MakeEmpty();	

		if ((status = tracker_messgr.SendMessage(&count_msg, &reply)) != B_OK)
		PRINT(("Error: Invalid Reply From Tracker!\n"));

		if (reply.FindInt32("result", & window_poses_count) == B_OK
			&& window_poses_count	==	dir_entry_count)
		{
			PRINT((" woohoo !\n"));
			got_match = true;
			break;
		}
		
		PRINT(("dir_entry_count: %ld\n", dir_entry_count));
		PRINT(("window_poses_count: %ld\n", window_poses_count));
			
		snooze(100000);
	}

	if (! got_match)
	{
		PRINT(("Error: BDir entries and BWindow poses did not match up.\n"));
		snooze(1000000);	// if no match, snooze 1/10 sec
		return;				// then return
	}
}
示例#10
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 );
	}
示例#11
0
/* be_sys_init:
 */
extern "C" int be_sys_init(void)
{
    int32       cookie;
    thread_info info;
    struct utsname os_name;
    char path[MAXPATHLEN];

    cookie = 0;

    if (get_next_thread_info(0, &cookie, &info) == B_OK) {
        main_thread_id = info.thread;
    }
    else {
        goto cleanup;
    }

    _be_mouse_view_attached = create_sem(0, "waiting for mouse view attach...");

    if (_be_mouse_view_attached < 0) {
        goto cleanup;
    }

    _be_sound_stream_lock = create_sem(1, "audiostream lock");

    if (_be_sound_stream_lock < 0) {
        goto cleanup;
    }

    system_started = create_sem(0, "starting system driver...");

    if(system_started < 0) {
        goto cleanup;
    }

    system_thread_id = spawn_thread(system_thread, SYS_THREAD_NAME,
                                    SYS_THREAD_PRIORITY, NULL);

    if (system_thread_id < 0) {
        goto cleanup;
    }

    resume_thread(system_thread_id);
    acquire_sem(system_started);
    delete_sem(system_started);

    uname(&os_name);
    os_type = OSTYPE_BEOS;
    os_multitasking = TRUE;

    chdir(app_path);

    _be_sys_get_executable_name(path, sizeof(path));
    path[sizeof(path)-1] = '\0';
    do_uconvert(get_filename(path), U_CURRENT, wnd_title, U_UTF8, WND_TITLE_SIZE);

    return 0;

cleanup: {
        be_sys_exit();
        return 1;
    }
}
示例#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;
}
示例#13
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;
}