m_flush_mutex_holder(0),
m_new(), m_recent(),
m_fd(-1),
+ m_uid(0),
+ m_gid(0),
m_syslog_log(-2), m_syslog_crash(-2),
m_stderr_log(1), m_stderr_crash(-1),
m_graylog_log(-3), m_graylog_crash(-3),
VOID_TEMP_FAILURE_RETRY(::close(m_fd));
if (m_log_file.length()) {
m_fd = ::open(m_log_file.c_str(), O_CREAT|O_WRONLY|O_APPEND, 0644);
+ if (m_uid || m_gid) {
+ int r = ::fchown(m_fd, m_uid, m_gid);
+ if (r < 0) {
+ r = -errno;
+ cerr << "failed to chown " << m_log_file << ": " << cpp_strerror(r)
+ << std::endl;
+ }
+ }
} else {
m_fd = -1;
}
pthread_mutex_unlock(&m_flush_mutex);
}
+void Log::chown_log_file(uid_t uid, gid_t gid)
+{
+ pthread_mutex_lock(&m_flush_mutex);
+ if (m_fd >= 0) {
+ int r = ::fchown(m_fd, uid, gid);
+ if (r < 0) {
+ r = -errno;
+ cerr << "failed to chown " << m_log_file << ": " << cpp_strerror(r)
+ << std::endl;
+ }
+ }
+ pthread_mutex_unlock(&m_flush_mutex);
+}
+
void Log::set_syslog_level(int log, int crash)
{
pthread_mutex_lock(&m_flush_mutex);
std::string m_log_file;
int m_fd;
+ uid_t m_uid;
+ gid_t m_gid;
int m_syslog_log, m_syslog_crash;
int m_stderr_log, m_stderr_crash;
void set_max_recent(int n);
void set_log_file(std::string fn);
void reopen_log_file();
+ void chown_log_file(uid_t uid, gid_t gid);
void flush();