Re: call_usermodehelper dont't execute mysql client?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jan 04, 2006 at 14:23:20 +0100, toni wrote:
> i'm having problems while executing mysql client from a work queue
> (process context), but with no problems other executable files (simple
> daemon i've programmed)

WHAT?!?! You are trying to run *MYSQL CLIENT* from kernel?!?!

I believe it does not like value of HOME='/', or lacks some other
environment vairalbe or somethig, or does not like being called without
stdin, stdout and stderr or something like that.

> the code is: (connection is a global structure)
> 
> static void my_call_usermodehelper(void *data) {
> 	int err;
> 	struct sendbuffer_t *sendbuffer = data;
> 
> 	/* prepare data */
> 	sendbuffer->argv[0] = "/usr/bin/mysql";
> 	sendbuffer->argv[1] = "--host='localhost'";
> 	sendbuffer->argv[2] = "--user='user'";
> 	sendbuffer->argv[3] = "--password='passwd'";
> 	sprintf(tmp, "--execute=\"USE pnvoip; INSERT INTO connections
> (id,src_ip,src_port,dst_ip,dst_port,bytes,packets,start_time,finish_time) VALUES ('%s',%u,%d,%u,%d,%d,%d,'%lu','%lu');\"",connection->id,connection->saddr,connection->sport,connection->daddr,connection->dport,connection->bytes,connection->packets,connection->first_seen,connection->last_seen);
> 	sendbuffer->argv[4] = tmp;
> 	sendbuffer->argv[5] = NULL;
> 
> 	sendbuffer->envp[0] = "HOME=/";
> 	sendbuffer->envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
> 	sendbuffer->envp[2] = NULL;
> 
> 	printk(KERN_INFO "call_usermodehelper(%s %s %s %s %s %s);
> \n",sendbuffer->argv[0],sendbuffer->argv[1],sendbuffer->argv[2],sendbuffer->argv[3],sendbuffer->argv[4], sendbuffer->argv[5]);
> 
> 	if ((err = call_usermodehelper(sendbuffer->argv[0], sendbuffer->argv,
> sendbuffer->envp, 0)) < 0)
> 		printk(KERN_INFO "exec mysql failed (error = %d)!\n", err);
> }
> 
> the /var/log/messages file prints out:
> 
> Jan  4 14:12:28 localhost kernel: call_usermodehelper(/usr/bin/mysql
> --host='localhost' --user='pnvoip_user' --password='pnvoip_passwd'
> --execute="USE pnvoip; INSERT INTO connections
> (callid,src_ip,src_port,dst_ip,dst_port,bytes,packets,start_time,finish_time) VALUES ('RTP_192.168.0.1.53_192.168.0.23.32790',16820416,53,385919168,32790,13560,1,'1136380346','1136380346'); COMMIT;" <NULL>);
> 
> (this command is correct, i've pasted on a termnal and it adds a row to
> my table)

Then the command is *NOT* correct! Because from the terminal, the shell
strips the quotes. But direct call to execve passes the arguments
exactly. And you do use a lot of quotes in the command.

> any idea to solve that? or what it's not working?

Well, you shouldn't be directly calling mysql client anyway. You should
be calling some wrapper that would get the data and assemble the SQL.
Why should the name of the table be hardcoded or even known to kernel?

Also if you call it often, you should instead create some communication
channel (/proc entry, device or netlink socket) and have the process
hang on there, reading data you send to it and doing the database work.

-- 
						 Jan 'Bulb' Hudec <bulb@xxxxxx>

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux