Skip to content

Commit

Permalink
Add close on exec support for old platforms
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
simo5 authored and sgallagher committed Jun 21, 2012
1 parent 7767a7d commit 611b6fc
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/sss_client/nss_mc_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 611b6fc

Please sign in to comment.