From: Yu Watanabe Date: Sun, 28 Sep 2025 01:09:44 +0000 (+0900) Subject: calendar-spec: use SAVE_TIMEZONE X-Git-Tag: v259-rc1~399^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=672924356f9dc2876cc416a8e0cb25c1b6f1c0dd;p=thirdparty%2Fsystemd.git calendar-spec: use SAVE_TIMEZONE Then, we can avoid heavy fork() operation. --- diff --git a/src/shared/calendarspec.c b/src/shared/calendarspec.c index 3569f15db4f..b15f9290367 100644 --- a/src/shared/calendarspec.c +++ b/src/shared/calendarspec.c @@ -1426,13 +1426,7 @@ static int calendar_spec_next_usec_impl(const CalendarSpec *spec, usec_t usec, u return 0; } -typedef struct SpecNextResult { - usec_t next; - int return_value; -} SpecNextResult; - int calendar_spec_next_usec(const CalendarSpec *spec, usec_t usec, usec_t *ret_next) { - SpecNextResult *shared, tmp; int r; assert(spec); @@ -1440,39 +1434,16 @@ int calendar_spec_next_usec(const CalendarSpec *spec, usec_t usec, usec_t *ret_n if (isempty(spec->timezone)) return calendar_spec_next_usec_impl(spec, usec, ret_next); - shared = mmap(NULL, sizeof *shared, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0); - if (shared == MAP_FAILED) - return negative_errno(); - - r = safe_fork("(sd-calendar)", FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_DEATHSIG_SIGKILL|FORK_WAIT, NULL); - if (r < 0) { - (void) munmap(shared, sizeof *shared); - return r; - } - if (r == 0) { - char *colon_tz; + SAVE_TIMEZONE; - /* tzset(3) says $TZ should be prefixed with ":" if we reference timezone files */ - colon_tz = strjoina(":", spec->timezone); + /* tzset(3) says $TZ should be prefixed with ":" if we reference timezone files */ + const char *colon_tz = strjoina(":", spec->timezone); - if (setenv("TZ", colon_tz, 1) != 0) { - shared->return_value = negative_errno(); - _exit(EXIT_FAILURE); - } - - tzset(); - - shared->return_value = calendar_spec_next_usec_impl(spec, usec, &shared->next); - - _exit(EXIT_SUCCESS); - } - - tmp = *shared; - if (munmap(shared, sizeof *shared) < 0) - return negative_errno(); + r = RET_NERRNO(setenv("TZ", colon_tz, 1)); + if (r < 0) + return r; - if (tmp.return_value == 0 && ret_next) - *ret_next = tmp.next; + tzset(); - return tmp.return_value; + return calendar_spec_next_usec_impl(spec, usec, ret_next); }