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);
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);
}