From 5a9a2445f0a9cd1ca49f3dfa6e347ba3f93dda98 Mon Sep 17 00:00:00 2001 From: cvs2svn Date: Fri, 2 Sep 2005 12:17:40 +0000 Subject: [PATCH] This commit was manufactured by cvs2svn to create branch 'glite-lb- common_branch_2_1_0_2'. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Sprout from glite-lb-common_branch_2_0_0 2005-08-05 14:35:29 UTC cvs2svn 'This commit was manufactured by cvs2svn to create branch 'glite-lb-' Cherrypick from master 2005-09-02 12:17:37 UTC Aleš Křenek 'Incremented build number [GLBUILDER]': org.glite.lb.common/Makefile org.glite.lb.common/interface/lb_maildir.h org.glite.lb.common/project/version.properties org.glite.lb.common/src/lb_maildir.c --- org.glite.lb.common/Makefile | 14 ++- org.glite.lb.common/interface/lb_maildir.h | 4 +- org.glite.lb.common/project/version.properties | 5 +- org.glite.lb.common/src/lb_maildir.c | 115 ++++++++++++++++++++++++- 4 files changed, 129 insertions(+), 9 deletions(-) diff --git a/org.glite.lb.common/Makefile b/org.glite.lb.common/Makefile index 8d7c5e9..93708e8 100644 --- a/org.glite.lb.common/Makefile +++ b/org.glite.lb.common/Makefile @@ -75,7 +75,7 @@ EXT_LIBS:= ${EXPAT_LIBS} ${ARES_LIBS} ${GLOBUS_LIBS} TEST_LIBS:=-L${cppunit}/lib -lcppunit TEST_INC:=-I${cppunit}/include -COMPILE:=libtool --mode=compile ${CC} ${CFLAGS} +COMPILE:=libtool --mode=compile ${CC} LINK:=libtool --mode=link ${CC} -rpath ${stagedir}/lib ${LDFLAGS} LINKXX:=libtool --mode=link ${CXX} -rpath ${stagedir}/lib ${LDFLAGS} INSTALL:=libtool --mode=install install @@ -111,6 +111,14 @@ default: all all compile: check_version ${STATICLIB} ${LTLIB} ${THRSTATICLIB} ${THRLTLIB} ${TRIO_LIB} ${MAILDIR_LIB} # all compile: ${STATICLIB} ${LTLIB} ${THRSTATICLIB} ${THRLTLIB} +# FIXME: to use libtool versioning correcty, we should have: +# +# current = major + minor + offset +# revision = patch +# age = minor +# +# where offset is a sum of maximal released minor's of all previous major's +# version_info=-version-info `echo ${version} | cut -d. -f1,2 | tr . :` ${STATICLIB}: ${OBJS} @@ -195,13 +203,13 @@ clean: %.o: %.c - ${COMPILE} ${GLOBUSINC} -c $< + ${COMPILE} ${GLOBUSINC} ${CFLAGS} -c $< il_int_test.o il_string_test.o il_test.o il_msg_test.o: %.o: %.cpp ${CXX} -c ${CFLAGS} ${TEST_INC} $< %.thr.o: %.c - ${COMPILE} ${GLOBUSTHRINC} -o $@ -c $< + ${COMPILE} ${GLOBUSTHRINC} ${CFLAGS} -o $@ -c $< %.h: %.h.T rm -f $@ diff --git a/org.glite.lb.common/interface/lb_maildir.h b/org.glite.lb.common/interface/lb_maildir.h index 4c918d4..45b2da8 100644 --- a/org.glite.lb.common/interface/lb_maildir.h +++ b/org.glite.lb.common/interface/lb_maildir.h @@ -9,13 +9,15 @@ enum { LBMD_TRANS_OK, - LBMD_TRANS_FAILED + LBMD_TRANS_FAILED, + LBMD_TRANS_FAILED_RETRY, }; extern char lbm_errdesc[]; extern int edg_wll_MaildirInit(const char *); extern int edg_wll_MaildirStoreMsg(const char *, const char *, const char *); +extern int edg_wll_MaildirRetryTransStart(const char *, time_t, char **, char **); extern int edg_wll_MaildirTransStart(const char *, char **, char **); extern int edg_wll_MaildirTransEnd(const char *, char *, int); diff --git a/org.glite.lb.common/project/version.properties b/org.glite.lb.common/project/version.properties index ad6ec55..69f99a3 100644 --- a/org.glite.lb.common/project/version.properties +++ b/org.glite.lb.common/project/version.properties @@ -1,3 +1,4 @@ -#Thu May 19 13:15:32 CEST 2005 -module.version=2.0.0 +#Fri Sep 02 14:17:07 CEST 2005 +module.version=2.1.0 +module.build=2 module.age=1 diff --git a/org.glite.lb.common/src/lb_maildir.c b/org.glite.lb.common/src/lb_maildir.c index 4155918..d2ccf67 100644 --- a/org.glite.lb.common/src/lb_maildir.c +++ b/org.glite.lb.common/src/lb_maildir.c @@ -16,10 +16,11 @@ enum { LBMD_DIR_TMP = 0, LBMD_DIR_NEW, - LBMD_DIR_WORK + LBMD_DIR_WORK, + LBMD_DIR_POST }; -static const char *dirs[] = { "tmp", "new", "work" }; +static const char *dirs[] = { "tmp", "new", "work", "post" }; #define MAX_ERR_LEN 1024 @@ -149,12 +150,14 @@ int edg_wll_MaildirTransEnd( return 0; } + if ( tstate == LBMD_TRANS_FAILED ) return 0; + if ( stat(origfname, &st) ) { snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't stat file '%s'", origfname); return -1; } - snprintf(newfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_NEW], fname); + snprintf(newfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_POST], fname); if ( link(origfname, newfname) ) { snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't link new file %s", newfname); return -1; @@ -164,6 +167,112 @@ int edg_wll_MaildirTransEnd( } +int edg_wll_MaildirRetryTransStart( + const char *root, + time_t tm, + char **msg, + char **fname) +{ + static DIR *dir = NULL; + struct dirent *ent; + time_t tlimit; + struct stat st; + char newfname[PATH_MAX], + oldfname[PATH_MAX], + *buf = NULL; + int fhnd, + toread, ct, + bufsz, bufuse; + + + if ( !root ) root = DEFAULT_ROOT; + + if ( !dir ) { + char dirname[PATH_MAX]; + snprintf(dirname, PATH_MAX, "%s/%s", root, dirs[LBMD_DIR_POST]); + if ( !(dir = opendir(dirname)) ) { + snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't open directory '%s'", root); + goto err; + } + } + + tlimit = time(NULL) - tm; + do { + errno = 0; + if ( !(ent = readdir(dir)) ) { + if ( errno == EBADF ) { + snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't read directory '%s'", root); + dir = NULL; + goto err; + } else { + closedir(dir); + dir = NULL; + return 0; + } + } + if ( ent->d_name[0] == '.' ) continue; + + snprintf(oldfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_POST], ent->d_name); + snprintf(newfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_WORK], ent->d_name); + + if ( stat(oldfname, &st) < 0 ) { + snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't stat file '%s'", oldfname); + goto err; + } + + if ( st.st_ctime > tlimit ) continue; + + if ( rename(oldfname, newfname) ) { + if ( errno == ENOENT ) { + /* maybe some other instance moved this file away... */ + continue; + } else { + snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't move file '%s'", oldfname); + goto err; + } + } else { + /* we have found and moved the file with which we will work now */ + break; + } + } while ( 1 ); + + if ( (fhnd = open(newfname, O_RDONLY)) < 0 ) { + snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't open file '%s'", newfname); + goto err; + } + + bufuse = bufsz = toread = ct = 0; + do { + errno = 0; + if ( bufuse == bufsz ) { + char *tmp = realloc(buf, bufsz+BUFSIZ); + if ( !tmp ) goto err; + buf = tmp; + bufsz += BUFSIZ; + } + toread = bufsz - bufuse; + if ( (ct = read(fhnd, buf+bufuse, toread)) < 0 ) { + if ( errno == EINTR ) continue; + snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't read file '%s'", newfname); + goto err; + } + if ( ct == 0 ) break; + bufuse += ct; + } while ( ct == toread ); + close(fhnd); + + if ( !(*fname = strdup(ent->d_name)) ) goto err; + *msg = buf; + return 1; + + +err: + if ( buf ) free(buf); + + return -1; +} + + int edg_wll_MaildirTransStart( const char *root, char **msg, -- 1.8.2.3