[PATCH 1/2] libbb/rtc: rtc_read_tm: return error code on RTC_RD_TIME failure
Thomas Perrot via busybox <[email protected]> Tue, 26 May 2026 11:21:47 +0200
| Newsgroups | gmane.linux.busybox |
|---|---|
| Message-ID | <[email protected]> |
rtc_read_tm() used xioctl() which calls bb_simple_perror_msg_and_die() on any ioctl failure, giving callers no way to distinguish error cases. Change the return type from void to int and use a plain ioctl() call. Return -errno on failure, 0 on success. This lets callers inspect the error and decide how to handle it rather than always dying. Signed-off-by: Thomas Perrot <[email protected]> Reviewed-by: Alexandre Belloni <[email protected]> --- include/rtc_.h | 2 +- libbb/rtc.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/rtc_.h b/include/rtc_.h index 7829660908a5..4f0ce05720d5 100644 --- a/include/rtc_.h +++ b/include/rtc_.h @@ -19,7 +19,7 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN int rtc_adjtime_is_utc(void) FAST_FUNC; int rtc_xopen(const char **default_rtc, int flags) FAST_FUNC; -void rtc_read_tm(struct tm *ptm, int fd) FAST_FUNC; +int rtc_read_tm(struct tm *ptm, int fd) FAST_FUNC; time_t rtc_tm2time(struct tm *ptm, int utc) FAST_FUNC; diff --git a/libbb/rtc.c b/libbb/rtc.c index 54b52f23a3c6..43ef2a7086cf 100644 --- a/libbb/rtc.c +++ b/libbb/rtc.c @@ -78,11 +78,13 @@ int FAST_FUNC rtc_xopen(const char **default_rtc, int flags) } } -void FAST_FUNC rtc_read_tm(struct tm *ptm, int fd) +int FAST_FUNC rtc_read_tm(struct tm *ptm, int fd) { memset(ptm, 0, sizeof(*ptm)); - xioctl(fd, RTC_RD_TIME, ptm); + if (ioctl(fd, RTC_RD_TIME, ptm) < 0) + return -errno; ptm->tm_isdst = -1; /* "not known" */ + return 0; } time_t FAST_FUNC rtc_tm2time(struct tm *ptm, int utc) -- 2.54.0