1 /* 2 ** 2011 March 28 3 ** 4 ** The author disclaims copyright to this source code. In place of 5 ** a legal notice, here is a blessing: 6 ** 7 ** May you do good and not evil. 8 ** May you find forgiveness for yourself and forgive others. 9 ** May you share freely, never taking more than you give. 10 ** 11 ************************************************************************* 12 ** 13 ** The code in this file implements a Tcl interface used to test error 14 ** handling in the os_unix.c module. Wrapper functions that support fault 15 ** injection are registered as the low-level OS functions using the 16 ** xSetSystemCall() method of the VFS. The Tcl interface is as follows: 17 ** 18 ** 19 ** test_syscall install LIST 20 ** Install wrapper functions for all system calls in argument LIST. 21 ** LIST must be a list consisting of zero or more of the following 22 ** literal values: 23 ** 24 ** open close access getcwd stat fstat 25 ** ftruncate fcntl read pread pread64 write 26 ** pwrite pwrite64 fchmod fallocate mmap 27 ** 28 ** test_syscall uninstall 29 ** Uninstall all wrapper functions. 30 ** 31 ** test_syscall fault ?COUNT PERSIST? 32 ** If [test_syscall fault] is invoked without the two arguments, fault 33 ** injection is disabled. Otherwise, fault injection is configured to 34 ** cause a failure on the COUNT'th next call to a system call with a 35 ** wrapper function installed. A COUNT value of 1 means fail the next 36 ** system call. 37 ** 38 ** Argument PERSIST is interpreted as a boolean. If true, the all 39 ** system calls following the initial failure also fail. Otherwise, only 40 ** the single transient failure is injected. 41 ** 42 ** test_syscall errno CALL ERRNO 43 ** Set the value that the global "errno" is set to following a fault 44 ** in call CALL. Argument CALL must be one of the system call names 45 ** listed above (under [test_syscall install]). ERRNO is a symbolic 46 ** name (i.e. "EACCES"). Not all errno codes are supported. Add extra 47 ** to the aErrno table in function test_syscall_errno() below as 48 ** required. 49 ** 50 ** test_syscall reset ?SYSTEM-CALL? 51 ** With no argument, this is an alias for the [uninstall] command. However, 52 ** this command uses a VFS call of the form: 53 ** 54 ** xSetSystemCall(pVfs, 0, 0); 55 ** 56 ** To restore the default system calls. The [uninstall] command restores 57 ** each system call individually by calling (i.e.): 58 ** 59 ** xSetSystemCall(pVfs, "open", 0); 60 ** 61 ** With an argument, this command attempts to reset the system call named 62 ** by the parameter using the same method as [uninstall]. 63 ** 64 ** test_syscall exists SYSTEM-CALL 65 ** Return true if the named system call exists. Or false otherwise. 66 ** 67 ** test_syscall list 68 ** Return a list of all system calls. The list is constructed using 69 ** the xNextSystemCall() VFS method. 70 */ 71 72 #include "sqlite3.h" 73 #include "tcl.h" 74 #include <stdlib.h> 75 #include <string.h> 76 #include <assert.h> 77 78 #include "sqliteInt.h" 79 #if SQLITE_OS_UNIX 80 81 /* From test1.c */ 82 extern const char *sqlite3TestErrorName(int); 83 84 #include <sys/mman.h> 85 #include <sys/types.h> 86 #include <errno.h> 87 88 static struct TestSyscallGlobal { 89 int bPersist; /* 1 for persistent errors, 0 for transient */ 90 int nCount; /* Fail after this many more calls */ 91 int nFail; /* Number of failures that have occurred */ 92 } gSyscall = { 0, 0 }; 93 94 static int ts_open(const char *, int, int); 95 static int ts_close(int fd); 96 static int ts_access(const char *zPath, int mode); 97 static char *ts_getcwd(char *zPath, size_t nPath); 98 static int ts_stat(const char *zPath, struct stat *p); 99 static int ts_fstat(int fd, struct stat *p); 100 static int ts_ftruncate(int fd, off_t n); 101 static int ts_fcntl(int fd, int cmd, ... ); 102 static int ts_read(int fd, void *aBuf, size_t nBuf); 103 static int ts_pread(int fd, void *aBuf, size_t nBuf, off_t off); 104 static int ts_pread64(int fd, void *aBuf, size_t nBuf, off_t off); 105 static int ts_write(int fd, const void *aBuf, size_t nBuf); 106 static int ts_pwrite(int fd, const void *aBuf, size_t nBuf, off_t off); 107 static int ts_pwrite64(int fd, const void *aBuf, size_t nBuf, off_t off); 108 static int ts_fchmod(int fd, mode_t mode); 109 static int ts_fallocate(int fd, off_t off, off_t len); 110 static void *ts_mmap(void *, size_t, int, int, int, off_t); 111 112 113 struct TestSyscallArray { 114 const char *zName; 115 sqlite3_syscall_ptr xTest; 116 sqlite3_syscall_ptr xOrig; 117 int default_errno; /* Default value for errno following errors */ 118 int custom_errno; /* Current value for errno if error */ 119 } aSyscall[] = { 120 /* 0 */ { "open", (sqlite3_syscall_ptr)ts_open, 0, EACCES, 0 }, 121 /* 1 */ { "close", (sqlite3_syscall_ptr)ts_close, 0, 0, 0 }, 122 /* 2 */ { "access", (sqlite3_syscall_ptr)ts_access, 0, 0, 0 }, 123 /* 3 */ { "getcwd", (sqlite3_syscall_ptr)ts_getcwd, 0, 0, 0 }, 124 /* 4 */ { "stat", (sqlite3_syscall_ptr)ts_stat, 0, 0, 0 }, 125 /* 5 */ { "fstat", (sqlite3_syscall_ptr)ts_fstat, 0, 0, 0 }, 126 /* 6 */ { "ftruncate", (sqlite3_syscall_ptr)ts_ftruncate, 0, EIO, 0 }, 127 /* 7 */ { "fcntl", (sqlite3_syscall_ptr)ts_fcntl, 0, EACCES, 0 }, 128 /* 8 */ { "read", (sqlite3_syscall_ptr)ts_read, 0, 0, 0 }, 129 /* 9 */ { "pread", (sqlite3_syscall_ptr)ts_pread, 0, 0, 0 }, 130 /* 10 */ { "pread64", (sqlite3_syscall_ptr)ts_pread64, 0, 0, 0 }, 131 /* 11 */ { "write", (sqlite3_syscall_ptr)ts_write, 0, 0, 0 }, 132 /* 12 */ { "pwrite", (sqlite3_syscall_ptr)ts_pwrite, 0, 0, 0 }, 133 /* 13 */ { "pwrite64", (sqlite3_syscall_ptr)ts_pwrite64, 0, 0, 0 }, 134 /* 14 */ { "fchmod", (sqlite3_syscall_ptr)ts_fchmod, 0, 0, 0 }, 135 /* 15 */ { "fallocate", (sqlite3_syscall_ptr)ts_fallocate, 0, 0, 0 }, 136 /* 16 */ { "mmap", (sqlite3_syscall_ptr)ts_mmap, 0, 0, 0 }, 137 { 0, 0, 0, 0, 0 } 138 }; 139 140 #define orig_open ((int(*)(const char *, int, int))aSyscall[0].xOrig) 141 #define orig_close ((int(*)(int))aSyscall[1].xOrig) 142 #define orig_access ((int(*)(const char*,int))aSyscall[2].xOrig) 143 #define orig_getcwd ((char*(*)(char*,size_t))aSyscall[3].xOrig) 144 #define orig_stat ((int(*)(const char*,struct stat*))aSyscall[4].xOrig) 145 #define orig_fstat ((int(*)(int,struct stat*))aSyscall[5].xOrig) 146 #define orig_ftruncate ((int(*)(int,off_t))aSyscall[6].xOrig) 147 #define orig_fcntl ((int(*)(int,int,...))aSyscall[7].xOrig) 148 #define orig_read ((ssize_t(*)(int,void*,size_t))aSyscall[8].xOrig) 149 #define orig_pread ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].xOrig) 150 #define orig_pread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].xOrig) 151 #define orig_write ((ssize_t(*)(int,const void*,size_t))aSyscall[11].xOrig) 152 #define orig_pwrite ((ssize_t(*)(int,const void*,size_t,off_t))\ 153 aSyscall[12].xOrig) 154 #define orig_pwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\ 155 aSyscall[13].xOrig) 156 #define orig_fchmod ((int(*)(int,mode_t))aSyscall[14].xOrig) 157 #define orig_fallocate ((int(*)(int,off_t,off_t))aSyscall[15].xOrig) 158 #define orig_mmap ((void*(*)(void*,size_t,int,int,int,off_t))aSyscall[16].xOrig) 159 160 /* 161 ** This function is called exactly once from within each invocation of a 162 ** system call wrapper in this file. It returns 1 if the function should 163 ** fail, or 0 if it should succeed. 164 */ 165 static int tsIsFail(void){ 166 gSyscall.nCount--; 167 if( gSyscall.nCount==0 || (gSyscall.nFail && gSyscall.bPersist) ){ 168 gSyscall.nFail++; 169 return 1; 170 } 171 return 0; 172 } 173 174 /* 175 ** Return the current error-number value for function zFunc. zFunc must be 176 ** the name of a system call in the aSyscall[] table. 177 ** 178 ** Usually, the current error-number is the value that errno should be set 179 ** to if the named system call fails. The exception is "fallocate". See 180 ** comments above the implementation of ts_fallocate() for details. 181 */ 182 static int tsErrno(const char *zFunc){ 183 int i; 184 int nFunc = strlen(zFunc); 185 for(i=0; aSyscall[i].zName; i++){ 186 if( strlen(aSyscall[i].zName)!=nFunc ) continue; 187 if( memcmp(aSyscall[i].zName, zFunc, nFunc) ) continue; 188 return aSyscall[i].custom_errno; 189 } 190 191 assert(0); 192 return 0; 193 } 194 195 /* 196 ** A wrapper around tsIsFail(). If tsIsFail() returns non-zero, set the 197 ** value of errno before returning. 198 */ 199 static int tsIsFailErrno(const char *zFunc){ 200 if( tsIsFail() ){ 201 errno = tsErrno(zFunc); 202 return 1; 203 } 204 return 0; 205 } 206 207 /* 208 ** A wrapper around open(). 209 */ 210 static int ts_open(const char *zFile, int flags, int mode){ 211 if( tsIsFailErrno("open") ){ 212 return -1; 213 } 214 return orig_open(zFile, flags, mode); 215 } 216 217 /* 218 ** A wrapper around close(). 219 */ 220 static int ts_close(int fd){ 221 if( tsIsFail() ){ 222 /* Even if simulating an error, close the original file-descriptor. 223 ** This is to stop the test process from running out of file-descriptors 224 ** when running a long test. If a call to close() appears to fail, SQLite 225 ** never attempts to use the file-descriptor afterwards (or even to close 226 ** it a second time). */ 227 orig_close(fd); 228 return -1; 229 } 230 return orig_close(fd); 231 } 232 233 /* 234 ** A wrapper around access(). 235 */ 236 static int ts_access(const char *zPath, int mode){ 237 if( tsIsFail() ){ 238 return -1; 239 } 240 return orig_access(zPath, mode); 241 } 242 243 /* 244 ** A wrapper around getcwd(). 245 */ 246 static char *ts_getcwd(char *zPath, size_t nPath){ 247 if( tsIsFail() ){ 248 return NULL; 249 } 250 return orig_getcwd(zPath, nPath); 251 } 252 253 /* 254 ** A wrapper around stat(). 255 */ 256 static int ts_stat(const char *zPath, struct stat *p){ 257 if( tsIsFail() ){ 258 return -1; 259 } 260 return orig_stat(zPath, p); 261 } 262 263 /* 264 ** A wrapper around fstat(). 265 */ 266 static int ts_fstat(int fd, struct stat *p){ 267 if( tsIsFailErrno("fstat") ){ 268 return -1; 269 } 270 return orig_fstat(fd, p); 271 } 272 273 /* 274 ** A wrapper around ftruncate(). 275 */ 276 static int ts_ftruncate(int fd, off_t n){ 277 if( tsIsFailErrno("ftruncate") ){ 278 return -1; 279 } 280 return orig_ftruncate(fd, n); 281 } 282 283 /* 284 ** A wrapper around fcntl(). 285 */ 286 static int ts_fcntl(int fd, int cmd, ... ){ 287 va_list ap; 288 void *pArg; 289 if( tsIsFailErrno("fcntl") ){ 290 return -1; 291 } 292 va_start(ap, cmd); 293 pArg = va_arg(ap, void *); 294 return orig_fcntl(fd, cmd, pArg); 295 } 296 297 /* 298 ** A wrapper around read(). 299 */ 300 static int ts_read(int fd, void *aBuf, size_t nBuf){ 301 if( tsIsFailErrno("read") ){ 302 return -1; 303 } 304 return orig_read(fd, aBuf, nBuf); 305 } 306 307 /* 308 ** A wrapper around pread(). 309 */ 310 static int ts_pread(int fd, void *aBuf, size_t nBuf, off_t off){ 311 if( tsIsFailErrno("pread") ){ 312 return -1; 313 } 314 return orig_pread(fd, aBuf, nBuf, off); 315 } 316 317 /* 318 ** A wrapper around pread64(). 319 */ 320 static int ts_pread64(int fd, void *aBuf, size_t nBuf, off_t off){ 321 if( tsIsFailErrno("pread64") ){ 322 return -1; 323 } 324 return orig_pread64(fd, aBuf, nBuf, off); 325 } 326 327 /* 328 ** A wrapper around write(). 329 */ 330 static int ts_write(int fd, const void *aBuf, size_t nBuf){ 331 if( tsIsFailErrno("write") ){ 332 if( tsErrno("write")==EINTR ) orig_write(fd, aBuf, nBuf/2); 333 return -1; 334 } 335 return orig_write(fd, aBuf, nBuf); 336 } 337 338 /* 339 ** A wrapper around pwrite(). 340 */ 341 static int ts_pwrite(int fd, const void *aBuf, size_t nBuf, off_t off){ 342 if( tsIsFailErrno("pwrite") ){ 343 return -1; 344 } 345 return orig_pwrite(fd, aBuf, nBuf, off); 346 } 347 348 /* 349 ** A wrapper around pwrite64(). 350 */ 351 static int ts_pwrite64(int fd, const void *aBuf, size_t nBuf, off_t off){ 352 if( tsIsFailErrno("pwrite64") ){ 353 return -1; 354 } 355 return orig_pwrite64(fd, aBuf, nBuf, off); 356 } 357 358 /* 359 ** A wrapper around fchmod(). 360 */ 361 static int ts_fchmod(int fd, mode_t mode){ 362 if( tsIsFail() ){ 363 return -1; 364 } 365 return orig_fchmod(fd, mode); 366 } 367 368 /* 369 ** A wrapper around fallocate(). 370 ** 371 ** SQLite assumes that the fallocate() function is compatible with 372 ** posix_fallocate(). According to the Linux man page (2009-09-30): 373 ** 374 ** posix_fallocate() returns zero on success, or an error number on 375 ** failure. Note that errno is not set. 376 */ 377 static int ts_fallocate(int fd, off_t off, off_t len){ 378 if( tsIsFail() ){ 379 return tsErrno("fallocate"); 380 } 381 return orig_fallocate(fd, off, len); 382 } 383 384 static void *ts_mmap( 385 void *pAddr, 386 size_t nByte, 387 int prot, 388 int flags, 389 int fd, 390 off_t iOff 391 ){ 392 if( tsIsFailErrno("mmap") ){ 393 return MAP_FAILED; 394 } 395 return orig_mmap(pAddr, nByte, prot, flags, fd, iOff); 396 } 397 398 static int test_syscall_install( 399 void * clientData, 400 Tcl_Interp *interp, 401 int objc, 402 Tcl_Obj *CONST objv[] 403 ){ 404 sqlite3_vfs *pVfs; 405 int nElem; 406 int i; 407 Tcl_Obj **apElem; 408 409 if( objc!=3 ){ 410 Tcl_WrongNumArgs(interp, 2, objv, "SYSCALL-LIST"); 411 return TCL_ERROR; 412 } 413 if( Tcl_ListObjGetElements(interp, objv[2], &nElem, &apElem) ){ 414 return TCL_ERROR; 415 } 416 pVfs = sqlite3_vfs_find(0); 417 418 for(i=0; i<nElem; i++){ 419 int iCall; 420 int rc = Tcl_GetIndexFromObjStruct(interp, 421 apElem[i], aSyscall, sizeof(aSyscall[0]), "system-call", 0, &iCall 422 ); 423 if( rc ) return rc; 424 if( aSyscall[iCall].xOrig==0 ){ 425 aSyscall[iCall].xOrig = pVfs->xGetSystemCall(pVfs, aSyscall[iCall].zName); 426 pVfs->xSetSystemCall(pVfs, aSyscall[iCall].zName, aSyscall[iCall].xTest); 427 } 428 aSyscall[iCall].custom_errno = aSyscall[iCall].default_errno; 429 } 430 431 return TCL_OK; 432 } 433 434 static int test_syscall_uninstall( 435 void * clientData, 436 Tcl_Interp *interp, 437 int objc, 438 Tcl_Obj *CONST objv[] 439 ){ 440 sqlite3_vfs *pVfs; 441 int i; 442 443 if( objc!=2 ){ 444 Tcl_WrongNumArgs(interp, 2, objv, ""); 445 return TCL_ERROR; 446 } 447 448 pVfs = sqlite3_vfs_find(0); 449 for(i=0; aSyscall[i].zName; i++){ 450 if( aSyscall[i].xOrig ){ 451 pVfs->xSetSystemCall(pVfs, aSyscall[i].zName, 0); 452 aSyscall[i].xOrig = 0; 453 } 454 } 455 return TCL_OK; 456 } 457 458 static int test_syscall_reset( 459 void * clientData, 460 Tcl_Interp *interp, 461 int objc, 462 Tcl_Obj *CONST objv[] 463 ){ 464 sqlite3_vfs *pVfs; 465 int i; 466 int rc; 467 468 if( objc!=2 && objc!=3 ){ 469 Tcl_WrongNumArgs(interp, 2, objv, ""); 470 return TCL_ERROR; 471 } 472 473 pVfs = sqlite3_vfs_find(0); 474 if( objc==2 ){ 475 rc = pVfs->xSetSystemCall(pVfs, 0, 0); 476 for(i=0; aSyscall[i].zName; i++) aSyscall[i].xOrig = 0; 477 }else{ 478 int nFunc; 479 char *zFunc = Tcl_GetStringFromObj(objv[2], &nFunc); 480 rc = pVfs->xSetSystemCall(pVfs, Tcl_GetString(objv[2]), 0); 481 for(i=0; rc==SQLITE_OK && aSyscall[i].zName; i++){ 482 if( strlen(aSyscall[i].zName)!=nFunc ) continue; 483 if( memcmp(aSyscall[i].zName, zFunc, nFunc) ) continue; 484 aSyscall[i].xOrig = 0; 485 } 486 } 487 if( rc!=SQLITE_OK ){ 488 Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3TestErrorName(rc), -1)); 489 return TCL_ERROR; 490 } 491 492 Tcl_ResetResult(interp); 493 return TCL_OK; 494 } 495 496 static int test_syscall_exists( 497 void * clientData, 498 Tcl_Interp *interp, 499 int objc, 500 Tcl_Obj *CONST objv[] 501 ){ 502 sqlite3_vfs *pVfs; 503 sqlite3_syscall_ptr x; 504 505 if( objc!=3 ){ 506 Tcl_WrongNumArgs(interp, 2, objv, ""); 507 return TCL_ERROR; 508 } 509 510 pVfs = sqlite3_vfs_find(0); 511 x = pVfs->xGetSystemCall(pVfs, Tcl_GetString(objv[2])); 512 513 Tcl_SetObjResult(interp, Tcl_NewBooleanObj(x!=0)); 514 return TCL_OK; 515 } 516 517 static int test_syscall_fault( 518 void * clientData, 519 Tcl_Interp *interp, 520 int objc, 521 Tcl_Obj *CONST objv[] 522 ){ 523 int nCount = 0; 524 int bPersist = 0; 525 526 if( objc!=2 && objc!=4 ){ 527 Tcl_WrongNumArgs(interp, 2, objv, "?COUNT PERSIST?"); 528 return TCL_ERROR; 529 } 530 531 if( objc==4 ){ 532 if( Tcl_GetIntFromObj(interp, objv[2], &nCount) 533 || Tcl_GetBooleanFromObj(interp, objv[3], &bPersist) 534 ){ 535 return TCL_ERROR; 536 } 537 } 538 539 Tcl_SetObjResult(interp, Tcl_NewIntObj(gSyscall.nFail)); 540 gSyscall.nCount = nCount; 541 gSyscall.bPersist = bPersist; 542 gSyscall.nFail = 0; 543 return TCL_OK; 544 } 545 546 static int test_syscall_errno( 547 void * clientData, 548 Tcl_Interp *interp, 549 int objc, 550 Tcl_Obj *CONST objv[] 551 ){ 552 int iCall; 553 int iErrno; 554 int rc; 555 556 struct Errno { 557 const char *z; 558 int i; 559 } aErrno[] = { 560 { "EACCES", EACCES }, 561 { "EINTR", EINTR }, 562 { "EIO", EIO }, 563 { "EOVERFLOW", EOVERFLOW }, 564 { "ENOMEM", ENOMEM }, 565 { "EAGAIN", EAGAIN }, 566 { "ETIMEDOUT", ETIMEDOUT }, 567 { "EBUSY", EBUSY }, 568 { "EPERM", EPERM }, 569 { "EDEADLK", EDEADLK }, 570 { "ENOLCK", ENOLCK }, 571 { 0, 0 } 572 }; 573 574 if( objc!=4 ){ 575 Tcl_WrongNumArgs(interp, 2, objv, "SYSCALL ERRNO"); 576 return TCL_ERROR; 577 } 578 579 rc = Tcl_GetIndexFromObjStruct(interp, 580 objv[2], aSyscall, sizeof(aSyscall[0]), "system-call", 0, &iCall 581 ); 582 if( rc!=TCL_OK ) return rc; 583 rc = Tcl_GetIndexFromObjStruct(interp, 584 objv[3], aErrno, sizeof(aErrno[0]), "errno", 0, &iErrno 585 ); 586 if( rc!=TCL_OK ) return rc; 587 588 aSyscall[iCall].custom_errno = aErrno[iErrno].i; 589 return TCL_OK; 590 } 591 592 static int test_syscall_list( 593 void * clientData, 594 Tcl_Interp *interp, 595 int objc, 596 Tcl_Obj *CONST objv[] 597 ){ 598 const char *zSys; 599 sqlite3_vfs *pVfs; 600 Tcl_Obj *pList; 601 602 if( objc!=2 ){ 603 Tcl_WrongNumArgs(interp, 2, objv, ""); 604 return TCL_ERROR; 605 } 606 607 pVfs = sqlite3_vfs_find(0); 608 pList = Tcl_NewObj(); 609 Tcl_IncrRefCount(pList); 610 for(zSys = pVfs->xNextSystemCall(pVfs, 0); 611 zSys!=0; 612 zSys = pVfs->xNextSystemCall(pVfs, zSys) 613 ){ 614 Tcl_ListObjAppendElement(interp, pList, Tcl_NewStringObj(zSys, -1)); 615 } 616 617 Tcl_SetObjResult(interp, pList); 618 Tcl_DecrRefCount(pList); 619 return TCL_OK; 620 } 621 622 static int test_syscall_defaultvfs( 623 void * clientData, 624 Tcl_Interp *interp, 625 int objc, 626 Tcl_Obj *CONST objv[] 627 ){ 628 sqlite3_vfs *pVfs; 629 630 if( objc!=2 ){ 631 Tcl_WrongNumArgs(interp, 2, objv, ""); 632 return TCL_ERROR; 633 } 634 635 pVfs = sqlite3_vfs_find(0); 636 Tcl_SetObjResult(interp, Tcl_NewStringObj(pVfs->zName, -1)); 637 return TCL_OK; 638 } 639 640 static int test_syscall( 641 void * clientData, 642 Tcl_Interp *interp, 643 int objc, 644 Tcl_Obj *CONST objv[] 645 ){ 646 struct SyscallCmd { 647 const char *zName; 648 Tcl_ObjCmdProc *xCmd; 649 } aCmd[] = { 650 { "fault", test_syscall_fault }, 651 { "install", test_syscall_install }, 652 { "uninstall", test_syscall_uninstall }, 653 { "reset", test_syscall_reset }, 654 { "errno", test_syscall_errno }, 655 { "exists", test_syscall_exists }, 656 { "list", test_syscall_list }, 657 { "defaultvfs", test_syscall_defaultvfs }, 658 { 0, 0 } 659 }; 660 int iCmd; 661 int rc; 662 663 if( objc<2 ){ 664 Tcl_WrongNumArgs(interp, 1, objv, "SUB-COMMAND ..."); 665 return TCL_ERROR; 666 } 667 rc = Tcl_GetIndexFromObjStruct(interp, 668 objv[1], aCmd, sizeof(aCmd[0]), "sub-command", 0, &iCmd 669 ); 670 if( rc!=TCL_OK ) return rc; 671 return aCmd[iCmd].xCmd(clientData, interp, objc, objv); 672 } 673 674 int SqlitetestSyscall_Init(Tcl_Interp *interp){ 675 struct SyscallCmd { 676 const char *zName; 677 Tcl_ObjCmdProc *xCmd; 678 } aCmd[] = { 679 { "test_syscall", test_syscall}, 680 }; 681 int i; 682 683 for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){ 684 Tcl_CreateObjCommand(interp, aCmd[i].zName, aCmd[i].xCmd, 0, 0); 685 } 686 return TCL_OK; 687 } 688 #else 689 int SqlitetestSyscall_Init(Tcl_Interp *interp){ 690 return TCL_OK; 691 } 692 #endif 693