summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Santolaria <xsa@cvs.openbsd.org>2005-08-04 13:31:15 +0000
committerXavier Santolaria <xsa@cvs.openbsd.org>2005-08-04 13:31:15 +0000
commit313d0163e407381abff749cdd6538fd69bf94703 (patch)
treede5d4d3f6f0deeedc6ec0957b6578662e0bb451c
parent2e1ad028e1b12abf3883ee1d1107fdc22a39c996 (diff)
handle TMPDIR environment variable as well as -T <tmpdir> global option;
Ok jfb@ joris@.
-rw-r--r--usr.bin/cvs/cvs.c28
-rw-r--r--usr.bin/cvs/cvs.h4
2 files changed, 29 insertions, 3 deletions
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 <jfb@openbsd.org>
* All rights reserved.
@@ -24,6 +24,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -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 <dir>
+ */
+ 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;
diff --git a/usr.bin/cvs/cvs.h b/usr.bin/cvs/cvs.h
index 3ab9da87f59..db3eadc6694 100644
--- a/usr.bin/cvs/cvs.h
+++ b/usr.bin/cvs/cvs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cvs.h,v 1.76 2005/08/03 14:43:08 xsa Exp $ */
+/* $OpenBSD: cvs.h,v 1.77 2005/08/04 13:31:14 xsa Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -109,6 +109,7 @@
#define CVS_SERVER_DEFAULT "cvs"
#define CVS_RSH_DEFAULT "ssh"
#define CVS_EDITOR_DEFAULT "vi"
+#define CVS_TMPDIR_DEFAULT "/tmp"
/* extensions */
#define CVS_DESCR_FILE_EXT ",t"
@@ -301,6 +302,7 @@ extern char *cvs_editor;
extern char *cvs_homedir;
extern char *cvs_msg;
extern char *cvs_rsh;
+extern char *cvs_tmpdir;
extern int verbosity;
extern int cvs_trace;