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

问题描述 投票:0回答:1

编写syslog消息的程序。

#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;
}
rsyslog
1个回答
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 ...
© www.soinside.com 2019 - 2024. All rights reserved.