From 313d0163e407381abff749cdd6538fd69bf94703 Mon Sep 17 00:00:00 2001 From: Xavier Santolaria Date: Thu, 4 Aug 2005 13:31:15 +0000 Subject: handle TMPDIR environment variable as well as -T global option; Ok jfb@ joris@. --- usr.bin/cvs/cvs.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'usr.bin/cvs/cvs.c') diff --git a/usr.bin/cvs/cvs.c b/usr.bin/cvs/cvs.c index 0e0dd26c415..e5277531a42 100644 --- a/usr.bin/cvs/cvs.c +++ b/usr.bin/cvs/cvs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cvs.c,v 1.79 2005/08/03 14:43:08 xsa Exp $ */ +/* $OpenBSD: cvs.c,v 1.80 2005/08/04 13:31:14 xsa Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. @@ -24,6 +24,7 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include @@ -67,6 +68,7 @@ char *cvs_editor = CVS_EDITOR_DEFAULT; char *cvs_homedir = NULL; char *cvs_msg = NULL; char *cvs_repo_base = NULL; +char *cvs_tmpdir = CVS_TMPDIR_DEFAULT; /* hierarchy of all the files affected by the command */ CVSFILE *cvs_files; @@ -99,6 +101,7 @@ main(int argc, char **argv) int i, ret, cmd_argc; struct cvs_cmd *cmdp; struct passwd *pw; + struct stat st; TAILQ_INIT(&cvs_variables); @@ -136,6 +139,9 @@ main(int argc, char **argv) cvs_homedir = pw->pw_dir; } + if ((envstr = getenv("TMPDIR")) != NULL) + cvs_tmpdir = envstr; + ret = cvs_getopt(argc, argv); argc -= ret; @@ -144,8 +150,23 @@ main(int argc, char **argv) usage(); exit(1); } + cvs_command = argv[0]; + /* + * check the tmp dir, either specified through + * the environment variable TMPDIR, or via + * the global option -T + */ + if (stat(cvs_tmpdir, &st) == -1) { + cvs_log(LP_ERR, "failed to stat `%s'", cvs_tmpdir); + exit(1); + } else if (!S_ISDIR(st.st_mode)) { + cvs_log(LP_ERR, "`%s' is not valid temporary directory", + cvs_tmpdir); + exit(1); + } + if (cvs_readrc == 1) { cvs_read_rcfile(); @@ -250,7 +271,7 @@ cvs_getopt(int argc, char **argv) int ret; char *ep; - while ((ret = getopt(argc, argv, "b:d:e:fHlnQqrs:tvz:")) != -1) { + while ((ret = getopt(argc, argv, "b:d:e:fHlnQqrs:T:tvz:")) != -1) { switch (ret) { case 'b': /* @@ -296,6 +317,9 @@ cvs_getopt(int argc, char **argv) if (cvs_var_set(optarg, ep) < 0) exit(1); break; + case 'T': + cvs_tmpdir = optarg; + break; case 't': (void)cvs_log_filter(LP_FILTER_UNSET, LP_TRACE); cvs_trace = 1; -- cgit v1.2.3