void add_hosts(Vector<SimpleCpcClient*> & hosts, BaseString list){ Vector<BaseString> split; list.split(split); for(size_t i = 0; i<split.size(); i++){ add_host(hosts, split[i]); } }
bool Logger::addHandler(const BaseString &logstring, int *err, int len, char* errStr) { size_t i; Vector<BaseString> logdest; Vector<LogHandler *>loghandlers; DBUG_ENTER("Logger::addHandler"); logstring.split(logdest, ";"); for(i = 0; i < logdest.size(); i++) { DBUG_PRINT("info",("adding: %s",logdest[i].c_str())); Vector<BaseString> v_type_args; logdest[i].split(v_type_args, ":", 2); BaseString type(v_type_args[0]); BaseString params; if(v_type_args.size() >= 2) params = v_type_args[1]; LogHandler *handler = NULL; #ifndef NDB_WIN32 if(type == "SYSLOG") { handler = new SysLogHandler(); } else #endif if(type == "FILE") handler = new FileLogHandler(); else if(type == "CONSOLE") handler = new ConsoleLogHandler(); if(handler == NULL) { snprintf(errStr,len,"Could not create log destination: %s", logdest[i].c_str()); DBUG_RETURN(false); } if(!handler->parseParams(params)) { *err= handler->getErrorCode(); if(handler->getErrorStr()) strncpy(errStr, handler->getErrorStr(), len); DBUG_RETURN(false); } loghandlers.push_back(handler); } for(i = 0; i < loghandlers.size(); i++) addHandler(loghandlers[i]); DBUG_RETURN(true); /* @todo handle errors */ }
void add_host(Vector<SimpleCpcClient*> & hosts, BaseString tmp){ Vector<BaseString> split; tmp.split(split, ":"); short port = g_settings.m_port; if(split.size() > 1) port = atoi(split[1].c_str()); hosts.push_back(new SimpleCpcClient(split[0].c_str(), port)); }
static int set_ulimit(const BaseString & pair){ #ifdef HAVE_GETRLIMIT errno = 0; Vector<BaseString> list; pair.split(list, ":"); if(list.size() != 2){ logger.error("Unable to process ulimit: split >%s< list.size()=%d", pair.c_str(), list.size()); return -1; } int res; rlim_t value = RLIM_INFINITY; if(!(list[1].trim() == "unlimited")){ value = atoi(list[1].c_str()); } struct rlimit rlp; #define _RLIMIT_FIX(x) { res = getrlimit(x,&rlp); if(!res){ rlp.rlim_cur = value; res = setrlimit(x, &rlp); }} if(list[0].trim() == "c"){ _RLIMIT_FIX(RLIMIT_CORE); } else if(list[0] == "d"){ _RLIMIT_FIX(RLIMIT_DATA); } else if(list[0] == "f"){ _RLIMIT_FIX(RLIMIT_FSIZE); } else if(list[0] == "n"){ _RLIMIT_FIX(RLIMIT_NOFILE); } else if(list[0] == "s"){ _RLIMIT_FIX(RLIMIT_STACK); } else if(list[0] == "t"){ _RLIMIT_FIX(RLIMIT_CPU); } else { res= -11; errno = EINVAL; } if(res){ logger.error("Unable to process ulimit: %s res=%d error=%d(%s)", pair.c_str(), res, errno, strerror(errno)); return -1; } #endif return 0; }
BaseString set_env_var(const BaseString& existing, const BaseString& name, const BaseString& value) { /* Split existing on space * (may have issues with env vars with spaces) * Split assignments on = * Where name == name, output new value */ BaseString newEnv; Vector<BaseString> assignments; int assignmentCount = existing.split(assignments, BaseString(" ")); for (int i=0; i < assignmentCount; i++) { Vector<BaseString> terms; int termCount = assignments[i].split(terms, BaseString("=")); if (termCount) { if (strcmp(name.c_str(), terms[0].c_str()) == 0) { /* Found element */ newEnv.append(name); newEnv.append('='); newEnv.append(value); } else { newEnv.append(assignments[i]); } } newEnv.append(' '); } return newEnv; }
bool call(const char* cmd, const Properties& args, const char* cmd_reply, Properties& reply, const char* bulk = NULL, bool name_value_pairs = true){ if (!is_connected()){ error("call: not connected"); return false; } SocketOutputStream out(socket()); if (out.println(cmd)){ error("call: println failed at line %d", __LINE__); return false; } Properties::Iterator iter(&args); const char *name; while((name = iter.next()) != NULL) { PropertiesType t; Uint32 val_i; Uint64 val_64; BaseString val_s; args.getTypeOf(name, &t); switch(t) { case PropertiesType_Uint32: args.get(name, &val_i); if (out.println("%s: %d", name, val_i)){ error("call: println failed at line %d", __LINE__); return false; } break; case PropertiesType_Uint64: args.get(name, &val_64); if (out.println("%s: %Ld", name, val_64)){ error("call: println failed at line %d", __LINE__); return false; } break; case PropertiesType_char: args.get(name, val_s); if (out.println("%s: %s", name, val_s.c_str())){ error("call: println failed at line %d", __LINE__); return false; } break; default: case PropertiesType_Properties: /* Illegal */ abort(); break; } } // Emtpy line terminates argument list if (out.print("\n")){ error("call: print('\n') failed at line %d", __LINE__); return false; } // Send any bulk data if (bulk && out.println(bulk)){ error("call: print('<bulk>') failed at line %d", __LINE__); return false; } BaseString buf; SocketInputStream2 in(socket()); if (cmd_reply) { // Read the reply header and compare against "cmd_reply" if (!in.gets(buf)){ error("call: could not read reply command"); return false; } // 1. Check correct reply header if (buf != cmd_reply){ error("call: unexpected reply command, expected: '%s', got '%s'", cmd_reply, buf.c_str()); return false; } } // 2. Read lines until empty line int line = 1; while(in.gets(buf)){ // empty line -> end of reply if (buf == "") return true; if (name_value_pairs) { // 3a. Read colon separated name value pair, split // the name value pair on first ':' Vector<BaseString> name_value_pair; if (buf.split(name_value_pair, ":", 2) != 2){ error("call: illegal name value pair '%s' received", buf.c_str()); return false; } reply.put(name_value_pair[0].trim(" ").c_str(), name_value_pair[1].trim(" ").c_str()); } else { // 3b. Not name value pair, save the line into "reply" // using unique key reply.put("line", line++, buf.c_str()); } } error("call: should never come here"); reply.print(); abort(); return false; }