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
This commit is contained in:
parent
ddfee90670
commit
8bc16536d6
@ -30,7 +30,7 @@ ACLOCAL_AMFLAGS = -I .. -I ../config
|
||||
# May be used by toolexeclibdir.
|
||||
gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER)
|
||||
|
||||
DEFS =
|
||||
DEFS = @DEFS@
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/../include
|
||||
AM_CFLAGS = $(XCFLAGS)
|
||||
AM_CCASFLAGS = $(XCFLAGS)
|
||||
|
@ -148,7 +148,7 @@ CXXCPP = @CXXCPP@
|
||||
CXXDEPMODE = @CXXDEPMODE@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEFS =
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
DSYMUTIL = @DSYMUTIL@
|
||||
DUMPBIN = @DUMPBIN@
|
||||
|
2021
libvtv/configure
vendored
2021
libvtv/configure
vendored
File diff suppressed because it is too large
Load Diff
@ -91,6 +91,12 @@ esac
|
||||
AC_SUBST(toolexecdir)
|
||||
AC_SUBST(toolexeclibdir)
|
||||
|
||||
AC_GNU_SOURCE
|
||||
AC_CHECK_FUNCS([__secure_getenv])
|
||||
|
||||
AC_GNU_SOURCE
|
||||
AC_CHECK_FUNCS([secure_getenv])
|
||||
|
||||
# Check for programs.
|
||||
m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
|
||||
m4_define([_AC_ARG_VAR_PRECIOUS],[])
|
||||
|
@ -396,7 +396,7 @@ log_memory_protection_data (char *message)
|
||||
static int 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);
|
||||
}
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <execinfo.h>
|
||||
#include <unistd.h>
|
||||
@ -38,24 +39,53 @@
|
||||
|
||||
#include "vtv_utils.h"
|
||||
|
||||
/* This is the directory into which all vtable verication log files
|
||||
get written. */
|
||||
static const char * const logs_dir = "/tmp/vtv_logs";
|
||||
#ifndef HAVE_SECURE_GETENV
|
||||
# ifdef HAVE___SECURE_GETENV
|
||||
# define secure_getenv __secure_getenv
|
||||
# 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
|
||||
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
|
||||
__vtv_open_log (const char *name)
|
||||
{
|
||||
char log_name[256];
|
||||
snprintf (log_name, sizeof (log_name), "%s/%s", logs_dir, name);
|
||||
mkdir (logs_dir, S_IRWXU);
|
||||
int fd = open (log_name, O_WRONLY | O_APPEND | O_CREAT, S_IRWXU);
|
||||
char log_name[1024];
|
||||
char log_dir[512];
|
||||
uid_t user_id = getuid ();
|
||||
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)
|
||||
__vtv_add_to_log (2, "Cannot open log file %s %s\n", name,
|
||||
strerror (errno));
|
||||
|
Loading…
Reference in New Issue
Block a user