mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-04 04:15:07 -05:00
Check return value of chmod() and fcntl()
This commit is contained in:
@@ -359,10 +359,12 @@ update_drift_file(double freq_ppm, double skew)
|
|||||||
/* Clone the file attributes from the existing file if there is one. */
|
/* Clone the file attributes from the existing file if there is one. */
|
||||||
|
|
||||||
if (!stat(drift_file,&buf)) {
|
if (!stat(drift_file,&buf)) {
|
||||||
if (chown(temp_drift_file,buf.st_uid,buf.st_gid)) {
|
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);
|
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). */
|
/* Rename the temporary file to the correct location (see rename(2) for details). */
|
||||||
|
|||||||
@@ -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. */
|
/* Clone the file attributes from the existing file if there is one. */
|
||||||
|
|
||||||
if (!stat(coefs_file_name,&buf)) {
|
if (!stat(coefs_file_name,&buf)) {
|
||||||
if (chown(temp_coefs_file_name,buf.st_uid,buf.st_gid)) {
|
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);
|
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). */
|
/* Rename the temporary file to the correct location (see rename(2) for details). */
|
||||||
|
|||||||
6
util.c
6
util.c
@@ -647,7 +647,7 @@ UTI_FloatHostToNetwork(double x)
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
int
|
||||||
UTI_FdSetCloexec(int fd)
|
UTI_FdSetCloexec(int fd)
|
||||||
{
|
{
|
||||||
int flags;
|
int flags;
|
||||||
@@ -655,8 +655,10 @@ UTI_FdSetCloexec(int fd)
|
|||||||
flags = fcntl(fd, F_GETFD);
|
flags = fcntl(fd, F_GETFD);
|
||||||
if (flags != -1) {
|
if (flags != -1) {
|
||||||
flags |= FD_CLOEXEC;
|
flags |= FD_CLOEXEC;
|
||||||
fcntl(fd, F_SETFD, flags);
|
return !fcntl(fd, F_SETFD, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|||||||
2
util.h
2
util.h
@@ -108,7 +108,7 @@ extern double UTI_FloatNetworkToHost(Float x);
|
|||||||
extern Float UTI_FloatHostToNetwork(double x);
|
extern Float UTI_FloatHostToNetwork(double x);
|
||||||
|
|
||||||
/* Set FD_CLOEXEC on descriptor */
|
/* 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,
|
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);
|
const unsigned char *data, int data_len, unsigned char *auth, int auth_len);
|
||||||
|
|||||||
Reference in New Issue
Block a user