@Override public boolean canWork() { try { if (File.pathSeparatorChar!=':') return false; // quick test to reject non-Unix without loading all the rest of the classes args = JavaVMArguments.current(); // go through the whole motion to make sure all the relevant classes are loaded now LIBC.getdtablesize(); int v = LIBC.fcntl(99999, F_GETFD); LIBC.fcntl(99999, F_SETFD, v); Daemon.getCurrentExecutable(); LIBC.execv("positively/no/such/executable", new StringArray(new String[]{"a","b","c"})); return true; } catch (UnsupportedOperationException | LinkageError | IOException e) { LOGGER.log(FINE, getClass()+" unsuitable", e); return false; } }
public void restart() throws Exception { // 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 String exe = Daemon.getCurrentExecutable(); LIBC.execv(exe, new StringArray(args.toArray(new String[args.size()]))); throw new IOException("Failed to exec '" + exe + "' " + LIBC.strerror(Native.getLastError())); }
@Override public boolean canWork() { try { if (File.pathSeparatorChar!=':') return false; // quick test to reject non-Unix without loading all the rest of the classes args = JavaVMArguments.current(); // go through the whole motion to make sure all the relevant classes are loaded now LIBC.getdtablesize(); int v = LIBC.fcntl(99999, F_GETFD); LIBC.fcntl(99999, F_SETFD, v); Daemon.getCurrentExecutable(); LIBC.execv("positively/no/such/executable", new StringArray(new String[]{"a","b","c"})); return true; } catch (UnsupportedOperationException e) { LOGGER.log(FINE, getClass()+" unsuitable", e); return false; } catch (LinkageError e) { LOGGER.log(FINE, getClass()+" unsuitable", e); return false; } catch (IOException e) { LOGGER.log(FINE, getClass()+" unsuitable", e); return false; } }
public void restart() throws Exception { // 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 String exe = Daemon.getCurrentExecutable(); LIBC.execv(exe, new StringArray(args.toArray(new String[args.size()]))); throw new IOException("Failed to exec '" + exe + "' " + LIBC.strerror(Native.getLastError())); }
@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())); }
@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())); }