mysqludf/lib_mysqludf_sys

[CentOS 6.6 64bit] sys_eval and sys_exec return strange values

elegos opened this issue · 6 comments

Hello!

I've compiled the lib via

gcc -DMYSQL_DYNAMIC_PLUGIN -fPIC -Wall -I/usr/include/mysql -I. -shared lib_mysqludf_sys.c -o lib_mysqludf_sys.so

I've then sym-linked it in the mysql's plugins folder. Eventually I've created the two functions:

CREATE FUNCTION sys_exec RETURNS int SONAME 'lib_mysqludf_sys.so';
CREATE FUNCTION sys_eval RETURNS int SONAME 'lib_mysqludf_sys.so';

So far so good. I've created a simple PHP script which prints out the time of execution and exits code status 0:

<?php

$date = date('Y-m-d h:i:s');
$text = sprintf("[%s] Execution\n", $date);
echo $text;
exit(0);

php is in /usr/bin/php

mysql> select sys_exec('/usr/bin/php /tmp/test/test.php');
+---------------------------------------------+
| sys_exec('/usr/bin/php /tmp/test/test.php') |
+---------------------------------------------+
|                                         0 |
+---------------------------------------------+
1 row in set (0.07 sec)

(fine). If I change the exit code to 1 (exit(1);), this is the output:

mysql> select sys_exec('/usr/bin/php /tmp/test/test.php');
+---------------------------------------------+
| sys_exec('/usr/bin/php /tmp/test/test.php') |
+---------------------------------------------+
|                                         256 |
+---------------------------------------------+
1 row in set (0.07 sec)

256? But let's return to exit 0 and try out sys_exec:

mysql> select sys_eval('/usr/bin/php /tmp/test/test.php');
+---------------------------------------------+
| sys_eval('/usr/bin/php /tmp/test/test.php') |
+---------------------------------------------+
|                                        NULL |
+---------------------------------------------+
1 row in set (0.07 sec)

Note: /tmp/test has rwx permissions for all (ugo+rwx).

Let's try something easier:

mysql> select sys_eval('pwd');
+-----------------+
| sys_eval('pwd') |
+-----------------+
|            NULL |
+-----------------+
1 row in set (0.02 sec)

Is my compiled library... failing?

You can try open /var/log/mysqld.log
This is my output when execute 'pwd'

mysql> select sys_exec('pwd');
+-----------------+
| sys_exec('pwd') |
+-----------------+
|               0 |
+-----------------+
1 row in set (0.01 sec)

and this from /var/log/mysqld.log

[root@db ~]# tail /var/log/mysqld.log
            s.parentNode.insertBefore(sc, s);
        })();
        _comscore.push({ c1: "2", c2: "17440561" });
        _qevents.push({ qacct: "p-c1rF4kxgLUzNc" });
    </script>
    </body>
</html>Tue Aug  4 12:24:02 WIB 2015
Tue Aug  4 12:24:04 WIB 2015
/var/lib/mysql
/var/lib/mysql

and you can try my Makefile setting if you install it from install.sh

gcc -m64 -fPIC -Wall -I/usr/include/mysql -I. -shared lib_mysqludf_sys.c -o /usr/lib64/mysql/plugin/lib_mysqludf_sys.so

Can you give me the way to install mysqludf
I'm using CentOS 7

Hello vanhiepdam,

Just compile with the provided command (gcc) and symlink the .so file in the MySQL's plugins folder. Then install it via the SQL commands

sys_eval is returning NULL because the function is only returning int, so drop it and the create it again with the following syntax:
CREATE FUNCTION sys_eval RETURNS string SONAME 'lib_mysqludf_sys.so';

sys_eval is returning NULL because the function is only returning int, so drop it and the create it again with the following syntax:
CREATE FUNCTION sys_eval RETURNS string SONAME 'lib_mysqludf_sys.so';
@yamelyamel16 you save me! Thanks a lot!