Summary:
/proc may be unavailable in restricted environments, which can
cause pthread_getattr_np to fail. This diff adds checking to the return
code from that function.
Reviewed By: yfeldblum
Differential Revision:
D6473789
fbshipit-source-id:
de016d32f29edf8410808dfb491987692f39e768
#include <folly/portability/PThread.h>
#include <folly/portability/SysMman.h>
#include <folly/portability/Unistd.h>
#include <folly/portability/PThread.h>
#include <folly/portability/SysMman.h>
#include <folly/portability/Unistd.h>
+#include <folly/synchronization/CallOnce.h>
#include <limits.h>
#include <stdio.h>
#include <limits.h>
#include <stdio.h>
}
static void fetchStackLimits() {
}
static void fetchStackLimits() {
- pthread_getattr_np(pthread_self(), &attr);
+ if ((err = pthread_getattr_np(pthread_self(), &attr))) {
+ // some restricted environments can't access /proc
+ static folly::once_flag flag;
+ folly::call_once(flag, [err]() {
+ LOG(WARNING) << "pthread_getaddr_np failed errno=" << err;
+ });
+
+ tls_stackSize = 1;
+ return;
+ }
SCOPE_EXIT { pthread_attr_destroy(&attr); };
void* addr;
size_t rawSize;
SCOPE_EXIT { pthread_attr_destroy(&attr); };
void* addr;
size_t rawSize;
if ((err = pthread_attr_getstack(&attr, &addr, &rawSize))) {
// unexpected, but it is better to continue in prod than do nothing
FB_LOG_EVERY_MS(ERROR, 10000) << "pthread_attr_getstack error " << err;
if ((err = pthread_attr_getstack(&attr, &addr, &rawSize))) {
// unexpected, but it is better to continue in prod than do nothing
FB_LOG_EVERY_MS(ERROR, 10000) << "pthread_attr_getstack error " << err;