diff options
author | chw <chw@noemail.net> | 2008-11-17 08:05:31 +0000 |
---|---|---|
committer | chw <chw@noemail.net> | 2008-11-17 08:05:31 +0000 |
commit | 971854898a42c2e3913dbf71407d4dbbbbd21447 (patch) | |
tree | a9610b521a619034e68b1561372e40478ee72b81 | |
parent | d92db531c8e9825fc9ae807b04ca3d99998b9942 (diff) | |
download | sqlite-971854898a42c2e3913dbf71407d4dbbbbd21447.tar.gz sqlite-971854898a42c2e3913dbf71407d4dbbbbd21447.zip |
Added support for vxworks >= 6.4; RTP mode tested, kernel mode untested. (CVS 5910)
FossilOrigin-Name: f45a1493636a5ee474dd6c0b5d286be2249b05aa
-rw-r--r-- | Makefile.vxwSH4 | 635 | ||||
-rw-r--r-- | manifest | 19 | ||||
-rw-r--r-- | manifest.uuid | 2 | ||||
-rw-r--r-- | src/mutex_unix.c | 4 | ||||
-rw-r--r-- | src/os_unix.c | 488 | ||||
-rw-r--r-- | src/shell.c | 12 |
6 files changed, 1135 insertions, 25 deletions
diff --git a/Makefile.vxwSH4 b/Makefile.vxwSH4 new file mode 100644 index 000000000..77ba884e9 --- /dev/null +++ b/Makefile.vxwSH4 @@ -0,0 +1,635 @@ +#!/usr/make +# +# Makefile for SQLITE on VxWorks + +ifeq ($(FORCPU),) + FORCPU = SH32gnule +endif + +TOOL_FAMILY = gnu + +include $(WIND_USR)/tool/gnu/make.$(FORCPU) + +#### The toplevel directory of the source tree. This is the directory +# that contains this "Makefile.in" and the "configure.in" script. +# +TOP = ../sqlite-3.6.5 + +#### C Compiler and options for use in building executables that +# will run on the platform that is doing the build. +# +BCC = gcc -g -O2 +#BCC = /opt/ancic/bin/c89 -0 + +#### If the target operating system supports the "usleep()" system +# call, then define the HAVE_USLEEP macro for all C modules. +# +USLEEP = +#USLEEP = -DHAVE_USLEEP=1 + +#### If you want the SQLite library to be safe for use within a +# multi-threaded program, then define the following macro +# appropriately: +# +THREADSAFE = -DSQLITE_THREADSAFE=1 +#THREADSAFE = -DSQLITE_THREADSAFE=0 + +#### Specify any extra linker options needed to make the library +# thread safe +# +#THREADLIB = -lpthread +THREADLIB = + +#### Specify any extra libraries needed to access required functions. +# +#TLIBS = -lrt # fdatasync on Solaris 8 +#for x86 vxWorks +#TLIBS += TLIBS = $(LD_LINK_PATH_ATEND) $(LD_PARTIAL_LAST_FLAGS) +#for SH4 shared library +TLIBS_SHARED += -L$(WIND_USR)/lib/sh/SH32/commonle/PIC +#TLIBS_SHARED += $(LD_LINK_PATH_ATEND) $(LD_PARTIAL_LAST_FLAGS) +#for SH4 static +TLIBS += $(LD_LINK_PATH_ATEND) $(LD_PARTIAL_LAST_FLAGS) + +#### Leave SQLITE_DEBUG undefined for maximum speed. Use SQLITE_DEBUG=1 +# to check for memory leaks. Use SQLITE_DEBUG=2 to print a log of all +# malloc()s and free()s in order to track down memory leaks. +# +# SQLite uses some expensive assert() statements in the inner loop. +# You can make the library go almost twice as fast if you compile +# with -DNDEBUG=1 +# +#OPTS = -DSQLITE_DEBUG=2 +#OPTS = -DSQLITE_DEBUG=1 +#OPTS = +OPTS = -DNDEBUG=1 -DSQLITE_OS_UNIX=1 $(THREADSAFE) +OPTS += -DSQLITE_OMIT_LOAD_EXTENSION=1 +OPTS += -DSQLITE_ENABLE_LOCKING_STYLE=1 +OPTS += -DSQLITE_THREAD_OVERRIDE_LOCK=0 +OPTS += -DSQLITE_ENABLE_COLUMN_METADATA=1 +OPTS += -DHAVE_FDATASYNC=1 + +#### The suffix to add to executable files. ".exe" for windows. +# Nothing for unix. +# +EXE = .vxe +#EXE = + +#### C Compile and options for use in building executables that +# will run on the target platform. This is usually the same +# as BCC, unless you are cross-compiling. +# +#TCC = gcc -O6 +#TCC = gcc -g -O0 -Wall +#TCC = gcc -g -O0 -Wall -fprofile-arcs -ftest-coverage +#TCC = /opt/mingw/bin/i386-mingw32-gcc -O6 +TCC = $(CC) $(DEFINE_CC) -O2 -g -mrtp $(CC_ARCH_SPEC) -D_REENTRANT=1 -D_VX_CPU=_VX_$(CPU) -D_VX_TOOL_FAMILY=$(TOOL_FAMILY) -D_VX_TOOL=$(TOOL) +TCC += -I$(WIND_USR)/h -I$(WIND_USR)/h/wrn/coreip +#TCC = /opt/ansic/bin/c89 -O +z -Wl,-a,archive + +#TCC_SHARED = $(TCC) -fPIC +TCC_SHARED = $(TCC) + +#### Tools used to build a static library. +# +#ARX = ar cr +#ARX = /opt/mingw/bin/i386-mingw32-ar cr +AR += cr +#RANLIB = ranlib +#RANLIB = /opt/mingw/bin/i386-mingw32-ranlib + +#MKSHLIB = gcc -shared +#SO = so +#SHPREFIX = lib +MKSHLIB = $(CC) $(DEFINE_CC) -mrtp -shared $(CC_ARCH_SPEC) -D_VX_CPU=_VX_$(CPU) -D_VX_TOOL_FAMILY=$(TOOL_FAMILY) -D_VX_TOOL=$(TOOL) +SO = so +SHPREFIX = lib + +#### Extra compiler options needed for programs that use the TCL library. +# +#TCL_FLAGS = +#TCL_FLAGS = -DSTATIC_BUILD=1 +TCL_FLAGS = -I/home/drh/tcltk/8.4linux +#TCL_FLAGS = -I/home/drh/tcltk/8.4win -DSTATIC_BUILD=1 +#TCL_FLAGS = -I/home/drh/tcltk/8.3hpux + +#### Linker options needed to link against the TCL library. +# +#LIBTCL = -ltcl -lm -ldl +LIBTCL = /home/drh/tcltk/8.4linux/libtcl8.4g.a -lm -ldl +#LIBTCL = /home/drh/tcltk/8.4win/libtcl84s.a -lmsvcrt +#LIBTCL = /home/drh/tcltk/8.3hpux/libtcl8.3.a -ldld -lm -lc + +#### Additional objects for SQLite library when TCL support is enabled. +TCLOBJ = +#TCLOBJ = tclsqlite.o + +#### Compiler options needed for programs that use the readline() library. +# +READLINE_FLAGS = +#READLINE_FLAGS = -DHAVE_READLINE=1 -I/usr/include/readline + +#### Linker options needed by programs using readline() must link against. +# +LIBREADLINE = +#LIBREADLINE = -static -lreadline -ltermcap + +#### Which "awk" program provides nawk compatibilty +# +# NAWK = nawk +NAWK = awk + + +#### Pasted and adapted main.mk file +############################################################################### +# The following macros should be defined before this script is +# invoked: +# +# TOP The toplevel directory of the source tree. This is the +# directory that contains this "Makefile.in" and the +# "configure.in" script. +# +# BCC C Compiler and options for use in building executables that +# will run on the platform that is doing the build. +# +# THREADLIB Specify any extra linker options needed to make the library +# thread safe +# +# OPTS Extra compiler command-line options. +# +# EXE The suffix to add to executable files. ".exe" for windows +# and "" for Unix. +# +# TCC C Compiler and options for use in building executables that +# will run on the target platform. This is usually the same +# as BCC, unless you are cross-compiling. +# +# AR Tools used to build a static library. +# RANLIB +# +# TCL_FLAGS Extra compiler options needed for programs that use the +# TCL library. +# +# LIBTCL Linker options needed to link against the TCL library. +# +# READLINE_FLAGS Compiler options needed for programs that use the +# readline() library. +# +# LIBREADLINE Linker options needed by programs using readline() must +# link against. +# +# NAWK Nawk compatible awk program. Older (obsolete?) solaris +# systems need this to avoid using the original AT&T AWK. +# +# Once the macros above are defined, the rest of this make script will +# build the SQLite library and testing tools. +################################################################################ + +# This is how we compile +# +TCCX = $(TCC) $(OPTS) -I. -I$(TOP)/src -I$(TOP) -I$(TOP)/ext/rtree +TCCX_SHARED = $(TCC_SHARED) $(OPTS) -I. -I$(TOP)/src -I$(TOP) -I$(TOP)/ext/rtree + +# Object files for the SQLite library. +# +LIBOBJ+= alter.o analyze.o attach.o auth.o \ + bitvec.o btmutex.o btree.o build.o \ + callback.o complete.o date.o delete.o \ + expr.o fault.o func.o global.o hash.o \ + icu.o insert.o journal.o legacy.o loadext.o \ + main.o malloc.o mem0.o mem1.o mem2.o mem3.o mem5.o memjournal.o \ + mutex.o mutex_os2.o mutex_unix.o mutex_w32.o mutex_noop.o \ + opcodes.o os.o os_os2.o os_unix.o os_win.o \ + pager.o parse.o pcache.o pragma.o prepare.o printf.o \ + random.o resolve.o rtree.o select.o status.o \ + table.o tokenize.o trigger.o \ + update.o util.o vacuum.o \ + vdbe.o vdbeapi.o vdbeaux.o vdbeblob.o vdbefifo.o vdbemem.o \ + walker.o where.o utf.o vtab.o + + +# All of the source code files. +# +SRC = \ + $(TOP)/src/alter.c \ + $(TOP)/src/analyze.c \ + $(TOP)/src/attach.c \ + $(TOP)/src/auth.c \ + $(TOP)/src/bitvec.c \ + $(TOP)/src/btmutex.c \ + $(TOP)/src/btree.c \ + $(TOP)/src/btree.h \ + $(TOP)/src/btreeInt.h \ + $(TOP)/src/build.c \ + $(TOP)/src/callback.c \ + $(TOP)/src/complete.c \ + $(TOP)/src/date.c \ + $(TOP)/src/delete.c \ + $(TOP)/src/expr.c \ + $(TOP)/src/fault.c \ + $(TOP)/src/func.c \ + $(TOP)/src/global.c \ + $(TOP)/src/hash.c \ + $(TOP)/src/hash.h \ + $(TOP)/src/hwtime.h \ + $(TOP)/src/insert.c \ + $(TOP)/src/journal.c \ + $(TOP)/src/legacy.c \ + $(TOP)/src/loadext.c \ + $(TOP)/src/main.c \ + $(TOP)/src/malloc.c \ + $(TOP)/src/mem0.c \ + $(TOP)/src/mem1.c \ + $(TOP)/src/mem2.c \ + $(TOP)/src/mem3.c \ + $(TOP)/src/mem5.c \ + $(TOP)/src/memjournal.c \ + $(TOP)/src/mutex.c \ + $(TOP)/src/mutex.h \ + $(TOP)/src/mutex_os2.c \ + $(TOP)/src/mutex_unix.c \ + $(TOP)/src/mutex_w32.c \ + $(TOP)/src/mutex_noop.c \ + $(TOP)/src/os.c \ + $(TOP)/src/os.h \ + $(TOP)/src/os_common.h \ + $(TOP)/src/os_os2.c \ + $(TOP)/src/os_unix.c \ + $(TOP)/src/os_win.c \ + $(TOP)/src/pager.c \ + $(TOP)/src/pager.h \ + $(TOP)/src/parse.y \ + $(TOP)/src/pcache.c \ + $(TOP)/src/pcache.h \ + $(TOP)/src/pragma.c \ + $(TOP)/src/prepare.c \ + $(TOP)/src/printf.c \ + $(TOP)/src/random.c \ + $(TOP)/src/resolve.c \ + $(TOP)/src/select.c \ + $(TOP)/src/status.c \ + $(TOP)/src/shell.c \ + $(TOP)/src/sqlite.h.in \ + $(TOP)/src/sqlite3ext.h \ + $(TOP)/src/sqliteInt.h \ + $(TOP)/src/sqliteLimit.h \ + $(TOP)/src/table.c \ + $(TOP)/src/tclsqlite.c \ + $(TOP)/src/tokenize.c \ + $(TOP)/src/trigger.c \ + $(TOP)/src/utf.c \ + $(TOP)/src/update.c \ + $(TOP)/src/util.c \ + $(TOP)/src/vacuum.c \ + $(TOP)/src/vdbe.c \ + $(TOP)/src/vdbe.h \ + $(TOP)/src/vdbeapi.c \ + $(TOP)/src/vdbeaux.c \ + $(TOP)/src/vdbeblob.c \ + $(TOP)/src/vdbefifo.c \ + $(TOP)/src/vdbemem.c \ + $(TOP)/src/vdbeInt.h \ + $(TOP)/src/vtab.c \ + $(TOP)/src/walker.c \ + $(TOP)/src/where.c + +# Source code for extensions +# +SRC += \ + $(TOP)/ext/fts1/fts1.c \ + $(TOP)/ext/fts1/fts1.h \ + $(TOP)/ext/fts1/fts1_hash.c \ + $(TOP)/ext/fts1/fts1_hash.h \ + $(TOP)/ext/fts1/fts1_porter.c \ + $(TOP)/ext/fts1/fts1_tokenizer.h \ + $(TOP)/ext/fts1/fts1_tokenizer1.c +SRC += \ + $(TOP)/ext/fts2/fts2.c \ + $(TOP)/ext/fts2/fts2.h \ + $(TOP)/ext/fts2/fts2_hash.c \ + $(TOP)/ext/fts2/fts2_hash.h \ + $(TOP)/ext/fts2/fts2_icu.c \ + $(TOP)/ext/fts2/fts2_porter.c \ + $(TOP)/ext/fts2/fts2_tokenizer.h \ + $(TOP)/ext/fts2/fts2_tokenizer.c \ + $(TOP)/ext/fts2/fts2_tokenizer1.c +SRC += \ + $(TOP)/ext/fts3/fts3.c \ + $(TOP)/ext/fts3/fts3.h \ + $(TOP)/ext/fts3/fts3_hash.c \ + $(TOP)/ext/fts3/fts3_hash.h \ + $(TOP)/ext/fts3/fts3_icu.c \ + $(TOP)/ext/fts3/fts3_porter.c \ + $(TOP)/ext/fts3/fts3_tokenizer.h \ + $(TOP)/ext/fts3/fts3_tokenizer.c \ + $(TOP)/ext/fts3/fts3_tokenizer1.c +SRC += \ + $(TOP)/ext/icu/icu.c \ + $(TOP)/ext/icu/sqliteicu.h +SRC += \ + $(TOP)/ext/rtree/rtree.h \ + $(TOP)/ext/rtree/rtree.c + + +# Generated source code files +# +SRC += \ + keywordhash.h \ + opcodes.c \ + opcodes.h \ + parse.c \ + parse.h \ + sqlite3.h + + +# Source code to the test files. +# +TESTSRC = \ + $(TOP)/src/test1.c \ + $(TOP)/src/test2.c \ + $(TOP)/src/test3.c \ + $(TOP)/src/test4.c \ + $(TOP)/src/test5.c \ + $(TOP)/src/test6.c \ + $(TOP)/src/test7.c \ + $(TOP)/src/test8.c \ + $(TOP)/src/test9.c \ + $(TOP)/src/test_autoext.c \ + $(TOP)/src/test_async.c \ + $(TOP)/src/test_btree.c \ + $(TOP)/src/test_config.c \ + $(TOP)/src/test_devsym.c \ + $(TOP)/src/test_func.c \ + $(TOP)/src/test_hexio.c \ + $(TOP)/src/test_malloc.c \ + $(TOP)/src/test_md5.c \ + $(TOP)/src/test_mutex.c \ + $(TOP)/src/test_onefile.c \ + $(TOP)/src/test_osinst.c \ + $(TOP)/src/test_schema.c \ + $(TOP)/src/test_server.c \ + $(TOP)/src/test_tclvar.c \ + $(TOP)/src/test_thread.c \ + +#TESTSRC += $(TOP)/ext/fts2/fts2_tokenizer.c +#TESTSRC += $(TOP)/ext/fts3/fts3_tokenizer.c + +TESTSRC2 = \ + $(TOP)/src/attach.c $(TOP)/src/btree.c $(TOP)/src/build.c $(TOP)/src/date.c \ + $(TOP)/src/expr.c $(TOP)/src/func.c $(TOP)/src/insert.c $(TOP)/src/os.c \ + $(TOP)/src/os_os2.c $(TOP)/src/os_unix.c $(TOP)/src/os_win.c \ + $(TOP)/src/pager.c $(TOP)/src/pragma.c $(TOP)/src/prepare.c \ + $(TOP)/src/printf.c $(TOP)/src/random.c $(TOP)/src/pcache.c \ + $(TOP)/src/select.c $(TOP)/src/tokenize.c \ + $(TOP)/src/utf.c $(TOP)/src/util.c $(TOP)/src/vdbeapi.c $(TOP)/src/vdbeaux.c \ + $(TOP)/src/vdbe.c $(TOP)/src/vdbemem.c $(TOP)/src/where.c parse.c + +# Header files used by all library source files. +# +HDR = \ + $(TOP)/src/btree.h \ + $(TOP)/src/btreeInt.h \ + $(TOP)/src/hash.h \ + $(TOP)/src/hwtime.h \ + keywordhash.h \ + $(TOP)/src/mutex.h \ + opcodes.h \ + $(TOP)/src/os.h \ + $(TOP)/src/os_common.h \ + $(TOP)/src/pager.h \ + $(TOP)/src/pcache.h \ + parse.h \ + sqlite3.h \ + $(TOP)/src/sqlite3ext.h \ + $(TOP)/src/sqliteInt.h \ + $(TOP)/src/sqliteLimit.h \ + $(TOP)/src/vdbe.h \ + $(TOP)/src/vdbeInt.h + +# Header files used by extensions +# +EXTHDR += \ + $(TOP)/ext/fts1/fts1.h \ + $(TOP)/ext/fts1/fts1_hash.h \ + $(TOP)/ext/fts1/fts1_tokenizer.h +EXTHDR += \ + $(TOP)/ext/fts2/fts2.h \ + $(TOP)/ext/fts2/fts2_hash.h \ + $(TOP)/ext/fts2/fts2_tokenizer.h +EXTHDR += \ + $(TOP)/ext/fts3/fts3.h \ + $(TOP)/ext/fts3/fts3_hash.h \ + $(TOP)/ext/fts3/fts3_tokenizer.h +EXTHDR += \ + $(TOP)/ext/rtree/rtree.h + +# This is the default Makefile target. The objects listed here +# are what get build when you type just "make" with no arguments. +# +all: sqlite3.h libsqlite3.a sqlite3$(EXE) + +libsqlite3.a: $(LIBOBJ) + $(AR) libsqlite3.a $(LIBOBJ) + $(RANLIB) libsqlite3.a + +$(SHPREFIX)sqlite3.$(SO): $(LIBOBJ) + $(MKSHLIB) -o $(SHPREFIX)sqlite3.$(SO) $(LIBOBJ) $(TLIBS_SHARED) + +sqlite3$(EXE): $(TOP)/src/shell.c libsqlite3.a sqlite3.h + $(TCCX) $(READLINE_FLAGS) -o sqlite3$(EXE) \ + $(TOP)/src/shell.c \ + $(LIBREADLINE) $(TLIBS) $(THREADLIB) -L. -lsqlite3 + +# This target creates a directory named "tsrc" and fills it with +# copies of all of the C source code and header files needed to +# build on the target system. Some of the C source code and header +# files are automatically generated. This target takes care of +# all that automatic generation. +# +target_source: $(SRC) + rm -rf tsrc + mkdir tsrc + cp -f $(SRC) tsrc + rm tsrc/sqlite.h.in tsrc/parse.y + touch target_source + +sqlite3.c: target_source $(TOP)/tool/mksqlite3c.tcl + tclsh $(TOP)/tool/mksqlite3c.tcl + cp sqlite3.c tclsqlite3.c + cat $(TOP)/src/tclsqlite.c >>tclsqlite3.c + +fts2amal.c: target_source $(TOP)/ext/fts2/mkfts2amal.tcl + tclsh $(TOP)/ext/fts2/mkfts2amal.tcl + +fts3amal.c: target_source $(TOP)/ext/fts3/mkfts3amal.tcl + tclsh $(TOP)/ext/fts3/mkfts3amal.tcl + +# Rules to build the LEMON compiler generator +# +lemon: $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c + $(BCC) -o lemon $(TOP)/tool/lemon.c + cp $(TOP)/tool/lempar.c . + +# Rules to build individual *.o files from generated *.c files. This +# applies to: +# +# parse.o +# opcodes.o +# +%.o: %.c $(HDR) + $(TCCX_SHARED) -c $< + +# Rules to build individual *.o files from files in the src directory. +# +%.o: $(TOP)/src/%.c $(HDR) + $(TCCX_SHARED) -c $< + +tclsqlite.o: $(TOP)/src/tclsqlite.c $(HDR) + $(TCCX_SHARED) $(TCL_FLAGS) -c $(TOP)/src/tclsqlite.c + + + +# Rules to build opcodes.c and opcodes.h +# +opcodes.c: opcodes.h $(TOP)/mkopcodec.awk + sort -n -b -k 3 opcodes.h | $(NAWK) -f $(TOP)/mkopcodec.awk >opcodes.c + +opcodes.h: parse.h $(TOP)/src/vdbe.c $(TOP)/mkopcodeh.awk + cat parse.h $(TOP)/src/vdbe.c | \ + $(NAWK) -f $(TOP)/mkopcodeh.awk >opcodes.h + +# Rules to build parse.c and parse.h - the outputs of lemon. +# +parse.h: parse.c + +parse.c: $(TOP)/src/parse.y lemon $(TOP)/addopcodes.awk + cp $(TOP)/src/parse.y . + rm -f parse.h + ./lemon $(OPTS) parse.y + mv parse.h parse.h.temp + awk -f $(TOP)/addopcodes.awk parse.h.temp >parse.h + +sqlite3.h: $(TOP)/src/sqlite.h.in + sed -e s/--VERS--/`cat ${TOP}/VERSION`/ \ + -e s/--VERSION-NUMBER--/`cat ${TOP}/VERSION | sed 's/[^0-9]/ /g' | $(NAWK) '{printf "%d%03d%03d",$$1,$$2,$$3}'`/ \ + $(TOP)/src/sqlite.h.in >sqlite3.h + +keywordhash.h: $(TOP)/tool/mkkeywordhash.c + $(BCC) -o mkkeywordhash $(OPTS) $(TOP)/tool/mkkeywordhash.c + ./mkkeywordhash >keywordhash.h + + + +# Rules to build the extension objects. +# +icu.o: $(TOP)/ext/icu/icu.c $(HDR) $(EXTHDR) + $(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/icu/icu.c + +fts2.o: $(TOP)/ext/fts2/fts2.c $(HDR) $(EXTHDR) + $(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts2/fts2.c + +fts2_hash.o: $(TOP)/ext/fts2/fts2_hash.c $(HDR) $(EXTHDR) + $(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts2/fts2_hash.c + +fts2_icu.o: $(TOP)/ext/fts2/fts2_icu.c $(HDR) $(EXTHDR) + $(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts2/fts2_icu.c + +fts2_porter.o: $(TOP)/ext/fts2/fts2_porter.c $(HDR) $(EXTHDR) + $(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts2/fts2_porter.c + +fts2_tokenizer.o: $(TOP)/ext/fts2/fts2_tokenizer.c $(HDR) $(EXTHDR) + $(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts2/fts2_tokenizer.c + +fts2_tokenizer1.o: $(TOP)/ext/fts2/fts2_tokenizer1.c $(HDR) $(EXTHDR) + $(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts2/fts2_tokenizer1.c + +fts3.o: $(TOP)/ext/fts3/fts3.c $(HDR) $(EXTHDR) + $(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3.c + +fts3_hash.o: $(TOP)/ext/fts3/fts3_hash.c $(HDR) $(EXTHDR) + $(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_hash.c + +fts3_icu.o: $(TOP)/ext/fts3/fts3_icu.c $(HDR) $(EXTHDR) + $(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_icu.c + +fts3_porter.o: $(TOP)/ext/fts3/fts3_porter.c $(HDR) $(EXTHDR) + $(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_porter.c + +fts3_tokenizer.o: $(TOP)/ext/fts3/fts3_tokenizer.c $(HDR) $(EXTHDR) + $(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_tokenizer.c + +fts3_tokenizer1.o: $(TOP)/ext/fts3/fts3_tokenizer1.c $(HDR) $(EXTHDR) + $(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_tokenizer1.c + +rtree.o: $(TOP)/ext/rtree/rtree.c $(HDR) $(EXTHDR) + $(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/rtree/rtree.c + + +# Rules for building test programs and for running tests +# +tclsqlite3: $(TOP)/src/tclsqlite.c libsqlite3.a + $(TCCX_SHARED) $(TCL_FLAGS) -DTCLSH=1 -o tclsqlite3 \ + $(TOP)/src/tclsqlite.c libsqlite3.a $(LIBTCL) $(THREADLIB) + + +# Rules to build the 'testfixture' application. +# +TESTFIXTURE_FLAGS = -DTCLSH=1 -DSQLITE_TEST=1 -DSQLITE_CRASH_TEST=1 +TESTFIXTURE_FLAGS += -DSQLITE_SERVER=1 -DSQLITE_PRIVATE="" -DSQLITE_CORE + +testfixture$(EXE): $(TESTSRC2) libsqlite3.a $(TESTSRC) $(TOP)/src/tclsqlite.c + $(TCCX) $(TCL_FLAGS) $(TESTFIXTURE_FLAGS) \ + $(TESTSRC) $(TESTSRC2) $(TOP)/src/tclsqlite.c \ + -o testfixture$(EXE) $(LIBTCL) $(THREADLIB) libsqlite3.a + +amalgamation-testfixture$(EXE): sqlite3.c $(TESTSRC) $(TOP)/src/tclsqlite.c + $(TCCX) $(TCL_FLAGS) $(TESTFIXTURE_FLAGS) \ + $(TESTSRC) $(TOP)/src/tclsqlite.c sqlite3.c \ + -o testfixture$(EXE) $(LIBTCL) $(THREADLIB) + +fts3-testfixture$(EXE): sqlite3.c fts3amal.c $(TESTSRC) $(TOP)/src/tclsqlite.c + $(TCCX) $(TCL_FLAGS) $(TESTFIXTURE_FLAGS) \ + -DSQLITE_ENABLE_FTS3=1 \ + $(TESTSRC) $(TOP)/src/tclsqlite.c sqlite3.c fts3amal.c \ + -o testfixture$(EXE) $(LIBTCL) $(THREADLIB) + +fulltest: testfixture$(EXE) sqlite3$(EXE) + ./testfixture$(EXE) $(TOP)/test/all.test + +soaktest: testfixture$(EXE) sqlite3$(EXE) + ./testfixture$(EXE) $(TOP)/test/all.test -soak 1 + +test: testfixture$(EXE) sqlite3$(EXE) + ./testfixture$(EXE) $(TOP)/test/veryquick.test + +sqlite3_analyzer$(EXE): $(TOP)/src/tclsqlite.c sqlite3.c $(TESTSRC) \ + $(TOP)/tool/spaceanal.tcl + sed \ + -e '/^#/d' \ + -e 's,\\,\\\\,g' \ + -e 's,",\\",g' \ + -e 's,^,",' \ + -e 's,$$,\\n",' \ + $(TOP)/tool/spaceanal.tcl >spaceanal_tcl.h + $(TCCX) $(TCL_FLAGS) $(TESTFIXTURE_FLAGS) \ + -DTCLSH=2 -DSQLITE_TEST=1 -DSQLITE_DEBUG=1 -DSQLITE_PRIVATE="" \ + $(TESTSRC) $(TOP)/src/tclsqlite.c sqlite3.c \ + -o sqlite3_analyzer$(EXE) \ + $(LIBTCL) $(THREADLIB) + +TEST_EXTENSION = $(SHPREFIX)testloadext.$(SO) +$(TEST_EXTENSION): $(TOP)/src/test_loadext.c + $(MKSHLIB) $(TOP)/src/test_loadext.c -o $(TEST_EXTENSION) + +extensiontest: testfixture$(EXE) $(TEST_EXTENSION) + ./testfixture$(EXE) $(TOP)/test/loadext.test + +clean: + rm -f *.o sqlite3$(EXE) libsqlite3.a sqlite3.h opcodes.* + rm -f lemon lempar.c parse.* sqlite*.tar.gz mkkeywordhash keywordhash.h + rm -f $(PUBLISH) + rm -f *.da *.bb *.bbg gmon.out + rm -rf tsrc target_source + rm -f testloadext.dll libtestloadext.so + rm -f sqlite3.c fts?amal.c tclsqlite3.c + rm -f $(SHPREFIX)sqlite3.$(SO) @@ -1,8 +1,9 @@ -C Modifications\sto\spager.c\sto\savoid\sthe\sunsigned/signed\swarnings.\s(CVS\s5909) -D 2008-11-17T04:56:24 +C Added\ssupport\sfor\svxworks\s>=\s6.4;\sRTP\smode\stested,\skernel\smode\suntested.\s(CVS\s5910) +D 2008-11-17T08:05:32 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 6cbc7db84c23804c368bc7ffe51367412212d7b2 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 +F Makefile.vxwSH4 d53b4be86491060d498b22148951b6d765884cab F README b974cdc3f9f12b87e851b04e75996d720ebf81ac F VERSION 4eb06187e9b9f72fdf3ba27c407e24665d0bb513 F aclocal.m4 7d02b11fed45174e11156144227278deb6236eea @@ -130,13 +131,13 @@ F src/mutex.c e9cb5fbe94afb4328869afaf3ac49bd1327559eb F src/mutex.h 9e686e83a88838dac8b9c51271c651e833060f1e F src/mutex_noop.c 0004efdbc2fd48d261d5b3416fe537e888c79a54 F src/mutex_os2.c 9c5637aa4c307c552566d0f0b3bd206245b54a97 -F src/mutex_unix.c 29049a61755cccddb2ee53904e6906bb7674223c +F src/mutex_unix.c 0c256ff11848a18443e6c99543c585c240fd9935 F src/mutex_w32.c 017b522f63ef09b834fefc9daa876c9ec167e7b5 F src/os.c 0b411644b87ad689d7250bbfd1834d99b81a3df4 F src/os.h ef8abeb9afc694b82dbd169a91c9b7e26db3c892 F src/os_common.h 24525d8b7bce66c374dfc1810a6c9043f3359b60 F src/os_os2.c 63be0987dbeb42e9b08c831863d2a315953b86e1 -F src/os_unix.c af390f03ebe339e63911aec2d4ccd1e53fde581e +F src/os_unix.c a25bea30c5beb2e193d96e1d4f382152c7b11f84 F src/os_win.c b1cd079217818e610d6a62c6c71f1e5366a70efe F src/pager.c d328fcea0bfb3abbc174dba6e6b1ca7c0e1ed7ba F src/pager.h 4a57b219c0765fe1870238064e3f46e4eb2cf5af @@ -150,7 +151,7 @@ F src/printf.c 785f87120589c1db672e37c6eb1087c456e6f84d F src/random.c a87afbd598aa877e23ac676ee92fd8ee5c786a51 F src/resolve.c 266bb03d2b456fe68f5df2dd5687e7e88ff8088d F src/select.c b03c6fe474ded7bd110ca7b551bf0236133c12da -F src/shell.c 01835f435d2e42be95480f7d7cce48e9b255652e +F src/shell.c 650d1a87408682280d0e9d014d0d328c59c84b38 F src/sqlite.h.in 85e159e1d634c84ddbf87481293d5b1d26e2d27b F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17 F src/sqliteInt.h 338ab7f86950b00225c94efbc9be133e1bafcb2c @@ -657,7 +658,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P ce77ea989ea0bf4b44d5b9d0e58d30fd956038d3 -R c97987ade6725f63c6dbc34968980cfe -U danielk1977 -Z cde1be3bc330d9514fc94b6ec61dd3ed +P cb6be84dfc5d6546d07359b32fe04555561325de +R 6d3664ec5d51df109c0369b6f829fb45 +U chw +Z 776091acde3bb0a16b853581fceacffc diff --git a/manifest.uuid b/manifest.uuid index 925702670..24817ca3e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cb6be84dfc5d6546d07359b32fe04555561325de
\ No newline at end of file +f45a1493636a5ee474dd6c0b5d286be2249b05aa
\ No newline at end of file diff --git a/src/mutex_unix.c b/src/mutex_unix.c index 31f9a97b9..b6e4c7643 100644 --- a/src/mutex_unix.c +++ b/src/mutex_unix.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains the C functions that implement mutexes for pthreads ** -** $Id: mutex_unix.c,v 1.13 2008/07/16 12:33:24 drh Exp $ +** $Id: mutex_unix.c,v 1.14 2008/11/17 08:05:32 chw Exp $ */ #include "sqliteInt.h" @@ -61,7 +61,7 @@ struct sqlite3_mutex { ** make sure no assert() statements are evaluated and hence these ** routines are never called. */ -#ifndef NDEBUG +#if !defined(NDEBUG) || defined(SQLITE_DEBUG) static int pthreadMutexHeld(sqlite3_mutex *p){ return (p->nRef!=0 && pthread_equal(p->owner, pthread_self())); } diff --git a/src/os_unix.c b/src/os_unix.c index f4db4a26e..364b6b0e1 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -12,7 +12,7 @@ ** ** This file contains code that is specific to Unix systems. ** -** $Id: os_unix.c,v 1.209 2008/11/11 18:34:35 danielk1977 Exp $ +** $Id: os_unix.c,v 1.210 2008/11/17 08:05:32 chw Exp $ */ #include "sqliteInt.h" #if SQLITE_OS_UNIX /* This file is used on unix only */ @@ -25,7 +25,8 @@ ** * No locking, ** * Dot-file locking, ** * flock() locking, -** * AFP locking (OSX only). +** * AFP locking (OSX only), +** * Named POSIX semaphores (VXWorks only). ** ** SQLITE_ENABLE_LOCKING_STYLE only works on a Mac. It is turned on by ** default on a Mac and disabled on all other posix platforms. @@ -72,8 +73,14 @@ #if SQLITE_ENABLE_LOCKING_STYLE #include <sys/ioctl.h> +#if defined(__RTP__) || defined(_WRS_KERNEL) +#define lstat stat +#include <semaphore.h> +#include <limits.h> +#else #include <sys/param.h> #include <sys/mount.h> +#endif #endif /* SQLITE_ENABLE_LOCKING_STYLE */ /* @@ -123,6 +130,10 @@ struct unixFile { pthread_t tid; /* The thread that "owns" this unixFile */ #endif int lastErrno; /* The unix errno from the last I/O error */ +#if defined(__RTP__) || defined(_WRS_KERNEL) + int isDelete; /* Delete on close if true */ + char *zRealpath; +#endif }; /* @@ -301,7 +312,11 @@ struct unixFile { */ struct lockKey { dev_t dev; /* Device number */ +#if defined(__RTP__) || defined(_WRS_KERNEL) + void *rnam; /* Realname since inode unusable */ +#else ino_t ino; /* Inode number */ +#endif #if SQLITE_THREADSAFE pthread_t tid; /* Thread ID or zero if threads can override each other */ #endif @@ -331,7 +346,11 @@ struct lockInfo { */ struct openKey { dev_t dev; /* Device number */ +#if defined(__RTP__) || defined(_WRS_KERNEL) + void *rnam; /* Realname since inode unusable */ +#else ino_t ino; /* Inode number */ +#endif }; /* @@ -347,6 +366,10 @@ struct openCnt { int nLock; /* Number of outstanding locks */ int nPending; /* Number of pending close() operations */ int *aPending; /* Malloced space holding fd's awaiting a close() */ +#if defined(__RTP__) || defined(_WRS_KERNEL) + sem_t *pSem; /* Named POSIX semaphore */ + char aSemName[MAX_PATHNAME+1]; /* Name of that semaphore */ +#endif struct openCnt *pNext, *pPrev; /* List of all openCnt objects */ }; @@ -359,6 +382,18 @@ struct openCnt { static struct lockInfo *lockList = 0; static struct openCnt *openList = 0; +#if defined(__RTP__) || defined(_WRS_KERNEL) +/* +** This hash table is used to bind the canonical file name to a +** unixFile structure and use the hash key (= canonical name) +** instead of the Inode number of the file to find the matching +** lockInfo and openCnt structures. It also helps to make the +** name of the semaphore when LOCKING_STYLE_NAMEDSEM is used +** for the file. +*/ +static Hash nameHash; +#endif + /* ** The locking styles are associated with the different file locking ** capabilities supported by different file systems. @@ -371,6 +406,8 @@ static struct openCnt *openList = 0; ** can be used on file systems that do not offer any reliable file locking ** NO locking means that no locking will be attempted, this is only used for ** read-only file systems currently +** NAMEDSEM is similar to DOTLOCK but uses a named semaphore instead of an +** indicator file. ** UNSUPPORTED means that no locking will be attempted, this is only used for ** file systems that are known to be unsupported */ @@ -379,6 +416,7 @@ static struct openCnt *openList = 0; #define LOCKING_STYLE_DOTFILE 3 #define LOCKING_STYLE_FLOCK 4 #define LOCKING_STYLE_AFP 5 +#define LOCKING_STYLE_NAMEDSEM 6 /* ** Only set the lastErrno if the error code is a real error and not @@ -598,10 +636,103 @@ static void releaseOpenCnt(struct openCnt *pOpen){ } } +#if defined(__RTP__) || defined(_WRS_KERNEL) +/* +** Implementation of a realpath() like function for vxWorks +** to determine canonical path name from given name. It does +** not support symlinks. Neither does it handle volume prefixes. +*/ +char * +vxrealpath(const char *pathname, int dostat) +{ + struct stat sbuf; + int len; + char *where, *ptr, *last; + char *result, *curpath, *workpath, *namebuf; + + len = pathconf(pathname, _PC_PATH_MAX); + if( len<0 ){ + len = PATH_MAX; + } + result = sqlite3_malloc(len * 4); + if( !result ){ + return 0; + } + curpath = result + len; + workpath = curpath + len; + namebuf = workpath + len; + strcpy(curpath, pathname); + if( *pathname!='/' ){ + if( !getcwd(workpath, len) ){ + sqlite3_free(result); + return 0; + } + }else{ + *workpath = '\0'; + } + where = curpath; + while( *where ){ + if( !strcmp(where, ".") ){ + where++; + continue; + } + if( !strncmp(where, "./", 2) ){ + where += 2; + continue; + } + if( !strncmp(where, "../", 3) ){ + where += 3; + ptr = last = workpath; + while( *ptr ){ + if( *ptr=='/' ){ + last = ptr; + } + ptr++; + } + *last = '\0'; + continue; + } + ptr = strchr(where, '/'); + if( !ptr ){ + ptr = where + strlen(where) - 1; + }else{ + *ptr = '\0'; + } + strcpy(namebuf, workpath); + for( last = namebuf; *last; last++ ){ + continue; + } + if( *--last!='/' ){ + strcat(namebuf, "/"); + } + strcat(namebuf, where); + where = ++ptr; + if( dostat ){ + if( stat(namebuf, &sbuf)==-1 ){ + sqlite3_free(result); + return 0; + } + if( (sbuf.st_mode & S_IFDIR)==S_IFDIR ){ + strcpy(workpath, namebuf); + continue; + } + if( *where ){ + sqlite3_free(result); + return 0; + } + } + strcpy(workpath, namebuf); + } + strcpy(result, workpath); + return result; +} +#endif + #if SQLITE_ENABLE_LOCKING_STYLE /* ** Tests a byte-range locking query to see if byte range locks are ** supported, if not we fall back to dotlockLockingStyle. +** On vxWorks we fall back to namedsemLockingStyle. */ static int testLockingStyle(int fd){ struct flock lockInfo; @@ -619,8 +750,12 @@ static int testLockingStyle(int fd){ /* Testing for flock() can give false positives. So if if the above ** test fails, then we fall back to using dot-file style locking. - */ + */ +#if defined(__RTP__) || defined(_WRS_KERNEL) + return LOCKING_STYLE_NAMEDSEM; +#else return LOCKING_STYLE_DOTFILE; +#endif } #endif @@ -641,6 +776,17 @@ static int detectLockingStyle( int fd ){ #if SQLITE_ENABLE_LOCKING_STYLE +#if defined(__RTP__) || defined(_WRS_KERNEL) + if( !filePath ){ + return LOCKING_STYLE_NONE; + } + if( pVfs->pAppData ){ + return SQLITE_PTR_TO_INT(pVfs->pAppData); + } + if (access(filePath, 0) != -1){ + return testLockingStyle(fd); + } +#else struct Mapping { const char *zFilesystem; int eLockingStyle; @@ -681,6 +827,7 @@ static int detectLockingStyle( /* Default case. Handles, amongst others, "nfs". */ return testLockingStyle(fd); #endif +#endif return LOCKING_STYLE_POSIX; } @@ -693,6 +840,9 @@ static int detectLockingStyle( */ static int findLockInfo( int fd, /* The file descriptor used in the key */ +#if defined(__RTP__) || defined(_WRS_KERNEL) + void *rnam, /* vxWorks realname */ +#endif struct lockInfo **ppLock, /* Return the lockInfo structure here */ struct openCnt **ppOpen /* Return the openCnt structure here */ ){ @@ -730,7 +880,11 @@ static int findLockInfo( memset(&key1, 0, sizeof(key1)); key1.dev = statbuf.st_dev; +#if defined(__RTP__) || defined(_WRS_KERNEL) + key1.rnam = rnam; +#else key1.ino = statbuf.st_ino; +#endif #if SQLITE_THREADSAFE if( threadsOverrideEachOthersLocks<0 ){ testThreadLockingBehavior(fd); @@ -739,7 +893,11 @@ static int findLockInfo( #endif memset(&key2, 0, sizeof(key2)); key2.dev = statbuf.st_dev; +#if defined(__RTP__) || defined(_WRS_KERNEL) + key2.rnam = rnam; +#else key2.ino = statbuf.st_ino; +#endif pLock = lockList; while( pLock && memcmp(&key1, &pLock->key, sizeof(key1)) ){ pLock = pLock->pNext; @@ -783,6 +941,10 @@ static int findLockInfo( pOpen->pPrev = 0; if( openList ) openList->pPrev = pOpen; openList = pOpen; +#if defined(__RTP__) || defined(_WRS_KERNEL) + pOpen->pSem = NULL; + pOpen->aSemName[0] = '\0'; +#endif }else{ pOpen->nRef++; } @@ -847,7 +1009,11 @@ static int transferOwnership(unixFile *pFile){ pFile->tid = hSelf; if (pFile->pLock != NULL) { releaseLockInfo(pFile->pLock); +#if defined(__RTP__) || defined(_WRS_KERNEL) + rc = findLockInfo(pFile->h, pFile->zRealpath, &pFile->pLock, 0); +#else rc = findLockInfo(pFile->h, &pFile->pLock, 0); +#endif OSTRACE5("LOCK %d is now %s(%s,%d)\n", pFile->h, locktypeName(pFile->locktype), locktypeName(pFile->pLock->locktype), pFile->pLock->cnt); @@ -1052,12 +1218,23 @@ static int full_fsync(int fd, int fullSync, int dataOnly){ #else if( dataOnly ){ rc = fdatasync(fd); +#if defined(__RTP__) || defined(_WRS_KERNEL) + if( rc==-1 && errno==ENOTSUP ){ + rc = fsync(fd); + } +#endif }else{ rc = fsync(fd); } #endif /* HAVE_FULLFSYNC */ #endif /* defined(SQLITE_NO_SYNC) */ +#if defined(__RTP__) || defined(_WRS_KERNEL) + if( rc!= -1 ){ + rc = 0; + } +#endif + return rc; } @@ -1646,6 +1823,25 @@ static int closeUnixFile(sqlite3_file *id){ if( pFile->h>=0 ){ close(pFile->h); } +#if defined(__RTP__) || defined(_WRS_KERNEL) + if( pFile->isDelete && pFile->zRealpath ){ + unlink(pFile->zRealpath); + } + if( pFile->zRealpath ){ + HashElem *pElem; + int n = strlen(pFile->zRealpath) + 1; + pElem = sqlite3HashFindElem(&nameHash, pFile->zRealpath, n); + if( pElem ){ + long cnt = (long)pElem->data; + cnt--; + if( cnt==0 ){ + sqlite3HashInsert(&nameHash, pFile->zRealpath, n, 0); + }else{ + pElem->data = (void*)cnt; + } + } + } +#endif OSTRACE2("CLOSE %-3d\n", pFile->h); OpenCounter(-1); memset(pFile, 0, sizeof(unixFile)); @@ -1689,6 +1885,8 @@ static int unixClose(sqlite3_file *id){ #if SQLITE_ENABLE_LOCKING_STYLE + +#if !defined(__RTP__) && !defined(_WRS_KERNEL) #pragma mark AFP Support /* @@ -2136,6 +2334,8 @@ static int flockClose(sqlite3_file *id) { return closeUnixFile(id); } +#endif /* !defined(__RTP__) && !defined(_WRS_KERNEL) */ + #pragma mark Old-School .lock file based locking /* Dotlock-style reserved lock checking following the behavior of @@ -2164,7 +2364,7 @@ static int dotlockCheckReservedLock(sqlite3_file *id, int *pResOut) { reserved = 1; }else{ /* file does not exist, we could have it if we want it */ - int tErrno = errno; + int tErrno = errno; if( ENOENT != tErrno ){ rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_CHECKRESERVEDLOCK); pFile->lastErrno = tErrno; @@ -2187,9 +2387,10 @@ static int dotlockLock(sqlite3_file *id, int locktype) { ** Just adjust level and punt on outta here. */ if (pFile->locktype > NO_LOCK) { pFile->locktype = locktype; - +#if !defined(__RTP__) && !defined(_WRS_KERNEL) /* Always update the timestamp on the old file */ utimes(zLockFile, NULL); +#endif rc = SQLITE_OK; goto dotlock_end_lock; } @@ -2264,14 +2465,148 @@ static int dotlockUnlock(sqlite3_file *id, int locktype) { ** Close a file. */ static int dotlockClose(sqlite3_file *id) { +#if defined(__RTP__) || defined(_WRS_KERNEL) + int rc; +#endif if( id ){ unixFile *pFile = (unixFile*)id; dotlockUnlock(id, NO_LOCK); sqlite3_free(pFile->lockingContext); } +#if defined(__RTP__) || defined(_WRS_KERNEL) + enterMutex(); + rc = closeUnixFile(id); + leaveMutex(); + return rc; +#else return closeUnixFile(id); +#endif +} + +#if defined(__RTP__) || defined(_WRS_KERNEL) + +#pragma mark POSIX/vxWorks named semaphore based locking + +/* Namedsem-style reserved lock checking following the behavior of +** unixCheckReservedLock, see the unixCheckReservedLock function comments */ +static int namedsemCheckReservedLock(sqlite3_file *id, int *pResOut) { + int rc = SQLITE_OK; + int reserved = 0; + unixFile *pFile = (unixFile*)id; + + SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; ); + + assert( pFile ); + + /* Check if a thread in this process holds such a lock */ + if( pFile->locktype>SHARED_LOCK ){ + reserved = 1; + } + + /* Otherwise see if some other process holds it. */ + if( !reserved ){ + sem_t *pSem = pFile->pOpen->pSem; + struct stat statBuf; + + if( sem_trywait(pSem)==-1 ){ + int tErrno = errno; + if( EAGAIN != tErrno ){ + rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_CHECKRESERVEDLOCK); + pFile->lastErrno = tErrno; + } else { + /* someone else has the lock when we are in NO_LOCK */ + reserved = (pFile->locktype < SHARED_LOCK); + } + }else{ + /* we could have it if we want it */ + sem_post(pSem); + } + } + OSTRACE4("TEST WR-LOCK %d %d %d\n", pFile->h, rc, reserved); + + *pResOut = reserved; + return rc; +} + +static int namedsemLock(sqlite3_file *id, int locktype) { + unixFile *pFile = (unixFile*)id; + int fd; + sem_t *pSem = pFile->pOpen->pSem; + int rc = SQLITE_OK; + + /* if we already have a lock, it is exclusive. + ** Just adjust level and punt on outta here. */ + if (pFile->locktype > NO_LOCK) { + pFile->locktype = locktype; + rc = SQLITE_OK; + goto namedsem_end_lock; + } + + /* lock semaphore now but bail out when already locked. */ + if( sem_trywait(pSem)==-1 ){ + rc = SQLITE_BUSY; + goto namedsem_end_lock; + } + + /* got it, set the type and return ok */ + pFile->locktype = locktype; + + namedsem_end_lock: + return rc; +} + +static int namedsemUnlock(sqlite3_file *id, int locktype) { + unixFile *pFile = (unixFile*)id; + sem_t *pSem = pFile->pOpen->pSem; + + assert( pFile ); + assert( pSem ); + OSTRACE5("UNLOCK %d %d was %d pid=%d\n", pFile->h, locktype, + pFile->locktype, getpid()); + assert( locktype<=SHARED_LOCK ); + + /* no-op if possible */ + if( pFile->locktype==locktype ){ + return SQLITE_OK; + } + + /* shared can just be set because we always have an exclusive */ + if (locktype==SHARED_LOCK) { + pFile->locktype = locktype; + return SQLITE_OK; + } + + /* no, really unlock. */ + if ( sem_post(pSem)==-1 ) { + int rc, tErrno = errno; + rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); + if( IS_LOCK_ERROR(rc) ){ + pFile->lastErrno = tErrno; + } + return rc; + } + pFile->locktype = NO_LOCK; + return SQLITE_OK; } +/* + ** Close a file. + */ +static int namedsemClose(sqlite3_file *id) { + if( id ){ + unixFile *pFile = (unixFile*)id; + namedsemUnlock(id, NO_LOCK); + assert( pFile ); + enterMutex(); + releaseLockInfo(pFile->pLock); + releaseOpenCnt(pFile->pOpen); + closeUnixFile(id); + leaveMutex(); + } + return SQLITE_OK; +} + +#endif /* defined(__RTP__) || defined(_WRS_KERNEL) */ #endif /* SQLITE_ENABLE_LOCKING_STYLE */ @@ -2297,7 +2632,15 @@ static int nolockUnlock(sqlite3_file *id, int locktype) { ** Close a file. */ static int nolockClose(sqlite3_file *id) { +#if defined(__RTP__) || defined(_WRS_KERNEL) + int rc; + enterMutex(); + rc = closeUnixFile(id); + leaveMutex(); + return rc; +#else return closeUnixFile(id); +#endif } @@ -2349,7 +2692,8 @@ static int fillInUnixFile( int dirfd, /* Directory file descriptor */ sqlite3_file *pId, /* Write to the unixFile structure here */ const char *zFilename, /* Name of the file being opened */ - int noLock /* Omit locking if true */ + int noLock, /* Omit locking if true */ + int isDelete /* Delete on close if true */ ){ int eLockingStyle; unixFile *pNew = (unixFile *)pId; @@ -2380,8 +2724,15 @@ static int fillInUnixFile( ,IOMETHODS(nolockClose, nolockLock, nolockUnlock, nolockCheckReservedLock) #if SQLITE_ENABLE_LOCKING_STYLE ,IOMETHODS(dotlockClose, dotlockLock, dotlockUnlock,dotlockCheckReservedLock) +#if defined(__RTP__) || defined(_WRS_KERNEL) + ,IOMETHODS(nolockClose, nolockLock, nolockUnlock, nolockCheckReservedLock) + ,IOMETHODS(nolockClose, nolockLock, nolockUnlock, nolockCheckReservedLock) + ,IOMETHODS(namedsemClose, namedsemLock, namedsemUnlock, namedsemCheckReservedLock) +#else ,IOMETHODS(flockClose, flockLock, flockUnlock, flockCheckReservedLock) ,IOMETHODS(afpClose, afpLock, afpUnlock, afpCheckReservedLock) + ,IOMETHODS(nolockClose, nolockLock, nolockUnlock, nolockCheckReservedLock) +#endif #endif }; /* The order of the IOMETHODS macros above is important. It must be the @@ -2392,6 +2743,7 @@ static int fillInUnixFile( assert(LOCKING_STYLE_DOTFILE==3); assert(LOCKING_STYLE_FLOCK==4); assert(LOCKING_STYLE_AFP==5); + assert(LOCKING_STYLE_NAMEDSEM==6); assert( pNew->pLock==NULL ); assert( pNew->pOpen==NULL ); @@ -2401,6 +2753,42 @@ static int fillInUnixFile( pNew->dirfd = dirfd; SET_THREADID(pNew); +#if defined(__RTP__) || defined(_WRS_KERNEL) + { + HashElem *pElem; + char *zRealname = vxrealpath(zFilename, 1); + int n; + pNew->zRealpath = 0; + if( !zRealname ){ + rc = SQLITE_NOMEM; + eLockingStyle = LOCKING_STYLE_NONE; + }else{ + n = strlen(zRealname) + 1; + enterMutex(); + pElem = sqlite3HashFindElem(&nameHash, zRealname, n); + if( pElem ){ + long cnt = (long)pElem->data; + cnt++; + pNew->zRealpath = pElem->pKey; + pElem->data = (void*)cnt; + }else{ + if( sqlite3HashInsert(&nameHash, zRealname, n, (void*)1)==0 ){ + pElem = sqlite3HashFindElem(&nameHash, zRealname, n); + if( pElem ){ + pNew->zRealpath = pElem->pKey; + }else{ + sqlite3HashInsert(&nameHash, zRealname, n, 0); + rc = SQLITE_NOMEM; + eLockingStyle = LOCKING_STYLE_NONE; + } + } + } + leaveMutex(); + sqlite3_free(zRealname); + } + } +#endif + if( noLock ){ eLockingStyle = LOCKING_STYLE_NONE; }else{ @@ -2411,12 +2799,18 @@ static int fillInUnixFile( case LOCKING_STYLE_POSIX: { enterMutex(); +#if defined(__RTP__) || defined(_WRS_KERNEL) + rc = findLockInfo(h, pNew->zRealpath, &pNew->pLock, &pNew->pOpen); +#else rc = findLockInfo(h, &pNew->pLock, &pNew->pOpen); +#endif leaveMutex(); break; } #if SQLITE_ENABLE_LOCKING_STYLE + +#if !defined(__RTP__) && !defined(_WRS_KERNEL) case LOCKING_STYLE_AFP: { /* AFP locking uses the file path so it needs to be included in ** the afpLockingContext. @@ -2434,6 +2828,7 @@ static int fillInUnixFile( } break; } +#endif case LOCKING_STYLE_DOTFILE: { /* Dotfile locking uses the file path so it needs to be included in @@ -2452,13 +2847,46 @@ static int fillInUnixFile( break; } +#if defined(__RTP__) || defined(_WRS_KERNEL) + case LOCKING_STYLE_NAMEDSEM: { + /* Named semaphore locking uses the file path so it needs to be + ** included in the namedsemLockingContext + */ + enterMutex(); + rc = findLockInfo(h, pNew->zRealpath, &pNew->pLock, &pNew->pOpen); + if( (rc==SQLITE_OK) && (pNew->pOpen->pSem==NULL) ){ + char *zSemName = pNew->pOpen->aSemName; + int n; + sqlite3_snprintf(MAX_PATHNAME, zSemName, "%s.sem", pNew->zRealpath); + for( n=0; zSemName[n]; n++ ) + if( zSemName[n]=='/' ) zSemName[n] = '_'; + pNew->pOpen->pSem = sem_open(zSemName, O_CREAT, 0666, 1); + if( pNew->pOpen->pSem == SEM_FAILED ){ + rc = SQLITE_NOMEM; + pNew->pOpen->aSemName[0] = '\0'; + } + } + leaveMutex(); + break; + } +#endif + +#if !defined(__RTP__) && !defined(_WRS_KERNEL) case LOCKING_STYLE_FLOCK: +#endif case LOCKING_STYLE_NONE: break; #endif } pNew->lastErrno = 0; +#if defined(__RTP__) || defined(_WRS_KERNEL) + if( rc!=SQLITE_OK ){ + unlink(zFilename); + isDelete = 0; + } + pNew->isDelete = isDelete; +#endif if( rc!=SQLITE_OK ){ if( dirfd>=0 ) close(dirfd); close(h); @@ -2657,6 +3085,7 @@ static int unixOpen( oflags |= (O_LARGEFILE|O_BINARY); fd = open(zName, oflags, isDelete?0600:SQLITE_DEFAULT_FILE_PERMISSIONS); + OSTRACE4("OPENX %-3d %s 0%o\n", fd, zName, oflags); if( fd<0 && errno!=EISDIR && isReadWrite && !isExclusive ){ /* Failed to open the file for read/write access. Try read-only. */ flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE); @@ -2667,7 +3096,11 @@ static int unixOpen( return SQLITE_CANTOPEN; } if( isDelete ){ +#if defined(__RTP__) || defined(_WRS_KERNEL) + zPath = zName; +#else unlink(zName); +#endif } if( pOutFlags ){ *pOutFlags = flags; @@ -2687,7 +3120,7 @@ static int unixOpen( #endif noLock = eType!=SQLITE_OPEN_MAIN_DB; - return fillInUnixFile(pVfs, fd, dirfd, pFile, zPath, noLock); + return fillInUnixFile(pVfs, fd, dirfd, pFile, zPath, noLock, isDelete); } /* @@ -2703,7 +3136,12 @@ static int unixDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ int fd; rc = openDirectory(zPath, &fd); if( rc==SQLITE_OK ){ - if( fsync(fd) ){ +#if defined(__RTP__) || defined(_WRS_KERNEL) + if( fsync(fd)==-1 ) +#else + if( fsync(fd) ) +#endif + { rc = SQLITE_IOERR_DIR_FSYNC; } close(fd); @@ -2774,6 +3212,19 @@ static int unixFullPathname( SimulateIOError( return SQLITE_ERROR ); assert( pVfs->mxPathname==MAX_PATHNAME ); + +#if defined(__RTP__) || defined(_WRS_KERNEL) + { + char *zRealname = vxrealpath(zPath, 0); + zOut[0] = '\0'; + if( !zRealname ){ + return SQLITE_CANTOPEN; + } + sqlite3_snprintf(nOut, zOut, "%s", zRealname); + sqlite3_free(zRealname); + return SQLITE_OK; + } +#else zOut[nOut-1] = '\0'; if( zPath[0]=='/' ){ sqlite3_snprintf(nOut, zOut, "%s", zPath); @@ -2812,6 +3263,7 @@ static int unixFullPathname( zFull[j] = 0; } #endif +#endif } @@ -2905,6 +3357,13 @@ static int unixRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){ ** than the argument. */ static int unixSleep(sqlite3_vfs *pVfs, int microseconds){ +#if defined(__RTP__) || defined(_WRS_KERNEL) + struct timespec sp; + + sp.tv_sec = microseconds / 1000000; + sp.tv_nsec = (microseconds % 1000000) * 1000; + nanosleep(&sp, NULL); +#else #if defined(HAVE_USLEEP) && HAVE_USLEEP usleep(microseconds); return microseconds; @@ -2913,6 +3372,7 @@ static int unixSleep(sqlite3_vfs *pVfs, int microseconds){ sleep(seconds); return seconds*1000000; #endif +#endif } /* @@ -2929,6 +3389,11 @@ int sqlite3_current_time = 0; ** return 0. Return 1 if the time and date cannot be found. */ static int unixCurrentTime(sqlite3_vfs *pVfs, double *prNow){ +#if defined(__RTP__) || defined(_WRS_KERNEL) + struct timespec sNow; + clock_gettime(CLOCK_REALTIME, &sNow); + *prNow = 2440587.5 + sNow.tv_sec/86400.0 + sNow.tv_nsec/86400000000000.0; +#else #ifdef NO_GETTOD time_t t; time(&t); @@ -2938,6 +3403,7 @@ static int unixCurrentTime(sqlite3_vfs *pVfs, double *prNow){ gettimeofday(&sNow, 0); *prNow = 2440587.5 + sNow.tv_sec/86400.0 + sNow.tv_usec/86400000000.0; #endif +#endif #ifdef SQLITE_TEST if( sqlite3_current_time ){ *prNow = sqlite3_current_time/86400.0 + 2440587.5; @@ -2988,12 +3454,16 @@ int sqlite3_os_init(void){ UNIXVFS("unix-afp", LOCKING_STYLE_AFP), UNIXVFS("unix-flock", LOCKING_STYLE_FLOCK), UNIXVFS("unix-dotfile", LOCKING_STYLE_DOTFILE), - UNIXVFS("unix-none", LOCKING_STYLE_NONE) + UNIXVFS("unix-none", LOCKING_STYLE_NONE), + UNIXVFS("unix-namedsem",LOCKING_STYLE_NAMEDSEM), }; for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){ sqlite3_vfs_register(&aVfs[i], 0); } #endif +#if defined(__RTP__) || defined(_WRS_KERNEL) + sqlite3HashInit(&nameHash, 1); +#endif sqlite3_vfs_register(&unixVfs, 1); return SQLITE_OK; } diff --git a/src/shell.c b/src/shell.c index a3654c6ee..fb7340bf1 100644 --- a/src/shell.c +++ b/src/shell.c @@ -12,7 +12,7 @@ ** This file contains code to implement the "sqlite" command line ** utility for accessing SQLite databases. ** -** $Id: shell.c,v 1.187 2008/11/11 18:55:04 drh Exp $ +** $Id: shell.c,v 1.188 2008/11/17 08:05:32 chw Exp $ */ #include <stdlib.h> #include <string.h> @@ -24,7 +24,9 @@ #if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) # include <signal.h> -# include <pwd.h> +# if !defined(__RTP__) && !defined(_WRS_KERNEL) +# include <pwd.h> +# endif # include <unistd.h> # include <sys/types.h> #endif @@ -60,7 +62,7 @@ extern int isatty(); #define isatty(x) 1 #endif -#if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) +#if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) && !defined(__RTP__) && !defined(_WRS_KERNEL) #include <sys/time.h> #include <sys/resource.h> @@ -1773,7 +1775,7 @@ static int process_input(struct callback_data *p, FILE *in){ static char *find_home_dir(void){ char *home_dir = NULL; -#if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) && !defined(_WIN32_WCE) +#if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) && !defined(_WIN32_WCE) && !defined(__RTP__) && !defined(_WRS_KERNEL) struct passwd *pwent; uid_t uid = getuid(); if( (pwent=getpwuid(uid)) != NULL) { @@ -1843,7 +1845,9 @@ static void process_sqliterc( if (sqliterc == NULL) { home_dir = find_home_dir(); if( home_dir==0 ){ +#if !defined(__RTP__) && !defined(_WRS_KERNEL) fprintf(stderr,"%s: cannot locate your home directory!\n", Argv0); +#endif return; } nBuf = strlen(home_dir) + 16; |