summaryrefslogtreecommitdiff
path: root/tests/src
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2012-03-05 11:23:32 +1100
committerRobert Ancell <robert.ancell@canonical.com>2012-03-05 11:23:32 +1100
commit457e99f08bba531f8452894a76306dee92fa6393 (patch)
tree4e16dc4fccfe1d7158898f613a9461677d712680 /tests/src
parent5f146e0db50357c8cd3630834a090f1ec33b083a (diff)
downloadlightdm-457e99f08bba531f8452894a76306dee92fa6393.tar.gz
Stop file descriptors leaking into the session processes
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/libsystem.c19
-rw-r--r--tests/src/test-session.c22
2 files changed, 37 insertions, 4 deletions
diff --git a/tests/src/libsystem.c b/tests/src/libsystem.c
index d964e82f..1ebfb082 100644
--- a/tests/src/libsystem.c
+++ b/tests/src/libsystem.c
@@ -4,6 +4,7 @@
#include <pwd.h>
#include <security/pam_appl.h>
#include <unistd.h>
+#include <fcntl.h>
#define __USE_GNU
#include <dlfcn.h>
#ifdef __linux__
@@ -59,19 +60,31 @@ setuid (uid_t uid)
#ifdef __linux__
int
-open (const char *pathname, int flags, mode_t mode)
+open (const char *pathname, int flags, ...)
{
int (*_open) (const char * pathname, int flags, mode_t mode);
+ int mode = 0;
+
+ if (flags & O_CREAT)
+ {
+ va_list ap;
+ va_start (ap, flags);
+ mode = va_arg (ap, int);
+ va_end (ap);
+ }
_open = (int (*)(const char * pathname, int flags, mode_t mode)) dlsym (RTLD_NEXT, "open");
if (strcmp (pathname, "/dev/console") == 0)
{
if (console_fd < 0)
- console_fd = _open ("/dev/null", 0, 0);
+ {
+ console_fd = _open ("/dev/null", flags, mode);
+ fcntl (console_fd, F_SETFD, FD_CLOEXEC);
+ }
return console_fd;
}
else
- return _open(pathname, flags, mode);
+ return _open (pathname, flags, mode);
}
int
diff --git a/tests/src/test-session.c b/tests/src/test-session.c
index fcb68954..8df53d45 100644
--- a/tests/src/test-session.c
+++ b/tests/src/test-session.c
@@ -4,6 +4,7 @@
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
+#include <fcntl.h>
#include <xcb/xcb.h>
#include <glib.h>
#include <glib-object.h>
@@ -11,8 +12,12 @@
#include "status.h"
+static GString *open_fds;
+
static GKeyFile *config;
+static xcb_connection_t *connection;
+
static void
quit_cb (int signum)
{
@@ -103,13 +108,28 @@ request_cb (const gchar *request)
g_clear_error (&error);
}
g_free (r);
+
+ r = g_strdup_printf ("SESSION %s LIST-UNKNOWN-FILE-DESCRIPTORS", getenv ("DISPLAY"));
+ if (strcmp (request, r) == 0)
+ status_notify ("SESSION %s LIST-UNKNOWN-FILE-DESCRIPTORS FDS=%s", getenv ("DISPLAY"), open_fds->str);
+ g_free (r);
}
int
main (int argc, char **argv)
{
GMainLoop *loop;
- xcb_connection_t *connection;
+ int fd, open_max;
+
+ open_fds = g_string_new ("");
+ open_max = sysconf (_SC_OPEN_MAX);
+ for (fd = STDERR_FILENO + 1; fd < open_max; fd++)
+ {
+ if (fcntl (fd, F_GETFD) >= 0)
+ g_string_append_printf (open_fds, "%d,", fd);
+ }
+ if (g_str_has_suffix (open_fds->str, ","))
+ open_fds->str[strlen (open_fds->str) - 1] = '\0';
signal (SIGINT, quit_cb);
signal (SIGTERM, quit_cb);