gpt4 book ai didi

c++ - 通过 posix_spawn 进行 Rsync

转载 作者:行者123 更新时间:2023-11-30 17:22:38 27 4
gpt4 key购买 nike

我有一个 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: failed to connect to 127.0.0.1 (127.0.0.1): Connection refused (111) rsync error: error in socket IO (code 10) at clientserver.c(128) [Receiver=3.1.0] 2015-01-16 15:27:08.421.732 28623 0x7fbc01914010 INFO Waking up parent whose child pid=30060. errno=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";

关于c++ - 通过 posix_spawn 进行 Rsync,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27981404/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com