Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/tool/showlocks.c # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / tool / showlocks.c` 99 lines ยท 2351 bytes Raw Blame History 1 /* 2 ** This file implements a simple command-line utility that shows all of the 3 ** Posix Advisory Locks on a file. 4 ** 5 ** Usage: 6 ** 7 ** showlocks FILENAME 8 ** 9 ** To compile: gcc -o showlocks showlocks.c 10 */ 11 #include 12 #include 13 #include 14 #include 15 #include 16 17 /* This utility only looks for locks in the first 2 billion bytes */ 18 #define MX_LCK `2147483647` 19 20 /* 21 ** Print all locks on the inode of "fd" that occur in between 22 ** lwr and upr, inclusive. 23 */ 24 static int showLocksInRange(int fd, off_t lwr, off_t upr){ 25 int cnt = 0; 26 struct flock x; 27 struct lockRange { 28 off_t lwr; 29 off_t upr; 30 } *aPending = 0; 31 int nAlloc = 1; 32 int nPending = 0; 33 int nDone = 0; 34 35 nPending = 1; 36 aPending = malloc( sizeof(aPending[0]) ); 37 if( aPending==0 ){ 38 fprintf(stderr, "out of memory\n"); 39 exit(1); 40 } 41 aPending[0].lwr = lwr; 42 aPending[0].upr = upr; 43 44 for(nDone=0; nDone=upr ) continue; 48 x.l_type = F_WRLCK; 49 x.l_whence = SEEK_SET; 50 x.l_start = lwr; 51 x.l_len = upr - lwr; 52 fcntl(fd, F_GETLK, &x); 53 if( x.l_type==F_UNLCK ) continue; 54 printf("start: %-12d len: %-5d pid: %-5d type: %s\n", 55 (int)x.l_start, (int)x.l_len, 56 x.l_pid, x.l_type==F_WRLCK ? "WRLCK" : "RDLCK"); 57 cnt++; 58 if( nPending+2 > nAlloc ){ 59 nAlloc = nAlloc*2 + 2; 60 aPending = realloc(aPending, sizeof(aPending[0])*nAlloc ); 61 } 62 if( aPending==0 ){ 63 fprintf(stderr, "unable to realloc for %d bytes\n", 64 (int)sizeof(aPending[0])*(nPending+2)); 65 exit(1); 66 } 67 if( lwr