From owner-svn-src-stable-6@FreeBSD.ORG Wed Jul 8 01:43:47 2009 Return-Path: Delivered-To: svn-src-stable-6@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B644C1065673; Wed, 8 Jul 2009 01:43:47 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A35038FC1C; Wed, 8 Jul 2009 01:43:47 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n681hlKb034675; Wed, 8 Jul 2009 01:43:47 GMT (envelope-from delphij@svn.freebsd.org) Received: (from delphij@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n681hl1M034673; Wed, 8 Jul 2009 01:43:47 GMT (envelope-from delphij@svn.freebsd.org) Message-Id: <200907080143.n681hl1M034673@svn.freebsd.org> From: Xin LI Date: Wed, 8 Jul 2009 01:43:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-6@freebsd.org X-SVN-Group: stable-6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195432 - in stable/6/lib/libc: . rpc X-BeenThere: svn-src-stable-6@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 6-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jul 2009 01:43:48 -0000 Author: delphij Date: Wed Jul 8 01:43:47 2009 New Revision: 195432 URL: http://svn.freebsd.org/changeset/base/195432 Log: MFC r194932 Lock around access to nc_file and netconfig_info ("ni"). The RPC part of libc is still not thread safe but this would at least reduce the problems we have. PR: threads/118544 Submitted by: Changming Sun Modified: stable/6/lib/libc/ (props changed) stable/6/lib/libc/rpc/getnetconfig.c Modified: stable/6/lib/libc/rpc/getnetconfig.c ============================================================================== --- stable/6/lib/libc/rpc/getnetconfig.c Wed Jul 8 01:41:41 2009 (r195431) +++ stable/6/lib/libc/rpc/getnetconfig.c Wed Jul 8 01:43:47 2009 (r195432) @@ -130,7 +130,11 @@ static struct netconfig *dup_ncp(struct static FILE *nc_file; /* for netconfig db */ +static pthread_mutex_t nc_file_lock = PTHREAD_MUTEX_INITIALIZER; + static struct netconfig_info ni = { 0, 0, NULL, NULL}; +static pthread_mutex_t ni_lock = PTHREAD_MUTEX_INITIALIZER; + #define MAXNETCONFIGLINE 1000 @@ -204,14 +208,24 @@ setnetconfig() * For multiple calls, i.e. nc_file is not NULL, we just return the * handle without reopening the netconfig db. */ + mutex_lock(&ni_lock); ni.ref++; + mutex_unlock(&ni_lock); + + mutex_lock(&nc_file_lock); if ((nc_file != NULL) || (nc_file = fopen(NETCONFIG, "r")) != NULL) { nc_vars->valid = NC_VALID; nc_vars->flag = 0; nc_vars->nc_configs = ni.head; + mutex_unlock(&nc_file_lock); return ((void *)nc_vars); } + mutex_unlock(&nc_file_lock); + + mutex_lock(&ni_lock); ni.ref--; + mutex_unlock(&ni_lock); + nc_error = NC_NONETCONFIG; free(nc_vars); return (NULL); @@ -234,14 +248,18 @@ void *handlep; char *stringp; /* tmp string pointer */ struct netconfig_list *list; struct netconfig *np; + struct netconfig *result; /* * Verify that handle is valid */ + mutex_lock(&nc_file_lock); if (ncp == NULL || nc_file == NULL) { nc_error = NC_NOTINIT; + mutex_unlock(&nc_file_lock); return (NULL); } + mutex_unlock(&nc_file_lock); switch (ncp->valid) { case NC_VALID: @@ -255,7 +273,9 @@ void *handlep; */ if (ncp->flag == 0) { /* first time */ ncp->flag = 1; + mutex_lock(&ni_lock); ncp->nc_configs = ni.head; + mutex_unlock(&ni_lock); if (ncp->nc_configs != NULL) /* entry already exist */ return(ncp->nc_configs->ncp); } @@ -268,7 +288,13 @@ void *handlep; * If we cannot find the entry in the list and is end of file, * we give up. */ - if (ni.eof == 1) return(NULL); + mutex_lock(&ni_lock); + if (ni.eof == 1) { + mutex_unlock(&ni_lock); + return(NULL); + } + mutex_unlock(&ni_lock); + break; default: nc_error = NC_NOTINIT; @@ -289,13 +315,18 @@ void *handlep; /* * Read a line from netconfig file. */ + mutex_lock(&nc_file_lock); do { if (fgets(stringp, MAXNETCONFIGLINE, nc_file) == NULL) { free(stringp); + mutex_lock(&ni_lock); ni.eof = 1; + mutex_unlock(&ni_lock); + mutex_unlock(&nc_file_lock); return (NULL); } } while (*stringp == '#'); + mutex_unlock(&nc_file_lock); list = (struct netconfig_list *) malloc(sizeof (struct netconfig_list)); if (list == NULL) { @@ -325,6 +356,7 @@ void *handlep; * Reposition the current pointer of the handle to the last entry * in the list. */ + mutex_lock(&ni_lock); if (ni.head == NULL) { /* first entry */ ni.head = ni.tail = list; } @@ -333,7 +365,9 @@ void *handlep; ni.tail = ni.tail->next; } ncp->nc_configs = ni.tail; - return(ni.tail->ncp); + result = ni.tail->ncp; + mutex_unlock(&ni_lock); + return(result); } } @@ -367,7 +401,9 @@ void *handlep; nc_handlep->valid = NC_INVALID; nc_handlep->flag = 0; nc_handlep->nc_configs = NULL; + mutex_lock(&ni_lock); if (--ni.ref > 0) { + mutex_unlock(&ni_lock); free(nc_handlep); return(0); } @@ -380,6 +416,8 @@ void *handlep; ni.eof = ni.ref = 0; ni.head = NULL; ni.tail = NULL; + mutex_unlock(&ni_lock); + while (q) { p = q->next; if (q->ncp->nc_lookups != NULL) free(q->ncp->nc_lookups); @@ -390,8 +428,11 @@ void *handlep; } free(nc_handlep); + mutex_lock(&nc_file_lock); fclose(nc_file); nc_file = NULL; + mutex_unlock(&nc_file_lock); + return (0); } @@ -439,15 +480,20 @@ getnetconfigent(netid) * If all the netconfig db has been read and placed into the list and * there is no match for the netid, return NULL. */ + mutex_lock(&ni_lock); if (ni.head != NULL) { for (list = ni.head; list; list = list->next) { if (strcmp(list->ncp->nc_netid, netid) == 0) { + mutex_unlock(&ni_lock); return(dup_ncp(list->ncp)); } } - if (ni.eof == 1) /* that's all the entries */ + if (ni.eof == 1) { /* that's all the entries */ + mutex_unlock(&ni_lock); return(NULL); + } } + mutex_unlock(&ni_lock); if ((file = fopen(NETCONFIG, "r")) == NULL) { From owner-svn-src-stable-6@FreeBSD.ORG Sat Jul 11 08:25:44 2009 Return-Path: Delivered-To: svn-src-stable-6@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 133C41065679; Sat, 11 Jul 2009 08:25:44 +0000 (UTC) (envelope-from dougb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id DA3C48FC25; Sat, 11 Jul 2009 08:25:43 +0000 (UTC) (envelope-from dougb@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6B8PhXB046875; Sat, 11 Jul 2009 08:25:43 GMT (envelope-from dougb@svn.freebsd.org) Received: (from dougb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6B8PhD1046873; Sat, 11 Jul 2009 08:25:43 GMT (envelope-from dougb@svn.freebsd.org) Message-Id: <200907110825.n6B8PhD1046873@svn.freebsd.org> From: Doug Barton Date: Sat, 11 Jul 2009 08:25:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-6@freebsd.org X-SVN-Group: stable-6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195616 - stable/6/usr.sbin/mergemaster X-BeenThere: svn-src-stable-6@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 6-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Jul 2009 08:25:45 -0000 Author: dougb Date: Sat Jul 11 08:25:43 2009 New Revision: 195616 URL: http://svn.freebsd.org/changeset/base/195616 Log: MFC r193853, update -U message when there is no mtree db, dramatically reduce the size of the saved mtree db, streamline find command for the main loop, and remove a spurious comment. Modified: stable/6/usr.sbin/mergemaster/ (props changed) stable/6/usr.sbin/mergemaster/mergemaster.sh Modified: stable/6/usr.sbin/mergemaster/mergemaster.sh ============================================================================== --- stable/6/usr.sbin/mergemaster/mergemaster.sh Sat Jul 11 08:24:51 2009 (r195615) +++ stable/6/usr.sbin/mergemaster/mergemaster.sh Sat Jul 11 08:25:43 2009 (r195616) @@ -353,7 +353,8 @@ case "${AUTO_UPGRADE}" in *) if [ ! -s "${DESTDIR}${MTREEFILE}" ]; then echo '' - echo "*** Unable to find mtree database. Skipping auto-upgrade." + echo "*** Unable to find mtree database. Skipping auto-upgrade on this run." + echo " It will be created for the next run when this one is complete." echo '' press_to_continue unset AUTO_UPGRADE @@ -668,8 +669,11 @@ rm -f ${TEMPROOT}/etc/*.db ${TEMPROOT}/e # We only need to compare things like freebsd.cf once find ${TEMPROOT}/usr/obj -type f -delete 2>/dev/null -# Delete 0 length files to make the mtree database as small as possible. +# Delete stuff we do not need to keep the mtree database small, +# and to make the actual comparison faster. +find ${TEMPROOT}/usr -type l -delete 2>/dev/null find ${TEMPROOT} -type f -size 0 -delete 2>/dev/null +find -d ${TEMPROOT} -type d -empty -delete 2>/dev/null # Build the mtree database in a temporary location. MTREENEW=`mktemp -t mergemaster.mtree` @@ -957,11 +961,7 @@ if [ -r "${MM_PRE_COMPARE_SCRIPT}" ]; th . "${MM_PRE_COMPARE_SCRIPT}" fi -# Using -size +0 avoids uselessly checking the empty log files created -# by ${SOURCEDIR}/etc/Makefile and the device entries in ./dev, but does -# check the scripts in ./dev, as we'd like (assuming no devfs of course). -# -for COMPFILE in `find . -type f -size +0`; do +for COMPFILE in `find . -type f`; do # First, check to see if the file exists in DESTDIR. If not, the # diff_loop function knows how to handle it.