1 Star 0 Fork 0

renhongxun/mcelog_github

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
client.c 1.97 KB
一键复制 编辑 原始数据 按行查看 历史
Brahmajit Das 提交于 2023-06-12 10:55 . client.c: fix build w/ musl libc
/* Copyright (C) 2009 Intel Corporation
Author: Andi Kleen
Client code to talk to the mcelog server.
mcelog is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; version
2.
mcelog is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should find a copy of v2 of the GNU General Public License somewhere
on your Linux system; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <string.h>
#include "mcelog.h"
#include "client.h"
#include "paths.h"
#include "config.h"
/* Send a command to the mcelog server and dump output */
void ask_server(char *command)
{
struct sockaddr_un sun;
int fd;
FILE * fp;
int n;
char buf[1024];
char *path = config_string("server", "socket-path");
if (!path)
path = SOCKET_PATH;
fd = socket(PF_UNIX, SOCK_STREAM, 0);
if (fd < 0) {
SYSERRprintf("client socket");
return;
}
sun.sun_family = AF_UNIX;
sun.sun_path[sizeof(sun.sun_path)-1] = 0;
strncpy(sun.sun_path, path, sizeof(sun.sun_path)-1);
if (connect(fd, (struct sockaddr *)&sun,
sizeof(struct sockaddr_un)) < 0)
SYSERRprintf("client connect");
n = strlen(command);
if (write(fd, command, n) != n)
SYSERRprintf("client command write");
if ((fp = fdopen(fd, "r")) != NULL) {
while (fgets(buf, sizeof buf, fp)) {
n = strlen(buf);
if (n >= 5 && !memcmp(buf + n - 5, "done\n", 5)) {
fclose(fp);
return;
}
fputs(buf, stdout);
}
fclose(fp);
}
SYSERRprintf("client read");
}
void client_cleanup(void)
{
char *path = config_string("server", "socket-path");
if (!path)
path = SOCKET_PATH;
unlink(path);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/renxichen/mcelog_github.git
git@gitee.com:renxichen/mcelog_github.git
renxichen
mcelog_github
mcelog_github
master

搜索帮助