Status MetadataLoader::makeCollectionMetadata( const string& ns, const string& shard, const CollectionMetadata* oldMetadata, CollectionMetadata* metadata ) { Status status = initCollection( ns, shard, metadata ); if ( !status.isOK() || metadata->getKeyPattern().isEmpty() ) return status; return initChunks( ns, shard, oldMetadata, metadata ); }
void Coeff3DTriLin4x4 ( int *theDim, /* dimensions of this buffer */ float* resBuf, /* result buffer */ int *resDim, /* dimensions of this buffer */ double* mat, /* transformation matrix */ int index ) { char *proc = "Coeff3DTriLin4x4"; size_t first = 0; size_t last; int i; typeChunks chunks; _LinearCoefficientParam p; /* preparing parallelism */ first = 0; last = (size_t)resDim[2] * (size_t)resDim[1] * (size_t)resDim[0] - 1; initChunks( &chunks ); if ( buildChunks( &chunks, first, last, proc ) != 1 ) { if ( _verbose_ ) fprintf( stderr, "%s: unable to compute chunks\n", proc ); return; } p.theDim = theDim; p.resBuf = resBuf; p.resDim = resDim; p.mat = mat; p.index = index; if ( index < 0 ) index = 0; if ( index > 7 ) index = 7; for ( i=0; i<chunks.n_allocated_chunks; i++ ) chunks.data[i].parameters = (void*)(&p); /* processing */ if ( processChunks( &_Coeff3DTriLin4x4, &chunks, proc ) != 1 ) { if ( _verbose_ ) fprintf( stderr, "%s: unable to resample image\n", proc ); freeChunks( &chunks ); return; } freeChunks( &chunks ); }
int main(int argc, char **argv) { FdEventHandlerPtr listener; int i; int rc; int expire = 0, printConfig = 0; initAtoms(); CONFIG_VARIABLE(daemonise, CONFIG_BOOLEAN, "Run as a daemon"); CONFIG_VARIABLE(pidFile, CONFIG_ATOM, "File with pid of running daemon."); preinitChunks(); preinitLog(); preinitObject(); preinitIo(); preinitDns(); preinitServer(); preinitHttp(); preinitDiskcache(); preinitLocal(); preinitForbidden(); preinitSocks(); preinitOffline(); i = 1; while(i < argc) { if(argv[i][0] != '-') break; if(strcmp(argv[i], "--") == 0) { i++; break; } else if(strcmp(argv[i], "-h") == 0) { usage(argv[0]); exit(0); } else if(strcmp(argv[i], "-v") == 0) { printConfig = 1; i++; } else if(strcmp(argv[i], "-x") == 0) { expire = 1; i++; } else if(strcmp(argv[i], "-c") == 0) { i++; if(i >= argc) { usage(argv[0]); exit(1); } if(configFile) releaseAtom(configFile); configFile = internAtom(argv[i]); i++; } else { usage(argv[0]); exit(1); } } if(configFile) configFile = expandTilde(configFile); if(configFile == NULL) { configFile = expandTilde(internAtom("~/.polipo")); if(configFile) if(access(configFile->string, F_OK) < 0) { releaseAtom(configFile); configFile = NULL; } } if(configFile == NULL) { if(access("/etc/polipo/config", F_OK) >= 0) configFile = internAtom("/etc/polipo/config"); if(configFile && access(configFile->string, F_OK) < 0) { releaseAtom(configFile); configFile = NULL; } } rc = parseConfigFile(configFile); if(rc < 0) exit(1); while(i < argc) { rc = parseConfigLine(argv[i], "command line", 0, 0); if(rc < 0) exit(1); i++; } initChunks(); initLog(); initObject(); if(!expire && !printConfig) initEvents(); initIo(); initDns(); initHttp(); initServer(); initDiskcache(); initForbidden(); initSocks(); initOffline(); if(printConfig) { printConfigVariables(stdout, 0); exit(0); } if(expire) { expireDiskObjects(); exit(0); } if(daemonise) do_daemonise(logFile == NULL || logFile->length == 0); if(pidFile) writePid(pidFile->string); listener = create_listener(proxyAddress->string, proxyPort, httpAccept, NULL); if(!listener) { if(pidFile) unlink(pidFile->string); exit(1); } eventLoop(); if(pidFile) unlink(pidFile->string); return 0; }
bool MetadataLoader::initCollection(const string& ns, const string& shard, const CollectionManager* oldManager, CollectionManager* manager, string* errMsg) { // // Bring collection entry from the config server. // BSONObj collObj; { scoped_ptr<ScopedDbConnection> connPtr; try { connPtr.reset( ScopedDbConnection::getInternalScopedDbConnection(_configLoc.toString(), 30)); ScopedDbConnection& conn = *connPtr; collObj = conn->findOne(CollectionType::ConfigNS, QUERY(CollectionType::ns()<<ns)); } catch (const DBException& e) { *errMsg = str::stream() << "caught exception accessing the config servers " << causedBy(e); // We deliberately do not return connPtr to the pool, since it was involved // with the error here. return false; } connPtr->done(); } CollectionType collDoc; if (!collDoc.parseBSON(collObj, errMsg) || !collDoc.isValid(errMsg)) { return false; } // // Load or generate default chunks for collection config. // if (!collDoc.getKeyPattern().isEmpty()) { manager->_key = collDoc.getKeyPattern(); if(!initChunks(collDoc, ns, shard, oldManager, manager, errMsg)){ return false; } } else if(collDoc.getPrimary() == shard) { if (shard == "") { warning() << "shard not verified, assuming collection " << ns << " is unsharded on this shard" << endl; } manager->_key = BSONObj(); manager->_maxShardVersion = ChunkVersion(1, 0, collDoc.getEpoch()); manager->_maxCollVersion = manager->_maxShardVersion; } else { *errMsg = str::stream() << "collection " << ns << " does not have a shard key " << "and primary " << collDoc.getPrimary() << " does not match this shard " << shard; return false; } return true; }
int psiphonMain( int bindAll, int proxyPortParam, int localParentProxyPortParam) { FdEventHandlerPtr listener; initAtoms(); CONFIG_VARIABLE(daemonise, CONFIG_BOOLEAN, "Run as a daemon"); CONFIG_VARIABLE(pidFile, CONFIG_ATOM, "File with pid of running daemon."); preinitChunks(); preinitLog(); preinitObject(); preinitIo(); preinitDns(); preinitServer(); preinitHttp(); preinitDiskcache(); preinitLocal(); preinitForbidden(); preinitSocks(); const int MAX_SIZE = 80; char proxyAddressParamLine[MAX_SIZE]; char proxyPortParamLine[MAX_SIZE]; char localParentProxyPortParamLine[MAX_SIZE]; snprintf( proxyAddressParamLine, MAX_SIZE, (0 == bindAll) ? "proxyAddress=127.0.0.1" : "proxyAddress=0.0.0.0"); snprintf( proxyPortParamLine, MAX_SIZE, "proxyPort=%d", proxyPortParam); snprintf( localParentProxyPortParamLine, MAX_SIZE, "socksParentProxy=127.0.0.1:%d", localParentProxyPortParam); if (0 > parseConfigLine(proxyAddressParamLine, "psiphon", 0, 0) || 0 > parseConfigLine(proxyPortParamLine, "psiphon", 0, 0) || 0 > parseConfigLine(localParentProxyPortParamLine, "psiphon", 0, 0) || 0 > parseConfigLine("disableLocalInterface=true", "psiphon", 0, 0) || 0 > parseConfigLine("logLevel=1", "psiphon", 0, 0) /* Allow HTTPS on all ports */ || 0 > parseConfigLine("tunnelAllowedPorts=1-65535", "psiphon", 0, 0)) { return -1; } initChunks(); initLog(); initObject(); initEvents(); initIo(); initDns(); initHttp(); initServer(); initDiskcache(); initForbidden(); initSocks(); listener = create_listener( proxyAddress->string, proxyPort, httpAccept, NULL); if (!listener) { return -1; } eventLoop(); return 0; }