Skip to content

Commit

Permalink
Handle jobserver file descriptors in btest.
Browse files Browse the repository at this point in the history
	PR testsuite/102742

libbacktrace/ChangeLog:

	* btest.c (MIN_DESCRIPTOR): New.
	(MAX_DESCRIPTOR): Likewise.
	(check_available_files): Likewise.
	(check_open_files): Check only file descriptors that
	were not available at the entry.
	(main): Call check_available_files.
  • Loading branch information
marxin authored and ianlancetaylor committed Jul 12, 2024
1 parent 8c05bcb commit ca24ca9
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions btest.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. */
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>

#include "filenames.h"

Expand Down Expand Up @@ -458,16 +459,29 @@ test5 (void)
return failures;
}

#define MIN_DESCRIPTOR 3
#define MAX_DESCRIPTOR 10

static int fstat_status[MAX_DESCRIPTOR];

/* Check files that are available. */

static void
check_available_files (void)
{
struct stat s;
for (unsigned i = MIN_DESCRIPTOR; i < MAX_DESCRIPTOR; i++)
fstat_status[i] = fstat (i, &s);
}

/* Check that are no files left open. */

static void
check_open_files (void)
{
int i;

for (i = 3; i < 10; i++)
for (unsigned i = MIN_DESCRIPTOR; i < MAX_DESCRIPTOR; i++)
{
if (close (i) == 0)
if (fstat_status[i] != 0 && close (i) == 0)
{
fprintf (stderr,
"ERROR: descriptor %d still open after tests complete\n",
Expand All @@ -482,6 +496,8 @@ check_open_files (void)
int
main (int argc ATTRIBUTE_UNUSED, char **argv)
{
check_available_files ();

state = backtrace_create_state (argv[0], BACKTRACE_SUPPORTS_THREADS,
error_callback_create, NULL);

Expand Down

0 comments on commit ca24ca9

Please sign in to comment.