bool _Insert(BSTNode<K,V>*& root, const K& key, const V& data) { if (root == NULL) { root = new BSTNode<K,V>(key, data); return true; } else { if (root->_key > key) { return _Insert(root->_left, key, data); } else if (root->_key < key) { return _Insert(root->_right, key, data); } else { return false; } } }
void insert(const_iterator _Where, _Iter _First, _Iter _Last) { // insert [_First, _Last) at _Where _Insert(_Where, _First, _Last, _Iter_cat(_First)); }
bool Insert_R(const K& key, const V& data) { return _Insert(_root, key, data); }
int PreExec_Exec( PreExec* self, const char* programPath, uid_t uid, uid_t gid) { char path[PAL_MAX_PATH_SIZE]; char key[PAL_MAX_PATH_SIZE]; char uidBuf[11]; const char* uidStr; char gidBuf[11]; const char* gidStr; /* If no pre-exec program, nothing to do */ if (programPath == NULL) return 0; /* Form the UID string */ { size_t dummy; uidStr = Uint32ToStr(uidBuf, (PAL_Uint32)uid, &dummy); } /* Form the GID string */ { size_t dummy; gidStr = Uint32ToStr(gidBuf, (PAL_Uint32)gid, &dummy); } /* Form a hash key from PREEXEC+UID+GID */ { key[0] = '\0'; Strlcat(key, programPath, PAL_MAX_PATH_SIZE); Strlcat(key, "+", PAL_MAX_PATH_SIZE); Strlcat(key, uidStr, PAL_MAX_PATH_SIZE); Strlcat(key, "+", PAL_MAX_PATH_SIZE); Strlcat(key, gidStr, PAL_MAX_PATH_SIZE); } /* If key already in cache, then return without doing anything */ { static pthread_mutex_t s_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_lock(&s_mutex); if (_Contains(&self->cache, key)) { pthread_mutex_unlock(&s_mutex); return 0; } /* Add key to cache */ _Insert(&self->cache, key); pthread_mutex_unlock(&s_mutex); } /* Form the full path of the pre-exec program */ { const char* bindir = OMI_GetPath(ID_BINDIR); path[0] = '\0'; if (bindir) { Strlcat(path, bindir, PAL_MAX_PATH_SIZE); Strlcat(path, "/", PAL_MAX_PATH_SIZE); } Strlcat(path, programPath, PAL_MAX_PATH_SIZE); } /* Execute and wait on the pre-exec program to exit */ _BlockSIGCHLD(); { pid_t pid = _Exec(path, uidStr, gidStr); if (pid == -1) { _UnblockSIGCHLD(); trace_PreExecFailed(path); return -1; } { pid_t r; int status; r = waitpid(pid, &status, 0); if (r != pid || WEXITSTATUS(status) != 0) { _UnblockSIGCHLD(); trace_PreExecFailed(path); return -1; } } } _UnblockSIGCHLD(); trace_PreExecOk(path); return 0; }