This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] libgcov and umask
- From: Johan Kristell <johan dot kristell at axis dot com>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 11 Aug 2009 08:05:36 +0200
- Subject: [PATCH] libgcov and umask
Profiling an application with a to restrictive set umask currently fails
due to libgcov inheriting the umask of the application.
This patch fixes this by temporarily changing the umask when writing to
the data file.
Tested on i386-linux
2009-08-04 Johan Kristell <johan.kristell@axis.com>
* libgcov.c (gcov_exit): Temporarily change the umask to allow
writing to the data file from the library even if the umask of
the application is set to restrictive.
* gcc.misc-tests/gcov-12.c: New testcase.
Index: gcc/libgcov.c
===================================================================
--- gcc/libgcov.c (revision 150364)
+++ gcc/libgcov.c (working copy)
@@ -166,6 +166,7 @@
int gcov_prefix_strip = 0;
size_t prefix_length;
char *gi_filename, *gi_filename_up;
+ mode_t saved_umask;
memset (&all, 0, sizeof (all));
/* Find the totals for this execution. */
@@ -219,6 +220,10 @@
memcpy (gi_filename, gcov_prefix, prefix_length);
gi_filename_up = gi_filename + prefix_length;
+ /* Temporarily change the umask so that writing to the data file
+ doesn't depend on the umask of the application being profiled. */
+ saved_umask = umask (S_IWGRP | S_IWOTH);
+
/* Now merge each file. */
for (gi_ptr = gcov_list; gi_ptr; gi_ptr = gi_ptr->next)
{
@@ -525,6 +530,9 @@
"profiling:%s:Error writing\n",
gi_filename);
}
+
+ /* Restore the umask. */
+ umask (saved_umask);
}
/* Add a new object file onto the bb chain. Invoked automatically
/* Test gcov with umask. */
/* { dg-options "-fprofile-arcs -ftest-coverage" } */
/* { dg-do run { target native } } */
extern unsigned int umask(unsigned int);
int main ()
{
umask(0777); /* count(1) */
return 0; /* count(1) */
}
/* { dg-final { run-gcov gcov-12.c } } */