summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Vojtovich <svoj@mariadb.org>2017-10-31 15:14:29 +0400
committerSergey Vojtovich <svoj@mariadb.org>2017-10-31 15:14:29 +0400
commitd2afcc0958bf83324bb894e54fc84692786970dd (patch)
tree43699d93ce6f7d9b0a2973bf3120bbdaa93cce99
parent6c8471920a5059ac868fe4d655eea5399692a357 (diff)
downloadmariadb-git-svoj-szworkshop.tar.gz
PROC_FDINFO plugin for workshopsvoj-szworkshop
-rw-r--r--plugin/proc_info/mysql-test/proc_info/fdinfo.test5
-rw-r--r--plugin/proc_info/proc_info.cc87
2 files changed, 92 insertions, 0 deletions
diff --git a/plugin/proc_info/mysql-test/proc_info/fdinfo.test b/plugin/proc_info/mysql-test/proc_info/fdinfo.test
new file mode 100644
index 00000000000..5131f08a5b9
--- /dev/null
+++ b/plugin/proc_info/mysql-test/proc_info/fdinfo.test
@@ -0,0 +1,5 @@
+SHOW CREATE TABLE INFORMATION_SCHEMA.PROC_FDINFO;
+query_vertical SELECT PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_TYPE, PLUGIN_AUTHOR, PLUGIN_DESCRIPTION, PLUGIN_LICENSE, PLUGIN_MATURITY FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME='proc_fdinfo';
+SELECT * FROM INFORMATION_SCHEMA.PROC_FDINFO;
+FLUSH TABLES;
+SELECT * FROM INFORMATION_SCHEMA.PROC_FDINFO;
diff --git a/plugin/proc_info/proc_info.cc b/plugin/proc_info/proc_info.cc
index cae9aa055c7..ae945b7364b 100644
--- a/plugin/proc_info/proc_info.cc
+++ b/plugin/proc_info/proc_info.cc
@@ -3,6 +3,7 @@
#include <sql_show.h>
#include <sql_class.h>
#include <mysql/plugin.h>
+#include <dirent.h>
static ST_FIELD_INFO meminfo_fields[]=
@@ -58,6 +59,77 @@ static struct st_mysql_information_schema meminfo_plugin=
{ MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION };
+static ST_FIELD_INFO fdinfo_fields[]=
+{
+ { "NAME", 100, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE },
+ { "VALUE", FN_REFLEN, MYSQL_TYPE_STRING, 0, MY_I_S_MAYBE_NULL, 0,
+ SKIP_OPEN_TABLE },
+ { 0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0 }
+};
+
+
+static int fdinfo_fill(MYSQL_THD thd, TABLE_LIST *tables, COND *cond)
+{
+ TABLE *table= tables->table;
+ int fd;
+ DIR *dir;
+ struct dirent dirbuf, *result;
+
+ if ((fd= open("/proc/self/fd", O_DIRECTORY)) < 0)
+ return 1;
+ if (!(dir= fdopendir(fd)))
+ {
+ close(fd);
+ return 1;
+ }
+
+ while (readdir_r(dir, &dirbuf, &result) == 0 && result)
+ {
+ char buf[FN_REFLEN];
+ ssize_t len;
+
+ if (result->d_name[0] == '.')
+ continue;
+ len= readlinkat(fd, result->d_name, buf, sizeof(buf));
+
+ table->field[0]->store(result->d_name, strlen(result->d_name), system_charset_info);
+ if (len < 0)
+ table->field[1]->set_null();
+ else
+ {
+ table->field[1]->store(buf, len, system_charset_info);
+ table->field[1]->set_notnull();
+ }
+
+ if (schema_table_store_record(thd, table))
+ {
+ close(fd);
+ closedir(dir);
+ return 1;
+ }
+ }
+ close(fd);
+ closedir(dir);
+
+ return 0;
+}
+
+
+static int fdinfo_init(void *p)
+{
+ ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *) p;
+
+ schema->fields_info= fdinfo_fields;
+ schema->fill_table= fdinfo_fill;
+
+ return 0;
+}
+
+
+static struct st_mysql_information_schema fdinfo_plugin=
+{ MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION };
+
+
maria_declare_plugin(proc_info)
{
MYSQL_INFORMATION_SCHEMA_PLUGIN, /* type */
@@ -73,5 +145,20 @@ maria_declare_plugin(proc_info)
NULL, /* system variables */
"1.0", /* version as a string */
MariaDB_PLUGIN_MATURITY_EXPERIMENTAL
+},
+{
+ MYSQL_INFORMATION_SCHEMA_PLUGIN, /* type */
+ &fdinfo_plugin, /* information schema */
+ "PROC_FDINFO", /* name */
+ "" , /* author */
+ "Useful information from /proc", /* description */
+ PLUGIN_LICENSE_BSD, /* license */
+ fdinfo_init, /* init callback */
+ 0, /* deinit callback */
+ 0x0100, /* version as hex */
+ NULL, /* status variables */
+ NULL, /* system variables */
+ "1.0", /* version as a string */
+ MariaDB_PLUGIN_MATURITY_EXPERIMENTAL
}
maria_declare_plugin_end;