summaryrefslogtreecommitdiffstats
path: root/usr.bin/cvs/logmsg.c
diff options
context:
space:
mode:
authorjoris <joris@openbsd.org>2008-06-10 01:00:34 +0000
committerjoris <joris@openbsd.org>2008-06-10 01:00:34 +0000
commitb034d592535c9013a730be7c6d5fe362a29dde95 (patch)
tree39611d6b0b6e48d37dbe37e8b98b35da32ce8943 /usr.bin/cvs/logmsg.c
parentAdditionnal checks on the file names supplied for -s and -x. (diff)
downloadwireguard-openbsd-b034d592535c9013a730be7c6d5fe362a29dde95.tar.xz
wireguard-openbsd-b034d592535c9013a730be7c6d5fe362a29dde95.zip
New trigger framework that allows us to run the required scripts
defined in CVSROOT/commitinfo and CVSROOT/loginfo and so on. This enables the use of log_accum2 and all that other nice stuff we like. This was mostly written by Jonathan Armani with help from tobias@ and myself. ok tobias@
Diffstat (limited to 'usr.bin/cvs/logmsg.c')
-rw-r--r--usr.bin/cvs/logmsg.c76
1 files changed, 72 insertions, 4 deletions
diff --git a/usr.bin/cvs/logmsg.c b/usr.bin/cvs/logmsg.c
index bf02daf29be..68a41e7860c 100644
--- a/usr.bin/cvs/logmsg.c
+++ b/usr.bin/cvs/logmsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: logmsg.c,v 1.49 2008/06/08 20:08:43 tobias Exp $ */
+/* $OpenBSD: logmsg.c,v 1.50 2008/06/10 01:00:34 joris Exp $ */
/*
* Copyright (c) 2007 Joris Vink <joris@openbsd.org>
*
@@ -96,11 +96,14 @@ char *
cvs_logmsg_create(char *dir, struct cvs_flisthead *added,
struct cvs_flisthead *removed, struct cvs_flisthead *modified)
{
- FILE *fp;
- int c, fd, saved_errno;
+ FILE *fp, *rp;
+ int c, fd, rd, saved_errno;
struct cvs_filelist *cf;
struct stat st1, st2;
- char *fpath, *logmsg;
+ char *fpath, *logmsg, repo[MAXPATHLEN];
+ struct stat st;
+ struct trigger_list *line_list;
+ struct trigger_line *line;
static int reuse = 0;
static char *prevmsg = NULL;
@@ -125,6 +128,33 @@ cvs_logmsg_create(char *dir, struct cvs_flisthead *added,
else
fputc('\n', fp);
+ line_list = cvs_trigger_getlines(CVS_PATH_RCSINFO, repo);
+ if (line_list != NULL) {
+ TAILQ_FOREACH(line, line_list, flist) {
+ if ((rd = open(line->line, O_RDONLY)) == -1)
+ fatal("cvs_logmsg_create: open %s",
+ strerror(errno));
+ if (fstat(rd, &st) == -1)
+ fatal("cvs_logmsg_create: fstat %s",
+ strerror(errno));
+ if (!S_ISREG(st.st_mode))
+ fatal("cvs_logmsg_create: file is not a "
+ "regular file");
+ if ((rp = fdopen(rd, "r")) == NULL)
+ fatal("cvs_logmsg_create: fdopen %s",
+ strerror(errno));
+ if (st.st_size > SIZE_MAX)
+ fatal("cvs_logmsg_create: %s: file size "
+ "too big", line->line);
+ logmsg = xmalloc(st.st_size);
+ fread(logmsg, st.st_size, 1, rp);
+ fwrite(logmsg, st.st_size, 1, fp);
+ xfree(logmsg);
+ (void)fclose(rp);
+ }
+ cvs_trigger_freelist(line_list);
+ }
+
fprintf(fp, "%s %s\n%s Enter Log. Lines beginning with `%s' are "
"removed automatically\n%s\n", CVS_LOGMSG_PREFIX, CVS_LOGMSG_LINE,
CVS_LOGMSG_PREFIX, CVS_LOGMSG_PREFIX, CVS_LOGMSG_PREFIX);
@@ -273,3 +303,41 @@ cvs_logmsg_edit(const char *pathname)
errno = saved_errno;
return (-1);
}
+
+int
+cvs_logmsg_verify(char *logmsg)
+{
+ int fd, ret = 0;
+ char *fpath;
+ struct trigger_list *line_list;
+ struct file_info_list files_info;
+ struct file_info *fi;
+
+ line_list = cvs_trigger_getlines(CVS_PATH_VERIFYMSG, "DEFAULT");
+ if (line_list != NULL) {
+ TAILQ_INIT(&files_info);
+
+ (void)xasprintf(&fpath, "%s/cvsXXXXXXXXXX", cvs_tmpdir);
+ if ((fd = mkstemp(fpath)) == -1)
+ fatal("cvs_logmsg_verify: mkstemp %s", strerror(errno));
+
+ fi = xcalloc(1, sizeof(*fi));
+ fi->file_path = xstrdup(fpath);
+ TAILQ_INSERT_TAIL(&files_info, fi, flist);
+
+ if (cvs_trigger_handle(CVS_TRIGGER_VERIFYMSG, NULL, NULL,
+ line_list, &files_info)) {
+ cvs_log(LP_ERR, "Log message check failed");
+ ret = 1;
+ }
+
+ cvs_trigger_freeinfo(&files_info);
+ (void)close(fd);
+ (void)unlink(fpath);
+ xfree(fpath);
+ cvs_trigger_freelist(line_list);
+ }
+
+ return ret;
+}
+