summaryrefslogtreecommitdiffstats
path: root/src/sss_client/nss_mc_common.c
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2012-06-21 13:18:31 -0400
committerStephen Gallagher <sgallagh@redhat.com>2012-06-21 15:26:53 -0400
commit611b6fcd3ae863bf36ae1fa4c0db89cfcdc76974 (patch)
tree7e7e1d545d6dabaac95d289e1d896f9bdbfbba0a /src/sss_client/nss_mc_common.c
parent7767a7d37685ee8863873d65fdbf21122d742a28 (diff)
downloadsssd-611b6fcd3ae863bf36ae1fa4c0db89cfcdc76974.tar.gz
sssd-611b6fcd3ae863bf36ae1fa4c0db89cfcdc76974.tar.xz
sssd-611b6fcd3ae863bf36ae1fa4c0db89cfcdc76974.zip
Add close on exec support for old platforms
Older platfroms like RHEL5 do not have support for O_CLOEXC and need an explicit fcntl after the fd is created. Add it conditionally so it can be clearly removed once we declared those platfroms obsolete and unsupported.
Diffstat (limited to 'src/sss_client/nss_mc_common.c')
-rw-r--r--src/sss_client/nss_mc_common.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/sss_client/nss_mc_common.c b/src/sss_client/nss_mc_common.c
index d910e17ba..400042eb1 100644
--- a/src/sss_client/nss_mc_common.c
+++ b/src/sss_client/nss_mc_common.c
@@ -83,6 +83,12 @@ errno_t sss_nss_check_header(struct sss_cli_mc_ctx *ctx)
return 0;
}
+#ifdef O_CLOEXEC
+#define SSS_MC_OPEN_FLAGS O_RDONLY|O_CLOEXEC
+#else
+#define SSS_MC_OPEN_FLAGS O_RDONLY
+#endif
+
errno_t sss_nss_mc_get_ctx(const char *name, struct sss_cli_mc_ctx *ctx)
{
struct stat fdstat;
@@ -106,10 +112,19 @@ errno_t sss_nss_mc_get_ctx(const char *name, struct sss_cli_mc_ctx *ctx)
goto done;
}
- ctx->fd = open(file, O_RDONLY|O_CLOEXEC);
+ ctx->fd = open(file, SSS_MC_OPEN_FLAGS);
if (ctx->fd == -1) {
ret = EIO;
goto done;
+#ifndef O_CLOEXEC
+ } else {
+ int v;
+
+ v = fcntl(ctx->fd, F_GETFD, 0);
+ /* we ignore an error, it's not fatal and there is nothing we
+ * can do about it anyways */
+ (void)fcntl(ctx->fd, F_SETFD, v | FD_CLOEXEC);
+#endif
}
ret = fstat(ctx->fd, &fdstat);