mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Enhance sqlite3_rsync so that if the first attempt to invoke a copy
of itself on the remote system using ssh fails, try again after augmenting the PATH. This enables sqlite3_rsync to work without the --exe option when the remote system is a Mac. FossilOrigin-Name: 38d4c94d8c7802101ef3bfb411002f9497fdbbbd2b4d3514cef5b76ffd66f75b
This commit is contained in:
12
manifest
12
manifest
@@ -1,5 +1,5 @@
|
||||
C Fix\sa\sharmless\sredundant\svariable\sdeclaration\sin\ssqlite3_rsync.
|
||||
D 2025-05-03T10:55:47.615
|
||||
C Enhance\ssqlite3_rsync\sso\sthat\sif\sthe\sfirst\sattempt\sto\sinvoke\sa\scopy\nof\sitself\son\sthe\sremote\ssystem\susing\sssh\sfails,\stry\sagain\safter\naugmenting\sthe\sPATH.\s\sThis\senables\ssqlite3_rsync\sto\swork\swithout\sthe\n--exe\soption\swhen\sthe\sremote\ssystem\sis\sa\sMac.
|
||||
D 2025-05-03T15:17:21.853
|
||||
F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
@@ -2189,7 +2189,7 @@ F tool/spellsift.tcl 52b4b04dc4333c7ab024f09d9d66ed6b6f7c6eb00b38497a09f338fa55d
|
||||
F tool/split-sqlite3c.tcl 07e18a1d8cc3f6b3a4a1f3528e63c9b29a5c8a7bca0b8d394b231da464ce1247
|
||||
F tool/sqldiff.c 134be7866be19f8beb32043d5aea5657f01aaeae2df8d33d758ff722c78666b9
|
||||
F tool/sqlite3_analyzer.c.in 14f02cb5ec3c264cd6107d1f1dad77092b1cf440fc196c30b69ae87b56a1a43b
|
||||
F tool/sqlite3_rsync.c fc1f0560be26fe50252eaf2427f6f3f6f3c50e68d08a2d9cafdf3adc65e281ff
|
||||
F tool/sqlite3_rsync.c dcf03373565eab543bd43926ed7e97ade744ab0599115fde1ff8aadf04fa4974
|
||||
F tool/sqltclsh.c.in 1bcc2e9da58fadf17b0bf6a50e68c1159e602ce057210b655d50bad5aaaef898
|
||||
F tool/sqltclsh.tcl 862f4cf1418df5e1315b5db3b5ebe88969e2a784525af5fbf9596592f14ed848
|
||||
F tool/src-verify.c d00f93263aa2fa6ba0cba0106d95458e6effb94fdb5fc634f56834f90c05bbb4
|
||||
@@ -2207,8 +2207,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350
|
||||
F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
|
||||
F tool/warnings.sh 49a486c5069de041aedcbde4de178293e0463ae9918ecad7539eedf0ec77a139
|
||||
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
||||
P c702999cfac37fdcae64d261408e58d1f49fee65434fe346db6a2a6c7f8ac54e
|
||||
R a9ba57abefc2ac2ac477ee0b0e67f826
|
||||
P f8f15eff6ae50d569ed13a3b18f33eaa43453c0cb80b6007df38e880b62f45d0
|
||||
R 92ec366dcda46ad4e89bcad267e1732a
|
||||
U drh
|
||||
Z 8fe7a400b8200d3506457658669b00b8
|
||||
Z 6f2331f004388e224b4ac4ea1a14b67b
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
@@ -1 +1 @@
|
||||
f8f15eff6ae50d569ed13a3b18f33eaa43453c0cb80b6007df38e880b62f45d0
|
||||
38d4c94d8c7802101ef3bfb411002f9497fdbbbd2b4d3514cef5b76ffd66f75b
|
||||
|
@@ -522,6 +522,53 @@ int append_escaped_arg(sqlite3_str *pStr, const char *zIn, int isFilename){
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Add an approprate PATH= argument to the SSH command under construction
|
||||
** in pStr
|
||||
**
|
||||
** About This Feature
|
||||
** ==================
|
||||
**
|
||||
** On some ssh servers (Macs in particular are guilty of this) the PATH
|
||||
** variable in the shell that runs the command that is sent to the remote
|
||||
** host contains a limited number of read-only system directories:
|
||||
**
|
||||
** /usr/bin:/bin:/usr/sbin:/sbin
|
||||
**
|
||||
** The sqlite3_rsync executable cannot be installed into any of those
|
||||
** directories because they are locked down, and so the "sqlite3_rsync"
|
||||
** command cannot run.
|
||||
**
|
||||
** To work around this, the sqlite3_rsync command is prefixed with a PATH=
|
||||
** argument, inserted by this function, to augment the PATH with additional
|
||||
** directories in which the sqlite3_rsync executable can be installed.
|
||||
**
|
||||
** But other ssh servers are confused by this initial PATH= argument.
|
||||
** Some ssh servers have a list of programs that they are allowed to run
|
||||
** and will fail if the first argument is not on that list, and PATH=....
|
||||
** is not on that list.
|
||||
**
|
||||
** So that sqlite3_rsync can invoke itself on a remote system using ssh
|
||||
** on a variety of platforms, the following algorithm is used:
|
||||
**
|
||||
** * First try running the sqlite3_rsync without any PATH= argument.
|
||||
** If that works (and it does on a majority of systems) then we are
|
||||
** done.
|
||||
**
|
||||
** * If the first attempt fails, then try again after adding the
|
||||
** PATH= prefix argument. (This function is what adds that
|
||||
** argument.)
|
||||
**
|
||||
** A consequence of this is that if the remote system is a Mac, the
|
||||
** "ssh" command always ends up being invoked twice. If anybody knows a
|
||||
** way around that problem, please bring it to the attention of the
|
||||
** developers.
|
||||
*/
|
||||
void add_path_argument(sqlite3_str *pStr){
|
||||
append_escaped_arg(pStr,
|
||||
"PATH=$HOME/bin:/usr/local/bin:/opt/homebrew/bin:$PATH", 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
** End of the append_escaped_arg() routine, adapted from the Fossil **
|
||||
*****************************************************************************/
|
||||
@@ -1968,9 +2015,9 @@ static char *hostSeparator(const char *zIn){
|
||||
zIn++;
|
||||
}
|
||||
return zPath;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Parse command-line arguments. Dispatch subroutines to do the
|
||||
** requested work.
|
||||
@@ -2175,18 +2222,21 @@ int main(int argc, char const * const *argv){
|
||||
tmStart = currentTime();
|
||||
zDiv = hostSeparator(ctx.zOrigin);
|
||||
if( zDiv ){
|
||||
int iRetry;
|
||||
if( hostSeparator(ctx.zReplica)!=0 ){
|
||||
fprintf(stderr,
|
||||
"At least one of ORIGIN and REPLICA must be a local database\n"
|
||||
"You provided two remote databases.\n");
|
||||
return 1;
|
||||
}
|
||||
*(zDiv++) = 0;
|
||||
/* Remote ORIGIN and local REPLICA */
|
||||
for(iRetry=0; 1 /*exit-via-break*/; iRetry++){
|
||||
sqlite3_str *pStr = sqlite3_str_new(0);
|
||||
append_escaped_arg(pStr, zSsh, 1);
|
||||
sqlite3_str_appendf(pStr, " -e none");
|
||||
*(zDiv++) = 0;
|
||||
append_escaped_arg(pStr, ctx.zOrigin, 0);
|
||||
if( iRetry ) add_path_argument(pStr);
|
||||
append_escaped_arg(pStr, zExe, 1);
|
||||
append_escaped_arg(pStr, "--origin", 0);
|
||||
if( ctx.bCommCheck ){
|
||||
@@ -2206,20 +2256,35 @@ int main(int argc, char const * const *argv){
|
||||
}
|
||||
append_escaped_arg(pStr, zDiv, 1);
|
||||
append_escaped_arg(pStr, file_tail(ctx.zReplica), 1);
|
||||
if( ctx.eVerbose<2 && iRetry==0 ){
|
||||
append_escaped_arg(pStr, "2>/dev/null", 0);
|
||||
}
|
||||
zCmd = sqlite3_str_finish(pStr);
|
||||
if( ctx.eVerbose>=2 ) printf("%s\n", zCmd);
|
||||
if( popen2(zCmd, &ctx.pIn, &ctx.pOut, &childPid, 0) ){
|
||||
if( iRetry>=1 ){
|
||||
fprintf(stderr, "Could not start auxiliary process: %s\n", zCmd);
|
||||
return 1;
|
||||
}
|
||||
if( ctx.eVerbose>=2 ){
|
||||
printf("ssh FAILED. Retry with a PATH= argument...\n");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
replicaSide(&ctx);
|
||||
if( ctx.nHashSent==0 && iRetry==0 ) continue;
|
||||
break;
|
||||
}
|
||||
}else if( (zDiv = hostSeparator(ctx.zReplica))!=0 ){
|
||||
/* Local ORIGIN and remote REPLICA */
|
||||
int iRetry;
|
||||
*(zDiv++) = 0;
|
||||
for(iRetry=0; 1 /*exit-by-break*/; iRetry++){
|
||||
sqlite3_str *pStr = sqlite3_str_new(0);
|
||||
append_escaped_arg(pStr, zSsh, 1);
|
||||
sqlite3_str_appendf(pStr, " -e none");
|
||||
*(zDiv++) = 0;
|
||||
append_escaped_arg(pStr, ctx.zReplica, 0);
|
||||
if( iRetry==1 ) add_path_argument(pStr);
|
||||
append_escaped_arg(pStr, zExe, 1);
|
||||
append_escaped_arg(pStr, "--replica", 0);
|
||||
if( ctx.bCommCheck ){
|
||||
@@ -2234,15 +2299,29 @@ int main(int argc, char const * const *argv){
|
||||
append_escaped_arg(pStr, "--debugfile", 0);
|
||||
append_escaped_arg(pStr, zRemoteDebugFile, 1);
|
||||
}
|
||||
if( ctx.bWalOnly ){
|
||||
append_escaped_arg(pStr, "--wal-only", 0);
|
||||
}
|
||||
append_escaped_arg(pStr, file_tail(ctx.zOrigin), 1);
|
||||
append_escaped_arg(pStr, zDiv, 1);
|
||||
if( ctx.eVerbose<2 && iRetry==0 ){
|
||||
append_escaped_arg(pStr, "2>/dev/null", 0);
|
||||
}
|
||||
zCmd = sqlite3_str_finish(pStr);
|
||||
if( ctx.eVerbose>=2 ) printf("%s\n", zCmd);
|
||||
if( popen2(zCmd, &ctx.pIn, &ctx.pOut, &childPid, 0) ){
|
||||
if( iRetry>=1 ){
|
||||
fprintf(stderr, "Could not start auxiliary process: %s\n", zCmd);
|
||||
return 1;
|
||||
}else if( ctx.eVerbose>=2 ){
|
||||
printf("ssh FAILED. Retry with a PATH= argument...\n");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
originSide(&ctx);
|
||||
if( ctx.nHashSent==0 && iRetry==0 ) continue;
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
/* Local ORIGIN and REPLICA */
|
||||
sqlite3_str *pStr = sqlite3_str_new(0);
|
||||
|
Reference in New Issue
Block a user