通过posix_spawn进行同步
Rsync through posix_spawn
我有一个正在运行的 rsync 守护进程,我可以成功执行以下命令:
rsync --port=1873 -avWh 127.0.0.1::jackfruit_peers/data.0a6/home/v/data
但从代码中:
local_dir =/home/v/data
remote_dir = 127.0.0.1::jackfruit_peers/data.0a6
pid_t child_pid;
char cmd[] = "rsync -avWh --port=1873";
char *argv[] = {cmd, remote_dir, local_dir,
(char*) 0};
if (0 != posix_spawn(&child_pid, "/usr/bin/rsync", NULL, NULL, argv, environ)) {
logger::error("posix spawn");
return ERR_INTERNAL_SERVER_ERROR;
}
我收到错误:
rsync:无法连接到 127.0.0.1(127.0.0.1):连接被拒绝 (111) rsync 错误:客户端服务器上的套接字 IO(代码 10)错误.c(128) [接收器=3.1.0] 2015-01-16 15:27:08.421.732 28623 0x7fbc01914010信息 唤醒其子 pid = 30060 的父母。错误=0
知道为什么吗?
编辑:rsync 句柄定义为:
[jackfruit_peers]
comment = for data transfer
path = /home/jackfruit/
read only = yes
timeout = 60
更改为这种丑陋的格式,它可以工作:
pid_t child_pid;
char a1[] = "rsync";
char a2[] = "-avWh";
char a3[] = "--port=1873";
char *argv[] = {a1, a2, a3, remote_dir, local_dir,
(char*)0};
if (0 != posix_spawn(&child_pid, "/usr/bin/rsync", NULL, NULL, argv, environ)) {
logger::error("posix spawn");
return ERR_INTERNAL_SERVER_ERROR;
}
当我使用实际的字符串常量代替 a1、a2、a3 时,我得到了从 const char* 到 char* 的不推荐使用的字符串转换,因此我愚蠢地将所有内容分解为:
char cmd[] = "rsync -avWh --port=1873";
相关文章:
- 松弛原子与无同步情况下的记忆连贯性
- 使用QQuickFramebufferObject时同步数据的最佳方式是什么
- 在C++中同步线程
- 与 stdio 同步是否使程序 I/O 非交互式?
- 如何在qt中同步应用程序和显示器的刷新率?
- Windows 进程间同步类似事件?
- 当对套接字 send() 的同步调用由于连接另一端丢失而被阻止时,如何恢复?
- 将 10 个线程与原子布尔值同步
- ofstream::close() 是否在 Linux 上调用同步?
- 与Visual Studios(c ++)同步时如何组织github存储库?
- 原子获取是否与互斥锁释放同步?
- Boost (Beast) websocket:同步写入挂起
- Postgres vs MySQL:命令不同步;.
- 线程过程中的线程同步问题
- 同步读取多个 TCP 响应
- 同步两个具有不同帧速率的传感器
- 如何定期同步线程?
- 同步对多个向量进行排序
- 同步类中的公共变量
- 如何检查 ntpd 是否仍在运行和同步