Bug #7174 RFE: libmysql should mark sockets close-on-exec
Submitted: 10 Dec 2004 16:44 Modified: 10 Dec 2004 19:10
Reporter: [ name withheld ] Email Updates:
Status: Open Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S4 (Feature request)
Version:4.1.7 OS:Any
Assigned to: CPU Architecture:Any

[10 Dec 2004 16:44] [ name withheld ]
Description:
It would be a good idea for libmysql to mark the server communication socket as close-on-exec (fcntl(sd, F_SETFD, FD_CLOEXEC)).  Without this, if a client application spawns subprocesses, the server connection may be held open inappropriately.  There doesn't seem to be any countervailing use for passing down the socket to an exec'd child, since libmysql's internal data structures will be lost on exec and there's no API for reconnecting to the socket.

How to repeat:
See discussion in Red Hat bugzilla
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=136686
[10 Dec 2004 19:10] Sergei Golubchik
see also http://bugs.mysql.com/3779
[9 Sep 2014 11:34] Juan Javier Baca
This flag should be configurable, so that fits any scenario. Also as mentioned in #3779 it shold be set by default.

We really have to use this flag and we've solved this way:
  (works with libmysql16 and libmysql18):

#include <fcntl.h>

//Fake redefinition
struct st_vio {
   my_socket sd;
};
 
void mysql_set_close_on_exec(MYSQL *conn) {
   fcntl(conn->net.vio->sd, F_SETFD, FD_CLOEXEC);
}

Call mysql_set_close_on_exec(myConnection);

Maybe someone can rely on this solution to solve their problems.