2015-01-16 55 views
0

我有一個rsync進程運行,我可以成功執行以下命令:的Rsync通過的posix_spawn

的rsync --port = 1873年-avWh 127.0.0.1::jackfruit_peers/data.0a6 /家庭/ V /數據

但是從代碼:

local_dir = /家庭/ v /數據

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 

回答

0

更改爲這個醜陋的格式,它的工作原理:

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

我漸漸棄用從爲const char *字符串轉換爲char *時我使用實際的字符串常量代替a1,a2,a3,因此我愚蠢地將所有東西都變成了:

char cmd[] = "rsync -avWh --port=1873";