From: Fredrik Tolf Date: Tue, 27 May 2008 14:45:07 +0000 (+0200) Subject: Merge branch 'master' of git.dolda2000.com:/srv/git/r/doldaconnect X-Git-Tag: 1.3~11^2^2~10 X-Git-Url: http://dolda2000.com/gitweb/?p=doldaconnect.git;a=commitdiff_plain;h=b65b119a8db3fcd383efcd65b38b333096c1cec2;hp=8bcadf2b067b3dceeed54a9f3dde8f8c1fd50467 Merge branch 'master' of git.dolda2000.com:/srv/git/r/doldaconnect --- diff --git a/configure.in b/configure.in index 73f67a9..effe65b 100644 --- a/configure.in +++ b/configure.in @@ -83,6 +83,21 @@ if test "$HAS_LIBNOTIFY" = yes; then AC_DEFINE(HAVE_NOTIFY) fi +# libattr check +AH_TEMPLATE(HAVE_XATTR, [define to compile support for extended attributes]) +AC_ARG_WITH(xattr, [ --with-xattr Enable XATTR support]) +DOLDA_PKG([HAS_XATTR], [test "$with_xattr" = no && HAS_XATTR=no], + [AC_CHECK_LIB(attr, getxattr, [:], [HAS_XATTR=no])], + [DOLDA_CHECK_HEADER(attr/xattr.h, [], [HAS_XATTR=no])], + [XATTR_LIBS=-lattr]) +if test "$with_xattr" = yes -a "$HAS_XATTR" = no; then + AC_MSG_ERROR([*** cannot find xattr support on this system]) +fi +if test "$HAS_XATTR" = yes; then + AC_DEFINE(HAVE_XATTR) +fi +AC_SUBST(XATTR_LIBS) + # libpanelapplet check DOLDA_PKG([HAS_LIBPANELAPPLET], [PKG_CHECK_MODULES(PANELAPPLET, libpanelapplet-2.0, [], [HAS_LIBPANELAPPLET=no])]) diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 532b4da..a80ad94 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -32,5 +32,5 @@ endif EXTRA_DIST=emacs-local doldacond_LDADD=$(top_srcdir)/common/libcommon.a \ - @KRB5_LIBS@ -lbz2 -lz -lgdbm @PAM_LIBS@ @KEYUTILS_LIBS@ + @KRB5_LIBS@ -lbz2 -lz -lgdbm @PAM_LIBS@ @KEYUTILS_LIBS@ @XATTR_LIBS@ doldacond_CPPFLAGS=-I$(top_srcdir)/include -DDAEMON @KRB5_CFLAGS@ -D_ISOC99_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 diff --git a/daemon/reqstat.c b/daemon/reqstat.c index cbe1c72..d3d849f 100644 --- a/daemon/reqstat.c +++ b/daemon/reqstat.c @@ -30,6 +30,10 @@ #include "module.h" #include "log.h" +#ifdef HAVE_XATTR +#include +#endif + struct trdata { size_t startpos; }; @@ -61,19 +65,60 @@ void filelog(char *format, ...) fclose(out); } +#ifdef HAVE_XATTR +void xainc(wchar_t *file, char *an, off_t inc) +{ + char buf[32]; + ssize_t al; + off_t val; + char *fn; + + if((fn = icswcstombs(file, NULL, NULL)) == NULL) { + flog(LOG_WARNING, "could not convert filename %ls into local charset: %s", file, strerror(errno)); + return; + } + if((al = getxattr(fn, an, buf, sizeof(buf) - 1)) < 0) { + if(errno != ENOATTR) { + flog(LOG_WARNING, "could not get xattr %s on %s: %s", an, fn, strerror(errno)); + return; + } + val = 0; + } else { + buf[al] = 0; + val = strtoll(buf, NULL, 10); + } + val += inc; + al = snprintf(buf, sizeof(buf), "%ji", (intmax_t)val); + if(setxattr(fn, an, buf, al, 0) < 0) + flog(LOG_WARNING, "could not set xattr %s on %s: %s", an, fn, strerror(errno)); +} +#endif + void request(struct transfer *transfer, struct trdata *data) { filelog("request %ls", transfer->path); +#ifdef HAVE_XATTR + if(confgetint("reqstat", "xa")) + xainc(transfer->path, "user.dc-req", 1); +#endif } void start(struct transfer *transfer, struct trdata *data) { filelog("start %ls at %zi", transfer->path, data->startpos); +#ifdef HAVE_XATTR + if(confgetint("reqstat", "xa")) + xainc(transfer->path, "user.dc-started", 1); +#endif } void finish(struct transfer *transfer, struct trdata *data) { filelog("finish %ls at %zi, total %zi", transfer->path, transfer->curpos, transfer->curpos - data->startpos); +#ifdef HAVE_XATTR + if(confgetint("reqstat", "xa")) + xainc(transfer->path, "user.dc-bytes", transfer->curpos - data->startpos); +#endif } static int chattr(struct transfer *transfer, wchar_t *attrib, struct trdata *data) @@ -140,6 +185,12 @@ static struct configvar myvars[] = { /** The name of a file to log upload request information to. If * unspecified, upload requests will not be logged. */ {CONF_VAR_STRING, "file", {.str = L""}}, + /** If set to true, upload statistics of files will be accumulated + * in counters stored in extends attributes (see attr(5)) on the + * files themselves. The data accumulated is the number of + * requests, the number of successfully started uploads and the + * number of uploaded bytes. */ + {CONF_VAR_BOOL, "xa", {.num = 0}}, {CONF_VAR_END} };