fdset.c revision b30e2f4c18ad81b04e4314fd191a5d458553773c
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
#include "set.h"
#include "util.h"
#include "macro.h"
#include "fdset.h"
#define MAKE_FDSET(s) ((FDSet*) s)
/* Make sure we can distuingish fd 0 and NULL */
}
void fdset_free(FDSet *s) {
void *p;
while ((p = set_steal_first(MAKE_SET(s)))) {
/* Valgrind's fd might have ended up in this set here,
* due to fdset_new_fill(). We'll ignore all failures
* here, so that the EBADFD that valgrind will return
* us on close() doesn't influence us */
/* When reloading duplicates of the private bus
* connection fds and suchlike are closed here, which
* has no effect at all, since they are only
* duplicates. So don't be surprised about these log
* messages. */
close_nointr(PTR_TO_FD(p));
}
}
assert(s);
}
int copy, r;
assert(s);
return -errno;
return r;
}
return copy;
}
assert(s);
}
assert(s);
}
DIR *d;
int r = 0;
FDSet *s;
/* Creates an fdsets and fills in all currently open file
* descriptors. */
return -errno;
if (!(s = fdset_new())) {
r = -ENOMEM;
goto finish;
}
int fd = -1;
continue;
goto finish;
if (fd < 3)
continue;
continue;
goto finish;
}
r = 0;
*_s = s;
s = NULL;
closedir(d);
/* We won't close the fds here! */
if (s)
return r;
}
Iterator i;
void *p;
int r;
if ((r = fd_cloexec(PTR_TO_FD(p), b)) < 0)
return r;
return 0;
}