os_linuxbsd.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /*************************************************************************/
  2. /* os_linuxbsd.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "os_linuxbsd.h"
  31. #include "core/io/dir_access.h"
  32. #include "main/main.h"
  33. #include "servers/display_server.h"
  34. #ifdef X11_ENABLED
  35. #include "display_server_x11.h"
  36. #endif
  37. #ifdef HAVE_MNTENT
  38. #include <mntent.h>
  39. #endif
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43. #include <dlfcn.h>
  44. #include <fcntl.h>
  45. #include <sys/stat.h>
  46. #include <sys/types.h>
  47. #include <unistd.h>
  48. void OS_LinuxBSD::alert(const String &p_alert, const String &p_title) {
  49. const char *message_programs[] = { "zenity", "kdialog", "Xdialog", "xmessage" };
  50. String path = get_environment("PATH");
  51. Vector<String> path_elems = path.split(":", false);
  52. String program;
  53. for (int i = 0; i < path_elems.size(); i++) {
  54. for (uint64_t k = 0; k < sizeof(message_programs) / sizeof(char *); k++) {
  55. String tested_path = path_elems[i].plus_file(message_programs[k]);
  56. if (FileAccess::exists(tested_path)) {
  57. program = tested_path;
  58. break;
  59. }
  60. }
  61. if (program.length()) {
  62. break;
  63. }
  64. }
  65. List<String> args;
  66. if (program.ends_with("zenity")) {
  67. args.push_back("--error");
  68. args.push_back("--width");
  69. args.push_back("500");
  70. args.push_back("--title");
  71. args.push_back(p_title);
  72. args.push_back("--text");
  73. args.push_back(p_alert);
  74. }
  75. if (program.ends_with("kdialog")) {
  76. args.push_back("--error");
  77. args.push_back(p_alert);
  78. args.push_back("--title");
  79. args.push_back(p_title);
  80. }
  81. if (program.ends_with("Xdialog")) {
  82. args.push_back("--title");
  83. args.push_back(p_title);
  84. args.push_back("--msgbox");
  85. args.push_back(p_alert);
  86. args.push_back("0");
  87. args.push_back("0");
  88. }
  89. if (program.ends_with("xmessage")) {
  90. args.push_back("-center");
  91. args.push_back("-title");
  92. args.push_back(p_title);
  93. args.push_back(p_alert);
  94. }
  95. if (program.length()) {
  96. execute(program, args);
  97. } else {
  98. print_line(p_alert);
  99. }
  100. }
  101. void OS_LinuxBSD::initialize() {
  102. crash_handler.initialize();
  103. OS_Unix::initialize_core();
  104. }
  105. void OS_LinuxBSD::initialize_joypads() {
  106. #ifdef JOYDEV_ENABLED
  107. joypad = memnew(JoypadLinux(Input::get_singleton()));
  108. #endif
  109. }
  110. String OS_LinuxBSD::get_unique_id() const {
  111. static String machine_id;
  112. if (machine_id.is_empty()) {
  113. Ref<FileAccess> f = FileAccess::open("/etc/machine-id", FileAccess::READ);
  114. if (f.is_valid()) {
  115. while (machine_id.is_empty() && !f->eof_reached()) {
  116. machine_id = f->get_line().strip_edges();
  117. }
  118. }
  119. }
  120. return machine_id;
  121. }
  122. String OS_LinuxBSD::get_processor_name() const {
  123. Ref<FileAccess> f = FileAccess::open("/proc/cpuinfo", FileAccess::READ);
  124. ERR_FAIL_COND_V_MSG(f.is_null(), "", String("Couldn't open `/proc/cpuinfo` to get the CPU model name. Returning an empty string."));
  125. while (!f->eof_reached()) {
  126. const String line = f->get_line();
  127. if (line.find("model name") != -1) {
  128. return line.split(":")[1].strip_edges();
  129. }
  130. }
  131. ERR_FAIL_V_MSG("", String("Couldn't get the CPU model name from `/proc/cpuinfo`. Returning an empty string."));
  132. }
  133. void OS_LinuxBSD::finalize() {
  134. if (main_loop) {
  135. memdelete(main_loop);
  136. }
  137. main_loop = nullptr;
  138. #ifdef ALSAMIDI_ENABLED
  139. driver_alsamidi.close();
  140. #endif
  141. #ifdef JOYDEV_ENABLED
  142. if (joypad) {
  143. memdelete(joypad);
  144. }
  145. #endif
  146. }
  147. MainLoop *OS_LinuxBSD::get_main_loop() const {
  148. return main_loop;
  149. }
  150. void OS_LinuxBSD::delete_main_loop() {
  151. if (main_loop) {
  152. memdelete(main_loop);
  153. }
  154. main_loop = nullptr;
  155. }
  156. void OS_LinuxBSD::set_main_loop(MainLoop *p_main_loop) {
  157. main_loop = p_main_loop;
  158. }
  159. String OS_LinuxBSD::get_name() const {
  160. #ifdef __linux__
  161. return "Linux";
  162. #elif defined(__FreeBSD__)
  163. return "FreeBSD";
  164. #elif defined(__NetBSD__)
  165. return "NetBSD";
  166. #elif defined(__OpenBSD__)
  167. return "OpenBSD";
  168. #else
  169. return "BSD";
  170. #endif
  171. }
  172. Error OS_LinuxBSD::shell_open(String p_uri) {
  173. Error ok;
  174. int err_code;
  175. List<String> args;
  176. args.push_back(p_uri);
  177. // Agnostic
  178. ok = execute("xdg-open", args, nullptr, &err_code);
  179. if (ok == OK && !err_code) {
  180. return OK;
  181. } else if (err_code == 2) {
  182. return ERR_FILE_NOT_FOUND;
  183. }
  184. // GNOME
  185. args.push_front("open"); // The command is `gio open`, so we need to add it to args
  186. ok = execute("gio", args, nullptr, &err_code);
  187. if (ok == OK && !err_code) {
  188. return OK;
  189. } else if (err_code == 2) {
  190. return ERR_FILE_NOT_FOUND;
  191. }
  192. args.pop_front();
  193. ok = execute("gvfs-open", args, nullptr, &err_code);
  194. if (ok == OK && !err_code) {
  195. return OK;
  196. } else if (err_code == 2) {
  197. return ERR_FILE_NOT_FOUND;
  198. }
  199. // KDE
  200. ok = execute("kde-open5", args, nullptr, &err_code);
  201. if (ok == OK && !err_code) {
  202. return OK;
  203. }
  204. ok = execute("kde-open", args, nullptr, &err_code);
  205. return !err_code ? ok : FAILED;
  206. }
  207. bool OS_LinuxBSD::_check_internal_feature_support(const String &p_feature) {
  208. return p_feature == "pc";
  209. }
  210. uint64_t OS_LinuxBSD::get_embedded_pck_offset() const {
  211. Ref<FileAccess> f = FileAccess::open(get_executable_path(), FileAccess::READ);
  212. if (f.is_null()) {
  213. return 0;
  214. }
  215. // Read and check ELF magic number.
  216. {
  217. uint32_t magic = f->get_32();
  218. if (magic != 0x464c457f) { // 0x7F + "ELF"
  219. return 0;
  220. }
  221. }
  222. // Read program architecture bits from class field.
  223. int bits = f->get_8() * 32;
  224. // Get info about the section header table.
  225. int64_t section_table_pos;
  226. int64_t section_header_size;
  227. if (bits == 32) {
  228. section_header_size = 40;
  229. f->seek(0x20);
  230. section_table_pos = f->get_32();
  231. f->seek(0x30);
  232. } else { // 64
  233. section_header_size = 64;
  234. f->seek(0x28);
  235. section_table_pos = f->get_64();
  236. f->seek(0x3c);
  237. }
  238. int num_sections = f->get_16();
  239. int string_section_idx = f->get_16();
  240. // Load the strings table.
  241. uint8_t *strings;
  242. {
  243. // Jump to the strings section header.
  244. f->seek(section_table_pos + string_section_idx * section_header_size);
  245. // Read strings data size and offset.
  246. int64_t string_data_pos;
  247. int64_t string_data_size;
  248. if (bits == 32) {
  249. f->seek(f->get_position() + 0x10);
  250. string_data_pos = f->get_32();
  251. string_data_size = f->get_32();
  252. } else { // 64
  253. f->seek(f->get_position() + 0x18);
  254. string_data_pos = f->get_64();
  255. string_data_size = f->get_64();
  256. }
  257. // Read strings data.
  258. f->seek(string_data_pos);
  259. strings = (uint8_t *)memalloc(string_data_size);
  260. if (!strings) {
  261. return 0;
  262. }
  263. f->get_buffer(strings, string_data_size);
  264. }
  265. // Search for the "pck" section.
  266. int64_t off = 0;
  267. for (int i = 0; i < num_sections; ++i) {
  268. int64_t section_header_pos = section_table_pos + i * section_header_size;
  269. f->seek(section_header_pos);
  270. uint32_t name_offset = f->get_32();
  271. if (strcmp((char *)strings + name_offset, "pck") == 0) {
  272. if (bits == 32) {
  273. f->seek(section_header_pos + 0x10);
  274. off = f->get_32();
  275. } else { // 64
  276. f->seek(section_header_pos + 0x18);
  277. off = f->get_64();
  278. }
  279. break;
  280. }
  281. }
  282. memfree(strings);
  283. return off;
  284. }
  285. String OS_LinuxBSD::get_config_path() const {
  286. if (has_environment("XDG_CONFIG_HOME")) {
  287. if (get_environment("XDG_CONFIG_HOME").is_absolute_path()) {
  288. return get_environment("XDG_CONFIG_HOME");
  289. } else {
  290. WARN_PRINT_ONCE("`XDG_CONFIG_HOME` is a relative path. Ignoring its value and falling back to `$HOME/.config` or `.` per the XDG Base Directory specification.");
  291. return has_environment("HOME") ? get_environment("HOME").plus_file(".config") : ".";
  292. }
  293. } else if (has_environment("HOME")) {
  294. return get_environment("HOME").plus_file(".config");
  295. } else {
  296. return ".";
  297. }
  298. }
  299. String OS_LinuxBSD::get_data_path() const {
  300. if (has_environment("XDG_DATA_HOME")) {
  301. if (get_environment("XDG_DATA_HOME").is_absolute_path()) {
  302. return get_environment("XDG_DATA_HOME");
  303. } else {
  304. WARN_PRINT_ONCE("`XDG_DATA_HOME` is a relative path. Ignoring its value and falling back to `$HOME/.local/share` or `get_config_path()` per the XDG Base Directory specification.");
  305. return has_environment("HOME") ? get_environment("HOME").plus_file(".local/share") : get_config_path();
  306. }
  307. } else if (has_environment("HOME")) {
  308. return get_environment("HOME").plus_file(".local/share");
  309. } else {
  310. return get_config_path();
  311. }
  312. }
  313. String OS_LinuxBSD::get_cache_path() const {
  314. if (has_environment("XDG_CACHE_HOME")) {
  315. if (get_environment("XDG_CACHE_HOME").is_absolute_path()) {
  316. return get_environment("XDG_CACHE_HOME");
  317. } else {
  318. WARN_PRINT_ONCE("`XDG_CACHE_HOME` is a relative path. Ignoring its value and falling back to `$HOME/.cache` or `get_config_path()` per the XDG Base Directory specification.");
  319. return has_environment("HOME") ? get_environment("HOME").plus_file(".cache") : get_config_path();
  320. }
  321. } else if (has_environment("HOME")) {
  322. return get_environment("HOME").plus_file(".cache");
  323. } else {
  324. return get_config_path();
  325. }
  326. }
  327. String OS_LinuxBSD::get_system_dir(SystemDir p_dir, bool p_shared_storage) const {
  328. String xdgparam;
  329. switch (p_dir) {
  330. case SYSTEM_DIR_DESKTOP: {
  331. xdgparam = "DESKTOP";
  332. } break;
  333. case SYSTEM_DIR_DCIM: {
  334. xdgparam = "PICTURES";
  335. } break;
  336. case SYSTEM_DIR_DOCUMENTS: {
  337. xdgparam = "DOCUMENTS";
  338. } break;
  339. case SYSTEM_DIR_DOWNLOADS: {
  340. xdgparam = "DOWNLOAD";
  341. } break;
  342. case SYSTEM_DIR_MOVIES: {
  343. xdgparam = "VIDEOS";
  344. } break;
  345. case SYSTEM_DIR_MUSIC: {
  346. xdgparam = "MUSIC";
  347. } break;
  348. case SYSTEM_DIR_PICTURES: {
  349. xdgparam = "PICTURES";
  350. } break;
  351. case SYSTEM_DIR_RINGTONES: {
  352. xdgparam = "MUSIC";
  353. } break;
  354. }
  355. String pipe;
  356. List<String> arg;
  357. arg.push_back(xdgparam);
  358. Error err = const_cast<OS_LinuxBSD *>(this)->execute("xdg-user-dir", arg, &pipe);
  359. if (err != OK) {
  360. return ".";
  361. }
  362. return pipe.strip_edges();
  363. }
  364. void OS_LinuxBSD::run() {
  365. force_quit = false;
  366. if (!main_loop) {
  367. return;
  368. }
  369. main_loop->initialize();
  370. //uint64_t last_ticks=get_ticks_usec();
  371. //int frames=0;
  372. //uint64_t frame=0;
  373. while (!force_quit) {
  374. DisplayServer::get_singleton()->process_events(); // get rid of pending events
  375. #ifdef JOYDEV_ENABLED
  376. joypad->process_joypads();
  377. #endif
  378. if (Main::iteration()) {
  379. break;
  380. }
  381. }
  382. main_loop->finalize();
  383. }
  384. void OS_LinuxBSD::disable_crash_handler() {
  385. crash_handler.disable();
  386. }
  387. bool OS_LinuxBSD::is_disable_crash_handler() const {
  388. return crash_handler.is_disabled();
  389. }
  390. static String get_mountpoint(const String &p_path) {
  391. struct stat s;
  392. if (stat(p_path.utf8().get_data(), &s)) {
  393. return "";
  394. }
  395. #ifdef HAVE_MNTENT
  396. dev_t dev = s.st_dev;
  397. FILE *fd = setmntent("/proc/mounts", "r");
  398. if (!fd) {
  399. return "";
  400. }
  401. struct mntent mnt;
  402. char buf[1024];
  403. size_t buflen = 1024;
  404. while (getmntent_r(fd, &mnt, buf, buflen)) {
  405. if (!stat(mnt.mnt_dir, &s) && s.st_dev == dev) {
  406. endmntent(fd);
  407. return String(mnt.mnt_dir);
  408. }
  409. }
  410. endmntent(fd);
  411. #endif
  412. return "";
  413. }
  414. Error OS_LinuxBSD::move_to_trash(const String &p_path) {
  415. String path = p_path.rstrip("/"); // Strip trailing slash when path points to a directory
  416. int err_code;
  417. List<String> args;
  418. args.push_back(path);
  419. args.push_front("trash"); // The command is `gio trash <file_name>` so we need to add it to args.
  420. Error result = execute("gio", args, nullptr, &err_code); // For GNOME based machines.
  421. if (result == OK && !err_code) {
  422. return OK;
  423. } else if (err_code == 2) {
  424. return ERR_FILE_NOT_FOUND;
  425. }
  426. args.pop_front();
  427. args.push_front("move");
  428. args.push_back("trash:/"); // The command is `kioclient5 move <file_name> trash:/`.
  429. result = execute("kioclient5", args, nullptr, &err_code); // For KDE based machines.
  430. if (result == OK && !err_code) {
  431. return OK;
  432. } else if (err_code == 2) {
  433. return ERR_FILE_NOT_FOUND;
  434. }
  435. args.pop_front();
  436. args.pop_back();
  437. result = execute("gvfs-trash", args, nullptr, &err_code); // For older Linux machines.
  438. if (result == OK && !err_code) {
  439. return OK;
  440. } else if (err_code == 2) {
  441. return ERR_FILE_NOT_FOUND;
  442. }
  443. // If the commands `kioclient5`, `gio` or `gvfs-trash` don't exist on the system we do it manually.
  444. String trash_path = "";
  445. String mnt = get_mountpoint(path);
  446. // If there is a directory "[Mountpoint]/.Trash-[UID], use it as the trash can.
  447. if (!mnt.is_empty()) {
  448. String mountpoint_trash_path(mnt + "/.Trash-" + itos(getuid()));
  449. struct stat s;
  450. if (!stat(mountpoint_trash_path.utf8().get_data(), &s)) {
  451. trash_path = mountpoint_trash_path;
  452. }
  453. }
  454. // Otherwise, if ${XDG_DATA_HOME} is defined, use "${XDG_DATA_HOME}/Trash" as the trash can.
  455. if (trash_path.is_empty()) {
  456. char *dhome = getenv("XDG_DATA_HOME");
  457. if (dhome) {
  458. trash_path = String::utf8(dhome) + "/Trash";
  459. }
  460. }
  461. // Otherwise, if ${HOME} is defined, use "${HOME}/.local/share/Trash" as the trash can.
  462. if (trash_path.is_empty()) {
  463. char *home = getenv("HOME");
  464. if (home) {
  465. trash_path = String::utf8(home) + "/.local/share/Trash";
  466. }
  467. }
  468. // Issue an error if none of the previous locations is appropriate for the trash can.
  469. ERR_FAIL_COND_V_MSG(trash_path.is_empty(), FAILED, "Could not determine the trash can location");
  470. // Create needed directories for decided trash can location.
  471. {
  472. Ref<DirAccess> dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  473. Error err = dir_access->make_dir_recursive(trash_path);
  474. // Issue an error if trash can is not created properly.
  475. ERR_FAIL_COND_V_MSG(err != OK, err, "Could not create the trash path \"" + trash_path + "\"");
  476. err = dir_access->make_dir_recursive(trash_path + "/files");
  477. ERR_FAIL_COND_V_MSG(err != OK, err, "Could not create the trash path \"" + trash_path + "/files\"");
  478. err = dir_access->make_dir_recursive(trash_path + "/info");
  479. ERR_FAIL_COND_V_MSG(err != OK, err, "Could not create the trash path \"" + trash_path + "/info\"");
  480. }
  481. // The trash can is successfully created, now we check that we don't exceed our file name length limit.
  482. // If the file name is too long trim it so we can add the identifying number and ".trashinfo".
  483. // Assumes that the file name length limit is 255 characters.
  484. String file_name = path.get_file();
  485. if (file_name.length() > 240) {
  486. file_name = file_name.substr(0, file_name.length() - 15);
  487. }
  488. String dest_path = trash_path + "/files/" + file_name;
  489. struct stat buff;
  490. int id_number = 0;
  491. String fn = file_name;
  492. // Checks if a resource with the same name already exist in the trash can,
  493. // if there is, add an identifying number to our resource's name.
  494. while (stat(dest_path.utf8().get_data(), &buff) == 0) {
  495. id_number++;
  496. // Added a limit to check for identically named files already on the trash can
  497. // if there are too many it could make the editor unresponsive.
  498. ERR_FAIL_COND_V_MSG(id_number > 99, FAILED, "Too many identically named resources already in the trash can.");
  499. fn = file_name + "." + itos(id_number);
  500. dest_path = trash_path + "/files/" + fn;
  501. }
  502. file_name = fn;
  503. String renamed_path = path.get_base_dir() + "/" + file_name;
  504. // Generates the .trashinfo file
  505. OS::Date date = OS::get_singleton()->get_date(false);
  506. OS::Time time = OS::get_singleton()->get_time(false);
  507. String timestamp = vformat("%04d-%02d-%02dT%02d:%02d:", date.year, (int)date.month, date.day, time.hour, time.minute);
  508. timestamp = vformat("%s%02d", timestamp, time.second); // vformat only supports up to 6 arguments.
  509. String trash_info = "[Trash Info]\nPath=" + path.uri_encode() + "\nDeletionDate=" + timestamp + "\n";
  510. {
  511. Error err;
  512. {
  513. Ref<FileAccess> file = FileAccess::open(trash_path + "/info/" + file_name + ".trashinfo", FileAccess::WRITE, &err);
  514. ERR_FAIL_COND_V_MSG(err != OK, err, "Can't create trashinfo file: \"" + trash_path + "/info/" + file_name + ".trashinfo\"");
  515. file->store_string(trash_info);
  516. }
  517. // Rename our resource before moving it to the trash can.
  518. Ref<DirAccess> dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  519. err = dir_access->rename(path, renamed_path);
  520. ERR_FAIL_COND_V_MSG(err != OK, err, "Can't rename file \"" + path + "\" to \"" + renamed_path + "\"");
  521. }
  522. // Move the given resource to the trash can.
  523. // Do not use DirAccess:rename() because it can't move files across multiple mountpoints.
  524. List<String> mv_args;
  525. mv_args.push_back(renamed_path);
  526. mv_args.push_back(trash_path + "/files");
  527. {
  528. int retval;
  529. Error err = execute("mv", mv_args, nullptr, &retval);
  530. // Issue an error if "mv" failed to move the given resource to the trash can.
  531. if (err != OK || retval != 0) {
  532. ERR_PRINT("move_to_trash: Could not move the resource \"" + path + "\" to the trash can \"" + trash_path + "/files\"");
  533. Ref<DirAccess> dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  534. err = dir_access->rename(renamed_path, path);
  535. ERR_FAIL_COND_V_MSG(err != OK, err, "Could not rename \"" + renamed_path + "\" back to its original name: \"" + path + "\"");
  536. return FAILED;
  537. }
  538. }
  539. return OK;
  540. }
  541. OS_LinuxBSD::OS_LinuxBSD() {
  542. main_loop = nullptr;
  543. force_quit = false;
  544. #ifdef PULSEAUDIO_ENABLED
  545. AudioDriverManager::add_driver(&driver_pulseaudio);
  546. #endif
  547. #ifdef ALSA_ENABLED
  548. AudioDriverManager::add_driver(&driver_alsa);
  549. #endif
  550. #ifdef X11_ENABLED
  551. DisplayServerX11::register_x11_driver();
  552. #endif
  553. }