diff options
author | Xavier Santolaria <xsa@cvs.openbsd.org> | 2005-08-03 14:43:09 +0000 |
---|---|---|
committer | Xavier Santolaria <xsa@cvs.openbsd.org> | 2005-08-03 14:43:09 +0000 |
commit | 42a21376b7456d1a73890bad1fec5222c74f639a (patch) | |
tree | c15d106c92ebcee2ee952e225d93eef547a087fb | |
parent | 1134e0bf54fadfc9102b9b8aa1cbbc16fcbd95a7 (diff) |
check only once for the HOME environment variable and reuse
its value (if any) to check for the .cvsrc and .cvsignore files;
ok jfb@ joris@.
-rw-r--r-- | usr.bin/cvs/cvs.c | 32 | ||||
-rw-r--r-- | usr.bin/cvs/cvs.h | 3 | ||||
-rw-r--r-- | usr.bin/cvs/file.c | 50 |
3 files changed, 40 insertions, 45 deletions
diff --git a/usr.bin/cvs/cvs.c b/usr.bin/cvs/cvs.c index 9df202f427a..0e0dd26c415 100644 --- a/usr.bin/cvs/cvs.c +++ b/usr.bin/cvs/cvs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cvs.c,v 1.78 2005/08/01 19:48:18 xsa Exp $ */ +/* $OpenBSD: cvs.c,v 1.79 2005/08/03 14:43:08 xsa Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -64,8 +64,9 @@ int cvs_cmdop; char *cvs_rootstr; char *cvs_rsh = CVS_RSH_DEFAULT; char *cvs_editor = CVS_EDITOR_DEFAULT; -char *cvs_repo_base = NULL; +char *cvs_homedir = NULL; char *cvs_msg = NULL; +char *cvs_repo_base = NULL; /* hierarchy of all the files affected by the command */ CVSFILE *cvs_files; @@ -97,6 +98,7 @@ main(int argc, char **argv) char *envstr, *cmd_argv[CVS_CMD_MAXARG], **targv; int i, ret, cmd_argc; struct cvs_cmd *cmdp; + struct passwd *pw; TAILQ_INIT(&cvs_variables); @@ -124,6 +126,16 @@ main(int argc, char **argv) if ((envstr = getenv("CVSREAD")) != NULL) cvs_readonly = 1; + if ((cvs_homedir = getenv("HOME")) == NULL) { + pw = getpwuid(getuid()); + if (pw == NULL) { + cvs_log(LP_NOTICE, + "failed to get user's password entry"); + exit(1); + } + cvs_homedir = pw->pw_dir; + } + ret = cvs_getopt(argc, argv); argc -= ret; @@ -330,25 +342,13 @@ cvs_getopt(int argc, char **argv) static void cvs_read_rcfile(void) { - char rcpath[MAXPATHLEN], linebuf[128], *envstr, *home, *lp, *p; + char rcpath[MAXPATHLEN], linebuf[128], *lp, *p; int l, linenum = 0; size_t len; struct cvs_cmd *cmdp; - struct passwd *pw; FILE *fp; - pw = getpwuid(getuid()); - if (pw == NULL) { - cvs_log(LP_NOTICE, "failed to get user's password entry"); - return; - } - - if ((envstr = getenv("HOME")) != NULL) - home = envstr; - else - home = pw->pw_dir; - - l = snprintf(rcpath, sizeof(rcpath), "%s/%s", home, CVS_PATH_RC); + l = snprintf(rcpath, sizeof(rcpath), "%s/%s", cvs_homedir, CVS_PATH_RC); if (l == -1 || l >= (int)sizeof(rcpath)) { errno = ENAMETOOLONG; cvs_log(LP_ERRNO, "%s", rcpath); diff --git a/usr.bin/cvs/cvs.h b/usr.bin/cvs/cvs.h index 7249a5e1aa9..3ab9da87f59 100644 --- a/usr.bin/cvs/cvs.h +++ b/usr.bin/cvs/cvs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cvs.h,v 1.75 2005/07/27 10:36:13 xsa Exp $ */ +/* $OpenBSD: cvs.h,v 1.76 2005/08/03 14:43:08 xsa Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -298,6 +298,7 @@ extern char *cvs_req_modulename; extern char *cvs_repo_base; extern char *cvs_command; extern char *cvs_editor; +extern char *cvs_homedir; extern char *cvs_msg; extern char *cvs_rsh; diff --git a/usr.bin/cvs/file.c b/usr.bin/cvs/file.c index d1cd3263d55..7a0931d7b3a 100644 --- a/usr.bin/cvs/file.c +++ b/usr.bin/cvs/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.110 2005/07/30 21:16:17 moritz Exp $ */ +/* $OpenBSD: file.c,v 1.111 2005/08/03 14:43:08 xsa Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -128,7 +128,6 @@ cvs_file_init(void) size_t len; char path[MAXPATHLEN], buf[MAXNAMLEN]; FILE *ifp; - struct passwd *pwd; TAILQ_INIT(&cvs_ign_pats); @@ -140,35 +139,30 @@ cvs_file_init(void) cvs_file_ignore(cvs_ign_std[i]); /* read the cvsignore file in the user's home directory, if any */ - pwd = getpwuid(getuid()); - if (pwd != NULL) { - l = snprintf(path, sizeof(path), "%s/.cvsignore", pwd->pw_dir); - if (l == -1 || l >= (int)sizeof(path)) { - errno = ENAMETOOLONG; - cvs_log(LP_ERRNO, "%s", path); - return (-1); - } + l = snprintf(path, sizeof(path), "%s/.cvsignore", cvs_homedir); + if (l == -1 || l >= (int)sizeof(path)) { + errno = ENAMETOOLONG; + cvs_log(LP_ERRNO, "%s", path); + return (-1); + } - ifp = fopen(path, "r"); - if (ifp == NULL) { - if (errno != ENOENT) - cvs_log(LP_ERRNO, - "failed to open user's cvsignore file " - "`%s'", path); - } else { - while (fgets(buf, sizeof(buf), ifp) != NULL) { - len = strlen(buf); - if (len == 0) - continue; - if (buf[len - 1] != '\n') { - cvs_log(LP_ERR, "line too long in `%s'", - path); - } - buf[--len] = '\0'; - cvs_file_ignore(buf); + ifp = fopen(path, "r"); + if (ifp == NULL) { + if (errno != ENOENT) + cvs_log(LP_ERRNO, + "failed to open user's cvsignore file `%s'", path); + } else { + while (fgets(buf, sizeof(buf), ifp) != NULL) { + len = strlen(buf); + if (len == 0) + continue; + if (buf[len - 1] != '\n') { + cvs_log(LP_ERR, "line too long in `%s'", path); } - (void)fclose(ifp); + buf[--len] = '\0'; + cvs_file_ignore(buf); } + (void)fclose(ifp); } return (0); |