Groups > Novell > Novell Libc > Re: fcntl not working proper?




fcntl not working proper?

fcntl not working proper?
Mon, 18 Jun 2007 22:49:42 GMT
Hello everyone,

I am trying to use sqlite3 which heavily uses fcntl. Attached is my 
source and its compiled nlm. Does anyone have a working sqlite3 ?

The program below fails with "database is locked" which means it
wasn't 
able to put an WRLCK on it. sqlite_debug trace turned out:

fcntl 15 7 SETLK RDLCK 0 1 0 015
fcntl 16 7 SETLK WRLCK 0 1 0 1
fcntl-failure-reason: RDLCK 0 1 0

looks like something went wrong using fcntl.

Testet with sqlite3.c 3.3.17 and 3.4.0.

Thanks in advance

Xatru

/* sqltest.c */
#include <stdio.h>
#include <stdlib.h>
#include "sqlite3.h"

static int callback(void *NotUsed, int argc, char **argv, char **azColName){
   int i;
   for(i=0; i<argc; i++){
     printf("%s = %s\n", azColName[i], argv[i] ? argv[i] :
"NULL");
   }
   printf("\n");
   return 0;
}

int main(int argc, char **argv){
int i;
int rc;
char buf[100];
sqlite3 *sdb;
char *zErrMsg;

zErrMsg=0;

  rc = sqlite3_open("sql.db", &sdb);
   if( rc ){
     consoleprintf("Can't open database: %s\n", sqlite3_errmsg(sdb));
     sqlite3_close(sdb);
     exit(1);
   }

consoleprintf("creating table\n");

   rc = sqlite3_exec(sdb, "CREATE TABLE test (test1 TEXT);", callback,

0, &zErrMsg);
   if( rc!=SQLITE_OK ){
     consoleprintf("SQL error: %s\n", zErrMsg);
     if (zErrMsg)
       free(zErrMsg);
   }

consoleprintf("insert into table\n");

   rc = sqlite3_exec(sdb, "insert into test (test1) values 
('teststring');", callback, 0, &zErrMsg);
   if( rc!=SQLITE_OK ){
     consoleprintf("SQL error: %s\n", zErrMsg);
     if (zErrMsg)
       free(zErrMsg);
   }


consoleprintf("select *\n");

   rc = sqlite3_exec(sdb, "select * from test;", callback, 0,
&zErrMsg);
   if( rc!=SQLITE_OK ){
     consoleprintf("SQL error: %s\n", zErrMsg);
     if (zErrMsg)
       free(zErrMsg);
   }

sqlite3_close(sdb);

return 0;
Post Reply
Re: fcntl not working proper?
Tue, 19 Jun 2007 01:25:39 GMT
Hi,

Xatru <xatru@kuehlbox.de> wrote in
news:a_Ddi.3958$%54.1938@prv-forum2.provo.novell.com: 

> Hello everyone,
> 
> I am trying to use sqlite3 which heavily uses fcntl. Attached is my 
> source and its compiled nlm. Does anyone have a working sqlite3 ?
I can confirm that we have a problem with locking on NetWare; I see similar 
with Perl, and also with the php_sqlite extension....
I'd suggest we should work out some simple samples which can nail down the 
prob so that Jeff can take a look into it...
regarding SQLite I have here the code which is used with PHP:
http://www.gknw.net/test/sqlite/
this contains a Makefile which builds the lib + commandline with either 
CodeWarrior or GCC.
Here's a simple flock() sample - something like that is needed to re-create 
the prob:
http://www.gknw.net/test/flock/

G.
Post Reply
Re: fcntl not working proper?
Tue, 19 Jun 2007 04:17:05 GMT
Xatru wrote:
> Hello everyone,
> 
> I am trying to use sqlite3 which heavily uses fcntl. Attached is my 
> source and its compiled nlm. Does anyone have a working sqlite3 ?
> 
> The program below fails with "database is locked" which means it
wasn't 
> able to put an WRLCK on it. sqlite_debug trace turned out:
> 
> fcntl 15 7 SETLK RDLCK 0 1 0 015
> fcntl 16 7 SETLK WRLCK 0 1 0 1
> fcntl-failure-reason: RDLCK 0 1 0
> 
> looks like something went wrong using fcntl.
> 
> Testet with sqlite3.c 3.3.17 and 3.4.0.
> 
> Thanks in advance
> 
> Xatru
> 
> /* sqltest.c */
> #include <stdio.h>
> #include <stdlib.h>
> #include "sqlite3.h"
> 
> static int callback(void *NotUsed, int argc, char **argv, char 
> **azColName){
>   int i;
>   for(i=0; i<argc; i++){
>     printf("%s = %s\n", azColName[i], argv[i] ? argv[i] :
"NULL");
>   }
>   printf("\n");
>   return 0;
> }
> 
> int main(int argc, char **argv){
> int i;
> int rc;
> char buf[100];
> sqlite3 *sdb;
> char *zErrMsg;
> 
> zErrMsg=0;
> 
>  rc = sqlite3_open("sql.db", &sdb);
>   if( rc ){
>     consoleprintf("Can't open database: %s\n",
sqlite3_errmsg(sdb));
>     sqlite3_close(sdb);
>     exit(1);
>   }
> 
> consoleprintf("creating table\n");
> 
>   rc = sqlite3_exec(sdb, "CREATE TABLE test (test1 TEXT);",
callback, 0, 
> &zErrMsg);
>   if( rc!=SQLITE_OK ){
>     consoleprintf("SQL error: %s\n", zErrMsg);
>     if (zErrMsg)
>       free(zErrMsg);
>   }
> 
> consoleprintf("insert into table\n");
> 
>   rc = sqlite3_exec(sdb, "insert into test (test1) values 
> ('teststring');", callback, 0, &zErrMsg);
>   if( rc!=SQLITE_OK ){
>     consoleprintf("SQL error: %s\n", zErrMsg);
>     if (zErrMsg)
>       free(zErrMsg);
>   }
> 
> 
> consoleprintf("select *\n");
> 
>   rc = sqlite3_exec(sdb, "select * from test;", callback, 0,
&zErrMsg);
>   if( rc!=SQLITE_OK ){
>     consoleprintf("SQL error: %s\n", zErrMsg);
>     if (zErrMsg)
>       free(zErrMsg);
>   }
> 
> sqlite3_close(sdb);
> 
> return 0;
> }
fcntl for file locking is extremely difficult to implement. Prior to 
leaving Novell, both John Gay and I worked on it, but it was only an 
experimental project and we had no real world test cases. I am now 
familiar with sqlite3 because I use it heavily where I work now (Quest 
Software), but fcntl never became enough of a priority back then for us 
to stress over it (no such use by MySQL, PostGRES, bash, etc.).

Post Reply
Re: fcntl not working proper?
Tue, 19 Jun 2007 09:01:40 GMT
Hello.

We have experienced similar problems with sqlite 3.3.16 using
configuration provided by Guenter.

Compilation of command-line shell.nlm with following Makefile changes:

# Global flags for all compilers
CFLAGS	= -nostdinc $(OPT) -D$(DB) -DNETWARE -DN_PLAT_NLM 
-DSQLITE_DEBUG=1 -DSQLITE_LOCK_TRACE
CFLAGS	+= -DOS_UNIX=1

and manually adding in os_common.h file:

int sqlite3_os_trace = 1;

The shell.nlm  test run ended in a hanged console:

fcntl 2 6 SETLK RDLCK 0 1 0 0
fcntl 3 6 SETLK WRLCK 0 1 0 -1
fcntl-failure-reason: RDLCK 0 1 0
OPEN    5   sys:php5/local/test.sq3
READ    5     100       0 0
SQLite version 3.3.16
Enter ".help" for instructions
sqlite>
sqlite> select * from tbl1;
LOCK    5 SHARED was NONE(NONE,0) pid=455
No-transfer, same thread

(hanged ...)

Earlier attempts with less aggressive debug options looked like this:

sqlite> select * from tbl1;
LOCK    5 SHARED was NONE(NONE,0) pid=433
No-transfer, same thread
LOCK    5 SHARED ok
READ    5    1024       0 0
UNLOCK  5 0 was 1(1,1) pid=433
LOCK    5 SHARED was NONE(NONE,0) pid=433
No-transfer, same thread
LOCK    5 SHARED ok
READ    5      16      24 0
READ    5    1024    1024 0
goodbye|20
UNLOCK  5 0 was 1(1,1) pid=433
sqlite> insert into tbl1 values('hello', 10);
LOCK    5 SHARED was NONE(NONE,0) pid=433
No-transfer, same thread
LOCK    5 SHARED ok
READ    5      16      24 0
LOCK    5 RESERVED was SHARED(SHARED,1) pid=433
No-transfer, same thread
TRACE PGAL CODE 006 EAGAIN 5 RESERVED was SHARED(SHARED,1) pid=433
LOCK    5 RESERVED failed
UNLOCK  5 0 was 1(1,1) pid=433
SQL error: database is locked
sqlite>

Piotr


> I am trying to use sqlite3 which heavily uses fcntl. Attached is my 
> source and its compiled nlm. Does anyone have a working sqlite3 ?

> The program below fails with "database is locked" which means it
wasn't 
> able to put an WRLCK on it. sqlite_debug trace turned out:

> fcntl 15 7 SETLK RDLCK 0 1 0 015
> fcntl 16 7 SETLK WRLCK 0 1 0 1
> fcntl-failure-reason: RDLCK 0 1 0

> looks like something went wrong using fcntl.

> Testet with sqlite3.c 3.3.17 and 3.4.0.


Post Reply
Re: fcntl not working proper?
Tue, 19 Jun 2007 09:08:21 GMT
Greetings All,
On the face of it, fcntl() and flock() seem to have a lot in common, and 
while checking NetWare Perl issues, found the flock() function in Perl 
to be disabled, and when I asked why, was told there were problems with 
the underlying LibC implementation of that too; perhaps these functions 
share a common LibC code base?
I found flock() (once I activated it in Perl) able to exclusive lock a 
file, but could not 'unlock it for shared access' other than by closing 
it altogether. (This was done on a single-user machine and one file).
Trust this doesn't muddy the water...
Norm.

Xatru wrote:
> Hello everyone,
> 
> I am trying to use sqlite3 which heavily uses fcntl. Attached is my 
> source and its compiled nlm. Does anyone have a working sqlite3 ?
> 
> The program below fails with "database is locked" which means it
wasn't 
> able to put an WRLCK on it. sqlite_debug trace turned out:
> 
> fcntl 15 7 SETLK RDLCK 0 1 0 015
> fcntl 16 7 SETLK WRLCK 0 1 0 1
> fcntl-failure-reason: RDLCK 0 1 0
> 
> looks like something went wrong using fcntl.
> 
> Testet with sqlite3.c 3.3.17 and 3.4.0.
> 
> Thanks in advance
> 
> Xatru
> 
> /* sqltest.c */
> #include <stdio.h>
> #include <stdlib.h>
> #include "sqlite3.h"
> 
> static int callback(void *NotUsed, int argc, char **argv, char 
> **azColName){
>   int i;
>   for(i=0; i<argc; i++){
>     printf("%s = %s\n", azColName[i], argv[i] ? argv[i] :
"NULL");
>   }
>   printf("\n");
>   return 0;
> }
> 
> int main(int argc, char **argv){
> int i;
> int rc;
> char buf[100];
> sqlite3 *sdb;
> char *zErrMsg;
> 
> zErrMsg=0;
> 
>  rc = sqlite3_open("sql.db", &sdb);
>   if( rc ){
>     consoleprintf("Can't open database: %s\n",
sqlite3_errmsg(sdb));
>     sqlite3_close(sdb);
>     exit(1);
>   }
> 
> consoleprintf("creating table\n");
> 
>   rc = sqlite3_exec(sdb, "CREATE TABLE test (test1 TEXT);",
callback, 0, 
> &zErrMsg);
>   if( rc!=SQLITE_OK ){
>     consoleprintf("SQL error: %s\n", zErrMsg);
>     if (zErrMsg)
>       free(zErrMsg);
>   }
> 
> consoleprintf("insert into table\n");
> 
>   rc = sqlite3_exec(sdb, "insert into test (test1) values 
> ('teststring');", callback, 0, &zErrMsg);
>   if( rc!=SQLITE_OK ){
>     consoleprintf("SQL error: %s\n", zErrMsg);
>     if (zErrMsg)
>       free(zErrMsg);
>   }
> 
> 
> consoleprintf("select *\n");
> 
>   rc = sqlite3_exec(sdb, "select * from test;", callback, 0,
&zErrMsg);
>   if( rc!=SQLITE_OK ){
>     consoleprintf("SQL error: %s\n", zErrMsg);
>     if (zErrMsg)
>       free(zErrMsg);
>   }
> 
> sqlite3_close(sdb);
> 
> return 0;
Post Reply
<< Previous 1 2 Next >>
( Page 1 of 2 )
about | contact