Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Jan 2009 11:54:00 +0000 (UTC)
From:      Ulf Lilleengen <lulf@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r186858 - projects/csup_wip/contrib/csup
Message-ID:  <200901071154.n07Bs06u084998@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: lulf
Date: Wed Jan  7 11:54:00 2009
New Revision: 186858
URL: http://svn.freebsd.org/changeset/base/186858

Log:
  - Handle SIGINFO in a way that prevents calling of non async-signal safe
    functions.

Modified:
  projects/csup_wip/contrib/csup/config.c
  projects/csup_wip/contrib/csup/config.h
  projects/csup_wip/contrib/csup/lister.c
  projects/csup_wip/contrib/csup/updater.c
  projects/csup_wip/contrib/csup/updater.h

Modified: projects/csup_wip/contrib/csup/config.c
==============================================================================
--- projects/csup_wip/contrib/csup/config.c	Wed Jan  7 11:44:03 2009	(r186857)
+++ projects/csup_wip/contrib/csup/config.c	Wed Jan  7 11:54:00 2009	(r186858)
@@ -311,7 +311,6 @@ coll_new(struct coll *def)
 	new->co_accepts = pattlist_new();
 	new->co_refusals = pattlist_new();
 	new->co_attrignore = FA_DEV | FA_INODE;
-	new->co_numdone = 0;
 	return (new);
 }
 

Modified: projects/csup_wip/contrib/csup/config.h
==============================================================================
--- projects/csup_wip/contrib/csup/config.h	Wed Jan  7 11:44:03 2009	(r186857)
+++ projects/csup_wip/contrib/csup/config.h	Wed Jan  7 11:54:00 2009	(r186858)
@@ -93,7 +93,6 @@ struct coll {
 	int co_options;
 	mode_t co_umask;
 	struct keyword *co_keyword;
-	int co_numdone;
 	STAILQ_ENTRY(coll) co_next;
 };
 

Modified: projects/csup_wip/contrib/csup/lister.c
==============================================================================
--- projects/csup_wip/contrib/csup/lister.c	Wed Jan  7 11:44:03 2009	(r186857)
+++ projects/csup_wip/contrib/csup/lister.c	Wed Jan  7 11:54:00 2009	(r186858)
@@ -29,6 +29,7 @@
 #include <assert.h>
 #include <errno.h>
 #include <limits.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -68,6 +69,9 @@ static int	lister_dorcsfile(struct liste
 		    struct statusrec *);
 static int	lister_dorcsdead(struct lister *, struct coll *,
 		    struct statusrec *);
+void		 lister_infohandler(int);
+
+int printinfo = 0;
 
 void *
 lister(void *arg)
@@ -81,6 +85,7 @@ lister(void *arg)
 	l->config = args->config;
 	l->wr = args->wr;
 	l->errmsg = NULL;
