mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 11:12:45 +00:00 
			
		
		
		
	HackStudio: Use Core::System APIs where possible
This commit is contained in:
		
							parent
							
								
									16543a1918
								
							
						
					
					
						commit
						336b8ed80b
					
				
					 4 changed files with 23 additions and 15 deletions
				
			
		|  | @ -480,11 +480,12 @@ void Editor::set_document(GUI::TextDocument& doc) | ||||||
|         // Otherwise, if the file has already been opened before in some Editor instance, it should exist in the LanguageServer's
 |         // Otherwise, if the file has already been opened before in some Editor instance, it should exist in the LanguageServer's
 | ||||||
|         // FileDB, and the LanguageServer should already have its up-to-date content.
 |         // FileDB, and the LanguageServer should already have its up-to-date content.
 | ||||||
|         // So it's OK to just pass an fd here (rather than the TextDocument's content).
 |         // So it's OK to just pass an fd here (rather than the TextDocument's content).
 | ||||||
|         int fd = open(code_document.file_path().characters(), O_RDONLY | O_NOCTTY); |         auto maybe_fd = Core::System::open(code_document.file_path(), O_RDONLY | O_NOCTTY); | ||||||
|         if (fd < 0) { |         if (maybe_fd.is_error()) { | ||||||
|             perror("open"); |             warnln("Failed to open `{}`: {}", code_document.file_path(), maybe_fd.release_error()); | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |         auto fd = maybe_fd.release_value(); | ||||||
|         m_language_client->open_file(code_document.file_path(), fd); |         m_language_client->open_file(code_document.file_path(), fd); | ||||||
|         close(fd); |         close(fd); | ||||||
|     } else { |     } else { | ||||||
|  |  | ||||||
|  | @ -239,8 +239,8 @@ void HackStudioWidget::open_project(ByteString const& root_path) | ||||||
| { | { | ||||||
|     if (warn_unsaved_changes("There are unsaved changes, do you want to save before closing current project?") == ContinueDecision::No) |     if (warn_unsaved_changes("There are unsaved changes, do you want to save before closing current project?") == ContinueDecision::No) | ||||||
|         return; |         return; | ||||||
|     if (chdir(root_path.characters()) < 0) { |     if (auto result = Core::System::chdir(root_path); result.is_error()) { | ||||||
|         perror("chdir"); |         warnln("Failed to open project: {}", result.release_error()); | ||||||
|         exit(1); |         exit(1); | ||||||
|     } |     } | ||||||
|     if (m_project) { |     if (m_project) { | ||||||
|  | @ -1024,7 +1024,7 @@ ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_debug_action() | ||||||
|         // The debugger calls wait() on the debuggee, so the TerminalWrapper can't do that.
 |         // The debugger calls wait() on the debuggee, so the TerminalWrapper can't do that.
 | ||||||
|         auto ptm_res = m_terminal_wrapper->setup_master_pseudoterminal(TerminalWrapper::WaitForChildOnExit::No); |         auto ptm_res = m_terminal_wrapper->setup_master_pseudoterminal(TerminalWrapper::WaitForChildOnExit::No); | ||||||
|         if (ptm_res.is_error()) { |         if (ptm_res.is_error()) { | ||||||
|             perror("setup_master_pseudoterminal"); |             warnln("Failed to set up master pseudoterminal: {}", ptm_res.release_error()); | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -29,12 +29,12 @@ void ConnectionFromClient::die() | ||||||
| void ConnectionFromClient::greet(ByteString const& project_root) | void ConnectionFromClient::greet(ByteString const& project_root) | ||||||
| { | { | ||||||
|     m_filedb.set_project_root(project_root); |     m_filedb.set_project_root(project_root); | ||||||
|     if (unveil(project_root.characters(), "r") < 0) { |     if (auto result = Core::System::unveil(project_root, "r"sv); result.is_error()) { | ||||||
|         perror("unveil"); |         warnln("Failed to unveil `{}`: {}", project_root, result.error()); | ||||||
|         exit(1); |         exit(1); | ||||||
|     } |     } | ||||||
|     if (unveil(nullptr, nullptr) < 0) { |     if (auto result = Core::System::unveil(nullptr, nullptr); result.is_error()) { | ||||||
|         perror("unveil"); |         warnln("Failed to lock the veil: {}", result.error()); | ||||||
|         exit(1); |         exit(1); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -93,18 +93,25 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
| 
 | 
 | ||||||
| static bool make_is_available() | static bool make_is_available() | ||||||
| { | { | ||||||
|     pid_t pid; |  | ||||||
|     char const* argv[] = { "make", "--version", nullptr }; |     char const* argv[] = { "make", "--version", nullptr }; | ||||||
|     posix_spawn_file_actions_t action; |     posix_spawn_file_actions_t action; | ||||||
|     posix_spawn_file_actions_init(&action); |     posix_spawn_file_actions_init(&action); | ||||||
|     posix_spawn_file_actions_addopen(&action, STDOUT_FILENO, "/dev/null", O_WRONLY, 0); |     posix_spawn_file_actions_addopen(&action, STDOUT_FILENO, "/dev/null", O_WRONLY, 0); | ||||||
| 
 | 
 | ||||||
|     if ((errno = posix_spawnp(&pid, "make", &action, nullptr, const_cast<char**>(argv), environ))) { |     auto maybe_pid = Core::System::posix_spawnp("make"sv, &action, nullptr, const_cast<char**>(argv), environ); | ||||||
|         perror("posix_spawn"); |     if (maybe_pid.is_error()) { | ||||||
|  |         warnln("Failed to posix_spawn make: {}", maybe_pid.release_error()); | ||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|     int wstatus; |     pid_t pid = maybe_pid.release_value(); | ||||||
|     waitpid(pid, &wstatus, 0); | 
 | ||||||
|  |     auto waitpid_result = Core::System::waitpid(pid, 0); | ||||||
|  |     if (waitpid_result.is_error()) { | ||||||
|  |         warnln("Failed to waitpid for make: {}", waitpid_result.release_error()); | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     int wstatus = waitpid_result.value().status; | ||||||
|     posix_spawn_file_actions_destroy(&action); |     posix_spawn_file_actions_destroy(&action); | ||||||
|     return WEXITSTATUS(wstatus) == 0; |     return WEXITSTATUS(wstatus) == 0; | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Sam Atkins
						Sam Atkins