From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: crypt mutex Date: Sat, 21 Feb 2004 10:32:53 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <87znbdi85m.fsf@zip.com.au> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1077324437 28955 80.91.224.253 (21 Feb 2004 00:47:17 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 21 Feb 2004 00:47:17 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat Feb 21 01:47:08 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AuLIS-0008WA-00 for ; Sat, 21 Feb 2004 01:47:08 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1AuLCH-0006Nw-0v for guile-devel@m.gmane.org; Fri, 20 Feb 2004 19:40:45 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1AuL5Y-0000TZ-Cl for guile-devel@gnu.org; Fri, 20 Feb 2004 19:33:48 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1AuL4z-0008WH-Td for guile-devel@gnu.org; Fri, 20 Feb 2004 19:33:45 -0500 Original-Received: from [61.8.0.85] (helo=mailout2.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.30) id 1AuL4w-0008Uy-8z for guile-devel@gnu.org; Fri, 20 Feb 2004 19:33:10 -0500 Original-Received: from mailproxy1.pacific.net.au (mailproxy1.pacific.net.au [61.8.0.86]) by mailout2.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i1L0X25O027072 for ; Sat, 21 Feb 2004 11:33:02 +1100 Original-Received: from localhost (ppp178.dyn248.pacific.net.au [203.143.248.178]) by mailproxy1.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i1L0X00H016466 for ; Sat, 21 Feb 2004 11:33:01 +1100 Original-Received: from gg by localhost with local (Exim 3.36 #1 (Debian)) id 1AuL4g-0008Dj-00; Sat, 21 Feb 2004 10:32:54 +1000 Original-To: guile-devel@gnu.org Mail-Copies-To: never User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Developers list for Guile, the GNU extensibility library List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:3417 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:3417 --=-=-= While nosing around the crypt function, I wondered if it ought to have a mutex, just in case two threads run it concurrently. * posix.c (crypt_mutex): New variable. (scm_init_posix): Initialize it. (scm_crypt): Use it to protect static data from crypt(). --=-=-= Content-Disposition: inline; filename=posix.c.crypt-mutex.diff --- posix.c.~1.124.~ 2004-02-21 09:19:52.000000000 +1000 +++ posix.c 2004-02-21 10:30:54.000000000 +1000 @@ -1420,7 +1420,11 @@ #undef FUNC_NAME #endif /* HAVE_SYNC */ +/* crypt() returns a pointer to a static buffer, so we use a mutex to avoid + another thread overwriting that buffer by another call. + OPTIMIZE-ME: Use glibc crypt_r() when available. */ #if HAVE_CRYPT +static scm_t_mutex crypt_mutex; SCM_DEFINE (scm_crypt, "crypt", 2, 0, 0, (SCM key, SCM salt), "Encrypt @var{key} using @var{salt} as the salt value to the\n" @@ -1428,12 +1432,16 @@ #define FUNC_NAME s_scm_crypt { char * p; + SCM ret; SCM_VALIDATE_STRING (1, key); SCM_VALIDATE_STRING (2, salt); + scm_mutex_lock (&crypt_mutex); p = crypt (SCM_STRING_CHARS (key), SCM_STRING_CHARS (salt)); - return scm_makfrom0str (p); + ret = scm_makfrom0str (p); + scm_mutex_unlock (&crypt_mutex); + return ret; } #undef FUNC_NAME #endif /* HAVE_CRYPT */ @@ -1826,6 +1834,10 @@ scm_c_define ("LOCK_NB", SCM_MAKINUM (LOCK_NB)); #endif +#if HAVE_CRYPT + scm_mutex_init (&crypt_mutex, &scm_i_plugin_mutex); +#endif + #include "libguile/cpp_sig_symbols.c" #include "libguile/posix.x" } --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel --=-=-=--