]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Check return value of chmod() and fcntl()
authorMiroslav Lichvar <mlichvar@redhat.com>
Fri, 6 Jun 2014 10:07:31 +0000 (12:07 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 6 Jun 2014 10:07:31 +0000 (12:07 +0200)
reference.c
rtc_linux.c
util.c
util.h

index 08648894b11bcc65ed9ef773bf28d0e438d9bd3b..288e10b9d45504e630c64f56e95204a0c750fc0a 100644 (file)
@@ -359,10 +359,12 @@ update_drift_file(double freq_ppm, double skew)
   /* Clone the file attributes from the existing file if there is one. */
 
   if (!stat(drift_file,&buf)) {
-    if (chown(temp_drift_file,buf.st_uid,buf.st_gid)) {
-      LOG(LOGS_WARN, LOGF_Reference, "Could not change ownership of temporary driftfile %s.tmp", drift_file);
+    if (chown(temp_drift_file,buf.st_uid,buf.st_gid) ||
+        chmod(temp_drift_file,buf.st_mode & 0777)) {
+      LOG(LOGS_WARN, LOGF_Reference,
+          "Could not change ownership or permissions of temporary driftfile %s.tmp",
+          drift_file);
     }
-    chmod(temp_drift_file,buf.st_mode&0777);
   }
 
   /* Rename the temporary file to the correct location (see rename(2) for details). */
index 5100808e4ef8a56bb92c7ca9b22c8070fba6e8da..b87d8f34ad5bb95a241877cc22b2cd14016eeafe 100644 (file)
@@ -508,10 +508,12 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate)
   /* Clone the file attributes from the existing file if there is one. */
 
   if (!stat(coefs_file_name,&buf)) {
-    if (chown(temp_coefs_file_name,buf.st_uid,buf.st_gid)) {
-      LOG(LOGS_WARN, LOGF_RtcLinux, "Could not change ownership of temporary RTC file %s.tmp", coefs_file_name);
+    if (chown(temp_coefs_file_name,buf.st_uid,buf.st_gid) ||
+        chmod(temp_coefs_file_name,buf.st_mode & 0777)) {
+      LOG(LOGS_WARN, LOGF_RtcLinux,
+          "Could not change ownership or permissions of temporary RTC file %s.tmp",
+          coefs_file_name);
     }
-    chmod(temp_coefs_file_name,buf.st_mode&0777);
   }
 
   /* Rename the temporary file to the correct location (see rename(2) for details). */
diff --git a/util.c b/util.c
index ec7703e6e284c0735db69aac307414b44a92927f..077456c0f9f1d8de09ddea395337f14467cd3392 100644 (file)
--- a/util.c
+++ b/util.c
@@ -647,7 +647,7 @@ UTI_FloatHostToNetwork(double x)
 
 /* ================================================== */
 
-void
+int
 UTI_FdSetCloexec(int fd)
 {
   int flags;
@@ -655,8 +655,10 @@ UTI_FdSetCloexec(int fd)
   flags = fcntl(fd, F_GETFD);
   if (flags != -1) {
     flags |= FD_CLOEXEC;
-    fcntl(fd, F_SETFD, flags);
+    return !fcntl(fd, F_SETFD, flags);
   }
+
+  return 0;
 }
 
 /* ================================================== */
diff --git a/util.h b/util.h
index 774509c2d77a68b8b4de117eeecb926b73c79bc7..a0a688db5df3f3ab5a17613e7b7453aa6d1b0e23 100644 (file)
--- a/util.h
+++ b/util.h
@@ -108,7 +108,7 @@ extern double UTI_FloatNetworkToHost(Float x);
 extern Float UTI_FloatHostToNetwork(double x);
 
 /* Set FD_CLOEXEC on descriptor */
-extern void UTI_FdSetCloexec(int fd);
+extern int UTI_FdSetCloexec(int fd);
 
 extern int UTI_GenerateNTPAuth(int hash_id, const unsigned char *key, int key_len,
     const unsigned char *data, int data_len, unsigned char *auth, int auth_len);