65 lines
1.7 KiB
C
65 lines
1.7 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <signal.h>
|
|
|
|
// 声明client.h中的函数
|
|
int seeking_solutions(const char* filename, char* const argv[],
|
|
char* const envp[], const char* logPath, int* output_fd);
|
|
|
|
static volatile int should_exit = 0;
|
|
|
|
void handle_sigint(int sig) {
|
|
(void)sig;
|
|
should_exit = 1;
|
|
printf("\n\n收到退出信号,正在关闭...\n");
|
|
}
|
|
|
|
int main() {
|
|
// 设置信号处理
|
|
signal(SIGINT, handle_sigint);
|
|
|
|
// 检查服务端是否运行(静默检查)
|
|
if (access("/var/run/bash-smart.sock", F_OK) != 0) {
|
|
fprintf(stderr, "错误:无法连接到服务端 (socket: /var/run/bash-smart.sock)\n");
|
|
fprintf(stderr, "请先启动 Go 服务端\n");
|
|
return 1;
|
|
}
|
|
|
|
// 创建模拟的命令执行场景
|
|
const char* filename = "/usr/bin/test_command";
|
|
char* argv[] = {
|
|
(char*)"test_command",
|
|
(char*)"--option",
|
|
(char*)"value",
|
|
NULL
|
|
};
|
|
|
|
// 简单的环境变量
|
|
extern char** environ;
|
|
char** envp = environ;
|
|
|
|
const char* logPath = "/tmp/test_client_error.log";
|
|
|
|
// 创建测试错误日志
|
|
FILE* f = fopen(logPath, "w");
|
|
if (f) {
|
|
fprintf(f, "测试错误信息:命令执行失败\n");
|
|
fprintf(f, "Error: Command not found\n");
|
|
fprintf(f, "Exit code: 127\n");
|
|
fclose(f);
|
|
}
|
|
|
|
int output_fd = STDOUT_FILENO;
|
|
|
|
// 连接并进入交互模式(所有输出由 Go 服务端控制)
|
|
int result = seeking_solutions(filename, argv, envp, logPath, &output_fd);
|
|
|
|
// 清理测试文件
|
|
unlink(logPath);
|
|
|
|
// 退出时不输出任何内容,让终端保持干净
|
|
return result;
|
|
}
|