Prechádzať zdrojové kódy

Allow error log file to be specified by $GIS_ERROR_LOG
Use getcwd() instead of popen("pwd")


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@33740 15284696-431f-4ddb-bdfa-cd5b030d7da7

Glynn Clements 16 rokov pred
rodič
commit
350b166a9b
1 zmenil súbory, kde vykonal 15 pridanie a 26 odobranie
  1. 15 26
      lib/gis/error.c

+ 15 - 26
lib/gis/error.c

@@ -51,7 +51,7 @@ static int print_word(FILE *, char **, int *, const int);
 static void print_sentence(FILE *, const int, const char *);
 static void print_sentence(FILE *, const int, const char *);
 static int print_error(const char *, const int);
 static int print_error(const char *, const int);
 static int mail_msg(const char *, int);
 static int mail_msg(const char *, int);
-static int write_error(const char *, int, const char *, time_t, const char *);
+static int write_error(const char *, int, time_t, const char *);
 static int log_error(const char *, int);
 static int log_error(const char *, int);
 
 
 static int vfprint_error(int type, const char *template, va_list ap)
 static int vfprint_error(int type, const char *template, va_list ap)
@@ -304,49 +304,38 @@ static int print_error(const char *msg, const int type)
 
 
 static int log_error(const char *msg, int fatal)
 static int log_error(const char *msg, int fatal)
 {
 {
-    FILE *pwd;
-    char cwd[1024];
+    char cwd[GPATH_MAX];
     time_t clock;
     time_t clock;
-    char *home;
     char *gisbase;
     char *gisbase;
 
 
     /* get time */
     /* get time */
     clock = time(NULL);
     clock = time(NULL);
 
 
     /* get current working directory */
     /* get current working directory */
-    sprintf(cwd, "?");
-    if ((pwd = G_popen("pwd", "r"))) {
-	if (fgets(cwd, sizeof(cwd), pwd)) {
-	    char *c;
-
-	    for (c = cwd; *c; c++)
-		if (*c == '\n')
-		    *c = 0;
-	}
-	G_pclose(pwd);
-    }
+    getcwd(cwd, sizeof(cwd));
 
 
-    /* write the 2 possible error log files */
+    /* write the error log file */
     if ((gisbase = G_gisbase()))
     if ((gisbase = G_gisbase()))
-	write_error(msg, fatal, gisbase, clock, cwd);
-
-    home = G__home();
-    if (home && gisbase && strcmp(home, gisbase))
-	write_error(msg, fatal, home, clock, cwd);
+	write_error(msg, fatal, clock, cwd);
 
 
     return 0;
     return 0;
 }
 }
 
 
 /* Write a message to the log file */
 /* Write a message to the log file */
 static int write_error(const char *msg, int fatal,
 static int write_error(const char *msg, int fatal,
-		       const char *dir, time_t clock, const char *cwd)
+		       time_t clock, const char *cwd)
 {
 {
-    char logfile[GNAME_MAX];
+    static char *logfile;
     FILE *log;
     FILE *log;
 
 
-    if (dir == 0 || *dir == 0)
-	return 1;
-    sprintf(logfile, "%s/GIS_ERROR_LOG", dir);
+    if (!logfile) {
+	logfile = getenv("GIS_ERROR_LOG");
+	if (!logfile) {
+	    char buf[GPATH_MAX];
+	    sprintf(buf, "%s/GIS_ERROR_LOG", G__home());
+	    logfile = G_store(buf);
+	}
+    }
 
 
     log = fopen(logfile, "r");
     log = fopen(logfile, "r");
     if (!log)
     if (!log)