Skip to Content.
Sympa Menu

freetds - RE: asprintf vasprintf

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Castellano, Nicholas" <Nicholas_Castellano AT acml.com>
  • To: "'TDS Development Group'" <freetds AT franklin.metalab.unc.edu>
  • Subject: RE: asprintf vasprintf
  • Date: Tue, 27 Aug 2002 12:21:26 -0400

Can you try this patch? It uses a pthread mutex to ensure that only one
thread at a time executes inside the vasprintf() code. I can't test this on
my system right now (my only box with pthreads is DU4.0d, and I'm unable to
compile src/tds/threadsafe.c when _REENTRANT is defined...I'll address that
problem later on)

--nick

-----Original Message-----
From: bounce-freetds-145195 AT franklin.oit.unc.edu
[mailto:bounce-freetds-145195 AT franklin.oit.unc.edu]
Sent: Tuesday, August 27, 2002 6:10 AM
To: TDS Development Group
Subject: [freetds] asprintf vasprintf


These function aren't reentrant, so they cause problem with multithread
environment (watch env variable...).

A solution should use SA_SIGINFO flag in sigaction. Is SA_SIGINFO flag
portable ?

freddy77


The information contained in this transmission may contain privileged and
confidential information and is intended only for the use of the person(s)
named above. If you are not the intended recipient, or an employee or agent
responsible for delivering this message to the intended recipient, any
review, dissemination, distribution or duplication of this communication is
strictly prohibited. If you are not the intended recipient, please contact
the sender immediately by reply e-mail and destroy all copies of the
original message. Please note that for certain accounts we do not accept
orders and/or instructions by e-mail, and for those accounts we will not be
responsible for carrying out such orders and/or instructions. Kindly refrain
from sending orders or instructions by e-mail unless you have confirmed that
we accept such communications for your account. Please also note that to
satisfy regulatory requirements we review the outgoing and incoming e-mail
correspondence of staff members serving certain functions.




Index: asprintf.c
===================================================================
RCS file: /cvsroot/freetds/freetds/src/tds/asprintf.c,v
retrieving revision 1.2
diff -u -r1.2 asprintf.c
--- asprintf.c 23 Aug 2002 13:10:15 -0000 1.2
+++ asprintf.c 27 Aug 2002 16:15:49 -0000
@@ -18,10 +18,34 @@
#include <signal.h>
#include <assert.h>
#include <string.h>
+#ifdef _REENTRANT
+#include <pthread.h>
+#endif

static char software_version[] = "$Id: asprintf.c,v 1.2 2002/08/23
13:10:15 freddy77 Exp $";
static void *no_unused_var_warn[] = {software_version,
no_unused_var_warn};
+
+#ifdef _REENTRANT
+static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+#endif
+
+static void
+mutex_lock(void)
+{
+#ifdef _REENTRANT
+ pthread_mutex_lock(&mutex);
+#endif
+}
+
+static void
+mutex_unlock(void)
+{
+#ifdef _REENTRANT
+ pthread_mutex_unlock(&mutex);
+#endif
+}
+
static jmp_buf env;

static void
@@ -39,9 +63,11 @@
int len;
long pgsize = sysconf(_SC_PAGE_SIZE);

+ mutex_lock();
pgs = ((strlen(fmt) + 1) / pgsize) + 1;
if (sigaction(SIGSEGV, NULL, &osa)) {
*ret = NULL;
+ mutex_unlock();
return -1;
}
sa.sa_handler = sigsegv;
@@ -54,12 +80,14 @@
}
if ((buf = valloc((pgs + 1) * pgsize)) == NULL) {
*ret = NULL;
+ mutex_unlock();
return -1;
}
assert(((unsigned long) buf % pgsize) == 0);
if (sigaction(SIGSEGV, &sa, NULL)) {
free((void *) buf);
*ret = NULL;
+ mutex_unlock();
return -1;
}
mprotect((void *) (buf + pgs * pgsize), pgsize, PROT_NONE);
@@ -68,18 +96,22 @@
if (sigaction(SIGSEGV, &osa, NULL)) {
free((void *) buf);
*ret = NULL;
+ mutex_unlock();
return -1;
}
if (len < 0) {
free((void *) buf);
*ret = NULL;
+ mutex_unlock();
return len;
}
if ((buf = realloc((void *) buf, len + 1)) == NULL) {
*ret = NULL;
+ mutex_unlock();
return -1;
}
*ret = (char *) buf;
+ mutex_unlock();
return len;
}




Archive powered by MHonArc 2.6.24.

Top of Page