5 messages in com.mysql.lists.bugsRe: libmysql.c should #include errno....| From | Sent On | Attachments |
|---|---|---|
| Thimble Smith | 07 Apr 2000 16:25 | |
| Nick Johnson | 08 Apr 2000 13:15 | |
| Michael Widenius | 08 Apr 2000 16:22 | |
| Nick Johnson | 10 Apr 2000 08:37 | |
| Michael Widenius | 10 Apr 2000 09:44 |
| Subject: | Re: libmysql.c should #include errno.h, not sys/errno.h![]() |
|---|---|
| From: | Nick Johnson (njoh...@cisco.com) |
| Date: | 04/10/2000 08:37:42 AM |
| List: | com.mysql.lists.bugs |
At 02:22 AM 4/9/00 +0300, Michael Widenius wrote:
"Nick" == Nick Johnson <njoh...@cisco.com> writes:
Nick> Ok, no problem. I just ran mysqlbug, which defaulted to sending to Nick> mys...@lists.mysql.com.
Nick> I submitted a patch about 2 months ago that restarts the select in Nick> mysql_real_connect upon signal interrupts... do you know if that report Nick> was noticed, or should I resubmit my patch to bugs@?
Hi!
I don't think the patch was forward to me :( Can you please resubmit it to bu...@list.mysql.com so I can check it out and put into the distribution if it looks ok.
Ok, here you go. The original message can be found at
http://lists.mysql.com/cgi-ez/ezmlm-cgi?1:mss:28287 also.
Description:
A signal can interrupt the select statement in mysql_real_connect() from libmysqlclient (libmysql.c). This can cause a timeout to be reported although there is still time remaining.
I think it makes sense to restart this select because its timeout can be controlled by the programmer through mysql_options().
How-To-Repeat:
alarm(2); handle = mysql_init(NULL); timeout = 10; mysql_options(handle, MYSQL_OPT_CONNECT_TIMEOUT, &timeout); if (!mysql_real_connect(handle, "foo", "bar", "baz", "doom", 0, NULL, 0)) { printf("(%s)\n", mysql_error(handle)); }
the alarm will activate the alarm handler, followed by the select in mysql_real_connect being interrupted, so mysql_real_connect returns after 2 seconds instead of 10.
Fix:
diff -c:
*** libmysql.c.orig Sat Dec 25 16:34:04 1999 --- libmysql.c Fri Feb 18 14:03:12 2000 *************** *** 59,64 **** --- 59,65 ---- #define closesocket(A) close(A) #endif
+ #include <time.h> static void mysql_once_init(void); static MYSQL_DATA *read_rows (MYSQL *mysql,MYSQL_FIELD *fields, uint field_count); *************** *** 90,95 **** --- 91,97 ---- size_socket s_err_size = sizeof(uint); fd_set sfds; struct timeval tv; + time_t start_time, now_time;
/* If they passed us a timeout of zero, we should behave
* exactly like the normal connect() call does.
***************
*** 134,140 ****
FD_SET(s, &sfds);
tv.tv_sec = (long) to;
tv.tv_usec = 0;
! res = select(s+1, NULL, &sfds, NULL, &tv);
if (res <= 0) /* Never became writable
*/
return(-1);
--- 136,156 ----
FD_SET(s, &sfds);
tv.tv_sec = (long) to;
tv.tv_usec = 0;
! start_time = time(NULL);
! /*
! * select could be interrupted by a signal, and if it is,
! * the timeout should be adjusted and the select restarted
! * to work around OSes that don't restart select and
! * implementations of select that don't adjust tv upon
! * failure to reflect the time remaining
! */
! while ((res = select(s+1, NULL, &sfds, NULL, &tv)) == -1) {
! now_time = time(NULL);
! if (errno != EINTR || (now_time > start_time + to)) {
! break;
! }
! tv.tv_sec = to - (now_time - start_time);
! }
if (res <= 0) /* Never became writable
*/
return(-1);
Submitter-Id: <submitter ID> Originator: Nicklas R. Johnson Organization: Cisco Systems MySQL support: none Synopsis: select in mysql_real_connect can return early on signal Severity: non-critical Priority: low Category: mysql Class: sw-bug Release: mysql-3.22.32 (Source distribution)
Environment:
System: SunOS 5.7 Generic sun4m sparc SUNW,SPARCstation-5 Architecture: sun4
Some paths:
gcc version 2.95.1 19990816 (release)
Compilation info: CC='gcc' CFLAGS='-pipe -D_REENTRANT' CXX='g++'
CXXFLAGS='-pipe -D_REENTRANT' LDFLAGS=''
Configure command: ./configure --with-threadsafe-client
--prefix=/usr/SD/mysql-patched
--exec-prefix=/usr/SD/mysql-patched
Perl: This is perl, version 5.004_05 built for sun4-solaris




