/[cvs]/ccvs/src/main.c
ViewVC logotype

Diff of /ccvs/src/main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.251 by dprice, Mon Sep 5 14:18:51 2005 UTC revision 1.252 by dprice, Tue Sep 6 00:40:50 2005 UTC
# Line 60  char *CurDir; Line 60  char *CurDir;
60  /*  /*
61   * Defaults, for the environment variables that are not set   * Defaults, for the environment variables that are not set
62   */   */
 char *Tmpdir = TMPDIR_DFLT;  
63  char *Editor = EDITOR_DFLT;  char *Editor = EDITOR_DFLT;
64    
65    
66    
67    /* Temp dir stuff.  */
68    
69    /* Temp dir, if set by the user.  */
70    static char *tmpdir_cmdline;
71    /* Temp dir, if set in the environment.  */
72    static const char *tmpdir_env;
73    
74    
75    
76    /* Returns in order of precedence:
77     *
78     *      1.  Temp dir as set via the command line.
79     *      2.  Temp dir as set in CVSROOT/config.
80     *      3.  Temp dir as set in $TMPDIR env var.
81     *      4.  Contents of TMPDIR_DFLT preprocessor macro.
82     *
83     * ERRORS
84     *  It is a fatal error if this function would otherwise return NULL or an
85     *  empty string.
86     */
87    const char *
88    get_cvs_tmp_dir (void)
89    {
90        const char *retval;
91        if (tmpdir_cmdline) retval = tmpdir_cmdline;
92        else if (config && config->TmpDir) retval = config->TmpDir;
93        else if (tmpdir_env) retval = tmpdir_env;
94        else retval = TMPDIR_DFLT;
95    
96        if (!retval || !*retval) error (1, 0, "No temp dir specified.");
97    
98        return retval;
99    }
100    
101    
102    
103    void
104    push_env_tmp_dir (void)
105    {
106        const char *tmpdir = get_cvs_tmp_dir ();
107        if (tmpdir_env && strcmp (tmpdir_env, tmpdir))
108            setenv (TMPDIR_ENV, tmpdir, 1);
109    }
110    
111    
112    
113  /* When our working directory contains subdirectories with different  /* When our working directory contains subdirectories with different
114     values in CVS/Root files, we maintain a list of them.  */     values in CVS/Root files, we maintain a list of them.  */
115  List *root_directories = NULL;  List *root_directories = NULL;
# Line 430  main (int argc, char **argv) Line 476  main (int argc, char **argv)
476      char *cp, *end;      char *cp, *end;
477      const struct cmd *cm;      const struct cmd *cm;
478      int c, err = 0;      int c, err = 0;
     int tmpdir_update_env;  
479      int free_Editor = 0;      int free_Editor = 0;
     int free_Tmpdir = 0;  
480    
481      int help = 0;               /* Has the user asked for help?  This      int help = 0;               /* Has the user asked for help?  This
482                                     lets us support the `cvs -H cmd'                                     lets us support the `cvs -H cmd'
# Line 488  main (int argc, char **argv) Line 532  main (int argc, char **argv)
532       * Query the environment variables up-front, so that       * Query the environment variables up-front, so that
533       * they can be overridden by command line arguments       * they can be overridden by command line arguments
534       */       */
     tmpdir_update_env = *Tmpdir;        /* TMPDIR_DFLT must be set */  
535      if ((cp = getenv (TMPDIR_ENV)) != NULL)      if ((cp = getenv (TMPDIR_ENV)) != NULL)
536      {          tmpdir_env = cp;
         Tmpdir = cp;  
         tmpdir_update_env = 0;          /* it's already there */  
     }  
537      if ((cp = getenv (EDITOR1_ENV)) != NULL)      if ((cp = getenv (EDITOR1_ENV)) != NULL)
538          Editor = cp;          Editor = cp;
539      else if ((cp = getenv (EDITOR2_ENV)) != NULL)      else if ((cp = getenv (EDITOR2_ENV)) != NULL)
# Line 628  distribution kit for a complete list of Line 668  distribution kit for a complete list of
668                     either new or old CVS.  */                     either new or old CVS.  */
669                  break;                  break;
670              case 'T':              case 'T':
671                  if (free_Tmpdir) free (Tmpdir);                  if (tmpdir_cmdline) free (tmpdir_cmdline);
672                  Tmpdir = xstrdup (optarg);                  tmpdir_cmdline = xstrdup (optarg);
                 free_Tmpdir = 1;  
                 tmpdir_update_env = 1;  /* need to update environment */  
673                  break;                  break;
674              case 'e':              case 'e':
675                  if (free_Editor) free (Editor);                  if (free_Editor) free (Editor);
# Line 814  cause intermittent sandbox corruption.") Line 852  cause intermittent sandbox corruption.")
852                  error (1, errno, "cannot get working directory");                  error (1, errno, "cannot get working directory");
853          }          }
854    
         if (Tmpdir == NULL || Tmpdir[0] == '\0')  
         {  
             if (free_Tmpdir) free (Tmpdir);  
             Tmpdir = "/tmp";  
         }  
   
         if (tmpdir_update_env)  
             setenv (TMPDIR_ENV, Tmpdir, 1);  
855          {          {
856              char *val;              char *val;
857              /* XXX pid < 10^32 */              /* XXX pid < 10^32 */
# Line 1009  cause intermittent sandbox corruption.") Line 1039  cause intermittent sandbox corruption.")
1039                     CVSROOT/config file to fix the broken one!  */                     CVSROOT/config file to fix the broken one!  */
1040                  if (config) free_config (config);                  if (config) free_config (config);
1041                  config = parse_config (current_parsed_root->directory, NULL);                  config = parse_config (current_parsed_root->directory, NULL);
1042    
1043                    /* Can set TMPDIR in the environment if necessary now, since
1044                     * if it was set in config, we now know it.
1045                     */
1046                    push_env_tmp_dir ();
1047              }              }
1048    
1049  #ifdef CLIENT_SUPPORT  #ifdef CLIENT_SUPPORT

Legend:
Removed from v.1.251  
changed lines
  Added in v.1.252

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26