Merge lp:~brianaker/drizzle/socket-file-clean into lp:drizzle/7.1

Proposed by Brian Aker
Status: Merged
Approved by: Brian Aker
Approved revision: not available
Merged at revision: 2542
Proposed branch: lp:~brianaker/drizzle/socket-file-clean
Merge into: lp:drizzle/7.1
Diff against target: 180 lines (+111/-1)
3 files modified
drizzled/drizzled.cc (+0/-1)
libdrizzle/conn.cc (+91/-0)
plugin/mysql_unix_socket_protocol/protocol.cc (+20/-0)
To merge this branch: bzr merge lp:~brianaker/drizzle/socket-file-clean
Reviewer Review Type Date Requested Status
Drizzle Trunk Pending
Review via email: mp+102252@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'drizzled/drizzled.cc'
--- drizzled/drizzled.cc 2012-04-16 22:00:59 +0000
+++ drizzled/drizzled.cc 2012-04-17 08:53:19 +0000
@@ -405,7 +405,6 @@
405 at_exit_pid_file[0]= 0;405 at_exit_pid_file[0]= 0;
406 }406 }
407 }407 }
408
409}408}
410409
411/**410/**
412411
=== modified file 'libdrizzle/conn.cc'
--- libdrizzle/conn.cc 2012-01-30 05:36:54 +0000
+++ libdrizzle/conn.cc 2012-04-17 08:53:19 +0000
@@ -58,6 +58,86 @@
58 */58 */
59static drizzle_return_t _con_setsockopt(drizzle_con_st *con);59static drizzle_return_t _con_setsockopt(drizzle_con_st *con);
6060
61static bool connect_poll(drizzle_con_st *con)
62{
63 struct pollfd fds[1];
64 fds[0].fd= con->fd;
65 fds[0].events= POLLOUT;
66
67 size_t loop_max= 5;
68 while (--loop_max) // Should only loop on cases of ERESTART or EINTR
69 {
70 int error= poll(fds, 1, con->drizzle->timeout);
71 switch (error)
72 {
73 case 1:
74 {
75 int err;
76 socklen_t len= sizeof (err);
77 // We replace errno with err if getsockopt() passes, but err has been
78 // set.
79 if (getsockopt(con->fd, SOL_SOCKET, SO_ERROR, &err, &len) == 0)
80 {
81 // We check the value to see what happened wth the socket.
82 if (err == 0)
83 {
84 return true;
85 }
86 errno= err;
87 }
88
89 // "getsockopt() failed"
90 return false;
91 }
92
93 case 0:
94 {
95 // "timeout occurred while trying to connect"
96 return false;
97 }
98
99 default: // A real error occurred and we need to completely bail
100 switch (get_socket_errno())
101 {
102#ifdef TARGET_OS_LINUX
103 case ERESTART:
104#endif
105 case EINTR:
106 continue;
107
108 case EFAULT:
109 case ENOMEM:
110 // "poll() failure"
111 return false;
112
113 case EINVAL:
114 // "RLIMIT_NOFILE exceeded, or if OSX the timeout value was invalid"
115 return false;
116
117 default: // This should not happen
118 if (fds[0].revents & POLLERR)
119 {
120 int err;
121 socklen_t len= sizeof (err);
122 (void)getsockopt(con->fd, SOL_SOCKET, SO_ERROR, &err, &len);
123 errno= err;
124 }
125 else
126 {
127 errno= get_socket_errno();
128 }
129
130 //"socket error occurred");
131 return false;
132 }
133 }
134 }
135
136 // This should only be possible from ERESTART or EINTR;
137 // "connection failed (error should be from either ERESTART or EINTR"
138 return false;
139}
140
61/** @} */141/** @} */
62142
63/*143/*
@@ -700,13 +780,17 @@
700780
701 *ret_ptr= drizzle_con_connect(con);781 *ret_ptr= drizzle_con_connect(con);
702 if (*ret_ptr != DRIZZLE_RETURN_OK)782 if (*ret_ptr != DRIZZLE_RETURN_OK)
783 {
703 return result;784 return result;
785 }
704 }786 }
705787
706 if (drizzle_state_none(con))788 if (drizzle_state_none(con))
707 {789 {
708 if (con->options & (DRIZZLE_CON_RAW_PACKET | DRIZZLE_CON_NO_RESULT_READ))790 if (con->options & (DRIZZLE_CON_RAW_PACKET | DRIZZLE_CON_NO_RESULT_READ))
791 {
709 con->result= NULL;792 con->result= NULL;
793 }
710 else794 else
711 {795 {
712 for (old_result= con->result_list; old_result != NULL; old_result= old_result->next)796 for (old_result= con->result_list; old_result != NULL; old_result= old_result->next)
@@ -743,7 +827,9 @@
743827
744 *ret_ptr= drizzle_state_loop(con);828 *ret_ptr= drizzle_state_loop(con);
745 if (*ret_ptr == DRIZZLE_RETURN_PAUSE)829 if (*ret_ptr == DRIZZLE_RETURN_PAUSE)
830 {
746 *ret_ptr= DRIZZLE_RETURN_OK;831 *ret_ptr= DRIZZLE_RETURN_OK;
832 }
747 else if (*ret_ptr != DRIZZLE_RETURN_OK &&833 else if (*ret_ptr != DRIZZLE_RETURN_OK &&
748 *ret_ptr != DRIZZLE_RETURN_IO_WAIT &&834 *ret_ptr != DRIZZLE_RETURN_IO_WAIT &&
749 *ret_ptr != DRIZZLE_RETURN_ERROR_CODE)835 *ret_ptr != DRIZZLE_RETURN_ERROR_CODE)
@@ -1300,6 +1386,11 @@
13001386
1301 if (errno == EINPROGRESS)1387 if (errno == EINPROGRESS)
1302 {1388 {
1389 if (connect_poll(con))
1390 {
1391 drizzle_state_pop(con);
1392 return DRIZZLE_RETURN_OK;
1393 }
1303 drizzle_state_pop(con);1394 drizzle_state_pop(con);
1304 drizzle_state_push(con, drizzle_state_connecting);1395 drizzle_state_push(con, drizzle_state_connecting);
1305 return DRIZZLE_RETURN_OK;1396 return DRIZZLE_RETURN_OK;
13061397
=== modified file 'plugin/mysql_unix_socket_protocol/protocol.cc'
--- plugin/mysql_unix_socket_protocol/protocol.cc 2012-01-15 20:54:59 +0000
+++ plugin/mysql_unix_socket_protocol/protocol.cc 2012-04-17 08:53:19 +0000
@@ -59,6 +59,24 @@
59 return 0;59 return 0;
60}60}
6161
62extern "C" {
63
64 char at_exit_socket_file[1024 * 4]= { 0 };
65
66 static void remove_socket_file(void)
67 {
68 if (at_exit_socket_file[0])
69 {
70 if (unlink(at_exit_socket_file) == -1)
71 {
72 std::cerr << "Could not remove socket: " << at_exit_socket_file << "(" << strerror(errno) << ")" << std::endl;
73 }
74
75 at_exit_socket_file[0]= 0;
76 }
77 }
78}
79
62static int init(drizzled::module::Context &context)80static int init(drizzled::module::Context &context)
63{ 81{
64 const module::option_map &vm= context.getOptions();82 const module::option_map &vm= context.getOptions();
@@ -72,6 +90,8 @@
72 context.registerVariable(new sys_var_const_string_val("path", fs::system_complete(uds_path).file_string()));90 context.registerVariable(new sys_var_const_string_val("path", fs::system_complete(uds_path).file_string()));
73 context.registerVariable(new sys_var_bool_ptr_readonly("clobber", &clobber));91 context.registerVariable(new sys_var_bool_ptr_readonly("clobber", &clobber));
74 context.registerVariable(new sys_var_uint32_t_ptr("max-connections", &Protocol::mysql_unix_counters.max_connections));92 context.registerVariable(new sys_var_uint32_t_ptr("max-connections", &Protocol::mysql_unix_counters.max_connections));
93 snprintf(at_exit_socket_file, sizeof(at_exit_socket_file), "%s", uds_path.file_string().c_str());
94 atexit(remove_socket_file);
75 }95 }
76 else96 else
77 {97 {

Subscribers

People subscribed via source and target branches

to all changes: