hwclock.c revision a866073d35dea05e6f3e56328d3eb6436943e7e6
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering This file is part of systemd.
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering Copyright 2010-2012 Lennart Poettering
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering systemd is free software; you can redistribute it and/or modify it
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering under the terms of the GNU Lesser General Public License as published by
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering (at your option) any later version.
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering systemd is distributed in the hope that it will be useful, but
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering Lesser General Public License for more details.
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering You should have received a copy of the GNU Lesser General Public License
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering /* First, we try to make use of the /dev/rtc symlink. If that
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering * doesn't exist, we open the first RTC which has hctosys=1
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering * set. If we don't find any we just take the first RTC that
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering * exists at all. */
d4fffc4b8beb86e77fd710c1f43913a490ed083aZbigniew Jędrzejewski-Szmek p = strjoin("/sys/class/rtc/", de->d_name, "/hctosys", NULL);
9444b1f20e311f073864d81e913bd4f32fe95cfdLennart Poettering /* This leaves the timezone fields of struct tm
7027ff61a34a12487712b382a061c654acc3a679Lennart Poettering * uninitialized! */
8b0849e9710d721c5d0b775aaf0fd662eefa1449Lennart Poettering /* We don't know daylight saving, so we reset this in order not
8b0849e9710d721c5d0b775aaf0fd662eefa1449Lennart Poettering * to confused mktime(). */
8b0849e9710d721c5d0b775aaf0fd662eefa1449Lennart Poetteringint hwclock_set_time(const struct tm *tm) {
fed1e721fd0c81e60c77120539f34e16c2585634Lennart Poettering * The third line of adjtime is "UTC" or "LOCAL" or nothing.
ae018d9bc900d6355dea4af05119b49c67945184Lennart Poettering assert_se(clock_gettime(CLOCK_REALTIME, &ts) == 0);
ae018d9bc900d6355dea4af05119b49c67945184Lennart Poettering * If the hardware clock does not run in UTC, but in local time:
ae018d9bc900d6355dea4af05119b49c67945184Lennart Poettering * The very first time we set the kernel's timezone, it will warp
ae018d9bc900d6355dea4af05119b49c67945184Lennart Poettering * the clock so that it runs in UTC instead of local time.
78edb35ab4f4227485cb9ec816b43c37e0d5e62aLennart Poettering * The very first time we set the kernel's timezone, it will warp
78edb35ab4f4227485cb9ec816b43c37e0d5e62aLennart Poettering * the clock. Do a dummy call here, so the time warping is sealed
78edb35ab4f4227485cb9ec816b43c37e0d5e62aLennart Poettering * and we set only the time zone with next call.