X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fbasic%2Ffd-util.c;h=3eb3324b57bc2ae53ecbca7e4baf65be3c3f50ab;hb=6414babd8b4554e19f9ac7826cb7e82ef6b3435c;hp=d1b1db3a4ddc83b8c73ecf7c3ff51a19885d2fef;hpb=b96ed50e3493103d075ff2ce4c3fbad8f26b2e22;p=elogind.git
diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c
index d1b1db3a4..3eb3324b5 100644
--- a/src/basic/fd-util.c
+++ b/src/basic/fd-util.c
@@ -1,5 +1,3 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
/***
This file is part of systemd.
@@ -19,9 +17,18 @@
along with systemd; If not, see .
***/
-#include "dirent-util.h"
+#include
+#include
+#include
+#include
+#include
+#include
+
#include "fd-util.h"
+#include "macro.h"
+#include "missing.h"
#include "parse-util.h"
+#include "path-util.h"
#include "socket-util.h"
#include "util.h"
@@ -120,6 +127,7 @@ FILE* safe_fclose(FILE *f) {
return NULL;
}
+#if 0 /// UNNEEDED by elogind
DIR* safe_closedir(DIR *d) {
if (d) {
@@ -130,6 +138,7 @@ DIR* safe_closedir(DIR *d) {
return NULL;
}
+#endif // 0
int fd_nonblock(int fd, bool nonblock) {
int flags, nflags;
@@ -177,6 +186,12 @@ int fd_cloexec(int fd, bool cloexec) {
return 0;
}
+void stdio_unset_cloexec(void) {
+ fd_cloexec(STDIN_FILENO, false);
+ fd_cloexec(STDOUT_FILENO, false);
+ fd_cloexec(STDERR_FILENO, false);
+}
+
_pure_ static bool fd_in_set(int fd, const int fdset[], unsigned n_fdset) {
unsigned i;
@@ -222,7 +237,7 @@ int close_all_fds(const int except[], unsigned n_except) {
while ((de = readdir(d))) {
int fd = -1;
- if (hidden_file(de->d_name))
+ if (hidden_or_backup_file(de->d_name))
continue;
if (safe_atoi(de->d_name, &fd) < 0)
@@ -248,6 +263,7 @@ int close_all_fds(const int except[], unsigned n_except) {
return r;
}
+#if 0 /// UNNEEDED by elogind
int same_fd(int a, int b) {
struct stat sta, stb;
pid_t pid;
@@ -349,3 +365,18 @@ bool fdname_is_valid(const char *s) {
return p - s < 256;
}
+
+int fd_get_path(int fd, char **ret) {
+ char procfs_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
+ int r;
+
+ xsprintf(procfs_path, "/proc/self/fd/%i", fd);
+
+ r = readlink_malloc(procfs_path, ret);
+
+ if (r == -ENOENT) /* If the file doesn't exist the fd is invalid */
+ return -EBADF;
+
+ return r;
+}
+#endif // 0