#At file:///home/hf/work/mysql_common/mysql-5.1-35916/
2672 Alexey Botchkov 2008-06-20
Bug#35916 logging to stderr in a UDF does not work if MySQL runs as a service.
When MySQL works as a service on Windows fprintf(stderr,..) doesn't work in dll.
Besides writing to the errlog with the plain fprintf(stderr, ) doesn't work well - we
need to provide sql_print_error function somehow.
So this function is provided by calling setup_log_function() from the udf's library.
modified:
include/my_sys.h
sql/mysql_priv.h
sql/sql_udf.cc
sql/sql_udf.h
sql/udf_example.c
per-file messages:
include/my_sys.h
Bug#35916 logging to stderr in a UDF does not work if MySQL runs as a service.
sql_print_message_func definition moved here
sql/mysql_priv.h
Bug#35916 logging to stderr in a UDF does not work if MySQL runs as a service.
sql_print_message_func definition moved to my_sys.h
sql/sql_udf.cc
Bug#35916 logging to stderr in a UDF does not work if MySQL runs as a service.
udf library setup_message_func() call added
sql/sql_udf.h
Bug#35916 logging to stderr in a UDF does not work if MySQL runs as a service.
Udf_func_setupmsg interface definition added
sql/udf_example.c
Bug#35916 logging to stderr in a UDF does not work if MySQL runs as a service.
example of the setup_message_func() added
=== modified file 'include/my_sys.h'
--- a/include/my_sys.h 2008-05-17 21:51:18 +0000
+++ b/include/my_sys.h 2008-06-20 06:36:05 +0000
@@ -978,5 +978,8 @@ void netware_reg_user(const char *ip, co
const char *application);
#endif
+typedef void (*sql_print_message_func)(const char *format, ...)
+ ATTRIBUTE_FORMAT(printf, 1, 2);
+
C_MODE_END
#endif /* _my_sys_h */
=== modified file 'sql/mysql_priv.h'
--- a/sql/mysql_priv.h 2008-05-20 07:29:16 +0000
+++ b/sql/mysql_priv.h 2008-06-20 06:36:05 +0000
@@ -824,8 +824,6 @@ void sql_print_error(const char *format,
void sql_print_warning(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
void sql_print_information(const char *format, ...)
ATTRIBUTE_FORMAT(printf, 1, 2);
-typedef void (*sql_print_message_func)(const char *format, ...)
- ATTRIBUTE_FORMAT(printf, 1, 2);
extern sql_print_message_func sql_print_message_handlers[];
int error_log_print(enum loglevel level, const char *format,
=== modified file 'sql/sql_udf.cc'
--- a/sql/sql_udf.cc 2008-02-19 11:43:01 +0000
+++ b/sql/sql_udf.cc 2008-06-20 06:36:05 +0000
@@ -55,6 +55,7 @@ static void *find_udf_dl(const char *dl)
static char *init_syms(udf_func *tmp, char *nm)
{
char *end;
+ Udf_func_setupmsg setupmsg;
if (!((tmp->func= (Udf_func_any) dlsym(tmp->dlhandle, tmp->name.str))))
return tmp->name.str;
@@ -88,6 +89,12 @@ static char *init_syms(udf_func *tmp, ch
if (current_thd->variables.log_warnings)
sql_print_warning(ER(ER_CANT_FIND_DL_ENTRY), nm);
}
+
+ if ((setupmsg=
+ (Udf_func_setupmsg) dlsym(tmp->dlhandle, "setup_message_func")))
+ {
+ setupmsg(sql_print_error);
+ }
return 0;
}
=== modified file 'sql/sql_udf.h'
--- a/sql/sql_udf.h 2007-07-06 12:18:49 +0000
+++ b/sql/sql_udf.h 2008-06-20 06:36:05 +0000
@@ -30,7 +30,8 @@ typedef void (*Udf_func_any)();
typedef double (*Udf_func_double)(UDF_INIT *, UDF_ARGS *, uchar *, uchar *);
typedef longlong (*Udf_func_longlong)(UDF_INIT *, UDF_ARGS *, uchar *,
uchar *);
-
+typedef void (*Udf_func_setupmsg)(sql_print_message_func);
+
typedef struct st_udf_func
{
LEX_STRING name;
=== modified file 'sql/udf_example.c'
--- a/sql/udf_example.c 2007-11-27 15:19:51 +0000
+++ b/sql/udf_example.c 2008-06-20 06:36:05 +0000
@@ -169,6 +169,14 @@ my_bool is_const_init(UDF_INIT *initid,
char *is_const(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long
*length, char *is_null, char *error);
+static sql_print_message_func log_msg;
+void setup_message_func(sql_print_message_func msg_func);
+
+void setup_message_func(sql_print_message_func msg_func)
+{
+ log_msg= msg_func;
+}
+
/*************************************************************************
** Example of init function
@@ -217,6 +225,10 @@ my_bool metaphon_init(UDF_INIT *initid,
strcpy(message,"Wrong arguments to metaphon; Use the source");
return 1;
}
+/**
+ if (log_msg)
+ log_msg("Metaphon function inited");
+**/
initid->max_length=MAXMETAPH;
return 0;
}
@@ -292,6 +304,10 @@ char *metaphon(UDF_INIT *initid __attrib
*is_null=1;
return 0;
}
+/**
+ if (log_msg)
+ log_msg("Metaphon function called");
+**/
w_end=word+args->lengths[0];
org_result=result;