Commit 8bc16536 by Caroline Tice

Fix logging to not use /tmp or the current directory...

Fix logging to not use /tmp or the current directory; get
the location for writing log files from an environment
variable; use secure getenv whenever possible.

From-SVN: r201890
parent ddfee906
...@@ -30,7 +30,7 @@ ACLOCAL_AMFLAGS = -I .. -I ../config ...@@ -30,7 +30,7 @@ ACLOCAL_AMFLAGS = -I .. -I ../config
# May be used by toolexeclibdir. # May be used by toolexeclibdir.
gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER) gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER)
DEFS = DEFS = @DEFS@
AM_CPPFLAGS = -I$(top_srcdir)/../include AM_CPPFLAGS = -I$(top_srcdir)/../include
AM_CFLAGS = $(XCFLAGS) AM_CFLAGS = $(XCFLAGS)
AM_CCASFLAGS = $(XCFLAGS) AM_CCASFLAGS = $(XCFLAGS)
......
...@@ -148,7 +148,7 @@ CXXCPP = @CXXCPP@ ...@@ -148,7 +148,7 @@ CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@ CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@ CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@ CYGPATH_W = @CYGPATH_W@
DEFS = DEFS = @DEFS@
DEPDIR = @DEPDIR@ DEPDIR = @DEPDIR@
DSYMUTIL = @DSYMUTIL@ DSYMUTIL = @DSYMUTIL@
DUMPBIN = @DUMPBIN@ DUMPBIN = @DUMPBIN@
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -91,6 +91,12 @@ esac ...@@ -91,6 +91,12 @@ esac
AC_SUBST(toolexecdir) AC_SUBST(toolexecdir)
AC_SUBST(toolexeclibdir) AC_SUBST(toolexeclibdir)
AC_GNU_SOURCE
AC_CHECK_FUNCS([__secure_getenv])
AC_GNU_SOURCE
AC_CHECK_FUNCS([secure_getenv])
# Check for programs. # Check for programs.
m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS]) m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
m4_define([_AC_ARG_VAR_PRECIOUS],[]) m4_define([_AC_ARG_VAR_PRECIOUS],[])
......
...@@ -396,7 +396,7 @@ log_memory_protection_data (char *message) ...@@ -396,7 +396,7 @@ log_memory_protection_data (char *message)
static int log_fd = -1; static int log_fd = -1;
if (log_fd == -1) if (log_fd == -1)
log_fd = __vtv_open_log ("vtv_memory_protection_data_%d.log"); log_fd = __vtv_open_log ("vtv_memory_protection_data.log");
__vtv_add_to_log (log_fd, "%s", message); __vtv_add_to_log (log_fd, "%s", message);
} }
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <execinfo.h> #include <execinfo.h>
#include <unistd.h> #include <unistd.h>
...@@ -38,24 +39,53 @@ ...@@ -38,24 +39,53 @@
#include "vtv_utils.h" #include "vtv_utils.h"
/* This is the directory into which all vtable verication log files #ifndef HAVE_SECURE_GETENV
get written. */ # ifdef HAVE___SECURE_GETENV
static const char * const logs_dir = "/tmp/vtv_logs"; # define secure_getenv __secure_getenv
static int vtv_failures_log_fd = -1; # else
# define secure_getenv getenv
# endif
#endif
static int vtv_failures_log_fd = -1;
/* This function takes the NAME of a log file to open, attempts to /* This function takes the NAME of a log file to open, attempts to
open it in the logs_dir directory, and returns the resulting file open it in the logs_dir directory, and returns the resulting file
decriptor. */ descriptor.
This function first checks to see if the user has specifed (via
the environment variable VTV_LOGS_DIR) a directory to use for the
vtable verification logs. If that fails, the function will open
the logs in the current directory.
*/
int int
__vtv_open_log (const char *name) __vtv_open_log (const char *name)
{ {
char log_name[256]; char log_name[1024];
snprintf (log_name, sizeof (log_name), "%s/%s", logs_dir, name); char log_dir[512];
mkdir (logs_dir, S_IRWXU); uid_t user_id = getuid ();
int fd = open (log_name, O_WRONLY | O_APPEND | O_CREAT, S_IRWXU); pid_t process_id = getpid ();
char *logs_prefix;
bool logs_dir_specified = false;
int fd = -1;
logs_prefix = secure_getenv ("VTV_LOGS_DIR");
if (logs_prefix && strlen (logs_prefix) > 0)
{
logs_dir_specified = true;
mkdir (logs_prefix, S_IRWXU);
snprintf (log_dir, sizeof (log_dir), "%s/vtv_logs", logs_prefix);
mkdir (log_dir, S_IRWXU);
snprintf (log_name, sizeof (log_name), "%s/%d_%d_%s", log_dir,
(unsigned) user_id, (unsigned) process_id, name);
fd = open (log_name, O_WRONLY | O_APPEND | O_CREAT | O_NOFOLLOW,
S_IRWXU);
}
else
fd = dup (2);
if (fd == -1) if (fd == -1)
__vtv_add_to_log (2, "Cannot open log file %s %s\n", name, __vtv_add_to_log (2, "Cannot open log file %s %s\n", name,
strerror (errno)); strerror (errno));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment