fix(log): remove remaining format specifiers and fix malformed log calls

- src/libipc/platform/posix/condition.h:
  * Replace all %d and %s format specifiers with stream-based syntax
  * Update log.error() calls to use proper streaming (e.g., "[", eno, "]")

- src/libipc/platform/posix/semaphore_impl.h:
  * Remove %d format specifiers from log.error() calls
  * Fix malformed parentheses (e.g., .c_str(, ""))
  * Remove unnecessary empty string arguments
  * Use stream-based logging consistently

- src/libipc/platform/win/mutex.h:
  * Fix malformed GetLastError() parentheses
  * Remove %lu format specifier, use explicit cast instead
  * Update to stream-based logging syntax

- src/libipc/platform/win/semaphore.h:
  * Fix malformed GetLastError() parentheses
  * Remove %lu format specifier, use explicit cast instead
  * Update to stream-based logging syntax

All format specifiers (%d, %s, %zd, %p, %lu) have been removed and replaced
with proper C++ stream-based logging that is type-safe and consistent with
the new imp/log interface.
This commit is contained in:
木头云 2025-12-15 10:06:52 +00:00
parent 1664526c40
commit 2b1ed4bc51
4 changed files with 18 additions and 18 deletions

View File

@ -23,7 +23,7 @@ class condition {
pthread_cond_t *acquire_cond(char const *name) { pthread_cond_t *acquire_cond(char const *name) {
LIBIPC_LOG(); LIBIPC_LOG();
if (!shm_.acquire(name, sizeof(pthread_cond_t))) { if (!shm_.acquire(name, sizeof(pthread_cond_t))) {
log.error("[acquire_cond] fail shm.acquire: %s", name); log.error("[acquire_cond] fail shm.acquire: ", name);
return nullptr; return nullptr;
} }
return static_cast<pthread_cond_t *>(shm_.get()); return static_cast<pthread_cond_t *>(shm_.get());
@ -62,17 +62,17 @@ public:
int eno; int eno;
pthread_condattr_t cond_attr; pthread_condattr_t cond_attr;
if ((eno = ::pthread_condattr_init(&cond_attr)) != 0) { if ((eno = ::pthread_condattr_init(&cond_attr)) != 0) {
log.error("fail pthread_condattr_init[%d]", eno); log.error("fail pthread_condattr_init[", eno, "]");
return false; return false;
} }
LIBIPC_UNUSED auto guard_cond_attr = guard([&cond_attr] { ::pthread_condattr_destroy(&cond_attr); }); LIBIPC_UNUSED auto guard_cond_attr = guard([&cond_attr] { ::pthread_condattr_destroy(&cond_attr); });
if ((eno = ::pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED)) != 0) { if ((eno = ::pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED)) != 0) {
log.error("fail pthread_condattr_setpshared[%d]", eno); log.error("fail pthread_condattr_setpshared[", eno, "]");
return false; return false;
} }
*cond_ = PTHREAD_COND_INITIALIZER; *cond_ = PTHREAD_COND_INITIALIZER;
if ((eno = ::pthread_cond_init(cond_, &cond_attr)) != 0) { if ((eno = ::pthread_cond_init(cond_, &cond_attr)) != 0) {
log.error("fail pthread_cond_init[%d]", eno); log.error("fail pthread_cond_init[", eno, "]");
return false; return false;
} }
finally.dismiss(); finally.dismiss();
@ -84,7 +84,7 @@ public:
if ((shm_.ref() <= 1) && cond_ != nullptr) { if ((shm_.ref() <= 1) && cond_ != nullptr) {
int eno; int eno;
if ((eno = ::pthread_cond_destroy(cond_)) != 0) { if ((eno = ::pthread_cond_destroy(cond_)) != 0) {
log.error("fail pthread_cond_destroy[%d]", eno); log.error("fail pthread_cond_destroy[", eno, "]");
} }
} }
shm_.release(); shm_.release();
@ -95,7 +95,7 @@ public:
if ((shm_.ref() <= 1) && cond_ != nullptr) { if ((shm_.ref() <= 1) && cond_ != nullptr) {
int eno; int eno;
if ((eno = ::pthread_cond_destroy(cond_)) != 0) { if ((eno = ::pthread_cond_destroy(cond_)) != 0) {
log.error("fail pthread_cond_destroy[%d]", eno); log.error("fail pthread_cond_destroy[", eno, "]");
} }
} }
shm_.clear(); // Make sure the storage is cleaned up. shm_.clear(); // Make sure the storage is cleaned up.
@ -113,7 +113,7 @@ public:
case invalid_value: { case invalid_value: {
int eno; int eno;
if ((eno = ::pthread_cond_wait(cond_, static_cast<pthread_mutex_t *>(mtx.native()))) != 0) { if ((eno = ::pthread_cond_wait(cond_, static_cast<pthread_mutex_t *>(mtx.native()))) != 0) {
log.error("fail pthread_cond_wait[%d]", eno); log.error("fail pthread_cond_wait[", eno, "]");
return false; return false;
} }
} }
@ -137,7 +137,7 @@ public:
if (!valid()) return false; if (!valid()) return false;
int eno; int eno;
if ((eno = ::pthread_cond_signal(cond_)) != 0) { if ((eno = ::pthread_cond_signal(cond_)) != 0) {
log.error("fail pthread_cond_signal[%d]", eno); log.error("fail pthread_cond_signal[", eno, "]");
return false; return false;
} }
return true; return true;
@ -147,7 +147,7 @@ public:
if (!valid()) return false; if (!valid()) return false;
int eno; int eno;
if ((eno = ::pthread_cond_broadcast(cond_)) != 0) { if ((eno = ::pthread_cond_broadcast(cond_)) != 0) {
log.error("fail pthread_cond_broadcast[%d]", eno); log.error("fail pthread_cond_broadcast[", eno, "]");
return false; return false;
} }
return true; return true;

View File

@ -37,7 +37,7 @@ public:
LIBIPC_LOG(); LIBIPC_LOG();
close(); close();
if (!shm_.acquire(name, 1)) { if (!shm_.acquire(name, 1)) {
log.error("[open_semaphore] fail shm.acquire: ", name, ""); log.error("[open_semaphore] fail shm.acquire: ", name);
return false; return false;
} }
// POSIX semaphore names must start with "/" on some platforms (e.g., FreeBSD) // POSIX semaphore names must start with "/" on some platforms (e.g., FreeBSD)
@ -49,7 +49,7 @@ public:
} }
h_ = ::sem_open(sem_name_.c_str(), O_CREAT, 0666, static_cast<unsigned>(count)); h_ = ::sem_open(sem_name_.c_str(), O_CREAT, 0666, static_cast<unsigned>(count));
if (h_ == SEM_FAILED) { if (h_ == SEM_FAILED) {
log.error("fail sem_open[%d]: ", errno, sem_name_.c_str(, "")); log.error("fail sem_open[", errno, "]: ", sem_name_);
return false; return false;
} }
return true; return true;
@ -59,13 +59,13 @@ public:
LIBIPC_LOG(); LIBIPC_LOG();
if (!valid()) return; if (!valid()) return;
if (::sem_close(h_) != 0) { if (::sem_close(h_) != 0) {
log.error("fail sem_close[%d]: ", errno, ""); log.error("fail sem_close[", errno, "]");
} }
h_ = SEM_FAILED; h_ = SEM_FAILED;
if (!sem_name_.empty() && shm_.name() != nullptr) { if (!sem_name_.empty() && shm_.name() != nullptr) {
if (shm_.release() <= 1) { if (shm_.release() <= 1) {
if (::sem_unlink(sem_name_.c_str()) != 0) { if (::sem_unlink(sem_name_.c_str()) != 0) {
log.error("fail sem_unlink[%d]: ", errno, sem_name_.c_str(, ", name: %s")); log.error("fail sem_unlink[", errno, "]: ", sem_name_);
} }
} }
} }
@ -76,7 +76,7 @@ public:
LIBIPC_LOG(); LIBIPC_LOG();
if (valid()) { if (valid()) {
if (::sem_close(h_) != 0) { if (::sem_close(h_) != 0) {
log.error("fail sem_close[%d]: ", errno, ""); log.error("fail sem_close[", errno, "]");
} }
h_ = SEM_FAILED; h_ = SEM_FAILED;
} }
@ -104,7 +104,7 @@ public:
if (!valid()) return false; if (!valid()) return false;
if (tm == invalid_value) { if (tm == invalid_value) {
if (::sem_wait(h_) != 0) { if (::sem_wait(h_) != 0) {
log.error("fail sem_wait[%d]: ", errno, ""); log.error("fail sem_wait[", errno, "]");
return false; return false;
} }
} else { } else {
@ -124,7 +124,7 @@ public:
if (!valid()) return false; if (!valid()) return false;
for (std::uint32_t i = 0; i < count; ++i) { for (std::uint32_t i = 0; i < count; ++i) {
if (::sem_post(h_) != 0) { if (::sem_post(h_) != 0) {
log.error("fail sem_post[%d]: ", errno, ""); log.error("fail sem_post[", errno, "]");
return false; return false;
} }
} }

View File

@ -40,7 +40,7 @@ public:
close(); close();
h_ = ::CreateMutex(detail::get_sa(), FALSE, detail::to_tchar(name).c_str()); h_ = ::CreateMutex(detail::get_sa(), FALSE, detail::to_tchar(name).c_str());
if (h_ == NULL) { if (h_ == NULL) {
log.error("fail CreateMutex[%lu]: ", ::GetLastError(, ""), name); log.error("fail CreateMutex[", static_cast<unsigned long>(::GetLastError()), "]: ", name);
return false; return false;
} }
return true; return true;

View File

@ -39,7 +39,7 @@ public:
static_cast<LONG>(count), LONG_MAX, static_cast<LONG>(count), LONG_MAX,
detail::to_tchar(name).c_str()); detail::to_tchar(name).c_str());
if (h_ == NULL) { if (h_ == NULL) {
log.error("fail CreateSemaphore[%lu]: ", ::GetLastError(, ""), name); log.error("fail CreateSemaphore[", static_cast<unsigned long>(::GetLastError()), "]: ", name);
return false; return false;
} }
return true; return true;