bring back ServiceConfig.argv
This commit is contained in:
parent
0b876faf31
commit
7579374e47
|
@ -7,12 +7,14 @@
|
||||||
#include "sigar.h"
|
#include "sigar.h"
|
||||||
#include "sigar_private.h"
|
#include "sigar_private.h"
|
||||||
#include "sigar_os.h"
|
#include "sigar_os.h"
|
||||||
|
#include <shellapi.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define STRING_SIG "Ljava/lang/String;"
|
#define STRING_SIG "Ljava/lang/String;"
|
||||||
|
#define ASTRING_SIG "[" STRING_SIG
|
||||||
|
|
||||||
#define SERVICE_SetStringField(field, str) \
|
#define SERVICE_SetStringField(field, str) \
|
||||||
id = env->GetFieldID(cls, field, STRING_SIG); \
|
id = env->GetFieldID(cls, field, STRING_SIG); \
|
||||||
|
@ -307,6 +309,10 @@ JNIEXPORT jboolean SIGAR_JNI(win32_Service_QueryServiceConfig)
|
||||||
jclass cls = env->GetObjectClass(obj);
|
jclass cls = env->GetObjectClass(obj);
|
||||||
jstring value;
|
jstring value;
|
||||||
HINSTANCE lib;
|
HINSTANCE lib;
|
||||||
|
LPWSTR *argv;
|
||||||
|
int argc;
|
||||||
|
jclass stringclass =
|
||||||
|
env->FindClass("java/lang/String");
|
||||||
|
|
||||||
if (!QueryServiceConfig((SC_HANDLE)handle, config,
|
if (!QueryServiceConfig((SC_HANDLE)handle, config,
|
||||||
sizeof(buffer), &bytes))
|
sizeof(buffer), &bytes))
|
||||||
|
@ -323,12 +329,22 @@ JNIEXPORT jboolean SIGAR_JNI(win32_Service_QueryServiceConfig)
|
||||||
|
|
||||||
SERVICE_SetStringField("path", config->lpBinaryPathName);
|
SERVICE_SetStringField("path", config->lpBinaryPathName);
|
||||||
|
|
||||||
SIGAR_W2A(config->lpBinaryPathName, exe, sizeof(exe));
|
if ((argv = CommandLineToArgvW(config->lpBinaryPathName, &argc))) {
|
||||||
ptr = sigar_service_exe_get(NULL, exe, 0);
|
int i;
|
||||||
|
jobjectArray jargv =
|
||||||
|
env->NewObjectArray(argc, stringclass, 0);
|
||||||
|
|
||||||
env->SetObjectField(obj,
|
for (i=0; i<argc; i++) {
|
||||||
env->GetFieldID(cls, "exe", STRING_SIG),
|
jstring jstr =
|
||||||
env->NewStringUTF(ptr));
|
env->NewString((const jchar *)argv[i], lstrlen(argv[i]));
|
||||||
|
env->SetObjectArrayElement(jargv, i, jstr);
|
||||||
|
}
|
||||||
|
|
||||||
|
id = env->GetFieldID(cls, "argv", ASTRING_SIG);
|
||||||
|
|
||||||
|
env->SetObjectField(obj, id, jargv);
|
||||||
|
LocalFree(argv);
|
||||||
|
}
|
||||||
|
|
||||||
SERVICE_SetStringField("loadOrderGroup", config->lpLoadOrderGroup);
|
SERVICE_SetStringField("loadOrderGroup", config->lpLoadOrderGroup);
|
||||||
|
|
||||||
|
@ -337,15 +353,12 @@ JNIEXPORT jboolean SIGAR_JNI(win32_Service_QueryServiceConfig)
|
||||||
if (config->lpDependencies) {
|
if (config->lpDependencies) {
|
||||||
/* first pass just get num for NewObjectArray */
|
/* first pass just get num for NewObjectArray */
|
||||||
int num = to_array(env, config->lpDependencies, NULL);
|
int num = to_array(env, config->lpDependencies, NULL);
|
||||||
jclass stringclass =
|
|
||||||
env->FindClass("java/lang/String");
|
|
||||||
jobjectArray dependencies =
|
jobjectArray dependencies =
|
||||||
env->NewObjectArray(num, stringclass, 0);
|
env->NewObjectArray(num, stringclass, 0);
|
||||||
|
|
||||||
to_array(env, config->lpDependencies, dependencies);
|
to_array(env, config->lpDependencies, dependencies);
|
||||||
|
|
||||||
id = env->GetFieldID(cls, "dependencies",
|
id = env->GetFieldID(cls, "dependencies", ASTRING_SIG);
|
||||||
"[" STRING_SIG);
|
|
||||||
|
|
||||||
env->SetObjectField(obj, id, dependencies);
|
env->SetObjectField(obj, id, dependencies);
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,6 +108,7 @@ public class ServiceConfig {
|
||||||
int errorControl;
|
int errorControl;
|
||||||
String path;
|
String path;
|
||||||
String exe;
|
String exe;
|
||||||
|
String[] argv;
|
||||||
String loadOrderGroup;
|
String loadOrderGroup;
|
||||||
int tagId;
|
int tagId;
|
||||||
String[] dependencies;
|
String[] dependencies;
|
||||||
|
@ -143,7 +144,17 @@ public class ServiceConfig {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String[] getArgv() {
|
||||||
|
return this.argv;
|
||||||
|
}
|
||||||
|
|
||||||
public String getExe() {
|
public String getExe() {
|
||||||
|
if (this.exe == null) {
|
||||||
|
String[] argv = getArgv();
|
||||||
|
if ((argv != null) && (argv.length != 0)) {
|
||||||
|
this.exe = argv[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
return this.exe;
|
return this.exe;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue