rsyslogd 是通过socket与客户端进行消息交换的。默认socket文件是/dev/log。

另外rsyslogd默认是采用DGRAM的socket模式.

下面代码是一个可以写log的程序。

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/time.h>
#include <string.h>
#include <netinet/in.h>

static struct sockaddr_un logAddr;
char *buf = "helloworld";
int main(void)
{
        int file;
        logAddr.sun_family = AF_UNIX;
        strncpy(logAddr.sun_path, "/dev/log", sizeof("/dev/log"));
        file = socket(AF_UNIX, SOCK_DGRAM, 0);
        connect(file, (struct sockaddr *)&logAddr, sizeof(logAddr));
        send(file, buf, 12, 0);
        close(file);
        return 0;
}

相关文章:

  • 2021-11-22
  • 2021-10-29
  • 2022-12-23
  • 2022-12-23
  • 2021-09-19
  • 2022-12-23
  • 2021-07-24
  • 2022-01-18
猜你喜欢
  • 2021-06-11
  • 2021-12-06
  • 2022-01-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-31
  • 2020-04-06
相关资源
相似解决方案