Changeset: fbda8398b9e5 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/fbda8398b9e5 Modified Files: monetdb5/mal/mal_client.c monetdb5/mal/mal_client.h monetdb5/mal/mal_session.c monetdb5/mal/mal_session.h monetdb5/modules/mal/clients.c monetdb5/modules/mal/mal_mapi.c Branch: clientinfo Log Message:
Create Client fields to hold new session info diffs (235 lines): 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 @@ -401,6 +401,27 @@ MCcloseClient(Client c) GDKfree(c->username); c->username = 0; } + if (c->peer) { + GDKfree(c->peer); + c->peer = 0; + } + if (c->client_hostname) { + GDKfree(c->client_hostname); + c->client_hostname = 0; + } + if (c->client_application) { + GDKfree(c->client_application); + c->client_application = 0; + } + if (c->client_library) { + GDKfree(c->client_library); + c->client_library = 0; + } + if (c->client_remark) { + GDKfree(c->client_remark); + c->client_remark = 0; + } + c->client_pid = 0; c->mythread = NULL; if (c->glb) { freeStack(c->glb); diff --git a/monetdb5/mal/mal_client.h b/monetdb5/mal/mal_client.h --- a/monetdb5/mal/mal_client.h +++ b/monetdb5/mal/mal_client.h @@ -85,6 +85,12 @@ typedef struct CLIENT { time_t login; /* Time when this session started */ lng session; /* usec since start of server */ time_t idle; /* Time when the session became idle */ + str peer; /* Remote end of network connection */ + str client_hostname; /* Host name if reported by client, peer otherwise */ + str client_application; /* Application name reported by the client*/ + str client_library; /* MAPI client library reported by the client */ + long client_pid; /* client process id reported by the client */ + str client_remark; /* Other information reported by the client */ /* * For program debugging and performance trace we keep the actual resource claims. diff --git a/monetdb5/mal/mal_session.c b/monetdb5/mal/mal_session.c --- a/monetdb5/mal/mal_session.c +++ b/monetdb5/mal/mal_session.c @@ -186,7 +186,7 @@ cleanUpScheduleClient(Client c, str *com void -MSscheduleClient(str command, str challenge, bstream *fin, stream *fout, +MSscheduleClient(str command, str peer, str challenge, bstream *fin, stream *fout, protocol_version protocol, size_t blocksize) { char *user = command, *algo = NULL, *passwd = NULL, *lang = NULL, @@ -341,6 +341,10 @@ MSscheduleClient(str command, str challe // at this point username should have being verified c->username = GDKstrdup(user); + if (peer) { + c->peer = GDKstrdup(peer); + c->client_hostname = GDKstrdup(peer); + } /* NOTE ABOUT STARTING NEW THREADS * At this point we have conducted experiments (Jun 2012) with diff --git a/monetdb5/mal/mal_session.h b/monetdb5/mal/mal_session.h --- a/monetdb5/mal/mal_session.h +++ b/monetdb5/mal/mal_session.h @@ -19,7 +19,7 @@ mal_export str malBootstrap(char *modules[], bool embedded, const char *initpasswd); mal_export str MSinitClientPrg(Client cntxt, const char *mod, const char *nme); -mal_export void MSscheduleClient(str command, str challenge, bstream *fin, +mal_export void MSscheduleClient(str command, str peer, str challenge, bstream *fin, stream *fout, protocol_version protocol, size_t blocksize); diff --git a/monetdb5/modules/mal/clients.c b/monetdb5/modules/mal/clients.c --- a/monetdb5/modules/mal/clients.c +++ b/monetdb5/modules/mal/clients.c @@ -797,7 +797,9 @@ CLTsessions(Client cntxt, MalBlkPtr mb, bat *clientpidId = getArgReference_bat(stk, pci, 14); bat *remarkId = getArgReference_bat(stk, pci, 15); Client c; - timestamp ret; + timestamp ts; + lng pid; + const char *s; int timeout; str msg = NULL; @@ -855,8 +857,8 @@ CLTsessions(Client cntxt, MalBlkPtr mb, username = str_nil; if (BUNappend(user, username, false) != GDK_SUCCEED) goto bailout; - ret = timestamp_fromtime(c->login); - if (is_timestamp_nil(ret)) { + ts = timestamp_fromtime(c->login); + if (is_timestamp_nil(ts)) { msg = createException(SQL, "sql.sessions", SQLSTATE(22003) "Failed to convert user logged time"); @@ -864,7 +866,7 @@ CLTsessions(Client cntxt, MalBlkPtr mb, } if (BUNappend(id, &c->idx, false) != GDK_SUCCEED) goto bailout; - if (BUNappend(login, &ret, false) != GDK_SUCCEED) + if (BUNappend(login, &ts, false) != GDK_SUCCEED) goto bailout; timeout = (int) (c->logical_sessiontimeout); if (BUNappend(sessiontimeout, &timeout, false) != GDK_SUCCEED) @@ -873,16 +875,16 @@ CLTsessions(Client cntxt, MalBlkPtr mb, if (BUNappend(querytimeout, &timeout, false) != GDK_SUCCEED) goto bailout; if (c->idle) { - ret = timestamp_fromtime(c->idle); - if (is_timestamp_nil(ret)) { + ts = timestamp_fromtime(c->idle); + if (is_timestamp_nil(ts)) { msg = createException(SQL, "sql.sessions", SQLSTATE(22003) "Failed to convert user logged time"); goto bailout; } } else - ret = timestamp_nil; - if (BUNappend(idle, &ret, false) != GDK_SUCCEED) + ts = timestamp_nil; + if (BUNappend(idle, &ts, false) != GDK_SUCCEED) goto bailout; if (BUNappend(opt, &c->optimizer, false) != GDK_SUCCEED) goto bailout; @@ -892,17 +894,23 @@ CLTsessions(Client cntxt, MalBlkPtr mb, goto bailout; if (BUNappend(language, getScenarioLanguage(c), false) != GDK_SUCCEED) goto bailout; - if (BUNappend(peer, &str_nil, false) != GDK_SUCCEED) + s = c->peer ? c->peer : str_nil; + if (BUNappend(peer, s, false) != GDK_SUCCEED) goto bailout; - if (BUNappend(hostname, &str_nil, false) != GDK_SUCCEED) + s = c->client_hostname ? c->client_hostname : str_nil; + if (BUNappend(hostname, s, false) != GDK_SUCCEED) goto bailout; - if (BUNappend(application, &str_nil, false) != GDK_SUCCEED) + s = c->client_application ? c->client_application : str_nil; + if (BUNappend(application, s, false) != GDK_SUCCEED) goto bailout; - if (BUNappend(client, &str_nil, false) != GDK_SUCCEED) + s = c->client_library ? c->client_library : str_nil; + if (BUNappend(client, s, false) != GDK_SUCCEED) goto bailout; - if (BUNappend(clientpid, &lng_nil, false) != GDK_SUCCEED) + pid = c->client_pid; + if (BUNappend(clientpid, pid ? &pid : &lng_nil, false) != GDK_SUCCEED) goto bailout; - if (BUNappend(remark, &str_nil, false) != GDK_SUCCEED) + s = c->client_remark ? c->client_remark : str_nil; + if (BUNappend(remark, s, false) != GDK_SUCCEED) goto bailout; } } diff --git a/monetdb5/modules/mal/mal_mapi.c b/monetdb5/modules/mal/mal_mapi.c --- a/monetdb5/modules/mal/mal_mapi.c +++ b/monetdb5/modules/mal/mal_mapi.c @@ -160,6 +160,8 @@ generateChallenge(str buf, int min, int struct challengedata { stream *in; stream *out; + struct sockaddr_storage peer; + socklen_t peerlen; char challenge[13]; }; @@ -168,23 +170,31 @@ static str SERVERsetAlias(void *ret, con static void doChallenge(void *data) { + struct challengedata *chdata = data; char *buf = GDKmalloc(BLOCK + 1); + char peer[120] = { 0 }; char challenge[13]; - stream *fdin = ((struct challengedata *) data)->in; - stream *fdout = ((struct challengedata *) data)->out; + stream *fdin = chdata->in; + stream *fdout = chdata->out; bstream *bs; ssize_t len = 0; protocol_version protocol = PROTOCOL_9; size_t buflen = BLOCK; + if (chdata->peer.ss_family != AF_UNSPEC) { + getnameinfo( + (struct sockaddr*)&chdata->peer, chdata->peerlen, + peer, sizeof(peer), NULL, 0, + NI_NUMERICSERV | NI_NUMERICHOST); + } + MT_thread_setworking("challenging client"); #ifdef _MSC_VER srand((unsigned int) GDKusec()); #endif - memcpy(challenge, ((struct challengedata *) data)->challenge, - sizeof(challenge)); - GDKfree(data); + memcpy(challenge, chdata->challenge, sizeof(challenge)); + GDKfree(chdata); if (buf == NULL) { TRC_ERROR(MAL_SERVER, MAL_MALLOC_FAIL "\n"); close_stream(fdin); @@ -225,7 +235,7 @@ doChallenge(void *data) return; } bs->eof = true; - MSscheduleClient(buf, challenge, bs, fdout, protocol, buflen); + MSscheduleClient(buf, peer, challenge, bs, fdout, protocol, buflen); } static ATOMIC_TYPE nlistener = ATOMIC_VAR_INIT(0); /* nr of listeners */ @@ -419,6 +429,9 @@ SERVERlistenThread(SOCKET *Sock) TRC_ERROR(MAL_SERVER, MAL_MALLOC_FAIL "\n"); continue; } + data->peerlen = sizeof(data->peer); + if (getpeername(msgsock, (struct sockaddr*)&data->peer, &data->peerlen) < 0) + data->peer.ss_family = AF_UNSPEC; data->in = socket_rstream(msgsock, "Server read"); if (data->in == NULL) { stream_alloc_fail: _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org