Changeset: f1b88ecf71b6 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/f1b88ecf71b6
Modified Files:
monetdb5/mal/mal.c
monetdb5/mal/mal_authorize.c
monetdb5/mal/mal_client.c
monetdb5/mal/mal_embedded.c
monetdb5/mal/mal_import.c
monetdb5/mal/mal_interpreter.c
monetdb5/mal/mal_private.h
sql/backends/monet5/sql.c
sql/server/rel_schema.c
sql/server/sql_mvc.c
Branch: Sep2022
Log Message:
removed (as much as possible in this branch) the get/setClientContext.
Moved some code from mal to sql layer (get password for AUTHadd remote).
This solves crash(assert) in monetdbe.
diffs (truncated from 452 to 300 lines):
diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -43,93 +43,13 @@ MT_Lock mal_copyLock = MT_LOCK_INITI
MT_Lock mal_delayLock = MT_LOCK_INITIALIZER(mal_delayLock);
-
-#ifdef HAVE_PTHREAD_H
-
-static pthread_key_t tl_client_key;
-
-static int
-initialize_tl_client_key(void)
-{
- static bool initialized = false;
- if (initialized)
- return 0;
-
- if (pthread_key_create(&tl_client_key, NULL) != 0)
- return -1;
-
- initialized = true;
- return 0;
-}
-
/* declared in mal_interpreter.h so MAL operators can access it */
Client
getClientContext(void)
{
- if (initialize_tl_client_key())
- return NULL;
- return (Client) pthread_getspecific(tl_client_key);
-}
-
-/* declared in mal_private.h so only the MAL interpreter core can access it */
-Client
-setClientContext(Client cntxt)
-{
- Client old = getClientContext();
-
- if (pthread_setspecific(tl_client_key, cntxt) != 0)
- GDKfatal("Failed to set thread local Client context");
-
- return old;
+ return NULL;
}
-#elif defined(WIN32)
-
-static DWORD tl_client_key = 0;
-
-static int
-initialize_tl_client_key(void)
-{
- static bool initialized = false;
- if (initialized)
- return 0;
-
- DWORD key = TlsAlloc();
- if (key == TLS_OUT_OF_INDEXES)
- return -1;
-
- tl_client_key = key;
- initialized = true;
- return 0;
-}
-
-/* declared in mal_interpreter.h so MAL operators can access it */
-Client
-getClientContext(void)
-{
- if (initialize_tl_client_key())
- return NULL;
- return (Client) TlsGetValue(tl_client_key);
-}
-
-/* declared in mal_private.h so only the MAL interpreter core can access it */
-Client
-setClientContext(Client cntxt)
-{
- Client old = getClientContext();
-
- if (TlsSetValue(tl_client_key, cntxt) == 0)
- GDKfatal("Failed to set thread local Client context");
-
- return old;
-}
-
-#else
-
-#error "no pthreads and no Win32, don't know what to do"
-
-#endif
-
const char *
mal_version(void)
{
@@ -160,9 +80,6 @@ mal_init(char *modules[], bool embedded,
return -1;
}
- if (initialize_tl_client_key() != 0)
- return -1;
-
if ((err = AUTHinitTables()) != MAL_SUCCEED) {
freeException(err);
return -1;
diff --git a/monetdb5/mal/mal_authorize.c b/monetdb5/mal/mal_authorize.c
--- a/monetdb5/mal/mal_authorize.c
+++ b/monetdb5/mal/mal_authorize.c
@@ -715,25 +715,17 @@ AUTHaddRemoteTableCredentials(const char
return output;
}
- if (pass == NULL) {
- // init client to have SQL callback hooks
- Client c = getClientContext();
- if((output = AUTHgetPasswordHash(&pwhash, c, local_user)) !=
MAL_SUCCEED)
- return output;
- }
- else {
- free_pw = true;
- if (pw_encrypted) {
- if((pwhash = strdup(pass)) == NULL)
- throw(MAL, "addRemoteTableCredentials",
SQLSTATE(HY013) MAL_MALLOC_FAIL);
- }
- else {
- /* Note: the remote server might have used a different
- * algorithm to hash the pwhash.
- */
- if((pwhash = mcrypt_BackendSum(pass, strlen(pass))) ==
NULL)
- throw(MAL, "addRemoteTableCredentials",
SQLSTATE(42000) "Crypt backend hash not found");
- }
+ assert(pass);
+ free_pw = true;
+ if (pw_encrypted) {
+ if((pwhash = strdup(pass)) == NULL)
+ throw(MAL, "addRemoteTableCredentials", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
+ } else {
+ /* Note: the remote server might have used a different
+ * algorithm to hash the pwhash.
+ */
+ if((pwhash = mcrypt_BackendSum(pass, strlen(pass))) == NULL)
+ throw(MAL, "addRemoteTableCredentials", SQLSTATE(42000)
"Crypt backend hash not found");
}
msg = AUTHverifyPassword(pwhash);
if( msg != MAL_SUCCEED){
diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c
--- a/monetdb5/mal/mal_client.c
+++ b/monetdb5/mal/mal_client.c
@@ -218,7 +218,6 @@ MCexitClient(Client c)
&(struct NonMalEvent)
{CLIENT_END, c, Tend, NULL, NULL, 0,
Tend-(c->session)});
}
- setClientContext(NULL);
}
static Client
@@ -303,12 +302,8 @@ MCinitClient(oid user, bstream *fin, str
MT_lock_set(&mal_contextLock);
c = MCnewClient();
- if (c) {
- Client c_old = setClientContext(c);
- (void) c_old;
- assert(NULL == c_old);
+ if (c)
c = MCinitClientRecord(c, user, fin, fout);
- }
MT_lock_unset(&mal_contextLock);
if (c && profilerStatus > 0)
diff --git a/monetdb5/mal/mal_embedded.c b/monetdb5/mal/mal_embedded.c
--- a/monetdb5/mal/mal_embedded.c
+++ b/monetdb5/mal/mal_embedded.c
@@ -45,7 +45,7 @@ static bool embeddedinitialized = false;
str
malEmbeddedBoot(int workerlimit, int memorylimit, int querytimeout, int
sessiontimeout, bool with_mapi_server)
{
- Client c, c_old;
+ Client c;
str msg = MAL_SUCCEED;
if( embeddedinitialized )
@@ -100,7 +100,6 @@ malEmbeddedBoot(int workerlimit, int mem
initParser();
initHeartbeat();
// initResource();
- c_old = setClientContext(NULL); //save context
c = MCinitClient((oid) 0, 0, 0);
if(c == NULL)
throw(MAL, "malEmbeddedBoot", "Failed to initialize client");
@@ -111,37 +110,31 @@ malEmbeddedBoot(int workerlimit, int mem
c->curmodule = c->usermodule = userModule();
if(c->usermodule == NULL) {
MCcloseClient(c);
- setClientContext(c_old); // restore context
throw(MAL, "malEmbeddedBoot", "Failed to initialize client MAL
module");
}
if ( (msg = defaultScenario(c)) ) {
MCcloseClient(c);
- setClientContext(c_old); // restore context
return msg;
}
if ((msg = MSinitClientPrg(c, "user", "main")) != MAL_SUCCEED) {
MCcloseClient(c);
- setClientContext(c_old); // restore context
return msg;
}
char *modules[5] = { "embedded", "sql", "generator", "udf" };
if ((msg = malIncludeModules(c, modules, 0, !with_mapi_server, NULL))
!= MAL_SUCCEED) {
MCcloseClient(c);
- setClientContext(c_old); // restore context
return msg;
}
pushEndInstruction(c->curprg->def);
msg = chkProgram(c->usermodule, c->curprg->def);
if ( msg != MAL_SUCCEED || (msg= c->curprg->def->errors) != MAL_SUCCEED
) {
MCcloseClient(c);
- setClientContext(c_old); // restore context
return msg;
}
msg = MALengine(c);
if (msg == MAL_SUCCEED)
embeddedinitialized = true;
MCcloseClient(c);
- setClientContext(c_old); // restore context
initProfiler();
return msg;
}
diff --git a/monetdb5/mal/mal_import.c b/monetdb5/mal/mal_import.c
--- a/monetdb5/mal/mal_import.c
+++ b/monetdb5/mal/mal_import.c
@@ -276,7 +276,7 @@ malInclude(Client c, const char *name, i
str
evalFile(str fname, int listing)
{
- Client c, c_old;
+ Client c;
stream *fd;
str filename;
str msg = MAL_SUCCEED;
@@ -297,7 +297,6 @@ evalFile(str fname, int listing)
close_stream(fd);
throw(MAL,"mal.eval",SQLSTATE(HY013) MAL_MALLOC_FAIL);
}
- c_old = setClientContext(NULL); // save context
c = MCinitClient(MAL_ADMIN, bs, 0);
if( c == NULL){
throw(MAL,"mal.eval","Can not create user context");
@@ -305,7 +304,6 @@ evalFile(str fname, int listing)
c->curmodule = c->usermodule = userModule();
if(c->curmodule == NULL) {
MCcloseClient(c);
- setClientContext(c_old); // restore context
throw(MAL,"mal.eval",SQLSTATE(HY013) MAL_MALLOC_FAIL);
}
c->promptlength = 0;
@@ -313,18 +311,15 @@ evalFile(str fname, int listing)
if ( (msg = defaultScenario(c)) ) {
MCcloseClient(c);
- setClientContext(c_old); // restore context
return msg;
}
if((msg = MSinitClientPrg(c, "user", "main")) != MAL_SUCCEED) {
MCcloseClient(c);
- setClientContext(c_old); // restore context
return msg;
}
msg = runScenario(c,0);
MCcloseClient(c);
- setClientContext(c_old); // restore context
return msg;
}
@@ -348,7 +343,7 @@ mal_cmdline(char *s, size_t *len)
str
compileString(Symbol *fcn, Client cntxt, str s)
{
- Client c, c_old;
+ Client c;
size_t len = strlen(s);
buffer *b;
str msg = MAL_SUCCEED;
@@ -387,7 +382,6 @@ compileString(Symbol *fcn, Client cntxt,
}
strncpy(fdin->buf, qry, len+1);
- c_old = setClientContext(NULL); // save context
// compile in context of called for
c = MCinitClient(MAL_ADMIN, fdin, 0);
if( c == NULL){
@@ -404,7 +398,6 @@ compileString(Symbol *fcn, Client cntxt,
GDKfree(b);
c->usermodule= 0;
MCcloseClient(c);
- setClientContext(c_old); // restore context
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]