diff options
author | Joris Vink <joris@cvs.openbsd.org> | 2008-02-04 19:08:33 +0000 |
---|---|---|
committer | Joris Vink <joris@cvs.openbsd.org> | 2008-02-04 19:08:33 +0000 |
commit | a0b9240664bddddeedb1798fffa69d36acef975d (patch) | |
tree | 85f4d5c4505a2332a154ddbbeef53ddecfbf046e /usr.bin/cvs | |
parent | bb6fd23cd9ea4d27e10b0e6b40885c7da78c0337 (diff) |
more CVSROOT/modules stuff:
- support for -i flag:
Run "prog" on "cvs commit" from top-level of module.
- fix some memory leaks in modules.c
- pass the line number from cvs_read_config() towards the callbacks
so its easier to print out where it's going wrong, if it ever does.
OK tobias@
Diffstat (limited to 'usr.bin/cvs')
-rw-r--r-- | usr.bin/cvs/checkout.c | 6 | ||||
-rw-r--r-- | usr.bin/cvs/config.c | 11 | ||||
-rw-r--r-- | usr.bin/cvs/config.h | 13 | ||||
-rw-r--r-- | usr.bin/cvs/modules.c | 60 | ||||
-rw-r--r-- | usr.bin/cvs/util.c | 21 | ||||
-rw-r--r-- | usr.bin/cvs/util.h | 3 |
6 files changed, 75 insertions, 39 deletions
diff --git a/usr.bin/cvs/checkout.c b/usr.bin/cvs/checkout.c index 31f818ab07c..6bd12c87157 100644 --- a/usr.bin/cvs/checkout.c +++ b/usr.bin/cvs/checkout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: checkout.c,v 1.125 2008/02/04 15:07:32 tobias Exp $ */ +/* $OpenBSD: checkout.c,v 1.126 2008/02/04 19:08:32 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -287,6 +287,10 @@ checkout_check_repository(int argc, char **argv) default: break; } + + if (mc->mc_prog != NULL && + mc->mc_flags & MODULE_RUN_ON_COMMIT) + cvs_exec(mc->mc_prog); } if (mc->mc_canfree == 1) { diff --git a/usr.bin/cvs/config.c b/usr.bin/cvs/config.c index b6bc4fd1101..1b9bea490c1 100644 --- a/usr.bin/cvs/config.c +++ b/usr.bin/cvs/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.13 2008/02/01 18:10:26 joris Exp $ */ +/* $OpenBSD: config.c,v 1.14 2008/02/04 19:08:32 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -35,7 +35,7 @@ cvs_parse_configfile(void) } void -config_parse_line(char *line) +config_parse_line(char *line, int lineno) { struct rlimit rl; const char *errstr; @@ -76,10 +76,11 @@ config_parse_line(char *line) } void -cvs_read_config(char *name, void (*cb)(char *)) +cvs_read_config(char *name, void (*cb)(char *, int)) { FILE *fp; size_t len; + int lineno; char *p, *buf, *lbuf, fpath[MAXPATHLEN]; (void)xsnprintf(fpath, sizeof(fpath), "%s/%s", @@ -89,7 +90,9 @@ cvs_read_config(char *name, void (*cb)(char *)) return; lbuf = NULL; + lineno = 0; while ((buf = fgetln(fp, &len)) != NULL) { + lineno++; if (buf[len - 1] == '\n') { buf[len - 1] = '\0'; } else { @@ -106,7 +109,7 @@ cvs_read_config(char *name, void (*cb)(char *)) if (p[0] == '#' || p[0] == '\0') continue; - cb(p); + cb(p, lineno); } if (lbuf != NULL) diff --git a/usr.bin/cvs/config.h b/usr.bin/cvs/config.h index 8d33c4e8a1f..ac0c3390da3 100644 --- a/usr.bin/cvs/config.h +++ b/usr.bin/cvs/config.h @@ -1,4 +1,4 @@ -/* $OpenBSD: config.h,v 1.6 2008/02/03 23:34:41 joris Exp $ */ +/* $OpenBSD: config.h,v 1.7 2008/02/04 19:08:32 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -18,13 +18,13 @@ #ifndef CONFIG_H #define CONFIG_H -void cvs_read_config(char *name, void (*cb)(char *)); +void cvs_read_config(char *name, void (*cb)(char *, int)); void cvs_parse_configfile(void); void cvs_parse_modules(void); -void config_parse_line(char *); -void modules_parse_line(char *); +void config_parse_line(char *, int); +void modules_parse_line(char *, int); #include <sys/queue.h> #include "file.h" @@ -38,15 +38,18 @@ void modules_parse_line(char *); struct module_checkout { char *mc_name; - int mc_flags; + char *mc_prog; + int mc_flags; int mc_canfree; + struct cvs_flisthead mc_modules; struct cvs_flisthead mc_ignores; }; struct module_info { char *mi_name; + char *mi_prog; int mi_flags; struct cvs_flisthead mi_modules; diff --git a/usr.bin/cvs/modules.c b/usr.bin/cvs/modules.c index 8acdfb82f0e..1af50afb71d 100644 --- a/usr.bin/cvs/modules.c +++ b/usr.bin/cvs/modules.c @@ -1,4 +1,4 @@ -/* $OpenBSD: modules.c,v 1.6 2008/02/03 23:34:41 joris Exp $ */ +/* $OpenBSD: modules.c,v 1.7 2008/02/04 19:08:32 joris Exp $ */ /* * Copyright (c) 2008 Joris Vink <joris@openbsd.org> * @@ -40,49 +40,42 @@ cvs_parse_modules(void) } void -modules_parse_line(char *line) +modules_parse_line(char *line, int lineno) { int flags; - struct cvs_filelist *fl; - char *val, *p, *module, *sp, *dp; struct module_info *mi; - char *dirname, fpath[MAXPATHLEN]; + char *val, *p, *module, *sp, *dp; + char *dirname, fpath[MAXPATHLEN], *prog; flags = 0; p = val = line; - while (*p != ' ' && *p != '\t') + while (*p != ' ' && *p != '\t' && *p != '\0') p++; + if (*p == '\0') + goto bad; + *(p++) = '\0'; module = val; - while (*p == ' ' || *p == '\t') + while ((*p == ' ' || *p == '\t') && *p != '\0') p++; - if (*p == '\0') { - cvs_log(LP_NOTICE, "premature ending of CVSROOT/modules line"); - return; - } + if (*p == '\0') + goto bad; val = p; while (*p != ' ' && *p != '\t') p++; - if (*p == '\0') { - cvs_log(LP_NOTICE, "premature ending of CVSROOT/modules line"); - return; - } - + prog = NULL; while (val[0] == '-') { p = val; while (*p != ' ' && *p != '\t' && *p != '\0') p++; - if (*p == '\0') { - cvs_log(LP_NOTICE, - "misplaced option in CVSROOT/modules"); - return; - } + if (*p == '\0') + goto bad; *(p++) = '\0'; @@ -105,11 +98,18 @@ modules_parse_line(char *line) flags |= MODULE_NORECURSE; break; case 'i': - if (flags != 0) { + if (flags != 0 || prog != NULL) { cvs_log(LP_NOTICE, "-i cannot be used with other flags"); return; } + + if ((val = strchr(p, ' ' )) == NULL) + goto bad; + + *(val++) = '\0'; + prog = xstrdup(p); + p = val; flags |= MODULE_RUN_ON_COMMIT; break; } @@ -117,13 +117,13 @@ modules_parse_line(char *line) val = p; } - /* XXX: until we support it */ - if (flags & MODULE_RUN_ON_COMMIT) - return; + if (*val == '\0') + goto bad; mi = xmalloc(sizeof(*mi)); mi->mi_name = xstrdup(module); mi->mi_flags = flags; + mi->mi_prog = prog; dirname = NULL; TAILQ_INIT(&(mi->mi_modules)); @@ -164,6 +164,10 @@ modules_parse_line(char *line) cvs_file_get(dirname, 0, &(mi->mi_modules)); TAILQ_INSERT_TAIL(&modules, mi, m_list); + return; + +bad: + cvs_log(LP_NOTICE, "malformed line in CVSROOT/modules: %d", lineno); } struct module_checkout * @@ -180,8 +184,9 @@ cvs_module_lookup(char *name) mc->mc_modules = mi->mi_modules; mc->mc_ignores = mi->mi_ignores; mc->mc_canfree = 0; - mc->mc_name = xstrdup(mi->mi_name); + mc->mc_name = mi->mi_name; mc->mc_flags = mi->mi_flags; + mc->mc_prog = mi->mi_prog; return (mc); } } @@ -190,8 +195,9 @@ cvs_module_lookup(char *name) TAILQ_INIT(&(mc->mc_ignores)); cvs_file_get(name, 0, &(mc->mc_modules)); mc->mc_canfree = 1; - mc->mc_name = xstrdup(name); + mc->mc_name = name; mc->mc_flags |= MODULE_ALIAS; + mc->mc_prog = NULL; return (mc); } diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c index 646755c0fd7..73d09fccd56 100644 --- a/usr.bin/cvs/util.c +++ b/usr.bin/cvs/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.131 2008/02/04 18:23:58 tobias Exp $ */ +/* $OpenBSD: util.c,v 1.132 2008/02/04 19:08:32 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * Copyright (c) 2005, 2006 Joris Vink <joris@openbsd.org> @@ -33,6 +33,7 @@ #include <md5.h> #include <stdlib.h> #include <string.h> +#include <paths.h> #include <unistd.h> #include "cvs.h" @@ -824,3 +825,21 @@ cvs_yesno(void) return (ret); } + +void +cvs_exec(const char *prog) +{ + pid_t pid; + char *argp[] = { "sh", "-c", NULL, NULL }; + + argp[2] = prog; + + if ((pid = fork()) == -1) { + cvs_log(LP_ERR, "cvs_exec: fork failed"); + return; + } else if (pid == 0) { + execv(_PATH_BSHELL, argp); + cvs_log(LP_ERR, "failed to run '%s'", prog); + _exit(127); + } +} diff --git a/usr.bin/cvs/util.h b/usr.bin/cvs/util.h index e34bdc853ef..629a013cff3 100644 --- a/usr.bin/cvs/util.h +++ b/usr.bin/cvs/util.h @@ -1,4 +1,4 @@ -/* $OpenBSD: util.h,v 1.23 2008/02/04 18:23:58 tobias Exp $ */ +/* $OpenBSD: util.h,v 1.24 2008/02/04 19:08:32 joris Exp $ */ /* * Copyright (c) 2006 Niall O'Higgins <niallo@openbsd.org> * All rights reserved. @@ -41,6 +41,7 @@ int cvs_unlink(const char *); int cvs_rmdir(const char *); char **cvs_makeargv(const char *, int *); void cvs_freeargv(char **, int); +void cvs_exec(const char *); u_int cvs_revision_select(RCSFILE *, char *); struct cvs_line { |