[SERVER-2587] clean up places where we use __linux__ but mean posix Created: 18/Feb/11  Updated: 29/Aug/11  Resolved: 19/Apr/11

Status: Closed
Project: Core Server
Component/s: Build
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Eliot Horowitz (Inactive) Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

some examples:
bson/oid.cpp
db/nonce.cpp



 Comments   
Comment by Mathias Stearn [ 19/Apr/11 ]

1) we don't currently directly test for POSIX anywhere. We use !defined(_WIN32) to mean POSIX.

2) I think all 11 current uses of _linux_ are correct, but there are three questionable cases in oid.cpp and nonce.cpp:

unsigned OID::ourPid()

{ unsigned pid; #if defined(_WIN32) pid = (unsigned short) GetCurrentProcessId(); #elif defined(__linux__) || defined(__APPLE__) || defined(__sunos__) pid = (unsigned short) getpid(); #else pid = (unsigned short) security.getNonce(); #endif return pid; }

#if defined(_linux) || defined(sunos) || defined(APPLE_)
_devrandom = new ifstream("/dev/urandom", ios::binary|ios::in);
massert( 10353 , "can't open dev/urandom", _devrandom->is_open() );
#elif defined(_WIN32)
srand(curTimeMicros());
#else
srandomdev();
#endif

#if defined(_linux) || defined(sunos) || defined(APPLE_)
_devrandom->read((char*)&n, sizeof);
massert( 10355 , "devrandom failed", !_devrandom->fail());
#elif defined(_WIN32)
unsigned a=0, b=0;
assert( rand_s(&a) == 0 );
assert( rand_s(&b) == 0 );
n = (((unsigned long long)a)<<32) | b;
#else
n = (((unsigned long long)random())<<32) | random();
#endif

Please reopen if you want any of these changed.

Generated at Thu Feb 08 03:00:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.