diff --git a/hphp/compiler/package.cpp b/hphp/compiler/package.cpp index 7dfbe94f7..35c627f6d 100644 --- a/hphp/compiler/package.cpp +++ b/hphp/compiler/package.cpp @@ -19,6 +19,7 @@ #include #include #include +#include "folly/String.h" #include "hphp/compiler/analysis/analysis_result.h" #include "hphp/compiler/parser/parser.h" #include "hphp/compiler/analysis/symbol_table.h" @@ -67,7 +68,7 @@ void Package::addInputList(const char *listFileName) { FILE *f = fopen(listFileName, "r"); if (f == nullptr) { throw Exception("Unable to open %s: %s", listFileName, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); } char fileName[PATH_MAX]; while (fgets(fileName, sizeof(fileName), f)) { diff --git a/hphp/runtime/base/exceptions.h b/hphp/runtime/base/exceptions.h index 1b190c7cb..542791d57 100644 --- a/hphp/runtime/base/exceptions.h +++ b/hphp/runtime/base/exceptions.h @@ -20,6 +20,7 @@ #include "hphp/util/exception.h" #include "hphp/util/util.h" #include "hphp/runtime/base/types.h" +#include "folly/String.h" namespace HPHP { /////////////////////////////////////////////////////////////////////////////// @@ -173,7 +174,7 @@ class SystemCallFailure : public ExtendedException { public: explicit SystemCallFailure(const char *func) : ExtendedException("%s returned %d: %s.", func, errno, - Util::safe_strerror(errno).c_str()) {} + folly::errnoStr(errno).c_str()) {} virtual ~SystemCallFailure() throw() {} EXCEPTION_COMMON_IMPL(SystemCallFailure); }; diff --git a/hphp/runtime/base/file.cpp b/hphp/runtime/base/file.cpp index 082b7ab65..70af8a750 100644 --- a/hphp/runtime/base/file.cpp +++ b/hphp/runtime/base/file.cpp @@ -30,9 +30,11 @@ #include "hphp/runtime/base/zend-string.h" #include "hphp/runtime/base/zend-printf.h" #include "hphp/runtime/base/exceptions.h" -#include #include "hphp/runtime/base/array-iterator.h" #include "hphp/runtime/base/stream-wrapper-registry.h" +#include "folly/String.h" + +#include namespace HPHP { /////////////////////////////////////////////////////////////////////////////// @@ -776,7 +778,7 @@ Array File::readCSV(int64_t length /* = 0 */, char delimiter_char /* = ',' */, } String File::getLastError() { - return Util::safe_strerror(errno); + return String(folly::errnoStr(errno).toStdString()); } diff --git a/hphp/runtime/base/hardware-counter.cpp b/hphp/runtime/base/hardware-counter.cpp index b1b8c33e1..9908a9205 100644 --- a/hphp/runtime/base/hardware-counter.cpp +++ b/hphp/runtime/base/hardware-counter.cpp @@ -37,6 +37,7 @@ #include "hphp/runtime/base/zend-url.h" #include "hphp/runtime/base/runtime-option.h" #include "hphp/runtime/vm/jit/translator-x64.h" +#include "folly/String.h" namespace HPHP { /////////////////////////////////////////////////////////////////////////////// @@ -76,13 +77,13 @@ public: m_fd = syscall(__NR_perf_event_open, &pe, 0, -1, -1, 0); if (m_fd < 0) { Logger::Verbose("perf_event_open failed with: %s", - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); m_err = -1; return; } if (ioctl(m_fd, PERF_EVENT_IOC_ENABLE, 0) < 0) { Logger::Warning("perf_event failed to enable: %s", - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); close(); m_err = -1; return; @@ -128,7 +129,7 @@ public: void reset() { if (m_fd > 0 && ioctl (m_fd, PERF_EVENT_IOC_RESET, 0) < 0) { Logger::Warning("perf_event failed to reset with: %s", - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); m_err = -1; } } diff --git a/hphp/runtime/base/runtime-option.cpp b/hphp/runtime/base/runtime-option.cpp index 2f0640778..514de30bc 100644 --- a/hphp/runtime/base/runtime-option.cpp +++ b/hphp/runtime/base/runtime-option.cpp @@ -41,6 +41,7 @@ #include "hphp/util/parser/scanner.h" #include "hphp/runtime/server/access_log.h" #include "hphp/runtime/base/crash-reporter.h" +#include "folly/String.h" namespace HPHP { /////////////////////////////////////////////////////////////////////////////// @@ -473,7 +474,7 @@ static void setResourceLimit(int resource, Hdf rlimit, const char *nodeName) { if (ret) { Logger::Error("Unable to set %s to %" PRId64 ": %s (%d)", nodeName, (int64_t)rl.rlim_cur, - Util::safe_strerror(errno).c_str(), errno); + folly::errnoStr(errno).c_str(), errno); } } } diff --git a/hphp/runtime/base/socket.h b/hphp/runtime/base/socket.h index 8cac40010..af6c010d0 100644 --- a/hphp/runtime/base/socket.h +++ b/hphp/runtime/base/socket.h @@ -24,7 +24,7 @@ #define SOCKET_ERROR(sock, msg, errn) \ sock->setError(errn); \ raise_warning("%s [%d]: %s", msg, errn, \ - Util::safe_strerror(errn).c_str()) \ + folly::errnoStr(errn).c_str()) \ namespace HPHP { /////////////////////////////////////////////////////////////////////////////// diff --git a/hphp/runtime/base/ssl-socket.cpp b/hphp/runtime/base/ssl-socket.cpp index cb92e7e89..4c51e9f20 100644 --- a/hphp/runtime/base/ssl-socket.cpp +++ b/hphp/runtime/base/ssl-socket.cpp @@ -18,6 +18,7 @@ #include "hphp/runtime/base/complex-types.h" #include "hphp/runtime/base/runtime-error.h" #include "hphp/util/util.h" +#include "folly/String.h" #include namespace HPHP { @@ -265,8 +266,7 @@ bool SSLSocket::handleError(int64_t nr_bytes, bool is_init) { m_eof = true; retry = false; } else { - string estr = Util::safe_strerror(errno); - raise_warning("SSL: %s", estr.c_str()); + raise_warning("SSL: %s", folly::errnoStr(errno).c_str()); retry = false; } break; diff --git a/hphp/runtime/base/thread-info.cpp b/hphp/runtime/base/thread-info.cpp index aec22c1f8..ee4996eac 100644 --- a/hphp/runtime/base/thread-info.cpp +++ b/hphp/runtime/base/thread-info.cpp @@ -20,6 +20,7 @@ #include "hphp/runtime/vm/jit/target-cache.h" #include "hphp/util/lock.h" #include "hphp/util/alloc.h" +#include "folly/String.h" #include @@ -170,7 +171,7 @@ void RequestInjectionData::setTimeout(int seconds) { sev.sigev_signo = SIGVTALRM; sev.sigev_value.sival_ptr = this; if (timer_create(CLOCK_REALTIME, &sev, &m_timer_id)) { - raise_error("Failed to set timeout: %s", strerror(errno)); + raise_error("Failed to set timeout: %s", folly::errnoStr(errno).c_str()); } m_hasTimer = true; } diff --git a/hphp/runtime/ext/ext_bzip2.cpp b/hphp/runtime/ext/ext_bzip2.cpp index 3f4abed18..31ba63814 100644 --- a/hphp/runtime/ext/ext_bzip2.cpp +++ b/hphp/runtime/ext/ext_bzip2.cpp @@ -18,6 +18,7 @@ #include "hphp/runtime/ext/ext_bzip2.h" #include "hphp/runtime/base/bzip2-file.h" #include "hphp/util/alloc.h" +#include "folly/String.h" namespace HPHP { /////////////////////////////////////////////////////////////////////////////// @@ -53,7 +54,7 @@ Variant f_bzopen(CVarRef filename, CStrRef mode) { bz = NEWOBJ(BZ2File)(); bool ret = bz->open(File::TranslatePath(filename.toString()), mode); if (!ret) { - raise_warning("%s", Util::safe_strerror(errno).c_str()); + raise_warning("%s", folly::errnoStr(errno).c_str()); return false; } } else { diff --git a/hphp/runtime/ext/ext_fb.cpp b/hphp/runtime/ext/ext_fb.cpp index 92855cd43..8d316c29f 100644 --- a/hphp/runtime/ext/ext_fb.cpp +++ b/hphp/runtime/ext/ext_fb.cpp @@ -21,6 +21,7 @@ #include "hphp/util/db_conn.h" #include "hphp/util/logger.h" #include "hphp/runtime/base/stat-cache.h" +#include "folly/String.h" #include "netinet/in.h" #include "hphp/runtime/base/externals.h" #include "hphp/runtime/base/string-util.h" @@ -1494,7 +1495,7 @@ static Variant do_lazy_stat(Function dostat, CStrRef filename) { struct stat sb; if (dostat(File::TranslatePathWithFileCache(filename).c_str(), &sb)) { Logger::Verbose("%s/%d: %s", __FUNCTION__, __LINE__, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); return false; } return stat_impl(&sb); diff --git a/hphp/runtime/ext/ext_file.cpp b/hphp/runtime/ext/ext_file.cpp index c81e2db42..1be22a093 100644 --- a/hphp/runtime/ext/ext_file.cpp +++ b/hphp/runtime/ext/ext_file.cpp @@ -35,6 +35,7 @@ #include "hphp/util/logger.h" #include "hphp/util/util.h" #include "hphp/util/process.h" +#include "folly/String.h" #include #include #include @@ -59,7 +60,7 @@ #define CHECK_SYSTEM(exp) \ if ((exp) != 0) { \ Logger::Verbose("%s/%d: %s", __FUNCTION__, __LINE__, \ - Util::safe_strerror(errno).c_str()); \ + folly::errnoStr(errno).c_str()); \ return false; \ } \ @@ -92,7 +93,7 @@ namespace HPHP { static bool check_error(const char *function, int line, bool ret) { if (!ret) { Logger::Verbose("%s/%d: %s", function, line, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); } return ret; } @@ -541,7 +542,7 @@ Variant f_readfile(CStrRef filename, bool use_include_path /* = false */, Variant f = f_fopen(filename, "rb", use_include_path, context); if (same(f, false)) { Logger::Verbose("%s/%d: %s", __FUNCTION__, __LINE__, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); return false; } Variant ret = f_fpassthru(f.toResource()); @@ -855,7 +856,7 @@ Variant f_readlink_internal(CStrRef path, bool warning_compliance) { int ret = readlink(File::TranslatePath(path).data(), buff, PATH_MAX-1); if (ret < 0) { Logger::Verbose("%s/%d: %s", __FUNCTION__, __LINE__, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); if (warning_compliance) { raise_warning("readlink(): No such file or directory %s",path.c_str()); } @@ -1051,7 +1052,7 @@ bool f_touch(CStrRef filename, int64_t mtime /* = 0 */, int64_t atime /* = 0 */) if (f == NULL) { Logger::Verbose("%s/%d: Unable to create file %s because %s", __FUNCTION__, __LINE__, translated.data(), - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); return false; } fclose(f); @@ -1265,7 +1266,7 @@ Variant f_tempnam(CStrRef dir, CStrRef prefix) { int fd = mkstemp(buf); if (fd < 0) { Logger::Verbose("%s/%d: %s", __FUNCTION__, __LINE__, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); return false; } diff --git a/hphp/runtime/ext/ext_ipc.cpp b/hphp/runtime/ext/ext_ipc.cpp index 49e9c3caa..160f87dd9 100644 --- a/hphp/runtime/ext/ext_ipc.cpp +++ b/hphp/runtime/ext/ext_ipc.cpp @@ -20,6 +20,7 @@ #include "hphp/runtime/base/variable-unserializer.h" #include "hphp/util/lock.h" #include "hphp/util/alloc.h" +#include "folly/String.h" #include @@ -87,7 +88,7 @@ Variant f_msg_get_queue(int64_t key, int64_t perms /* = 0666 */) { id = msgget(key, IPC_CREAT | IPC_EXCL | perms); if (id < 0) { raise_warning("Failed to create message queue for key 0x%" PRIx64 ": %s", - key, Util::safe_strerror(errno).c_str()); + key, folly::errnoStr(errno).c_str()); return false; } } @@ -200,7 +201,7 @@ bool f_msg_send(CResRef queue, int64_t msgtype, CVarRef message, if (result < 0) { int err = errno; raise_warning("Unable to send message: %s", - Util::safe_strerror(err).c_str()); + folly::errnoStr(err).c_str()); if (!errorcode.isNull()) { errorcode = err; } @@ -241,7 +242,7 @@ bool f_msg_receive(CResRef queue, int64_t desiredmsgtype, VRefParam msgtype, if (result < 0) { int err = errno; raise_warning("Unable to receive message: %s", - Util::safe_strerror(err).c_str()); + folly::errnoStr(err).c_str()); if (!errorcode.isNull()) { errorcode = err; } @@ -324,7 +325,7 @@ public: if (errno != EINTR) { raise_warning("failed to %s key 0x%x: %s", acquire ? "acquire" : "release", - key, Util::safe_strerror(errno).c_str()); + key, folly::errnoStr(errno).c_str()); return false; } } @@ -386,7 +387,7 @@ Variant f_sem_get(int64_t key, int64_t max_acquire /* = 1 */, int semid = semget(key, 3, perm|IPC_CREAT); if (semid == -1) { raise_warning("failed for key 0x%" PRIx64 ": %s", key, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); return false; } @@ -418,7 +419,7 @@ Variant f_sem_get(int64_t key, int64_t max_acquire /* = 1 */, while (semop(semid, sop, 3) == -1) { if (errno != EINTR) { raise_warning("failed acquiring SYSVSEM_SETVAL for key 0x%" PRIx64 ": %s", - key, Util::safe_strerror(errno).c_str()); + key, folly::errnoStr(errno).c_str()); break; } } @@ -427,7 +428,7 @@ Variant f_sem_get(int64_t key, int64_t max_acquire /* = 1 */, int count = semctl(semid, SYSVSEM_USAGE, GETVAL, NULL); if (count == -1) { raise_warning("failed for key 0x%" PRIx64 ": %s", key, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); } /* If we are the only user, then take this opportunity to set the max. */ @@ -436,7 +437,7 @@ Variant f_sem_get(int64_t key, int64_t max_acquire /* = 1 */, semarg.val = max_acquire; if (semctl(semid, SYSVSEM_SEM, SETVAL, semarg) == -1) { raise_warning("failed for key 0x%" PRIx64 ": %s", key, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); } } @@ -447,7 +448,7 @@ Variant f_sem_get(int64_t key, int64_t max_acquire /* = 1 */, while (semop(semid, sop, 1) == -1) { if (errno != EINTR) { raise_warning("failed releasing SYSVSEM_SETVAL for key 0x%" PRIx64 ": %s", - key, Util::safe_strerror(errno).c_str()); + key, folly::errnoStr(errno).c_str()); break; } } @@ -479,7 +480,7 @@ bool f_sem_remove(CResRef sem_identifier) { if (semctl(sem_ptr->semid, 0, IPC_RMID, un) < 0) { raise_warning("failed for SysV sempphore %d: %s", sem_identifier->o_getId(), - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); return false; } @@ -620,14 +621,14 @@ Variant f_shm_attach(int64_t shm_key, int64_t shm_size /* = 10000 */, if ((shm_id = shmget(shm_key, shm_size, shm_flag | IPC_CREAT | IPC_EXCL)) < 0) { raise_warning("failed for key 0x%" PRIx64 ": %s", shm_key, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); return false; } } if ((shm_ptr = (char*)shmat(shm_id, NULL, 0)) == (char *)-1) { raise_warning("failed for key 0x%" PRIx64 ": %s", shm_key, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); return false; } @@ -676,7 +677,7 @@ bool f_shm_remove(int64_t shm_identifier) { if (shmctl(shm_list_ptr->id, IPC_RMID,NULL) < 0) { raise_warning("failed for key 0x%x, id %" PRId64 ": %s", shm_list_ptr->key, - shm_identifier, Util::safe_strerror(errno).c_str()); + shm_identifier, folly::errnoStr(errno).c_str()); return false; } return true; diff --git a/hphp/runtime/ext/ext_ldap.cpp b/hphp/runtime/ext/ext_ldap.cpp index 8dcb06a55..c557f5db5 100644 --- a/hphp/runtime/ext/ext_ldap.cpp +++ b/hphp/runtime/ext/ext_ldap.cpp @@ -19,6 +19,7 @@ #include "hphp/runtime/ext/ext_function.h" #include "hphp/runtime/base/builtin-functions.h" #include "hphp/util/thread_local.h" +#include "folly/String.h" #include #define LDAP_DEPRECATED 1 @@ -556,7 +557,7 @@ Variant f_ldap_connect(CStrRef hostname /* = null_string */, return ret; } raise_warning("Unable to initialize LDAP: %s", - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); return false; } diff --git a/hphp/runtime/ext/ext_mysql.cpp b/hphp/runtime/ext/ext_mysql.cpp index 1cd6f75db..31d45ea92 100644 --- a/hphp/runtime/ext/ext_mysql.cpp +++ b/hphp/runtime/ext/ext_mysql.cpp @@ -28,6 +28,7 @@ #include "hphp/runtime/base/extended-logger.h" #include "hphp/util/timer.h" #include "hphp/util/db_mysql.h" +#include "folly/String.h" #include "netinet/in.h" #include @@ -1504,7 +1505,7 @@ Variant f_mysql_async_wait_actionable(CVarRef items, double timeout) { int res = poll(fds, nfds, timeout_millis); if (res == -1) { raise_warning("unable to poll [%d]: %s", errno, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); return Array::Create(); } diff --git a/hphp/runtime/ext/ext_posix.cpp b/hphp/runtime/ext/ext_posix.cpp index 881db2cac..229dd8b8e 100644 --- a/hphp/runtime/ext/ext_posix.cpp +++ b/hphp/runtime/ext/ext_posix.cpp @@ -17,6 +17,7 @@ #include "hphp/runtime/ext/ext_posix.h" #include "hphp/runtime/base/file.h" +#include "folly/String.h" #include #include #include @@ -367,7 +368,7 @@ bool f_posix_setuid(int uid) { } String f_posix_strerror(int errnum) { - return String(Util::safe_strerror(errnum)); + return String(folly::errnoStr(errnum).toStdString()); } const StaticString diff --git a/hphp/runtime/ext/ext_process.cpp b/hphp/runtime/ext/ext_process.cpp index ed142cc78..37906f87f 100644 --- a/hphp/runtime/ext/ext_process.cpp +++ b/hphp/runtime/ext/ext_process.cpp @@ -21,6 +21,7 @@ #include "hphp/runtime/base/string-buffer.h" #include "hphp/runtime/base/zend-string.h" #include "hphp/runtime/base/thread-init-fini.h" +#include "folly/String.h" #include #include #include @@ -142,7 +143,7 @@ void f_pcntl_exec(CStrRef path, CArrRef args /* = null_array */, char **envp = build_envp(envs, senvs); if (execve(path.c_str(), argv, envp) == -1) { raise_warning("Error has occured: (errno %d) %s", - errno, Util::safe_strerror(errno).c_str()); + errno, folly::errnoStr(errno).c_str()); } free(envp); @@ -598,7 +599,7 @@ public: childend = dup(file->fd()); if (childend < 0) { raise_warning("unable to dup File-Handle for descriptor %d - %s", - index, Util::safe_strerror(errno).c_str()); + index, folly::errnoStr(errno).c_str()); return false; } return true; @@ -609,7 +610,7 @@ public: int newpipe[2]; if (0 != pipe(newpipe)) { raise_warning("unable to create pipe %s", - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); return false; } @@ -741,7 +742,7 @@ static Variant post_proc_open(CStrRef cmd, Variant &pipes, for (int i = 0; i < (int)items.size(); i++) { items[i].cleanup(); } - raise_warning("fork failed - %s", Util::safe_strerror(errno).c_str()); + raise_warning("fork failed - %s", folly::errnoStr(errno).c_str()); return false; } diff --git a/hphp/runtime/ext/ext_session.cpp b/hphp/runtime/ext/ext_session.cpp index 9199ea51c..147b2f6f0 100644 --- a/hphp/runtime/ext/ext_session.cpp +++ b/hphp/runtime/ext/ext_session.cpp @@ -32,6 +32,7 @@ #include "hphp/util/lock.h" #include "hphp/util/logger.h" #include "hphp/util/compatibility.h" +#include "folly/String.h" #include #include #include @@ -630,7 +631,8 @@ public: if (n != (int)m_st_size) { if (n == -1) { - raise_warning("read failed: %s (%d)", strerror(errno), errno); + raise_warning("read failed: %s (%d)", folly::errnoStr(errno).c_str(), + errno); } else { raise_warning("read returned less bytes than requested"); } @@ -659,7 +661,8 @@ public: */ if (value.size() < (int)m_st_size) { if (ftruncate(m_fd, 0) < 0) { - raise_warning("truncate failed: %s (%d)", strerror(errno), errno); + raise_warning("truncate failed: %s (%d)", + folly::errnoStr(errno).c_str(), errno); return false; } } @@ -673,7 +676,8 @@ public: if (n != value.size()) { if (n == -1) { - raise_warning("write failed: %s (%d)", strerror(errno), errno); + raise_warning("write failed: %s (%d)", + folly::errnoStr(errno).c_str(), errno); } else { raise_warning("write wrote less bytes than requested"); } @@ -816,12 +820,12 @@ private: # endif if (fcntl(m_fd, F_SETFD, FD_CLOEXEC)) { raise_warning("fcntl(%d, F_SETFD, FD_CLOEXEC) failed: %s (%d)", - m_fd, strerror(errno), errno); + m_fd, folly::errnoStr(errno).c_str(), errno); } #endif } else { raise_warning("open(%s, O_RDWR) failed: %s (%d)", buf, - strerror(errno), errno); + folly::errnoStr(errno).c_str(), errno); } } } @@ -830,7 +834,7 @@ private: DIR *dir = opendir(dirname); if (!dir) { raise_notice("ps_files_cleanup_dir: opendir(%s) failed: %s (%d)", - dirname, strerror(errno), errno); + dirname, folly::errnoStr(errno).c_str(), errno); return 0; } diff --git a/hphp/runtime/ext/ext_socket.cpp b/hphp/runtime/ext/ext_socket.cpp index b5b656fd0..e950da1f1 100644 --- a/hphp/runtime/ext/ext_socket.cpp +++ b/hphp/runtime/ext/ext_socket.cpp @@ -19,6 +19,7 @@ #include "hphp/runtime/base/socket.h" #include "hphp/runtime/base/ssl-socket.h" #include "hphp/runtime/server/server_stats.h" +#include "folly/String.h" #include #include @@ -306,7 +307,7 @@ static bool create_new_socket(const char *&name, int port, Variant &errnum, if (!sock->valid()) { SOCKET_ERROR(sock, "unable to create socket", errno); errnum = sock->getError(); - errstr = String(Util::safe_strerror(sock->getError())); + errstr = String(folly::errnoStr(sock->getError()).toStdString()); return false; } return true; @@ -645,7 +646,7 @@ Variant f_socket_select(VRefParam read, VRefParam write, VRefParam except, int retval = poll(fds, count, timeout_ms); if (retval == -1) { raise_warning("unable to select [%d]: %s", errno, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); free(fds); return false; } @@ -962,7 +963,7 @@ void f_socket_close(CResRef socket) { } String f_socket_strerror(int errnum) { - return String(Util::safe_strerror(errnum)); + return String(folly::errnoStr(errnum).toStdString()); } int64_t f_socket_last_error(CResRef socket /* = null_object */) { @@ -1054,7 +1055,7 @@ static Variant sockopen_impl(CStrRef hostname, int port, Variant &errnum, msg += boost::lexical_cast(port); SOCKET_ERROR(sock, msg.c_str(), valopt); errnum = sock->getError(); - errstr = String(Util::safe_strerror(sock->getError())); + errstr = String(folly::errnoStr(sock->getError()).toStdString()); return false; } else { retval = 0; // success @@ -1068,7 +1069,7 @@ static Variant sockopen_impl(CStrRef hostname, int port, Variant &errnum, msg += boost::lexical_cast(port); SOCKET_ERROR(sock, msg.c_str(), ETIMEDOUT); errnum = sock->getError(); - errstr = String(Util::safe_strerror(sock->getError())); + errstr = String(folly::errnoStr(sock->getError()).toStdString()); return false; } } @@ -1081,7 +1082,7 @@ static Variant sockopen_impl(CStrRef hostname, int port, Variant &errnum, if (retval != 0) { errnum = sock->getError(); - errstr = String(Util::safe_strerror(sock->getError())); + errstr = String(folly::errnoStr(sock->getError()).toStdString()); return false; } diff --git a/hphp/runtime/ext/ext_zlib.cpp b/hphp/runtime/ext/ext_zlib.cpp index 43ca0cfce..d447f5f78 100644 --- a/hphp/runtime/ext/ext_zlib.cpp +++ b/hphp/runtime/ext/ext_zlib.cpp @@ -24,6 +24,7 @@ #include "hphp/runtime/base/file-stream-wrapper.h" #include "hphp/util/compression.h" #include "hphp/util/logger.h" +#include "folly/String.h" #ifdef HAVE_SNAPPY #include #endif @@ -321,7 +322,7 @@ Resource f_gzopen(CStrRef filename, CStrRef mode, Resource handle(file); bool ret = file->open(File::TranslatePath(filename), mode); if (!ret) { - raise_warning("%s",Util::safe_strerror(errno).c_str()); + raise_warning("%s",folly::errnoStr(errno).c_str()); return NULL; } return handle; diff --git a/hphp/runtime/server/libevent_server_with_fd.cpp b/hphp/runtime/server/libevent_server_with_fd.cpp index 576aa1438..efdc19fd8 100644 --- a/hphp/runtime/server/libevent_server_with_fd.cpp +++ b/hphp/runtime/server/libevent_server_with_fd.cpp @@ -16,6 +16,7 @@ #include "hphp/runtime/server/libevent_server_with_fd.h" #include "hphp/util/logger.h" +#include "folly/String.h" /* * LibEventServer that supports using existing/inherited accept sockets. @@ -40,14 +41,14 @@ int LibEventServerWithFd::getAcceptSocket() { int ret = listen(m_accept_sock, RuntimeOption::ServerBacklog); if (ret != 0) { Logger::Error("inheritfd: listen() failed: %s", - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); return -1; } ret = evhttp_accept_socket(m_server, m_accept_sock); if (ret < 0) { Logger::Error("evhttp_accept_socket: %s", - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); int errno_save = errno; close(m_accept_sock); m_accept_sock = -1; @@ -69,14 +70,14 @@ int LibEventServerWithFd::getAcceptSocketSSL() { int ret = listen(m_accept_sock_ssl, RuntimeOption::ServerBacklog); if (ret != 0) { Logger::Error("inheritfd: listen() failed for ssl: %s", - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); return -1; } ret = evhttp_accept_socket(m_server_ssl, m_accept_sock_ssl); if (ret < 0) { Logger::Error("evhttp_accept_socket: (ssl) %s", - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); int errno_save = errno; close(m_accept_sock_ssl); m_accept_sock_ssl = -1; diff --git a/hphp/runtime/server/libevent_server_with_takeover.cpp b/hphp/runtime/server/libevent_server_with_takeover.cpp index f7f139771..96af450f6 100644 --- a/hphp/runtime/server/libevent_server_with_takeover.cpp +++ b/hphp/runtime/server/libevent_server_with_takeover.cpp @@ -17,6 +17,7 @@ #include "hphp/runtime/server/libevent_server_with_takeover.h" #include "hphp/util/logger.h" #include "hphp/runtime/base/string-util.h" +#include "folly/String.h" #include /* @@ -63,7 +64,7 @@ static void fd_transfer_error_hander( afdt_phase_str(err->phase), afdt_operation_str(err->operation), err->message, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); } static int fd_transfer_request_handler( @@ -168,7 +169,7 @@ void LibEventServerWithTakeover::setupFdServer() { ret = unlink(m_transfer_fname.c_str()); if (ret < 0 && errno != ENOENT) { Logger::Error("Unalbe to unlink '%s': %s", - m_transfer_fname.c_str(), Util::safe_strerror(errno).c_str()); + m_transfer_fname.c_str(), folly::errnoStr(errno).c_str()); return; } @@ -248,7 +249,7 @@ int LibEventServerWithTakeover::getAcceptSocket() { ret = evhttp_accept_socket(m_server, m_accept_sock); if (ret < 0) { Logger::Error("evhttp_accept_socket: %s", - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); int errno_save = errno; close(m_accept_sock); m_accept_sock = -1; diff --git a/hphp/runtime/server/transport.cpp b/hphp/runtime/server/transport.cpp index b9dc5dda5..0d63b958d 100644 --- a/hphp/runtime/server/transport.cpp +++ b/hphp/runtime/server/transport.cpp @@ -32,6 +32,7 @@ #include "hphp/util/compatibility.h" #include "hphp/util/timer.h" #include "hphp/runtime/base/hardware-counter.h" +#include "folly/String.h" namespace HPHP { /////////////////////////////////////////////////////////////////////////////// @@ -837,7 +838,7 @@ bool Transport::moveUploadedFileHelper(CStrRef filename, CStrRef destination) { if (Util::rename(filename.c_str(), dest.c_str()) < 0) { Logger::Error("Unable to move uploaded file %s to %s: %s.", filename.c_str(), dest.c_str(), - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); return false; } Logger::Verbose("Successfully moved uploaded file %s to %s.", diff --git a/hphp/runtime/vm/as.cpp b/hphp/runtime/vm/as.cpp index 0659d8225..9d5f7f331 100644 --- a/hphp/runtime/vm/as.cpp +++ b/hphp/runtime/vm/as.cpp @@ -89,6 +89,8 @@ #include #include +#include "folly/String.h" + #include "hphp/runtime/vm/unit.h" #include "hphp/runtime/vm/hhbc.h" #include "hphp/runtime/vm/preclass-emit.h" @@ -319,7 +321,7 @@ private: void io_error_if_bad() { if (m_in.bad()) { error("I/O error reading stream: " + - std::string(strerror(errno))); + folly::errnoStr(errno).toStdString()); } } diff --git a/hphp/runtime/vm/backup-gc.cpp b/hphp/runtime/vm/backup-gc.cpp index aac07b8b1..ace7f24ff 100644 --- a/hphp/runtime/vm/backup-gc.cpp +++ b/hphp/runtime/vm/backup-gc.cpp @@ -22,6 +22,8 @@ #include #include +#include "folly/String.h" + #include "hphp/util/assertions.h" #include "hphp/util/timer.h" #include "hphp/util/trace.h" @@ -571,7 +573,7 @@ void gc_detect_cycles(const std::string& filename) { std::ofstream out(filename.c_str()); if (!out.is_open()) { raise_error("couldn't open output file for gc_detect_cycles, %s", - strerror(errno)); + folly::errnoStr(errno).c_str()); return; } diff --git a/hphp/runtime/vm/bytecode.cpp b/hphp/runtime/vm/bytecode.cpp index 0ac18b258..ed58cbd6d 100644 --- a/hphp/runtime/vm/bytecode.cpp +++ b/hphp/runtime/vm/bytecode.cpp @@ -531,7 +531,8 @@ class StackElms { size_t algnSz = RuntimeOption::EvalVMStackElms * sizeof(TypedValue); if (posix_memalign((void**)&m_elms, algnSz, algnSz) != 0) { throw std::runtime_error( - std::string("VM stack initialization failed: ") + strerror(errno)); + std::string("VM stack initialization failed: ") + + folly::errnoStr(errno).c_str()); } } return m_elms; diff --git a/hphp/runtime/vm/jit/translator-x64.cpp b/hphp/runtime/vm/jit/translator-x64.cpp index 0e3bc6508..86415d899 100644 --- a/hphp/runtime/vm/jit/translator-x64.cpp +++ b/hphp/runtime/vm/jit/translator-x64.cpp @@ -51,6 +51,7 @@ #include #include "folly/Format.h" +#include "folly/String.h" #include "hphp/util/asm-x64.h" #include "hphp/util/bitops.h" @@ -3859,7 +3860,7 @@ TranslatorX64::TranslatorX64() if (sigaction(SIGSEGV, &sa, &old_sa) != 0) { throw std::runtime_error( std::string("Failed to install SIGSEGV handler: ") + - strerror(errno)); + folly::errnoStr(errno).c_str()); } m_segvChain = old_sa.sa_flags & SA_SIGINFO ? old_sa.sa_sigaction : (sigaction_t)old_sa.sa_handler; diff --git a/hphp/runtime/vm/type-profile.cpp b/hphp/runtime/vm/type-profile.cpp index 24415f7c7..27ad049e7 100644 --- a/hphp/runtime/vm/type-profile.cpp +++ b/hphp/runtime/vm/type-profile.cpp @@ -19,6 +19,8 @@ #include "hphp/runtime/vm/jit/translator.h" #include "hphp/util/trace.h" +#include "folly/String.h" + #include #include #include @@ -106,7 +108,7 @@ profileInitMmap() { int fd = open(path.c_str(), O_RDWR | O_CREAT, 0600); if (fd < 0) { TRACE(0, "profileInit: open %s failed: %s\n", path.c_str(), - strerror(errno)); + folly::errnoStr(errno).c_str()); perror("open"); return nullptr; } @@ -116,7 +118,7 @@ profileInitMmap() { if (retval < 0) { perror("truncate"); TRACE(0, "profileInit: truncate %s failed: %s\n", path.c_str(), - strerror(errno)); + folly::errnoStr(errno).c_str()); return nullptr; } @@ -127,7 +129,7 @@ profileInitMmap() { if (mmapRet == MAP_FAILED) { perror("mmap"); TRACE(0, "profileInit: mmap %s failed: %s\n", path.c_str(), - strerror(errno)); + folly::errnoStr(errno).c_str()); return nullptr; } return (ValueProfileLine*)mmapRet; diff --git a/hphp/util/asm-x64.cpp b/hphp/util/asm-x64.cpp index d69f29b9c..f397212eb 100644 --- a/hphp/util/asm-x64.cpp +++ b/hphp/util/asm-x64.cpp @@ -25,6 +25,8 @@ #include #include +#include "folly/String.h" + #include "hphp/util/assertions.h" #include "hphp/util/maphuge.h" #include "hphp/runtime/base/runtime-option.h" @@ -45,7 +47,7 @@ Address allocSlab(size_t size) { mmap(0, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); if (result == MAP_FAILED) { panic("%s:%d: (%s) map of %zu bytes failed (%s)\n", - __FILE__, __LINE__, __func__, size, strerror(errno)); + __FILE__, __LINE__, __func__, size, folly::errnoStr(errno).c_str()); } return result; } @@ -77,7 +79,7 @@ void DataBlock::makeExecable() { if (mprotect(base, size, PROT_READ | PROT_WRITE | PROT_EXEC)) { panic("%s:%d (%s): mprotect @%p %zu bytes failed (%s)\n", __FILE__, __LINE__, __func__, - base, (long)size, strerror(errno)); + base, (long)size, folly::errnoStr(errno).c_str()); } } diff --git a/hphp/util/capability.cpp b/hphp/util/capability.cpp index 557754e3b..2986068c7 100644 --- a/hphp/util/capability.cpp +++ b/hphp/util/capability.cpp @@ -18,6 +18,7 @@ #include "hphp/util/capability.h" #include "hphp/util/logger.h" +#include "folly/String.h" #include "linux/types.h" #include #include @@ -96,17 +97,20 @@ bool Capability::ChangeUnixUser(uid_t uid) { struct passwd *pw; if ((pw = getpwuid(uid)) == nullptr) { - Logger::Error("unable to getpwuid(%d): %s", uid, strerror(errno)); + Logger::Error("unable to getpwuid(%d): %s", uid, + folly::errnoStr(errno).c_str()); return false; } if (pw->pw_gid == 0 || setgid(pw->pw_gid) < 0) { - Logger::Error("unable to drop gid privs: %s", strerror(errno)); + Logger::Error("unable to drop gid privs: %s", + folly::errnoStr(errno).c_str()); return false; } if (uid == 0 || setuid(uid) < 0) { - Logger::Error("unable to drop uid privs: %s", strerror(errno)); + Logger::Error("unable to drop uid privs: %s", + folly::errnoStr(errno).c_str()); return false; } @@ -131,7 +135,8 @@ bool Capability::ChangeUnixUser(const std::string &username) { bool Capability::SetDumpable() { if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0)) { - Logger::Error("Unable to make process dumpable: %s", strerror(errno)); + Logger::Error("Unable to make process dumpable: %s", + folly::errnoStr(errno).c_str()); } return true; diff --git a/hphp/util/file_cache.cpp b/hphp/util/file_cache.cpp index 5c8339ce4..6971fabf3 100644 --- a/hphp/util/file_cache.cpp +++ b/hphp/util/file_cache.cpp @@ -19,6 +19,7 @@ #include "hphp/util/compression.h" #include "util.h" #include "hphp/util/logger.h" +#include "folly/String.h" #include namespace HPHP { @@ -125,7 +126,7 @@ void FileCache::write(const char *name, const char *fullpath) { struct stat sb; if (stat(fullpath, &sb) != 0) { throw Exception("Unable to stat %s: %s", fullpath, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); } int len = sb.st_size; Buffer &buffer = m_files[name]; @@ -138,7 +139,7 @@ void FileCache::write(const char *name, const char *fullpath) { FILE *f = fopen(fullpath, "r"); if (f == nullptr) { throw Exception("Unable to open %s: %s", fullpath, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); } char *buf = buffer.data = (char *)malloc(len); @@ -171,7 +172,7 @@ void FileCache::save(const char *filename) { FILE *f = fopen(filename, "w"); if (f == nullptr) { throw Exception("Unable to open %s: %s", filename, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); } // write an invalid length followed by a version number @@ -215,7 +216,7 @@ short FileCache::getVersion(const char *filename) { FILE *f = fopen(filename, "r"); if (f == nullptr) { throw Exception("Unable to open %s: %s", filename, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); } short tag = -1; @@ -233,7 +234,7 @@ void FileCache::load(const char *filename, bool onDemandUncompress, FILE *f = fopen(filename, "r"); if (f == nullptr) { throw Exception("Unable to open %s: %s", filename, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); } if (version > 0) { @@ -313,7 +314,7 @@ void FileCache::load(const char *filename, bool onDemandUncompress, void FileCache::adviseOutMemory() { if (posix_madvise(m_addr, m_size, POSIX_MADV_DONTNEED)) { Logger::Error("posix_madvise failed: %s", - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); } } @@ -324,19 +325,19 @@ void FileCache::loadMmap(const char *filename, short version) { struct stat sbuf; if (stat(filename, &sbuf) == -1) { throw Exception("Unable to stat %s: %s", filename, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); } m_fd = open(filename, O_RDONLY); if (m_fd == -1) { throw Exception("Unable to open %s: %s", filename, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); } m_addr = mmap(nullptr, sbuf.st_size, PROT_READ, MAP_PRIVATE, m_fd, 0); if (m_addr == (void *)-1) { close(m_fd); throw Exception("Unable to mmap %s: %s", filename, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); } m_size = sbuf.st_size; char *p = (char *)m_addr; diff --git a/hphp/util/light_process.cpp b/hphp/util/light_process.cpp index 2a5d18758..0d32b608e 100644 --- a/hphp/util/light_process.cpp +++ b/hphp/util/light_process.cpp @@ -18,6 +18,7 @@ #include "hphp/util/process.h" #include "util.h" #include "hphp/util/logger.h" +#include "folly/String.h" #include #include @@ -124,7 +125,7 @@ static void do_popen(FILE *fin, FILE *fout, int afdt_fd) { if (f == nullptr) { Logger::Error("Light process failed popen: %d (%s).", errno, - strerror(errno)); + folly::errnoStr(errno).c_str()); fprintf(fout, "error\n"); fflush(fout); } else { @@ -367,7 +368,7 @@ bool LightProcess::initShadow(const std::string &prefix, int id, CPipe p1, p2; if (!p1.open() || !p2.open()) { Logger::Warning("Unable to create pipe: %d %s", errno, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); return false; } @@ -402,7 +403,7 @@ bool LightProcess::initShadow(const std::string &prefix, int id, } else if (child < 0) { // failed Logger::Warning("Unable to fork lightly: %d %s", errno, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); return false; } else { // parent diff --git a/hphp/util/parser/xhpast2/xhpast2.cpp b/hphp/util/parser/xhpast2/xhpast2.cpp index e7cffb5f0..616b7428f 100644 --- a/hphp/util/parser/xhpast2/xhpast2.cpp +++ b/hphp/util/parser/xhpast2/xhpast2.cpp @@ -18,6 +18,8 @@ #include #include +#include "folly/String.h" + #include "hphp/util/parser/xhpast2/parser.h" namespace HPHP { namespace HPHP_PARSER_NS { @@ -77,7 +79,7 @@ int main(int argc, char** argv) try { std::ifstream in(argv[1]); if (!in.is_open()) { std::cerr << argv[0] << ": couldn't open file: " - << strerror(errno) << '\n'; + << folly::errnoStr(errno).toStdString() << '\n'; } std::cout << "1..1\n"; diff --git a/hphp/util/process.cpp b/hphp/util/process.cpp index ee36b59cf..080529821 100644 --- a/hphp/util/process.cpp +++ b/hphp/util/process.cpp @@ -20,6 +20,7 @@ #include "hphp/util/logger.h" #include "hphp/util/async_func.h" #include "hphp/util/text_color.h" +#include "folly/String.h" #include @@ -186,7 +187,7 @@ int Process::Exec(const std::string &cmd, const std::string &outf, int pid = fork(); if (pid < 0) { Logger::Error("Unable to fork: %d %s", errno, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); return 0; } if (pid == 0) { @@ -221,7 +222,7 @@ int Process::Exec(const char *path, const char *argv[], int *fdin, int *fdout, int pid = fork(); if (pid < 0) { Logger::Error("Unable to fork: %d %s", errno, - Util::safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); return 0; } if (pid == 0) { diff --git a/hphp/util/util.cpp b/hphp/util/util.cpp index 82e7be6dc..19bf6fe0f 100644 --- a/hphp/util/util.cpp +++ b/hphp/util/util.cpp @@ -20,6 +20,7 @@ #include "hphp/util/logger.h" #include "hphp/util/exception.h" #include "hphp/util/network.h" +#include "folly/String.h" #include #include @@ -266,11 +267,11 @@ int Util::copy(const char *srcfile, const char *dstfile) { if (rbytes == 0) break; if (rbytes == -1) { err = true; - Logger::Error("read failed: %s", safe_strerror(errno).c_str()); + Logger::Error("read failed: %s", folly::errnoStr(errno).c_str()); } else if ((wbytes = write(dstFd, buf, rbytes)) != rbytes) { err = true; Logger::Error("write failed: %zd, %s", wbytes, - safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); } if (err) { close(srcFd); @@ -342,27 +343,27 @@ int Util::directCopy(const char *srcfile, const char *dstfile) { if (rbytes == -1) { err = true; - Logger::Error("read failed: %s", safe_strerror(errno).c_str()); + Logger::Error("read failed: %s", folly::errnoStr(errno).c_str()); } else if (force_sync(srcFd) == -1) { err = true; Logger::Error("read sync failed: %s", - safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); } else if (drop_cache(srcFd) == -1) { err = true; Logger::Error("read cache drop failed: %s", - safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); } else if ((wbytes = write(dstFd, buf, rbytes)) != rbytes) { err = true; Logger::Error("write failed: %zd, %s", wbytes, - safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); } else if (force_sync(dstFd) == -1) { err = true; Logger::Error("write sync failed: %s", - safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); } else if (drop_cache(dstFd) == -1) { err = true; Logger::Error("write cache drop failed: %s", - safe_strerror(errno).c_str()); + folly::errnoStr(errno).c_str()); } if (err) { close(srcFd); @@ -398,23 +399,14 @@ int Util::directRename(const char *oldname, const char *newname) { int Util::ssystem(const char* command) { int ret = system(command); if (ret == -1) { - Logger::Error("system(\"%s\"): %s", command, safe_strerror(errno).c_str()); + Logger::Error("system(\"%s\"): %s", command, + folly::errnoStr(errno).c_str()); } else if (ret != 0) { Logger::Error("command failed: \"%s\"", command); } return ret; } -std::string Util::safe_strerror(int errnum) { - char buf[1024]; -#ifdef __GLIBC__ - return strerror_r(errnum, buf, sizeof(buf)); -#else - strerror_r(errnum, buf, sizeof(buf)); - return buf; -#endif -} - size_t Util::dirname_helper(char *path, int len) { if (len == 0) { /* Illegal use of this function */ diff --git a/hphp/util/util.h b/hphp/util/util.h index 7945207dc..a88f31f0c 100644 --- a/hphp/util/util.h +++ b/hphp/util/util.h @@ -195,11 +195,6 @@ const char *canonicalize(const char *path, size_t len, */ std::string normalizeDir(const std::string &dirname); -/** - * Thread-safe strerror(). - */ -std::string safe_strerror(int errnum); - /** * Thread-safe dirname(). */