Search in sources :

Example 1 with StringArray

use of com.sun.jna.StringArray in project hudson-2.x by hudson.

the class UnixLifecycle method restart.

@Override
public void restart() throws IOException, InterruptedException {
    Hudson h = Hudson.getInstance();
    if (h != null)
        h.cleanUp();
    // close all files upon exec, except stdin, stdout, and stderr
    int sz = LIBC.getdtablesize();
    for (int i = 3; i < sz; i++) {
        int flags = LIBC.fcntl(i, F_GETFD);
        if (flags < 0)
            continue;
        LIBC.fcntl(i, F_SETFD, flags | FD_CLOEXEC);
    }
    // exec to self
    LIBC.execv(Daemon.getCurrentExecutable(), new StringArray(args.toArray(new String[args.size()])));
    throw new IOException("Failed to exec " + LIBC.strerror(Native.getLastError()));
}
Also used : StringArray(com.sun.jna.StringArray) Hudson(hudson.model.Hudson) IOException(java.io.IOException)

Example 2 with StringArray

use of com.sun.jna.StringArray in project intellij-community by JetBrains.

the class NativeFileManager method getProcessesUsing.

public static List<Process> getProcessesUsing(File file) {
    List<Process> processes = new LinkedList<>();
    // If the DLL was not present (XP or other OS), do not try to find it again.
    if (ourFailed) {
        return processes;
    }
    try {
        IntByReference session = new IntByReference();
        char[] sessionKey = new char[Win32RestartManager.CCH_RM_SESSION_KEY + 1];
        int error = Win32RestartManager.INSTANCE.RmStartSession(session, 0, sessionKey);
        if (error != 0) {
            Runner.logger().warn("Unable to start restart manager session");
            return processes;
        }
        StringArray resources = new StringArray(new WString[] { new WString(file.toString()) });
        error = Win32RestartManager.INSTANCE.RmRegisterResources(session.getValue(), 1, resources, 0, Pointer.NULL, 0, null);
        if (error != 0) {
            Runner.logger().warn("Unable to register restart manager resource " + file.getAbsolutePath());
            return processes;
        }
        IntByReference procInfoNeeded = new IntByReference();
        Win32RestartManager.RmProcessInfo info = new Win32RestartManager.RmProcessInfo();
        Win32RestartManager.RmProcessInfo[] infos = (Win32RestartManager.RmProcessInfo[]) info.toArray(MAX_PROCESSES);
        IntByReference procInfo = new IntByReference(infos.length);
        error = Win32RestartManager.INSTANCE.RmGetList(session.getValue(), procInfoNeeded, procInfo, info, new LongByReference());
        if (error != 0) {
            Runner.logger().warn("Unable to get the list of processes using " + file.getAbsolutePath());
            return processes;
        }
        for (int i = 0; i < procInfo.getValue(); i++) {
            processes.add(new Process(infos[i].Process.dwProcessId, new String(infos[i].strAppName).trim()));
        }
        Win32RestartManager.INSTANCE.RmEndSession(session.getValue());
    } catch (Throwable t) {
        // Best effort approach, if no DLL is found ignore.
        ourFailed = true;
    }
    return processes;
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) WString(com.sun.jna.WString) LinkedList(java.util.LinkedList) WString(com.sun.jna.WString) StringArray(com.sun.jna.StringArray) LongByReference(com.sun.jna.ptr.LongByReference)

Aggregations

StringArray (com.sun.jna.StringArray)2 WString (com.sun.jna.WString)1 IntByReference (com.sun.jna.ptr.IntByReference)1 LongByReference (com.sun.jna.ptr.LongByReference)1 Hudson (hudson.model.Hudson)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1