int main( int argc, char *argv[] ) { if ( argc != 2 ) { mbedtls_printf( USAGE, argv[0] ); return( MBEDTLS_EXIT_FAILURE ); } return( query_config( argv[1] ) ); }
void partition_resolver_simple::call(request_context_ptr&& request, bool from_meta_ack) { int pindex = request->partition_index; if (-1 != pindex) { // fill target address if possible rpc_address addr; auto err = get_address(pindex, addr); // target address known if (err == ERR_OK) { end_request(std::move(request), ERR_OK, addr); return; } } auto nts = dsn_now_us(); // timeout will happen very soon, no way to get the rpc call done if (nts + 100 >= request->timeout_ts_us) // within 100 us { end_request(std::move(request), ERR_TIMEOUT, rpc_address()); return; } // delay 1 second for further config query if (from_meta_ack) { tasking::enqueue( LPC_REPLICATION_DELAY_QUERY_CONFIG, this, [=, req2 = request]() mutable { call(std::move(req2), false); }, 0, std::chrono::seconds(1) ); return; } // calculate timeout int timeout_ms; if (nts + 1000 >= request->timeout_ts_us) timeout_ms = 1; else timeout_ms = static_cast<int>(request->timeout_ts_us - nts) / 1000; // init timeout timer only when necessary { zauto_lock l(request->lock); if (request->timeout_timer == nullptr) { request->timeout_timer = tasking::enqueue( LPC_REPLICATION_CLIENT_REQUEST_TIMEOUT, this, [=, req2 = request]() mutable { on_timeout(std::move(req2)); }, 0, std::chrono::milliseconds(timeout_ms) ); } } { zauto_lock l(_requests_lock); if (-1 != pindex) { // put into pending queue of querying target partition auto it = _pending_requests.find(pindex); if (it == _pending_requests.end()) { auto pc = new partition_context(); it = _pending_requests.emplace(pindex, pc).first; } it->second->requests.push_back(std::move(request)); // init configuration query task if necessary if (nullptr == it->second->query_config_task) { it->second->query_config_task = query_config(pindex); } } else { _pending_requests_before_partition_count_unknown.push_back(std::move(request)); if (_pending_requests_before_partition_count_unknown.size() == 1) { _query_config_task = query_config(pindex); } } } }
JNIEXPORT jboolean SIGAR_JNI(win32_Service_QueryServiceConfig) (JNIEnv *env, jclass, jlong handle, jobject obj) { char buffer[8192]; /* 8k is max size from mdsn docs */ char exe[SIGAR_CMDLINE_MAX], *ptr; LPQUERY_SERVICE_CONFIG config = (LPQUERY_SERVICE_CONFIG)buffer; DWORD bytes; jfieldID id; jclass cls = env->GetObjectClass(obj); jstring value; HINSTANCE lib; LPWSTR *argv; int argc; jclass stringclass = env->FindClass("java/lang/String"); if (!QueryServiceConfig((SC_HANDLE)handle, config, sizeof(buffer), &bytes)) { win32_throw_last_error(env); return JNI_FALSE; } SERVICE_SetIntField("type", config->dwServiceType); SERVICE_SetIntField("startType", config->dwStartType); SERVICE_SetIntField("errorControl", config->dwErrorControl); SERVICE_SetStringField("path", config->lpBinaryPathName); if ((argv = CommandLineToArgvW(config->lpBinaryPathName, &argc))) { int i; jobjectArray jargv = env->NewObjectArray(argc, stringclass, 0); if (env->ExceptionCheck()) { LocalFree(argv); return JNI_FALSE; } for (i=0; i<argc; i++) { jstring jstr = env->NewString((const jchar *)argv[i], lstrlen(argv[i])); env->SetObjectArrayElement(jargv, i, jstr); if (env->ExceptionCheck()) { LocalFree(argv); return JNI_FALSE; } } id = env->GetFieldID(cls, "argv", ASTRING_SIG); env->SetObjectField(obj, id, jargv); LocalFree(argv); } SERVICE_SetStringField("loadOrderGroup", config->lpLoadOrderGroup); SERVICE_SetIntField("tagId", config->dwTagId); if (config->lpDependencies) { /* first pass just get num for NewObjectArray */ jobjectArray dependencies; int num = to_array(env, config->lpDependencies, NULL); if (num < 0) { return JNI_FALSE; /* Exception thrown */ } dependencies = env->NewObjectArray(num, stringclass, 0); if (env->ExceptionCheck()) { return JNI_FALSE; } to_array(env, config->lpDependencies, dependencies); if (num < 0) { return JNI_FALSE; /* Exception thrown */ } id = env->GetFieldID(cls, "dependencies", ASTRING_SIG); env->SetObjectField(obj, id, dependencies); } SERVICE_SetStringField("startName", config->lpServiceStartName); SERVICE_SetStringField("displayName", config->lpDisplayName); if ((lib = LoadLibrary(L"advapi32"))) { LPSERVICE_DESCRIPTION desc = (LPSERVICE_DESCRIPTION)buffer; QueryServiceConfig2_func_t query_config = (QueryServiceConfig2_func_t) GetProcAddress(lib, "QueryServiceConfig2W"); if (query_config) { BOOL retval = query_config((SC_HANDLE)handle, SERVICE_CONFIG_DESCRIPTION, desc, sizeof(buffer), &bytes); if (retval && (desc->lpDescription != NULL)) { SERVICE_SetStringField("description", desc->lpDescription); } } FreeLibrary(lib); } return JNI_TRUE; }