svn commit: r186837 - projects/csup_wip/contrib/csup
Ulf Lilleengen
lulf at FreeBSD.org
Tue Jan 6 19:52:41 UTC 2009
Author: lulf
Date: Tue Jan 6 19:52:40 2009
New Revision: 186837
URL: http://svn.freebsd.org/changeset/base/186837
Log:
- Add a handler for SIGINFO, which will print the collection, and the progress
of updating the current collection.
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/status.c
projects/csup_wip/contrib/csup/status.h
projects/csup_wip/contrib/csup/updater.c
Modified: projects/csup_wip/contrib/csup/config.c
==============================================================================
--- projects/csup_wip/contrib/csup/config.c Tue Jan 6 19:25:24 2009 (r186836)
+++ projects/csup_wip/contrib/csup/config.c Tue Jan 6 19:52:40 2009 (r186837)
@@ -311,6 +311,7 @@ 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 Tue Jan 6 19:25:24 2009 (r186836)
+++ projects/csup_wip/contrib/csup/config.h Tue Jan 6 19:52:40 2009 (r186837)
@@ -93,6 +93,7 @@ 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 Tue Jan 6 19:25:24 2009 (r186836)
+++ projects/csup_wip/contrib/csup/lister.c Tue Jan 6 19:52:40 2009 (r186837)
@@ -212,6 +212,7 @@ lister_coll(struct lister *l, struct col
}
break;
}
+ coll->co_numdone++;
}
if (ret == -1) {
l->errmsg = status_errmsg(st);
Modified: projects/csup_wip/contrib/csup/status.c
==============================================================================
--- projects/csup_wip/contrib/csup/status.c Tue Jan 6 19:25:24 2009 (r186836)
+++ projects/csup_wip/contrib/csup/status.c Tue Jan 6 19:52:40 2009 (r186837)
@@ -86,6 +86,7 @@ struct status {
int linenum;
int depth;
int dirty;
+ int numentries;
};
static void
@@ -521,11 +522,12 @@ struct status *
status_open(struct coll *coll, time_t scantime, char **errmsg)
{
struct status *st;
- struct stream *file;
+ struct stream *file, *tmp;
struct fattr *fa;
char *destpath, *path;
- int error, rv;
+ int error, isnew, rv;
+ isnew = access(path, F_OK);
path = coll_statuspath(coll);
file = stream_open_file(path, O_RDONLY);
if (file == NULL) {
@@ -536,6 +538,7 @@ status_open(struct coll *coll, time_t sc
return (NULL);
}
st = status_fromnull(path);
+ isnew = 1;
} else {
st = status_fromrd(path, file);
if (st == NULL) {
@@ -591,6 +594,17 @@ status_open(struct coll *coll, time_t sc
return (NULL);
}
}
+
+ /* Count the number of entries in the file. */
+ if (isnew) {
+ st->numentries = 0;
+ tmp = stream_open_file(path, O_RDONLY);
+ if (tmp == NULL)
+ return (st);
+ while (stream_getln(tmp, NULL) != NULL)
+ st->numentries++;
+ stream_close(tmp);
+ }
return (st);
}
@@ -872,3 +886,9 @@ status_close(struct status *st, char **e
bad:
status_free(st);
}
+
+int
+status_numentries(struct status *st)
+{
+ return (st->numentries);
+}
Modified: projects/csup_wip/contrib/csup/status.h
==============================================================================
--- projects/csup_wip/contrib/csup/status.h Tue Jan 6 19:25:24 2009 (r186836)
+++ projects/csup_wip/contrib/csup/status.h Tue Jan 6 19:52:40 2009 (r186837)
@@ -68,5 +68,6 @@ int status_eof(struct status *);
char *status_errmsg(struct status *);
int status_delete(struct status *, char *, int);
void status_close(struct status *, char **);
+int status_numentries(struct status *);
#endif /* !_STATUS_H_ */
Modified: projects/csup_wip/contrib/csup/updater.c
==============================================================================
--- projects/csup_wip/contrib/csup/updater.c Tue Jan 6 19:25:24 2009 (r186836)
+++ projects/csup_wip/contrib/csup/updater.c Tue Jan 6 19:52:40 2009 (r186837)
@@ -33,6 +33,7 @@
#include <err.h>
#include <errno.h>
#include <fcntl.h>
+#include <signal.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@@ -85,6 +86,9 @@ 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 *);
@@ -117,6 +121,7 @@ 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)
@@ -127,6 +132,7 @@ fup_new(struct coll *coll, struct status
memset(fup, 0, sizeof(*fup));
fup->coll = coll;
fup->st = st;
+ fup->coname = NULL;
return (fup);
}
@@ -233,6 +239,8 @@ 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);
@@ -316,8 +324,14 @@ 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. */
@@ -2013,3 +2027,18 @@ 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);
+}
More information about the svn-src-projects
mailing list