From: arron <[email protected]>

When we update timezone info, we write changes to /etc/localtime, but
sometimes file /etc/localtime is a symlink, then inotify to watch this
file can't reflect the status of timezone update, also may change the
linked file.
The default umask value in connman is 0077, then when /etc/localtime
does not exists, the new created file can't be accessed by normal user
program.
---
 src/timezone.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/timezone.c b/src/timezone.c
index c6d8d68..7eac128 100644
--- a/src/timezone.c
+++ b/src/timezone.c
@@ -271,11 +271,19 @@ done:
 
 static int write_file(void *src_map, struct stat *src_st, const char *pathname)
 {
+       struct stat st;
        int fd;
        ssize_t written;
+       mode_t old_mask;
 
        DBG("pathname %s", pathname);
 
+       if (lstat(pathname, &st) == 0) {
+               if (S_ISLNK(st.st_mode))
+                       unlink(pathname);
+       }
+
+       old_mask = umask(0022);
        fd = open(pathname, O_WRONLY | O_CREAT | O_TRUNC, 0644);
        if (fd < 0)
                return -EIO;
@@ -283,6 +291,7 @@ static int write_file(void *src_map, struct stat *src_st, 
const char *pathname)
        written = write(fd, src_map, src_st->st_size);
 
        close(fd);
+       umask(old_mask);
 
        if (written < 0)
                return -EIO;
-- 
1.7.2.2

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to