summaryrefslogtreecommitdiff
path: root/src/timezone.c
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2011-04-20 10:01:34 -0700
committerMarcel Holtmann <marcel@holtmann.org>2011-04-20 10:01:34 -0700
commit847d9e301526290c8d7450c8249445b36049bf7f (patch)
tree25073753f66037ebcc2bf1c3d0360596fac5d5fe /src/timezone.c
parentebfaaf23882ebf0f113a079e7650b5cd917a0028 (diff)
downloadconnman-847d9e301526290c8d7450c8249445b36049bf7f.tar.gz
connman-847d9e301526290c8d7450c8249445b36049bf7f.tar.bz2
connman-847d9e301526290c8d7450c8249445b36049bf7f.zip
timezone: Add support for writing new timezone information
Diffstat (limited to 'src/timezone.c')
-rw-r--r--src/timezone.c50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/timezone.c b/src/timezone.c
index 717270b4..263ee4ef 100644
--- a/src/timezone.c
+++ b/src/timezone.c
@@ -268,11 +268,59 @@ done:
return zone;
}
+static int write_file(void *src_map, struct stat *src_st, const char *pathname)
+{
+ int fd;
+ ssize_t written;
+
+ DBG("pathname %s", pathname);
+
+ fd = open(pathname, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ if (fd < 0)
+ return -EIO;
+
+ written = write(fd, src_map, src_st->st_size);
+
+ close(fd);
+
+ if (written < 0)
+ return -EIO;
+
+ return 0;
+}
+
int __connman_timezone_change(const char *zone)
{
+ struct stat st;
+ char *map, pathname[PATH_MAX];
+ int fd, err;
+
DBG("zone %s", zone);
- return -EIO;
+ snprintf(pathname, PATH_MAX, "%s/%s", USR_SHARE_ZONEINFO, zone);
+
+ fd = open(pathname, O_RDONLY);
+ if (fd < 0)
+ return -EINVAL;
+
+ if (fstat(fd, &st) < 0) {
+ close(fd);
+ return -EIO;
+ }
+
+ map = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
+ if (map == NULL || map == MAP_FAILED) {
+ close(fd);
+ return -EIO;
+ }
+
+ err = write_file(map, &st, ETC_LOCALTIME);
+
+ munmap(map, st.st_size);
+
+ close(fd);
+
+ return err;
}
static guint inotify_watch = 0;