diff --git a/gearmand-0.32.etsy/configure.ac b/gearmand-0.32.etsy/configure.ac index d04bf9d..c02575f 100644 --- a/gearmand-0.32.etsy/configure.ac +++ b/gearmand-0.32.etsy/configure.ac @@ -111,6 +111,7 @@ AX_HAVE_LIBPQ PANDORA_HAVE_LIBTOKYOCABINET AC_FUNC_STRERROR_R SOCKET_SEND_FLAGS +FCNTL_FLAGS AX_HAVE_LIBHIREDIS AX_LIB_MYSQL([5.0]) diff --git a/gearmand-0.32.etsy/m4/fcntl_flags.m4 b/gearmand-0.32.etsy/m4/fcntl_flags.m4 new file mode 100644 index 0000000..cc19b85 --- /dev/null +++ b/gearmand-0.32.etsy/m4/fcntl_flags.m4 @@ -0,0 +1,26 @@ +dnl Copyright (C) 2012 Data Differential LLC +dnl Copyright (C) 2011 Keyur Govande +dnl This file is free software; Keyur Govande +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. +dnl --------------------------------------------------------------------------- +dnl Macro: FCNTL_FLAGS +dnl --------------------------------------------------------------------------- + +AC_DEFUN([FCNTL_FLAGS], +[ + AC_CACHE_CHECK([for O_CLOEXEC], [ac_cv_o_cloexec], [ + AC_LANG_PUSH([C]) + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -I${srcdir}" + + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include ], [ int flags= O_CLOEXEC])], [ac_cv_o_cloexec="yes"], [ac_cv_o_cloexec="no"]) + AC_LANG_POP + ]) + + AS_IF([test "x$ac_cv_o_cloexec" = "xyes"],[ AC_DEFINE(HAVE_O_CLOEXEC, 1, [Define to 1 if you have O_CLOEXEC defined])]) +]) + +dnl --------------------------------------------------------------------------- +dnl End Macro: FCNTL_FLAGS +dnl --------------------------------------------------------------------------- diff --git a/gearmand-0.32.etsy/util/pidfile.cc b/gearmand-0.32.etsy/util/pidfile.cc index f33b3b8..ebb2177 100644 --- a/gearmand-0.32.etsy/util/pidfile.cc +++ b/gearmand-0.32.etsy/util/pidfile.cc @@ -119,7 +119,12 @@ bool Pidfile::create() } int file; - if ((file = open(_filename.c_str(), O_CREAT|O_WRONLY|O_TRUNC|O_CLOEXEC, S_IRWXU|S_IRGRP|S_IROTH)) < 0) + int oflags = O_CREAT|O_WRONLY|O_TRUNC; +#ifdef HAVE_O_CLOEXEC + oflags = oflags | O_CLOEXEC; +#endif + + if ((file = open(_filename.c_str(), oflags, S_IRWXU|S_IRGRP|S_IROTH)) < 0) { std::stringstream error_stream; error_stream << "Could not open pid file for writing: " << _filename << "(" << strerror(errno) << ")";