【问题标题】:Rsync through posix_spawn通过 posix_spawn 进行 Rsync
【发布时间】:2015-01-16 10:00:09
【问题描述】:

我有一个 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 错误:clientserver.c(128) 处的套接字 IO(代码 10)错误 [接收方=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

【问题讨论】:

    标签: c++ c posix rsync


    【解决方案1】:

    改成这种丑陋的格式就可以了:

       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";
    

    【讨论】:

      猜你喜欢
      • 2013-05-15
      • 2015-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-23
      • 2019-01-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多