mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 22:02:44 +00:00 
			
		
		
		
	Inspector: Check if RemoteProcess is_inspectable
				
					
				
			The previous check of looking at `/proc/PID` was not working, it would always fail even if the process was indeed inspectable. Commit 70117781 introduced a new IPC for asking InspectorServer whether or not a given `pid` is actually inspectable. If a process is not inspectable, the `GUI::ProcessChooser` is redisplayed if it was previously displayed, otherwise it exits.
This commit is contained in:
		
							parent
							
								
									00c8b74ab4
								
							
						
					
					
						commit
						fe026fef47
					
				
					 3 changed files with 25 additions and 13 deletions
				
			
		|  | @ -88,6 +88,11 @@ void RemoteProcess::set_property(FlatPtr object, const StringView& name, const J | ||||||
|     m_client->async_set_object_property(m_pid, object, name, value.to_string()); |     m_client->async_set_object_property(m_pid, object, name, value.to_string()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | bool RemoteProcess::is_inspectable() | ||||||
|  | { | ||||||
|  |     return m_client->is_inspectable(m_pid); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void RemoteProcess::update() | void RemoteProcess::update() | ||||||
| { | { | ||||||
|     { |     { | ||||||
|  |  | ||||||
|  | @ -32,6 +32,8 @@ public: | ||||||
| 
 | 
 | ||||||
|     void set_property(FlatPtr object, const StringView& name, const JsonValue& value); |     void set_property(FlatPtr object, const StringView& name, const JsonValue& value); | ||||||
| 
 | 
 | ||||||
|  |     bool is_inspectable(); | ||||||
|  | 
 | ||||||
|     Function<void()> on_update; |     Function<void()> on_update; | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|  |  | ||||||
|  | @ -66,11 +66,13 @@ int main(int argc, char** argv) | ||||||
| 
 | 
 | ||||||
|     unveil(nullptr, nullptr); |     unveil(nullptr, nullptr); | ||||||
| 
 | 
 | ||||||
|  |     bool gui_mode = argc != 2; | ||||||
|     pid_t pid; |     pid_t pid; | ||||||
| 
 | 
 | ||||||
|     auto app = GUI::Application::construct(argc, argv); |     auto app = GUI::Application::construct(argc, argv); | ||||||
|     auto app_icon = GUI::Icon::default_icon("app-inspector"); |     auto app_icon = GUI::Icon::default_icon("app-inspector"); | ||||||
|     if (argc != 2) { |     if (gui_mode) { | ||||||
|  |     choose_pid: | ||||||
|         auto process_chooser = GUI::ProcessChooser::construct("Inspector", "Inspect", app_icon.bitmap_for_size(16)); |         auto process_chooser = GUI::ProcessChooser::construct("Inspector", "Inspect", app_icon.bitmap_for_size(16)); | ||||||
|         if (process_chooser->exec() == GUI::Dialog::ExecCancel) |         if (process_chooser->exec() == GUI::Dialog::ExecCancel) | ||||||
|             return 0; |             return 0; | ||||||
|  | @ -84,21 +86,26 @@ int main(int argc, char** argv) | ||||||
| 
 | 
 | ||||||
|     auto window = GUI::Window::construct(); |     auto window = GUI::Window::construct(); | ||||||
| 
 | 
 | ||||||
|     if (!Desktop::Launcher::add_allowed_handler_with_only_specific_urls( |  | ||||||
|             "/bin/Help", |  | ||||||
|             { URL::create_with_file_protocol("/usr/share/man/man1/Inspector.md") }) |  | ||||||
|         || !Desktop::Launcher::seal_allowlist()) { |  | ||||||
|         warnln("Failed to set up allowed launch URLs"); |  | ||||||
|         return 1; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     if (pid == getpid()) { |     if (pid == getpid()) { | ||||||
|         GUI::MessageBox::show(window, "Cannot inspect Inspector itself!", "Error", GUI::MessageBox::Type::Error); |         GUI::MessageBox::show(window, "Cannot inspect Inspector itself!", "Error", GUI::MessageBox::Type::Error); | ||||||
|         return 1; |         return 1; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (access(String::formatted("/proc/{}", pid).characters(), R_OK) == -1) { |     RemoteProcess remote_process(pid); | ||||||
|         GUI::MessageBox::show(window, "Inspector doesn't have permission to access the process.", "Error", GUI::MessageBox::Type::Error); |     if (!remote_process.is_inspectable()) { | ||||||
|  |         GUI::MessageBox::show(window, String::formatted("Process pid={} is not inspectable", remote_process.pid()), "Error", GUI::MessageBox::Type::Error); | ||||||
|  |         if (gui_mode) { | ||||||
|  |             goto choose_pid; | ||||||
|  |         } else { | ||||||
|  |             return 1; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if (!Desktop::Launcher::add_allowed_handler_with_only_specific_urls( | ||||||
|  |             "/bin/Help", | ||||||
|  |             { URL::create_with_file_protocol("/usr/share/man/man1/Inspector.md") }) | ||||||
|  |         || !Desktop::Launcher::seal_allowlist()) { | ||||||
|  |         warnln("Failed to set up allowed launch URLs"); | ||||||
|         return 1; |         return 1; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -123,8 +130,6 @@ int main(int argc, char** argv) | ||||||
| 
 | 
 | ||||||
|     auto& splitter = widget.add<GUI::HorizontalSplitter>(); |     auto& splitter = widget.add<GUI::HorizontalSplitter>(); | ||||||
| 
 | 
 | ||||||
|     RemoteProcess remote_process(pid); |  | ||||||
| 
 |  | ||||||
|     remote_process.on_update = [&] { |     remote_process.on_update = [&] { | ||||||
|         if (!remote_process.process_name().is_null()) |         if (!remote_process.process_name().is_null()) | ||||||
|             window->set_title(String::formatted("{} ({}) - Inspector", remote_process.process_name(), remote_process.pid())); |             window->set_title(String::formatted("{} ({}) - Inspector", remote_process.process_name(), remote_process.pid())); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Matthew Jones
						Matthew Jones