diff options
Diffstat (limited to 'drivers/unix')
-rw-r--r-- | drivers/unix/file_access_unix.cpp | 23 | ||||
-rw-r--r-- | drivers/unix/ip_unix.cpp | 2 | ||||
-rw-r--r-- | drivers/unix/net_socket_posix.cpp | 20 | ||||
-rw-r--r-- | drivers/unix/net_socket_posix.h | 1 | ||||
-rw-r--r-- | drivers/unix/os_unix.cpp | 6 |
5 files changed, 37 insertions, 15 deletions
diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp index 071734eb48..8be1d5d8f3 100644 --- a/drivers/unix/file_access_unix.cpp +++ b/drivers/unix/file_access_unix.cpp @@ -58,7 +58,7 @@ void FileAccessUnix::check_errors() const { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); if (feof(f)) { @@ -76,7 +76,7 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) { path = fix_path(p_path); //printf("opening %ls, %i\n", path.c_str(), Memory::get_static_mem_usage()); - ERR_FAIL_COND_V(f, ERR_ALREADY_IN_USE); + ERR_FAIL_COND_V_MSG(f, ERR_ALREADY_IN_USE, "File is already in use."); const char *mode_string; if (p_mode_flags == READ) @@ -171,7 +171,7 @@ String FileAccessUnix::get_path_absolute() const { void FileAccessUnix::seek(size_t p_position) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); last_error = OK; if (fseek(f, p_position, SEEK_SET)) @@ -180,7 +180,7 @@ void FileAccessUnix::seek(size_t p_position) { void FileAccessUnix::seek_end(int64_t p_position) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); if (fseek(f, p_position, SEEK_END)) check_errors(); @@ -188,7 +188,7 @@ void FileAccessUnix::seek_end(int64_t p_position) { size_t FileAccessUnix::get_position() const { - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); long pos = ftell(f); if (pos < 0) { @@ -200,7 +200,7 @@ size_t FileAccessUnix::get_position() const { size_t FileAccessUnix::get_len() const { - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); long pos = ftell(f); ERR_FAIL_COND_V(pos < 0, 0); @@ -219,7 +219,7 @@ bool FileAccessUnix::eof_reached() const { uint8_t FileAccessUnix::get_8() const { - ERR_FAIL_COND_V(!f, 0); + ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); uint8_t b; if (fread(&b, 1, 1, f) == 0) { check_errors(); @@ -230,7 +230,7 @@ uint8_t FileAccessUnix::get_8() const { int FileAccessUnix::get_buffer(uint8_t *p_dst, int p_length) const { - ERR_FAIL_COND_V(!f, -1); + ERR_FAIL_COND_V_MSG(!f, -1, "File must be opened before use."); int read = fread(p_dst, 1, p_length, f); check_errors(); return read; @@ -243,18 +243,19 @@ Error FileAccessUnix::get_error() const { void FileAccessUnix::flush() { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); fflush(f); } void FileAccessUnix::store_8(uint8_t p_dest) { - ERR_FAIL_COND(!f); + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); ERR_FAIL_COND(fwrite(&p_dest, 1, 1, f) != 1); } void FileAccessUnix::store_buffer(const uint8_t *p_src, int p_length) { - ERR_FAIL_COND(!f); + + ERR_FAIL_COND_MSG(!f, "File must be opened before use."); ERR_FAIL_COND((int)fwrite(p_src, 1, p_length, f) != p_length); } diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp index ac7195abc1..cf47cdc7e8 100644 --- a/drivers/unix/ip_unix.cpp +++ b/drivers/unix/ip_unix.cpp @@ -152,7 +152,7 @@ void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) co Interface_Info info; info.name = name; info.name_friendly = hostname->DisplayName->Data(); - info.index = 0; + info.index = String::num_uint64(0); E = r_interfaces->insert(name, info); ERR_CONTINUE(!E); } diff --git a/drivers/unix/net_socket_posix.cpp b/drivers/unix/net_socket_posix.cpp index 6a57a2e562..da46b393c6 100644 --- a/drivers/unix/net_socket_posix.cpp +++ b/drivers/unix/net_socket_posix.cpp @@ -30,6 +30,7 @@ #include "net_socket_posix.h" +#ifndef UNIX_SOCKET_UNAVAILABLE #if defined(UNIX_ENABLED) #include <errno.h> @@ -280,6 +281,21 @@ void NetSocketPosix::_set_socket(SOCKET_TYPE p_sock, IP::Type p_ip_type, bool p_ _sock = p_sock; _ip_type = p_ip_type; _is_stream = p_is_stream; + // Disable descriptor sharing with subprocesses. + _set_close_exec_enabled(true); +} + +void NetSocketPosix::_set_close_exec_enabled(bool p_enabled) { +#ifndef WINDOWS_ENABLED + // Enable close on exec to avoid sharing with subprocesses. Off by default on Windows. +#if defined(NO_FCNTL) + unsigned long par = p_enabled ? 1 : 0; + SOCK_IOCTL(_sock, FIOCLEX, &par); +#else + int opts = fcntl(_sock, F_GETFD); + fcntl(_sock, F_SETFD, opts | FD_CLOEXEC); +#endif +#endif } Error NetSocketPosix::open(Type p_sock_type, IP::Type &ip_type) { @@ -320,6 +336,9 @@ Error NetSocketPosix::open(Type p_sock_type, IP::Type &ip_type) { _is_stream = p_sock_type == TYPE_TCP; + // Disable descriptor sharing with subprocesses. + _set_close_exec_enabled(true); + #if defined(WINDOWS_ENABLED) if (!_is_stream) { // Disable windows feature/bug reporting WSAECONNRESET/WSAENETRESET when @@ -691,3 +710,4 @@ Error NetSocketPosix::join_multicast_group(const IP_Address &p_multi_address, St Error NetSocketPosix::leave_multicast_group(const IP_Address &p_multi_address, String p_if_name) { return _change_multicast_group(p_multi_address, p_if_name, false); } +#endif diff --git a/drivers/unix/net_socket_posix.h b/drivers/unix/net_socket_posix.h index 40406b241a..e549ea1d6a 100644 --- a/drivers/unix/net_socket_posix.h +++ b/drivers/unix/net_socket_posix.h @@ -61,6 +61,7 @@ private: NetError _get_socket_error(); void _set_socket(SOCKET_TYPE p_sock, IP::Type p_ip_type, bool p_is_stream); _FORCE_INLINE_ Error _change_multicast_group(IP_Address p_ip, String p_if_name, bool p_add); + _FORCE_INLINE_ void _set_close_exec_enabled(bool p_enabled); protected: static NetSocket *_create_func(); diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index ab5590dba4..b3d98a0648 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -187,7 +187,7 @@ uint64_t OS_Unix::get_system_time_secs() const { uint64_t OS_Unix::get_system_time_msecs() const { struct timeval tv_now; gettimeofday(&tv_now, NULL); - return uint64_t(tv_now.tv_sec * 1000 + tv_now.tv_usec / 1000); + return uint64_t(tv_now.tv_sec) * 1000 + uint64_t(tv_now.tv_usec) / 1000; } OS::Date OS_Unix::get_date(bool utc) const { @@ -298,7 +298,7 @@ Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bo } FILE *f = popen(argss.utf8().get_data(), "r"); - ERR_FAIL_COND_V(!f, ERR_CANT_OPEN); + ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot pipe stream from process running with following arguments '" + argss + "'."); char buf[65535]; @@ -314,7 +314,7 @@ Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bo } int rv = pclose(f); if (r_exitcode) - *r_exitcode = rv; + *r_exitcode = WEXITSTATUS(rv); return OK; } |