syslog程序无法写入/ var / log / messages文件

时间:2018-08-27 11:49:52

标签: rsyslog

编写系统日志消息的程序。

#include <stdio.h>
#include <unistd.h>
#include <syslog.h>

int main(void) {
    openlog("slog", LOG_PID|LOG_CONS, LOG_USER);
    syslog(LOG_INFO, "A different kind of Hello world ... ");
    closelog();
    return 0;
}

1 个答案:

答案 0 :(得分:0)

为我工作

% cat > syslog.c
#include <stdio.h>
#include <unistd.h>
#include <syslog.h>

int main(void) {
    openlog("slog", LOG_PID|LOG_CONS, LOG_USER);
    syslog(LOG_INFO, "A different kind of Hello world ... ");
    closelog();
    return 0;
}

% cc syslog.c
% ./a.out
% tail /var/log/messages
tail: cannot open ‘/var/log/messages’ for reading: Permission denied

% su
Password: 
[root@build-centos7 src]# tail /var/log/messages | grep slog
Sep 17 13:09:10 build-centos7 slog[3040]: A different kind of Hello world ...