CVS commit: src/usr.bin/cvslatest
Module Name:src Committed By: christos Date: Tue Nov 3 22:21:44 UTC 2020 Modified Files: src/usr.bin/cvslatest: cvslatest.c Log Message: Handle dummy timestamp better and check for I/O errors. From khorben@ To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/usr.bin/cvslatest/cvslatest.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/cvslatest/cvslatest.c diff -u src/usr.bin/cvslatest/cvslatest.c:1.8 src/usr.bin/cvslatest/cvslatest.c:1.9 --- src/usr.bin/cvslatest/cvslatest.c:1.8 Sat Mar 9 11:18:22 2019 +++ src/usr.bin/cvslatest/cvslatest.c Tue Nov 3 17:21:43 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: cvslatest.c,v 1.8 2019/03/09 16:18:22 christos Exp $ */ +/* $NetBSD: cvslatest.c,v 1.9 2020/11/03 22:21:43 christos Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #endif #include -__RCSID("$NetBSD: cvslatest.c,v 1.8 2019/03/09 16:18:22 christos Exp $"); +__RCSID("$NetBSD: cvslatest.c,v 1.9 2020/11/03 22:21:43 christos Exp $"); /* * Find the latest timestamp in a set of CVS trees, by examining the @@ -115,10 +115,18 @@ getlatest(const FTSENT *e, const char *r goto mal; if ((dt = strtok(NULL, "/")) == NULL) goto mal; + if (strcmp(dt, "dummy timestamp") == 0) { + warnx("Can't get timestamp from uncommitted file `%s'", + ename); + if (!ignore) +exit(EXIT_FAILURE); + continue; + } if ((p = strptime(dt, fmt, &tm)) == NULL || *p) { warnx("Malformed time `%s' in `%s'", dt, ename); if (!ignore) exit(EXIT_FAILURE); + continue; } tm.tm_isdst = 0; // We are in GMT anyway if ((t = mktime(&tm)) == (time_t)-1) @@ -132,6 +140,8 @@ getlatest(const FTSENT *e, const char *r printlat(lat); } } + if (ferror(fp)) + err(EXIT_FAILURE, "Can't read `%s'", ename); fclose(fp); return;
CVS commit: src/usr.bin/cvslatest
Module Name:src Committed By: christos Date: Sat Mar 9 16:18:22 UTC 2019 Modified Files: src/usr.bin/cvslatest: Makefile cvslatest.c Log Message: Fix another bug found by jemalloc: don't access dirent entry after closedir(3). To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/usr.bin/cvslatest/Makefile cvs rdiff -u -r1.7 -r1.8 src/usr.bin/cvslatest/cvslatest.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/cvslatest/Makefile diff -u src/usr.bin/cvslatest/Makefile:1.1 src/usr.bin/cvslatest/Makefile:1.2 --- src/usr.bin/cvslatest/Makefile:1.1 Sun Jan 24 12:08:16 2016 +++ src/usr.bin/cvslatest/Makefile Sat Mar 9 11:18:22 2019 @@ -1,6 +1,7 @@ -# $NetBSD: Makefile,v 1.1 2016/01/24 17:08:16 christos Exp $ +# $NetBSD: Makefile,v 1.2 2019/03/09 16:18:22 christos Exp $ WARNS=6 PROG= cvslatest +DBG=-g .include Index: src/usr.bin/cvslatest/cvslatest.c diff -u src/usr.bin/cvslatest/cvslatest.c:1.7 src/usr.bin/cvslatest/cvslatest.c:1.8 --- src/usr.bin/cvslatest/cvslatest.c:1.7 Sun Mar 11 10:59:41 2018 +++ src/usr.bin/cvslatest/cvslatest.c Sat Mar 9 11:18:22 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: cvslatest.c,v 1.7 2018/03/11 14:59:41 christos Exp $ */ +/* $NetBSD: cvslatest.c,v 1.8 2019/03/09 16:18:22 christos Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #endif #include -__RCSID("$NetBSD: cvslatest.c,v 1.7 2018/03/11 14:59:41 christos Exp $"); +__RCSID("$NetBSD: cvslatest.c,v 1.8 2019/03/09 16:18:22 christos Exp $"); /* * Find the latest timestamp in a set of CVS trees, by examining the @@ -212,8 +212,8 @@ findCVSDir(char *path, size_t pathlen, c } n = "CVS"; out: - closedir(dirp); strlcpy(path, n, pathlen); + closedir(dirp); return path; }
CVS commit: src/usr.bin/cvslatest
Module Name:src Committed By: christos Date: Sat Mar 9 16:18:37 UTC 2019 Modified Files: src/usr.bin/cvslatest: Makefile Log Message: no -g To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/usr.bin/cvslatest/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/cvslatest/Makefile diff -u src/usr.bin/cvslatest/Makefile:1.2 src/usr.bin/cvslatest/Makefile:1.3 --- src/usr.bin/cvslatest/Makefile:1.2 Sat Mar 9 11:18:22 2019 +++ src/usr.bin/cvslatest/Makefile Sat Mar 9 11:18:37 2019 @@ -1,7 +1,6 @@ -# $NetBSD: Makefile,v 1.2 2019/03/09 16:18:22 christos Exp $ +# $NetBSD: Makefile,v 1.3 2019/03/09 16:18:37 christos Exp $ WARNS=6 PROG= cvslatest -DBG=-g .include
CVS commit: src/usr.bin/cvslatest
Module Name:src Committed By: christos Date: Sun Mar 11 14:59:41 UTC 2018 Modified Files: src/usr.bin/cvslatest: cvslatest.c Log Message: deal with cvs meta-data directories not called CVS. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/usr.bin/cvslatest/cvslatest.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/cvslatest/cvslatest.c diff -u src/usr.bin/cvslatest/cvslatest.c:1.6 src/usr.bin/cvslatest/cvslatest.c:1.7 --- src/usr.bin/cvslatest/cvslatest.c:1.6 Sun Sep 24 05:43:27 2017 +++ src/usr.bin/cvslatest/cvslatest.c Sun Mar 11 10:59:41 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: cvslatest.c,v 1.6 2017/09/24 09:43:27 joerg Exp $ */ +/* $NetBSD: cvslatest.c,v 1.7 2018/03/11 14:59:41 christos Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #endif #include -__RCSID("$NetBSD: cvslatest.c,v 1.6 2017/09/24 09:43:27 joerg Exp $"); +__RCSID("$NetBSD: cvslatest.c,v 1.7 2018/03/11 14:59:41 christos Exp $"); /* * Find the latest timestamp in a set of CVS trees, by examining the @@ -52,6 +52,7 @@ __RCSID("$NetBSD: cvslatest.c,v 1.6 2017 #include #include #include +#include #include #include #include @@ -174,11 +175,55 @@ usage(void) exit(EXIT_FAILURE); } +static int +checkDir(char *path, size_t pathlen, const char *name) +{ + static const char *files[] = { + "Entries", "Root", "Repository", + }; + size_t i; + + for (i = 0; i < __arraycount(files); i++) { + snprintf(path, pathlen, "%s/%s", name, files[i]); + if (access(path, F_OK) == -1) + return 0; + } + + return 1; +} + +static const char * +findCVSDir(char *path, size_t pathlen, const char *name) +{ + DIR *dirp; + struct dirent *dp; + const char *n; + + if ((dirp = opendir(name)) == NULL) + err(EXIT_FAILURE, "Can't open `%s'", name); + + while ((dp = readdir(dirp)) != NULL) { + n = dp->d_name; + if (n[0] == '.' && (n[1] == '\0' || + (n[1] == '.' && n[2] == '\0'))) + continue; + if (checkDir(path, pathlen, n)) + goto out; + } + n = "CVS"; +out: + closedir(dirp); + strlcpy(path, n, pathlen); + return path; +} + + int main(int argc, char *argv[]) { struct latest lat; - const char *name = "CVS"; + const char *name = NULL; + char path[MAXPATHLEN]; int c; while ((c = getopt(argc, argv, "din:")) != -1) @@ -202,6 +247,9 @@ main(int argc, char *argv[]) // So that mktime behaves consistently setenv("TZ", "UTC", 1); + if (name == NULL) + name = findCVSDir(path, sizeof(path), argv[optind]); + cvsscan(argv + optind, name, &lat); if (debug) printlat(&lat);
CVS commit: src/usr.bin/cvslatest
Module Name:src Committed By: joerg Date: Sun Sep 24 09:43:27 UTC 2017 Modified Files: src/usr.bin/cvslatest: cvslatest.c Log Message: Force _GNU_SOURCE on Linux, otherwise strptime is not defined and more restrictive macros result in even nastier fallout. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/usr.bin/cvslatest/cvslatest.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/cvslatest/cvslatest.c diff -u src/usr.bin/cvslatest/cvslatest.c:1.5 src/usr.bin/cvslatest/cvslatest.c:1.6 --- src/usr.bin/cvslatest/cvslatest.c:1.5 Thu Jan 12 14:27:14 2017 +++ src/usr.bin/cvslatest/cvslatest.c Sun Sep 24 09:43:27 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: cvslatest.c,v 1.5 2017/01/12 14:27:14 christos Exp $ */ +/* $NetBSD: cvslatest.c,v 1.6 2017/09/24 09:43:27 joerg Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -29,12 +29,16 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#ifdef __linux__ +#define _GNU_SOURCE +#endif + #ifdef HAVE_NBTOOL_CONFIG_H #include "nbtool_config.h" #endif #include -__RCSID("$NetBSD: cvslatest.c,v 1.5 2017/01/12 14:27:14 christos Exp $"); +__RCSID("$NetBSD: cvslatest.c,v 1.6 2017/09/24 09:43:27 joerg Exp $"); /* * Find the latest timestamp in a set of CVS trees, by examining the
CVS commit: src/usr.bin/cvslatest
Module Name:src Committed By: christos Date: Thu Jan 12 14:27:14 UTC 2017 Modified Files: src/usr.bin/cvslatest: cvslatest.c Log Message: give the absolute path for the error message. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.bin/cvslatest/cvslatest.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/cvslatest/cvslatest.c diff -u src/usr.bin/cvslatest/cvslatest.c:1.4 src/usr.bin/cvslatest/cvslatest.c:1.5 --- src/usr.bin/cvslatest/cvslatest.c:1.4 Mon Dec 26 09:53:17 2016 +++ src/usr.bin/cvslatest/cvslatest.c Thu Jan 12 09:27:14 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: cvslatest.c,v 1.4 2016/12/26 14:53:17 christos Exp $ */ +/* $NetBSD: cvslatest.c,v 1.5 2017/01/12 14:27:14 christos Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ #endif #include -__RCSID("$NetBSD: cvslatest.c,v 1.4 2016/12/26 14:53:17 christos Exp $"); +__RCSID("$NetBSD: cvslatest.c,v 1.5 2017/01/12 14:27:14 christos Exp $"); /* * Find the latest timestamp in a set of CVS trees, by examining the @@ -67,37 +67,39 @@ printlat(const struct latest *lat) } static void -getrepo(const char *path, char *repo, size_t maxrepo) +getrepo(const FTSENT *e, char *repo, size_t maxrepo) { FILE *fp; - char name[MAXPATHLEN]; + char name[MAXPATHLEN], ename[MAXPATHLEN]; char *ptr; - snprintf(name, sizeof(name), "%s/Repository", path); + snprintf(name, sizeof(name), "%s/Repository", e->fts_accpath); + snprintf(ename, sizeof(ename), "%s/Repository", e->fts_path); if ((fp = fopen(name, "r")) == NULL) - err(EXIT_FAILURE, "Can't open `%s'", name); + err(EXIT_FAILURE, "Can't open `%s'", ename); if (fgets(repo, (int)maxrepo, fp) == NULL) - err(EXIT_FAILURE, "Can't read `%s'", name); + err(EXIT_FAILURE, "Can't read `%s'", ename); if ((ptr = strchr(repo, '\n')) == NULL) - errx(EXIT_FAILURE, "Malformed line in `%s'", name); + errx(EXIT_FAILURE, "Malformed line in `%s'", ename); *ptr = '\0'; fclose(fp); } static void -getlatest(const char *path, const char *repo, struct latest *lat) +getlatest(const FTSENT *e, const char *repo, struct latest *lat) { static const char fmt[] = "%a %b %d %H:%M:%S %Y"; - char name[MAXPATHLEN]; + char name[MAXPATHLEN], ename[MAXPATHLEN]; char entry[MAXPATHLEN * 2]; char *fn, *dt, *p; time_t t; struct tm tm; FILE *fp; - snprintf(name, sizeof(name), "%s/Entries", path); + snprintf(name, sizeof(name), "%s/Entries", e->fts_accpath); + snprintf(ename, sizeof(ename), "%s/Entries", e->fts_path); if ((fp = fopen(name, "r")) == NULL) - err(EXIT_FAILURE, "Can't open `%s'", name); + err(EXIT_FAILURE, "Can't open `%s'", ename); while (fgets(entry, (int)sizeof(entry), fp) != NULL) { if (entry[0] != '/') @@ -109,14 +111,14 @@ getlatest(const char *path, const char * if ((dt = strtok(NULL, "/")) == NULL) goto mal; if ((p = strptime(dt, fmt, &tm)) == NULL || *p) { - warnx("Malformed time `%s' in `%s'", dt, name); + warnx("Malformed time `%s' in `%s'", dt, ename); if (!ignore) exit(EXIT_FAILURE); } tm.tm_isdst = 0; // We are in GMT anyway if ((t = mktime(&tm)) == (time_t)-1) errx(EXIT_FAILURE, "Time conversion `%s' in `%s'", - dt, name); + dt, ename); if (lat->time == 0 || lat->time < t) { lat->time = t; snprintf(lat->path, sizeof(lat->path), @@ -130,7 +132,7 @@ getlatest(const char *path, const char * return; mal: - errx(EXIT_FAILURE, "Malformed line in `%s'", name); + errx(EXIT_FAILURE, "Malformed line in `%s'", ename); } static void @@ -153,8 +155,8 @@ cvsscan(char **pathv, const char *name, if (strcmp(entry->fts_name, name) != 0) continue; - getrepo(entry->fts_accpath, repo, sizeof(repo)); - getlatest(entry->fts_accpath, repo, lat); + getrepo(entry, repo, sizeof(repo)); + getlatest(entry, repo, lat); } (void)fts_close(dh);
CVS commit: src/usr.bin/cvslatest
Module Name:src Committed By: christos Date: Mon Dec 26 14:53:17 UTC 2016 Modified Files: src/usr.bin/cvslatest: cvslatest.c Log Message: - use UTC - initialize tm_isdst - use accpath to handle relative paths To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/usr.bin/cvslatest/cvslatest.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/cvslatest/cvslatest.c diff -u src/usr.bin/cvslatest/cvslatest.c:1.3 src/usr.bin/cvslatest/cvslatest.c:1.4 --- src/usr.bin/cvslatest/cvslatest.c:1.3 Sun Dec 18 20:48:00 2016 +++ src/usr.bin/cvslatest/cvslatest.c Mon Dec 26 09:53:17 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: cvslatest.c,v 1.3 2016/12/19 01:48:00 christos Exp $ */ +/* $NetBSD: cvslatest.c,v 1.4 2016/12/26 14:53:17 christos Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ #endif #include -__RCSID("$NetBSD: cvslatest.c,v 1.3 2016/12/19 01:48:00 christos Exp $"); +__RCSID("$NetBSD: cvslatest.c,v 1.4 2016/12/26 14:53:17 christos Exp $"); /* * Find the latest timestamp in a set of CVS trees, by examining the @@ -113,6 +113,7 @@ getlatest(const char *path, const char * if (!ignore) exit(EXIT_FAILURE); } + tm.tm_isdst = 0; // We are in GMT anyway if ((t = mktime(&tm)) == (time_t)-1) errx(EXIT_FAILURE, "Time conversion `%s' in `%s'", dt, name); @@ -152,8 +153,8 @@ cvsscan(char **pathv, const char *name, if (strcmp(entry->fts_name, name) != 0) continue; - getrepo(entry->fts_path, repo, sizeof(repo)); - getlatest(entry->fts_path, repo, lat); + getrepo(entry->fts_accpath, repo, sizeof(repo)); + getlatest(entry->fts_accpath, repo, lat); } (void)fts_close(dh); @@ -192,6 +193,9 @@ main(int argc, char *argv[]) if (argc == optind) usage(); + // So that mktime behaves consistently + setenv("TZ", "UTC", 1); + cvsscan(argv + optind, name, &lat); if (debug) printlat(&lat);
CVS commit: src/usr.bin/cvslatest
Module Name:src Committed By: christos Date: Mon Dec 19 01:48:00 UTC 2016 Modified Files: src/usr.bin/cvslatest: cvslatest.c Log Message: print only the latest entry for debugging. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/usr.bin/cvslatest/cvslatest.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/cvslatest/cvslatest.c diff -u src/usr.bin/cvslatest/cvslatest.c:1.2 src/usr.bin/cvslatest/cvslatest.c:1.3 --- src/usr.bin/cvslatest/cvslatest.c:1.2 Sun Jan 24 15:14:44 2016 +++ src/usr.bin/cvslatest/cvslatest.c Sun Dec 18 20:48:00 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: cvslatest.c,v 1.2 2016/01/24 20:14:44 christos Exp $ */ +/* $NetBSD: cvslatest.c,v 1.3 2016/12/19 01:48:00 christos Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ #endif #include -__RCSID("$NetBSD: cvslatest.c,v 1.2 2016/01/24 20:14:44 christos Exp $"); +__RCSID("$NetBSD: cvslatest.c,v 1.3 2016/12/19 01:48:00 christos Exp $"); /* * Find the latest timestamp in a set of CVS trees, by examining the @@ -120,7 +120,7 @@ getlatest(const char *path, const char * lat->time = t; snprintf(lat->path, sizeof(lat->path), "%s/%s", repo, fn); - if (debug) + if (debug > 1) printlat(lat); } }
CVS commit: src/usr.bin/cvslatest
Module Name:src Committed By: christos Date: Sun Jan 24 20:14:44 UTC 2016 Modified Files: src/usr.bin/cvslatest: cvslatest.c Log Message: Toolify To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/usr.bin/cvslatest/cvslatest.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/cvslatest/cvslatest.c diff -u src/usr.bin/cvslatest/cvslatest.c:1.1 src/usr.bin/cvslatest/cvslatest.c:1.2 --- src/usr.bin/cvslatest/cvslatest.c:1.1 Sun Jan 24 12:08:16 2016 +++ src/usr.bin/cvslatest/cvslatest.c Sun Jan 24 15:14:44 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: cvslatest.c,v 1.1 2016/01/24 17:08:16 christos Exp $ */ +/* $NetBSD: cvslatest.c,v 1.2 2016/01/24 20:14:44 christos Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -28,8 +28,13 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ + +#ifdef HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif + #include -__RCSID("$NetBSD: cvslatest.c,v 1.1 2016/01/24 17:08:16 christos Exp $"); +__RCSID("$NetBSD: cvslatest.c,v 1.2 2016/01/24 20:14:44 christos Exp $"); /* * Find the latest timestamp in a set of CVS trees, by examining the