BSONObj WaitProgram( const BSONObj& a, void* data ) { ProcessId pid = ProcessId::fromNative(singleArg( a ).numberInt()); int exit_code = -123456; // sentinel value wait_for_pid( pid, true, &exit_code ); registry.deletePid( pid ); return BSON( string("") << exit_code); }
BSONObj CheckProgram(const BSONObj& args, void* data) { ProcessId pid = ProcessId::fromNative(singleArg(args).numberInt()); bool isDead = wait_for_pid(pid, false); if (isDead) registry.deleteProgram(pid); return BSON(string("") << (!isDead)); }
BSONObj CheckProgram(const BSONObj& args, void* data) { ProcessId pid = ProcessId::fromNative(singleArg(args).numberInt()); int exit_code = -123456; // sentinel value bool isDead = wait_for_pid(pid, false, &exit_code); if (!isDead) { return BSON("" << BSON("alive" << true)); } return BSON("" << BSON("alive" << false << "exitCode" << exit_code)); }
int main() { printf("MAIN Begins!\n"); printf("Accessing global_var: %d\n", global_var); global_var = global_var + 1; singleArg(750); varTest(); return 0; }
BSONObj removeFile(const BSONObj& args, void* data) { BSONElement e = singleArg(args); bool found = false; boost::filesystem::path root(e.valuestrsafe()); if (boost::filesystem::exists(root)) { found = true; boost::filesystem::remove_all(root); } BSONObjBuilder b; b.appendBool("removed", found); return b.obj(); }
BSONObj cat(const BSONObj& args, void* data) { BSONElement e = singleArg(args); stringstream ss; ifstream f(e.valuestrsafe()); uassert(CANT_OPEN_FILE, "couldn't open file", f.is_open() ); streamsize sz = 0; while( 1 ) { char ch = 0; // slow...maybe change one day f.get(ch); if( ch == 0 ) break; ss << ch; sz += 1; uassert(13301, "cat() : file to big to load as a variable", sz < 1024 * 1024 * 16); } return BSON( "" << ss.str() ); }
BSONObj md5sumFile(const BSONObj& args, void* data) { BSONElement e = singleArg(args); stringstream ss; FILE* f = fopen(e.valuestrsafe(), "rb"); uassert(CANT_OPEN_FILE, "couldn't open file", f ); md5digest d; md5_state_t st; md5_init(&st); enum {BUFLEN = 4*1024}; char buffer[BUFLEN]; int bytes_read; while( (bytes_read = fread(buffer, 1, BUFLEN, f)) ) { md5_append( &st , (const md5_byte_t*)(buffer) , bytes_read ); } md5_finish(&st, d); return BSON( "" << digestToString( d ) ); }
BSONObj WaitProgram( const BSONObj& a, void* data ) { ProcessId pid = ProcessId::fromNative(singleArg( a ).numberInt()); BSONObj x = BSON( "" << wait_for_pid( pid ) ); registry.deletePid( pid ); return x; }
BSONObj WaitProgram( const BSONObj& a, void* data ) { int pid = singleArg( a ).numberInt(); BSONObj x = BSON( "" << wait_for_pid( pid ) ); registry.deletePid( pid ); return x; }