mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-22 16:43:03 +01:00
Added remote process name to the monitoring data. Applications are allowed to override this value via DPB.
This commit is contained in:
parent
23f45b4bfa
commit
bc7c4d0054
@ -84,6 +84,7 @@ Monitoring tables
|
||||
- MON$REMOTE_PROTOCOL (remote protocol name)
|
||||
- MON$REMOTE_ADDRESS (remote address)
|
||||
- MON$REMOTE_PID (remote client process ID)
|
||||
- MON$REMOTE_PROCESS (remote client process pathname)
|
||||
- MON$CHARACTER_SET_ID (attachment character set)
|
||||
- MON$TIMESTAMP (connection date/time)
|
||||
- MON$GARBAGE_COLLECTION (garbage collection flag)
|
||||
@ -136,8 +137,10 @@ Monitoring tables
|
||||
in the system table RDB$TYPES
|
||||
|
||||
2) For table MON$ATTACHMENTS:
|
||||
- column MON$REMOTE_PID contains non-NULL value only if the client
|
||||
library has version 2.1 or higher
|
||||
- columns MON$REMOTE_PID and MON$REMOTE_PROCESS contains non-NULL values
|
||||
only if the client library has version 2.1 or higher
|
||||
- column MON$REMOTE_PROCESS can contain a non-pathname value
|
||||
if an application has specified a custom process name via DPB
|
||||
|
||||
3) For table MON$STATEMENTS:
|
||||
- column MON$SQL_TEXT contains NULL for GDML statements
|
||||
|
@ -518,4 +518,32 @@ bool validateProductSuite (LPCSTR lpszSuiteToValidate)
|
||||
}
|
||||
|
||||
#endif // WIN_NT
|
||||
|
||||
// *******************************
|
||||
// g e t _ p r o c e s s _ n a m e
|
||||
// *******************************
|
||||
// Return the name of the current process
|
||||
|
||||
Firebird::PathName get_process_name()
|
||||
{
|
||||
char buffer[MAXPATHLEN];
|
||||
|
||||
#if defined(WIN_NT)
|
||||
const int len = GetModuleFileName(NULL, buffer, sizeof(buffer));
|
||||
#elif defined(HAVE__PROC_SELF_EXE)
|
||||
const int len = readlink("/proc/self/exe", buffer, sizeof(buffer));
|
||||
#else
|
||||
const int len = 0;
|
||||
#endif
|
||||
|
||||
if (len < 0)
|
||||
buffer[0] = 0;
|
||||
else if (len < sizeof(buffer))
|
||||
buffer[len] = 0;
|
||||
else
|
||||
buffer[len - 1] = 0;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
} // namespace fb_utils
|
||||
|
@ -97,6 +97,8 @@ namespace fb_utils
|
||||
#ifdef WIN_NT
|
||||
void prefix_kernel_object_name(char*, size_t);
|
||||
#endif
|
||||
|
||||
Firebird::PathName get_process_name();
|
||||
} // namespace fb_utils
|
||||
|
||||
#endif // INCLUDE_UTILS_PROTO_H
|
||||
|
@ -101,9 +101,10 @@
|
||||
#define isc_dpb_set_db_charset 68
|
||||
#define isc_dpb_gsec_attach 69
|
||||
#define isc_dpb_address_path 70
|
||||
#define isc_dpb_pid 71
|
||||
#define isc_dpb_process_id 71
|
||||
#define isc_dpb_no_db_triggers 72
|
||||
#define isc_dpb_trusted_auth 73
|
||||
#define isc_dpb_process_name 74
|
||||
|
||||
/**************************************************/
|
||||
/* clumplet tags used inside isc_dpb_address_path */
|
||||
@ -251,8 +252,9 @@
|
||||
#define isc_spb_verbose 107
|
||||
#define isc_spb_options 108
|
||||
#define isc_spb_address_path 109
|
||||
#define isc_spb_pid 110
|
||||
#define isc_spb_process_id 110
|
||||
#define isc_spb_trusted_auth 111
|
||||
#define isc_spb_process_name 112
|
||||
|
||||
|
||||
#define isc_spb_connect_timeout isc_dpb_connect_timeout
|
||||
|
@ -336,6 +336,7 @@ enum fids {
|
||||
f_mon_att_charset_id,
|
||||
f_mon_att_timestamp,
|
||||
f_mon_att_gc,
|
||||
f_mon_att_remote_process,
|
||||
|
||||
f_mon_tra_id = 0,
|
||||
f_mon_tra_att_id,
|
||||
|
@ -672,6 +672,7 @@ const char* DatabaseSnapshot::checkNull(int rid, int fid, const char* source, si
|
||||
switch (fid) {
|
||||
case f_mon_att_remote_proto:
|
||||
case f_mon_att_remote_addr:
|
||||
case f_mon_att_remote_process:
|
||||
return length ? source : NULL;
|
||||
case f_mon_att_remote_pid:
|
||||
return (*(SLONG*) source) ? source : NULL;
|
||||
@ -932,6 +933,8 @@ void DatabaseSnapshot::putAttachment(Attachment* attachment,
|
||||
attachment->att_remote_address);
|
||||
// remote process id
|
||||
writer.insertInt(f_mon_att_remote_pid, attachment->att_remote_pid);
|
||||
// remote process name
|
||||
writer.insertPath(f_mon_att_remote_process, attachment->att_remote_process);
|
||||
// charset
|
||||
writer.insertInt(f_mon_att_charset_id, attachment->att_charset);
|
||||
// timestamp
|
||||
|
@ -394,6 +394,7 @@ public:
|
||||
#ifdef TRUSTED_AUTH
|
||||
Firebird::string dpb_trusted_login;
|
||||
#endif
|
||||
Firebird::PathName dpb_remote_process;
|
||||
|
||||
public:
|
||||
DatabaseOptions()
|
||||
@ -785,6 +786,7 @@ ISC_STATUS GDS_ATTACH_DATABASE(ISC_STATUS* user_status,
|
||||
attachment->att_network_protocol = options.dpb_network_protocol;
|
||||
attachment->att_remote_address = options.dpb_remote_address;
|
||||
attachment->att_remote_pid = options.dpb_remote_pid;
|
||||
attachment->att_remote_process = options.dpb_remote_process;
|
||||
attachment->att_next = dbb->dbb_attachments;
|
||||
|
||||
dbb->dbb_attachments = attachment;
|
||||
@ -1865,6 +1867,7 @@ ISC_STATUS GDS_CREATE_DATABASE(ISC_STATUS* user_status,
|
||||
attachment->att_network_protocol = options.dpb_network_protocol;
|
||||
attachment->att_remote_address = options.dpb_remote_address;
|
||||
attachment->att_remote_pid = options.dpb_remote_pid;
|
||||
attachment->att_remote_process = options.dpb_remote_process;
|
||||
attachment->att_next = dbb->dbb_attachments;
|
||||
|
||||
dbb->dbb_attachments = attachment;
|
||||
@ -5681,10 +5684,14 @@ void DatabaseOptions::get(const UCHAR* dpb, USHORT dpb_length)
|
||||
}
|
||||
break;
|
||||
|
||||
case isc_dpb_pid:
|
||||
case isc_dpb_process_id:
|
||||
dpb_remote_pid = rdr.getInt();
|
||||
break;
|
||||
|
||||
case isc_dpb_process_name:
|
||||
rdr.getPath(dpb_remote_process);
|
||||
break;
|
||||
|
||||
case isc_dpb_no_db_triggers:
|
||||
dpb_no_db_triggers = rdr.getInt() != 0;
|
||||
break;
|
||||
|
@ -500,7 +500,8 @@ public:
|
||||
att_filename(*dbb->dbb_permanent),
|
||||
att_context_vars(*dbb->dbb_permanent),
|
||||
att_network_protocol(*dbb->dbb_permanent),
|
||||
att_remote_address(*dbb->dbb_permanent)
|
||||
att_remote_address(*dbb->dbb_permanent),
|
||||
att_remote_process(*dbb->dbb_permanent)
|
||||
#ifndef SUPERSERVER
|
||||
, att_dsql_cache(*dbb->dbb_permanent)
|
||||
#endif
|
||||
@ -564,6 +565,7 @@ public:
|
||||
Firebird::string att_network_protocol; // Network protocol used by client for connection
|
||||
Firebird::string att_remote_address; // Protocol-specific addess of remote client
|
||||
SLONG att_remote_pid; // Process id of remote client
|
||||
Firebird::PathName att_remote_process; // Process name of remote client
|
||||
#ifndef SUPERSERVER
|
||||
Lock* att_temp_pg_lock; // temporary pagespace ID lock
|
||||
Firebird::GenericMap<Firebird::Pair<Firebird::Left<
|
||||
|
@ -266,6 +266,7 @@ NAME("MON$PAGE_BUFFERS", nam_mon_page_bufs)
|
||||
NAME("MON$PAGES", nam_mon_pages)
|
||||
NAME("MON$REMOTE_ADDRESS", nam_mon_remote_addr)
|
||||
NAME("MON$REMOTE_PID", nam_mon_remote_pid)
|
||||
NAME("MON$REMOTE_PROCESS", nam_mon_remote_process)
|
||||
NAME("MON$REMOTE_PROTOCOL", nam_mon_remote_proto)
|
||||
NAME("MON$ROLE", nam_mon_role)
|
||||
NAME("MON$SERVER_PID", nam_mon_server_pid)
|
||||
|
@ -42,35 +42,14 @@ typedef Firebird::PathName string;
|
||||
* Platform-specific root locator
|
||||
*/
|
||||
|
||||
#if defined SUPERSERVER || defined EMBEDDED
|
||||
#ifdef HAVE__PROC_SELF_EXE
|
||||
static string getExePathViaProcEntry()
|
||||
{
|
||||
char buffer[MAXPATHLEN];
|
||||
const int len = readlink("/proc/self/exe", buffer, sizeof(buffer));
|
||||
if (len >= 0) {
|
||||
buffer[len] = 0;
|
||||
return buffer;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined SUPERSERVER || defined EMBEDDED
|
||||
static string getRootPathFromExePath()
|
||||
{
|
||||
#ifdef HAVE__PROC_SELF_EXE
|
||||
// get the pathname of the running executable
|
||||
string bin_dir = getExePathViaProcEntry();
|
||||
string bin_dir = fb_utils::get_process_name();
|
||||
if (bin_dir.length() == 0)
|
||||
return "";
|
||||
|
||||
|
||||
// get rid of the filename
|
||||
int index = bin_dir.rfind(PathUtils::dir_sep);
|
||||
bin_dir = bin_dir.substr(0, index);
|
||||
@ -87,9 +66,6 @@ static string getRootPathFromExePath()
|
||||
index = bin_dir.rfind(PathUtils::dir_sep, bin_dir.length());
|
||||
string root_dir = (index ? bin_dir.substr(0, index) : bin_dir) + PathUtils::dir_sep;
|
||||
return root_dir;
|
||||
#else
|
||||
return "";
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -104,6 +80,6 @@ void ConfigRoot::osConfigRoot()
|
||||
#endif
|
||||
|
||||
// As a last resort get it from the default install directory
|
||||
root_dir = string(FB_PREFIX) + PathUtils::dir_sep;
|
||||
root_dir = string(FB_PREFIX) + PathUtils::dir_sep;
|
||||
}
|
||||
|
||||
|
@ -76,28 +76,27 @@ void ConfigRoot::osConfigRoot()
|
||||
#endif
|
||||
|
||||
// get the pathname of the running executable
|
||||
string bin_dir;
|
||||
string bin_dir = fb_utils::get_process_name();
|
||||
if (bin_dir.length() != 0)
|
||||
{
|
||||
// Given the current semantics of PathName, when "buffer" goes
|
||||
// out of scope, it's already bitwise copied into bin_dir.
|
||||
char buffer[MAXPATHLEN];
|
||||
GetModuleFileName(NULL, buffer, sizeof(buffer));
|
||||
bin_dir = buffer;
|
||||
}
|
||||
|
||||
// get rid of the filename
|
||||
int index = bin_dir.rfind(PathUtils::dir_sep);
|
||||
bin_dir = bin_dir.substr(0, index);
|
||||
// get rid of the filename
|
||||
int index = bin_dir.rfind(PathUtils::dir_sep);
|
||||
bin_dir = bin_dir.substr(0, index);
|
||||
|
||||
// how should we decide to use bin_dir instead of root_dir? any ideas?
|
||||
// ???
|
||||
// how should we decide to use bin_dir instead of root_dir? any ideas?
|
||||
// ???
|
||||
#if defined(EMBEDDED)
|
||||
root_dir = bin_dir + PathUtils::dir_sep;
|
||||
return;
|
||||
root_dir = bin_dir + PathUtils::dir_sep;
|
||||
return;
|
||||
#endif
|
||||
|
||||
// go to the parent directory
|
||||
index = bin_dir.rfind(PathUtils::dir_sep, bin_dir.length());
|
||||
root_dir = (index ? bin_dir.substr(0, index) : bin_dir) + PathUtils::dir_sep;
|
||||
// go to the parent directory
|
||||
index = bin_dir.rfind(PathUtils::dir_sep, bin_dir.length());
|
||||
root_dir = (index ? bin_dir.substr(0, index) : bin_dir) + PathUtils::dir_sep;
|
||||
return;
|
||||
}
|
||||
|
||||
// As a last resort get it from the default install directory
|
||||
root_dir = FB_PREFIX;
|
||||
}
|
||||
|
||||
|
@ -377,6 +377,7 @@ RELATION(nam_mon_attachments, rel_mon_attachments, ODS_11_1, rel_virtual)
|
||||
FIELD(f_mon_att_charset_id, nam_mon_charset_id, fld_charset_id, 0, 0, 0, 0)
|
||||
FIELD(f_mon_att_timestamp, nam_mon_timestamp, fld_time, 0, 0, 0, 0)
|
||||
FIELD(f_mon_att_gc, nam_mon_gc, fld_flag, 0, 0, 0, 0)
|
||||
FIELD(f_mon_att_remote_process, nam_mon_remote_process, fld_file_name, 0, 0, 0, 0)
|
||||
END_RELATION
|
||||
RELATION(nam_mon_transactions, rel_mon_transactions, ODS_11_1, rel_virtual)
|
||||
FIELD(f_mon_tra_id, nam_mon_tra_id, fld_trans_id, 0, 0, 0, 0)
|
||||
|
@ -66,6 +66,7 @@
|
||||
#include "../jrd/thread_proto.h"
|
||||
#include "../common/classes/ClumpletWriter.h"
|
||||
#include "../common/config/config.h"
|
||||
#include "../common/utils_proto.h"
|
||||
#include "../auth/trusted/AuthSspi.h"
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
@ -111,7 +112,7 @@ namespace {
|
||||
// for both services and databases attachments
|
||||
struct ParametersSet {
|
||||
UCHAR dummy_packet_interval, user_name, sys_user_name,
|
||||
password, password_enc, address_path, pid, trusted_auth;
|
||||
password, password_enc, address_path, process_id, process_name, trusted_auth;
|
||||
};
|
||||
const ParametersSet dpbParam = {isc_dpb_dummy_packet_interval,
|
||||
isc_dpb_user_name,
|
||||
@ -119,7 +120,8 @@ namespace {
|
||||
isc_dpb_password,
|
||||
isc_dpb_password_enc,
|
||||
isc_dpb_address_path,
|
||||
isc_dpb_pid,
|
||||
isc_dpb_process_id,
|
||||
isc_dpb_process_name,
|
||||
isc_dpb_trusted_auth};
|
||||
const ParametersSet spbParam = {isc_spb_dummy_packet_interval,
|
||||
isc_spb_user_name,
|
||||
@ -127,7 +129,8 @@ namespace {
|
||||
isc_spb_password,
|
||||
isc_spb_password_enc,
|
||||
isc_spb_address_path,
|
||||
isc_spb_pid,
|
||||
isc_spb_process_id,
|
||||
isc_spb_process_name,
|
||||
isc_spb_trusted_auth};
|
||||
}
|
||||
|
||||
@ -5754,10 +5757,14 @@ static bool get_new_dpb(Firebird::ClumpletWriter& dpb,
|
||||
}
|
||||
}
|
||||
|
||||
if (dpb.find(par.pid)) {
|
||||
if (dpb.find(par.process_id)) {
|
||||
dpb.deleteClumplet();
|
||||
}
|
||||
dpb.insertInt(par.pid, getpid());
|
||||
dpb.insertInt(par.process_id, getpid());
|
||||
|
||||
if (!dpb.find(par.process_name)) {
|
||||
dpb.insertPath(par.process_name, fb_utils::get_process_name());
|
||||
}
|
||||
|
||||
#ifndef NO_PASSWORD_ENCRYPTION
|
||||
if (dpb.find(par.password))
|
||||
|
Loading…
Reference in New Issue
Block a user