+	signal(SIGINFO, lister_infohandler);
 	error = lister_batch(l);
 	switch (error) {
 	case LISTER_ERR_WRITE:
@@ -150,10 +155,11 @@ lister_coll(struct lister *l, struct col
 	struct statusrec *sr;
 	struct fattr *fa;
 	size_t i;
-	int depth, error, ret, prunedepth;
+	int depth, error, numdone, ret, prunedepth;
 
 	wr = l->wr;
 	depth = 0;
+	numdone = 0;
 	prunedepth = INT_MAX;
 	as = attrstack_new();
 	while ((ret = status_get(st, NULL, 0, 0, &sr)) == 1) {
@@ -212,7 +218,16 @@ lister_coll(struct lister *l, struct col
 			}
 			break;
 		}
-		coll->co_numdone++;
+		numdone++;
+		if (printinfo) {
+			printf("Updating %s", coll->co_name);
+			if (status_numentries(st) > 0)
+				printf(" (%d%% done)", (int)
+				    (((double)numdone * 100.0) /
+				    (double)status_numentries(st)));
+			printf("\n");
+			printinfo = 0;
+		}
 	}
 	if (ret == -1) {
 		l->errmsg = status_errmsg(st);
@@ -568,3 +583,9 @@ lister_dorcsdead(struct lister *l, struc
 		return (LISTER_ERR_WRITE);
 	return (0);
 }
+
+void
+lister_infohandler(int sig __unused)
+{
+	printinfo = 1;
+}

Modified: projects/csup_wip/contrib/csup/updater.c
==============================================================================
--- projects/csup_wip/contrib/csup/updater.c	Wed Jan  7 11:44:03 2009	(r186857)
+++ projects/csup_wip/contrib/csup/updater.c	Wed Jan  7 11:54:00 2009	(r186858)
@@ -33,7 +33,6 @@
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <signal.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -86,9 +85,6 @@ struct updater {
 	int deletecount;
 };
 
-static struct file_update *curfup = NULL;
-static pthread_mutex_t fuplock;
-
 static struct file_update	*fup_new(struct coll *, struct status *);
 static int	 fup_prepare(struct file_update *, char *, int);
 static void	 fup_cleanup(struct file_update *);
@@ -121,7 +117,6 @@ int		 updater_append_file(struct updater
 		     off_t);
 static int	 updater_rsync(struct updater *, struct file_update *, size_t);
 static int	 updater_read_checkout(struct stream *, struct stream *);
-void		 updater_infohandler(int);
 
 static struct file_update *
 fup_new(struct coll *coll, struct status *st)
@@ -132,7 +127,6 @@ fup_new(struct coll *coll, struct status
 	memset(fup, 0, sizeof(*fup));
 	fup->coll = coll;
 	fup->st = st;
-	fup->coname = NULL;
 	return (fup);
 }
 
@@ -239,8 +233,6 @@ updater(void *arg)
 	up->rd = args->rd;
 	up->errmsg = NULL;
 	up->deletecount = 0;
-	pthread_mutex_init(&fuplock, NULL);
-	signal(SIGINFO, updater_infohandler);
 
 	error = updater_batch(up, 0);
 
@@ -324,14 +316,8 @@ updater_batch(struct updater *up, int is
 			return (UPDATER_ERR_MSG);
 		}
 		fup = fup_new(coll, st);
-		pthread_mutex_lock(&fuplock);
-		curfup = fup;
-		pthread_mutex_unlock(&fuplock);
 		error = updater_docoll(up, fup, isfixups);
 		status_close(st, &errmsg);
-		pthread_mutex_lock(&fuplock);
-		curfup = NULL;
-		pthread_mutex_unlock(&fuplock);
 		fup_free(fup);
 		if (errmsg != NULL) {
 			/* Discard previous error. */
@@ -2027,18 +2013,3 @@ bad:
 	free(buf);
 	return (error);
 }
-
-void
-updater_infohandler(int sig __unused)
-{
-	pthread_mutex_lock(&fuplock);
-	if (curfup != NULL) {
-		printf("Updating %s", curfup->coll->co_name);
-		if (status_numentries(curfup->st) > 0)
-			printf(" (%d%% done)", (int)
-			    (((double)curfup->coll->co_numdone * 100.0) /
-			     (double)status_numentries(curfup->st)));
-		printf("\n");
-	}
-	pthread_mutex_unlock(&fuplock);
-}

Modified: projects/csup_wip/contrib/csup/updater.h
==============================================================================
--- projects/csup_wip/contrib/csup/updater.h	Wed Jan  7 11:44:03 2009	(r186857)
+++ projects/csup_wip/contrib/csup/updater.h	Wed Jan  7 11:54:00 2009	(r186858)
@@ -29,5 +29,6 @@
 #define _UPDATER_H
 
 void	*updater(void *);
+void	 updater_printinfo(void);
 
 #endif /* !_UPDATER_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200901071154.n07Bs06u084998>