Fossil SCM
Add the test-ssh-far-side command that can be used in place of a shell for the remote side of an ssh: sync.
Commit
43c452262344bf18bf9f89cfeafaad60e35e750d
Parent
2163cd9666f2ae1…
1 file changed
+40
-1
+40
-1
| --- src/http_transport.c | ||
| +++ src/http_transport.c | ||
| @@ -223,11 +223,26 @@ | ||
| 223 | 223 | zHost = mprintf("%s", g.urlName); |
| 224 | 224 | } |
| 225 | 225 | n = blob_size(&zCmd); |
| 226 | 226 | blob_append(&zCmd, " ", 1); |
| 227 | 227 | shell_escape(&zCmd, zHost); |
| 228 | - if( g.urlShell ) blob_appendf(&zCmd, " %s", g.urlShell); | |
| 228 | + if( g.urlShell ){ | |
| 229 | + blob_appendf(&zCmd, " %s", g.urlShell); | |
| 230 | + }else{ | |
| 231 | +#if defined(FOSSIL_ENABLE_SSH_FAR_SIDE) | |
| 232 | + /* The following works. But only if the fossil on the remote side | |
| 233 | + ** is recent enough to support the test-ssh-far-side command. That | |
| 234 | + ** command was added on 2013-02-06. We will leave this turned off | |
| 235 | + ** until most fossil servers have upgraded to that version or a later | |
| 236 | + ** version. The sync will still work as long as the shell on the far | |
| 237 | + ** side is bash and not tcsh. And if the default far side shell is | |
| 238 | + ** tcsh, then the shell=/bin/bash query parameter can be used as a | |
| 239 | + ** work-around. Enable this code after about a year... | |
| 240 | + */ | |
| 241 | + blob_appendf(&zCmd, " exec %s test-ssh-far-side", g.urlFossil); | |
| 242 | +#endif | |
| 243 | + } | |
| 229 | 244 | fossil_print("%s\n", blob_str(&zCmd)+n); /* Show tail of SSH command */ |
| 230 | 245 | free(zHost); |
| 231 | 246 | popen2(blob_str(&zCmd), &sshIn, &sshOut, &sshPid); |
| 232 | 247 | if( sshPid==0 ){ |
| 233 | 248 | fossil_fatal("cannot start ssh tunnel using [%b]", &zCmd); |
| @@ -234,10 +249,34 @@ | ||
| 234 | 249 | } |
| 235 | 250 | blob_reset(&zCmd); |
| 236 | 251 | transport_ssh_startup(); |
| 237 | 252 | } |
| 238 | 253 | } |
| 254 | + | |
| 255 | +/* | |
| 256 | +** COMMAND: test-ssh-far-side | |
| 257 | +** | |
| 258 | +** Read lines of input text, one by one, and evaluate each line using | |
| 259 | +** system(). The ssh: sync protocol uses this on the far side of the | |
| 260 | +** SSH link. | |
| 261 | +*/ | |
| 262 | +void test_ssh_far_side_cmd(void){ | |
| 263 | + int i = 0; | |
| 264 | + int got; | |
| 265 | + char zLine[5000]; | |
| 266 | + while( i<sizeof(zLine) ){ | |
| 267 | + got = read(0, zLine+i, 1); | |
| 268 | + if( got==0 ) return; | |
| 269 | + if( zLine[i]=='\n' ){ | |
| 270 | + zLine[i] = 0; | |
| 271 | + system(zLine); | |
| 272 | + i = 0; | |
| 273 | + }else{ | |
| 274 | + i++; | |
| 275 | + } | |
| 276 | + } | |
| 277 | +} | |
| 239 | 278 | |
| 240 | 279 | /* |
| 241 | 280 | ** Open a connection to the server. The server is defined by the following |
| 242 | 281 | ** global variables: |
| 243 | 282 | ** |
| 244 | 283 |
| --- src/http_transport.c | |
| +++ src/http_transport.c | |
| @@ -223,11 +223,26 @@ | |
| 223 | zHost = mprintf("%s", g.urlName); |
| 224 | } |
| 225 | n = blob_size(&zCmd); |
| 226 | blob_append(&zCmd, " ", 1); |
| 227 | shell_escape(&zCmd, zHost); |
| 228 | if( g.urlShell ) blob_appendf(&zCmd, " %s", g.urlShell); |
| 229 | fossil_print("%s\n", blob_str(&zCmd)+n); /* Show tail of SSH command */ |
| 230 | free(zHost); |
| 231 | popen2(blob_str(&zCmd), &sshIn, &sshOut, &sshPid); |
| 232 | if( sshPid==0 ){ |
| 233 | fossil_fatal("cannot start ssh tunnel using [%b]", &zCmd); |
| @@ -234,10 +249,34 @@ | |
| 234 | } |
| 235 | blob_reset(&zCmd); |
| 236 | transport_ssh_startup(); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | /* |
| 241 | ** Open a connection to the server. The server is defined by the following |
| 242 | ** global variables: |
| 243 | ** |
| 244 |
| --- src/http_transport.c | |
| +++ src/http_transport.c | |
| @@ -223,11 +223,26 @@ | |
| 223 | zHost = mprintf("%s", g.urlName); |
| 224 | } |
| 225 | n = blob_size(&zCmd); |
| 226 | blob_append(&zCmd, " ", 1); |
| 227 | shell_escape(&zCmd, zHost); |
| 228 | if( g.urlShell ){ |
| 229 | blob_appendf(&zCmd, " %s", g.urlShell); |
| 230 | }else{ |
| 231 | #if defined(FOSSIL_ENABLE_SSH_FAR_SIDE) |
| 232 | /* The following works. But only if the fossil on the remote side |
| 233 | ** is recent enough to support the test-ssh-far-side command. That |
| 234 | ** command was added on 2013-02-06. We will leave this turned off |
| 235 | ** until most fossil servers have upgraded to that version or a later |
| 236 | ** version. The sync will still work as long as the shell on the far |
| 237 | ** side is bash and not tcsh. And if the default far side shell is |
| 238 | ** tcsh, then the shell=/bin/bash query parameter can be used as a |
| 239 | ** work-around. Enable this code after about a year... |
| 240 | */ |
| 241 | blob_appendf(&zCmd, " exec %s test-ssh-far-side", g.urlFossil); |
| 242 | #endif |
| 243 | } |
| 244 | fossil_print("%s\n", blob_str(&zCmd)+n); /* Show tail of SSH command */ |
| 245 | free(zHost); |
| 246 | popen2(blob_str(&zCmd), &sshIn, &sshOut, &sshPid); |
| 247 | if( sshPid==0 ){ |
| 248 | fossil_fatal("cannot start ssh tunnel using [%b]", &zCmd); |
| @@ -234,10 +249,34 @@ | |
| 249 | } |
| 250 | blob_reset(&zCmd); |
| 251 | transport_ssh_startup(); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | /* |
| 256 | ** COMMAND: test-ssh-far-side |
| 257 | ** |
| 258 | ** Read lines of input text, one by one, and evaluate each line using |
| 259 | ** system(). The ssh: sync protocol uses this on the far side of the |
| 260 | ** SSH link. |
| 261 | */ |
| 262 | void test_ssh_far_side_cmd(void){ |
| 263 | int i = 0; |
| 264 | int got; |
| 265 | char zLine[5000]; |
| 266 | while( i<sizeof(zLine) ){ |
| 267 | got = read(0, zLine+i, 1); |
| 268 | if( got==0 ) return; |
| 269 | if( zLine[i]=='\n' ){ |
| 270 | zLine[i] = 0; |
| 271 | system(zLine); |
| 272 | i = 0; |
| 273 | }else{ |
| 274 | i++; |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | /* |
| 280 | ** Open a connection to the server. The server is defined by the following |
| 281 | ** global variables: |
| 282 | ** |
| 283 |