~robert-ancell/lightdm/xorg-displayfd

« back to all changes in this revision

Viewing changes to tests/src/libsystem.c

  • Committer: Robert Ancell
  • Date: 2012-03-05 00:23:32 UTC
  • Revision ID: robert.ancell@canonical.com-20120305002332-eox30d8k6gb70qrc
Stop file descriptors leaking into the session processes

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#include <pwd.h>
5
5
#include <security/pam_appl.h>
6
6
#include <unistd.h>
 
7
#include <fcntl.h>
7
8
#define __USE_GNU
8
9
#include <dlfcn.h>
9
10
#ifdef __linux__
59
60
 
60
61
#ifdef __linux__
61
62
int
62
 
open (const char *pathname, int flags, mode_t mode)
 
63
open (const char *pathname, int flags, ...)
63
64
{
64
65
    int (*_open) (const char * pathname, int flags, mode_t mode);
 
66
    int mode = 0;
 
67
  
 
68
    if (flags & O_CREAT)
 
69
    {
 
70
        va_list ap;
 
71
        va_start (ap, flags);
 
72
        mode = va_arg (ap, int);
 
73
        va_end (ap);
 
74
    }
65
75
 
66
76
    _open = (int (*)(const char * pathname, int flags, mode_t mode)) dlsym (RTLD_NEXT, "open");      
67
77
    if (strcmp (pathname, "/dev/console") == 0)
68
78
    {
69
79
        if (console_fd < 0)
70
 
            console_fd = _open ("/dev/null", 0, 0);
 
80
        {
 
81
            console_fd = _open ("/dev/null", flags, mode);
 
82
            fcntl (console_fd, F_SETFD, FD_CLOEXEC);
 
83
        }
71
84
        return console_fd;
72
85
    }
73
86
    else
74
 
        return _open(pathname, flags, mode);
 
87
        return _open (pathname, flags, mode);
75
88
}
76
89
 
77
90
int