mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-05-05 00:37:59 +02:00
Move _dbus_check_fdleaks_* from dbus-message-util to tests
This is only called from test code. Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
parent
0b8878133f
commit
0ba41e071c
5 changed files with 135 additions and 147 deletions
|
|
@ -143,10 +143,6 @@ _dbus_clear_variant (DBusVariant **variant_p)
|
|||
_dbus_clear_pointer_impl (DBusVariant, variant_p, _dbus_variant_free);
|
||||
}
|
||||
|
||||
typedef struct DBusInitialFDs DBusInitialFDs;
|
||||
DBusInitialFDs *_dbus_check_fdleaks_enter (void);
|
||||
void _dbus_check_fdleaks_leave (DBusInitialFDs *fds);
|
||||
|
||||
DBUS_END_DECLS
|
||||
|
||||
#endif /* DBUS_MESSAGE_INTERNAL_H */
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
/* dbus-message-util.c Would be in dbus-message.c, but only used by bus/tests
|
||||
*
|
||||
* Copyright 2009 Red Hat, Inc.
|
||||
* Copyright 2011-2017 Collabora Ltd.
|
||||
* Copyright 2017 Endless Mobile, Inc.
|
||||
* Copyright 2017 Collabora Ltd.
|
||||
*
|
||||
* Licensed under the Academic Free License version 2.1
|
||||
*
|
||||
|
|
@ -25,23 +23,7 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#include "dbus-internals.h"
|
||||
#include "dbus-test.h"
|
||||
#include "dbus-message-private.h"
|
||||
#include "dbus-marshal-recursive.h"
|
||||
#include "dbus-string.h"
|
||||
#ifdef HAVE_UNIX_FD_PASSING
|
||||
#include "dbus-sysdeps-unix.h"
|
||||
#endif
|
||||
#include <dbus/dbus-test-tap.h>
|
||||
|
||||
#ifdef __linux__
|
||||
/* Necessary for the Linux-specific fd leak checking code only */
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @addtogroup DBusMessage
|
||||
|
|
@ -63,125 +45,3 @@ _dbus_message_get_n_unix_fds (DBusMessage *message)
|
|||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
|
||||
|
||||
#ifdef __linux__
|
||||
struct DBusInitialFDs {
|
||||
fd_set set;
|
||||
};
|
||||
#endif
|
||||
|
||||
DBusInitialFDs *
|
||||
_dbus_check_fdleaks_enter (void)
|
||||
{
|
||||
#ifdef __linux__
|
||||
DIR *d;
|
||||
DBusInitialFDs *fds;
|
||||
|
||||
/* this is plain malloc so it won't interfere with leak checking */
|
||||
fds = malloc (sizeof (DBusInitialFDs));
|
||||
_dbus_assert (fds != NULL);
|
||||
|
||||
/* This works on Linux only */
|
||||
|
||||
if ((d = opendir ("/proc/self/fd")))
|
||||
{
|
||||
struct dirent *de;
|
||||
|
||||
while ((de = readdir(d)))
|
||||
{
|
||||
long l;
|
||||
char *e = NULL;
|
||||
int fd;
|
||||
|
||||
if (de->d_name[0] == '.')
|
||||
continue;
|
||||
|
||||
errno = 0;
|
||||
l = strtol (de->d_name, &e, 10);
|
||||
_dbus_assert (errno == 0 && e && !*e);
|
||||
|
||||
fd = (int) l;
|
||||
|
||||
if (fd < 3)
|
||||
continue;
|
||||
|
||||
if (fd == dirfd (d))
|
||||
continue;
|
||||
|
||||
if (fd >= FD_SETSIZE)
|
||||
{
|
||||
_dbus_verbose ("FD %d unexpectedly large; cannot track whether "
|
||||
"it is leaked\n", fd);
|
||||
continue;
|
||||
}
|
||||
|
||||
FD_SET (fd, &fds->set);
|
||||
}
|
||||
|
||||
closedir (d);
|
||||
}
|
||||
|
||||
return fds;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
_dbus_check_fdleaks_leave (DBusInitialFDs *fds)
|
||||
{
|
||||
#ifdef __linux__
|
||||
DIR *d;
|
||||
|
||||
/* This works on Linux only */
|
||||
|
||||
if ((d = opendir ("/proc/self/fd")))
|
||||
{
|
||||
struct dirent *de;
|
||||
|
||||
while ((de = readdir(d)))
|
||||
{
|
||||
long l;
|
||||
char *e = NULL;
|
||||
int fd;
|
||||
|
||||
if (de->d_name[0] == '.')
|
||||
continue;
|
||||
|
||||
errno = 0;
|
||||
l = strtol (de->d_name, &e, 10);
|
||||
_dbus_assert (errno == 0 && e && !*e);
|
||||
|
||||
fd = (int) l;
|
||||
|
||||
if (fd < 3)
|
||||
continue;
|
||||
|
||||
if (fd == dirfd (d))
|
||||
continue;
|
||||
|
||||
if (fd >= FD_SETSIZE)
|
||||
{
|
||||
_dbus_verbose ("FD %d unexpectedly large; cannot track whether "
|
||||
"it is leaked\n", fd);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (FD_ISSET (fd, &fds->set))
|
||||
continue;
|
||||
|
||||
_dbus_test_fatal ("file descriptor %i leaked in %s.", fd, __FILE__);
|
||||
}
|
||||
|
||||
closedir (d);
|
||||
}
|
||||
|
||||
free (fds);
|
||||
#else
|
||||
_dbus_assert (fds == NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@
|
|||
|
||||
#include "dbus-message-factory.h"
|
||||
|
||||
#include "test/test-utils.h"
|
||||
|
||||
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
|
||||
/**
|
||||
* Reads arguments from a message iterator given a variable argument
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright 2002-2008 Red Hat Inc.
|
||||
* Copyright 2002-2009 Red Hat Inc.
|
||||
* Copyright 2011-2017 Collabora Ltd.
|
||||
* Copyright 2017 Endless Mobile, Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
|
@ -46,6 +47,12 @@
|
|||
# include <dbus/dbus-sysdeps-win.h>
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
/* Necessary for the Linux-specific fd leak checking code only */
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#include "dbus/dbus-message-internal.h"
|
||||
#include "dbus/dbus-test-tap.h"
|
||||
|
||||
|
|
@ -526,6 +533,124 @@ _dbus_test_append_different_uid (DBusString *uid)
|
|||
|
||||
#endif /* !defined(DBUS_UNIX) */
|
||||
|
||||
#ifdef __linux__
|
||||
struct DBusInitialFDs {
|
||||
fd_set set;
|
||||
};
|
||||
#endif
|
||||
|
||||
DBusInitialFDs *
|
||||
_dbus_check_fdleaks_enter (void)
|
||||
{
|
||||
#ifdef __linux__
|
||||
DIR *d;
|
||||
DBusInitialFDs *fds;
|
||||
|
||||
/* this is plain malloc so it won't interfere with leak checking */
|
||||
fds = malloc (sizeof (DBusInitialFDs));
|
||||
_dbus_assert (fds != NULL);
|
||||
|
||||
/* This works on Linux only */
|
||||
|
||||
if ((d = opendir ("/proc/self/fd")))
|
||||
{
|
||||
struct dirent *de;
|
||||
|
||||
while ((de = readdir(d)))
|
||||
{
|
||||
long l;
|
||||
char *e = NULL;
|
||||
int fd;
|
||||
|
||||
if (de->d_name[0] == '.')
|
||||
continue;
|
||||
|
||||
errno = 0;
|
||||
l = strtol (de->d_name, &e, 10);
|
||||
_dbus_assert (errno == 0 && e && !*e);
|
||||
|
||||
fd = (int) l;
|
||||
|
||||
if (fd < 3)
|
||||
continue;
|
||||
|
||||
if (fd == dirfd (d))
|
||||
continue;
|
||||
|
||||
if (fd >= FD_SETSIZE)
|
||||
{
|
||||
_dbus_verbose ("FD %d unexpectedly large; cannot track whether "
|
||||
"it is leaked\n", fd);
|
||||
continue;
|
||||
}
|
||||
|
||||
FD_SET (fd, &fds->set);
|
||||
}
|
||||
|
||||
closedir (d);
|
||||
}
|
||||
|
||||
return fds;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
_dbus_check_fdleaks_leave (DBusInitialFDs *fds)
|
||||
{
|
||||
#ifdef __linux__
|
||||
DIR *d;
|
||||
|
||||
/* This works on Linux only */
|
||||
|
||||
if ((d = opendir ("/proc/self/fd")))
|
||||
{
|
||||
struct dirent *de;
|
||||
|
||||
while ((de = readdir(d)))
|
||||
{
|
||||
long l;
|
||||
char *e = NULL;
|
||||
int fd;
|
||||
|
||||
if (de->d_name[0] == '.')
|
||||
continue;
|
||||
|
||||
errno = 0;
|
||||
l = strtol (de->d_name, &e, 10);
|
||||
_dbus_assert (errno == 0 && e && !*e);
|
||||
|
||||
fd = (int) l;
|
||||
|
||||
if (fd < 3)
|
||||
continue;
|
||||
|
||||
if (fd == dirfd (d))
|
||||
continue;
|
||||
|
||||
if (fd >= FD_SETSIZE)
|
||||
{
|
||||
_dbus_verbose ("FD %d unexpectedly large; cannot track whether "
|
||||
"it is leaked\n", fd);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (FD_ISSET (fd, &fds->set))
|
||||
continue;
|
||||
|
||||
_dbus_test_fatal ("file descriptor %i leaked in %s.", fd, __FILE__);
|
||||
}
|
||||
|
||||
closedir (d);
|
||||
}
|
||||
|
||||
free (fds);
|
||||
#else
|
||||
_dbus_assert (fds == NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* _dbus_test_main:
|
||||
* @argc: number of command-line arguments
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright 2002-2008 Red Hat Inc.
|
||||
* Copyright 2002-2009 Red Hat Inc.
|
||||
* Copyright 2011-2017 Collabora Ltd.
|
||||
* Copyright 2017 Endless Mobile, Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
|
@ -96,4 +97,8 @@ _DBUS_WARN_UNUSED_RESULT
|
|||
dbus_bool_t _dbus_test_append_different_username (DBusString *username);
|
||||
#endif
|
||||
|
||||
typedef struct DBusInitialFDs DBusInitialFDs;
|
||||
DBusInitialFDs *_dbus_check_fdleaks_enter (void);
|
||||
void _dbus_check_fdleaks_leave (DBusInitialFDs *fds);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue