mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-15 09:17:42 +00:00
Moved TimedProcessTerminator to ExecUtil class. Addressed other comments
This commit is contained in:
parent
4a16c911d8
commit
b7d05b876d
@ -24,6 +24,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -149,7 +150,59 @@ public final class ExecUtil {
|
|||||||
logger.log(Level.WARNING, "Error occurred when attempting to kill process: {0}", ex.getMessage()); // NON-NLS
|
logger.log(Level.WARNING, "Error occurred when attempting to kill process: {0}", ex.getMessage()); // NON-NLS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Timed process terminator that triggers either based on default process time out value
|
||||||
|
* or user specified time out value.
|
||||||
|
*/
|
||||||
|
public static class TimedProcessTerminator implements ProcessTerminator {
|
||||||
|
|
||||||
|
private final long creationTimeSec; // time when TimedProcessTerminator was constructed
|
||||||
|
private final long timeoutSec; // time out value (seconds)
|
||||||
|
private static final long DEFAULT_TIMEOUT_SEC = 172800; // 48 hours
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a process terminator for an ingest module. Uses default
|
||||||
|
* process execution timeout value.
|
||||||
|
*/
|
||||||
|
public TimedProcessTerminator() {
|
||||||
|
creationTimeSec = (new Date().getTime()) / 1000;
|
||||||
|
timeoutSec = DEFAULT_TIMEOUT_SEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a process terminator for an ingest module.
|
||||||
|
*
|
||||||
|
* @param userSpecifiedTimeoutSec Process execution timeout value (seconds)
|
||||||
|
*/
|
||||||
|
public TimedProcessTerminator(long userSpecifiedTimeoutSec) {
|
||||||
|
creationTimeSec = (new Date().getTime()) / 1000;
|
||||||
|
|
||||||
|
if (userSpecifiedTimeoutSec > 0) {
|
||||||
|
timeoutSec = userSpecifiedTimeoutSec;
|
||||||
|
} else {
|
||||||
|
logger.log(Level.WARNING, "Process time out value must be greater than zero. Using default time out instead."); // NON-NLS
|
||||||
|
timeoutSec = DEFAULT_TIMEOUT_SEC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if process should be terminated, false otherwise
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean shouldTerminateProcess() {
|
||||||
|
|
||||||
|
// check if maximum execution time elapsed
|
||||||
|
long currentTimeSec = (new Date().getTime()) / 1000;
|
||||||
|
if (currentTimeSec - creationTimeSec > timeoutSec) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EVERYTHING FOLLOWING THIS LINE IS DEPRECATED AND SLATED FOR REMOVAL
|
* EVERYTHING FOLLOWING THIS LINE IS DEPRECATED AND SLATED FOR REMOVAL
|
||||||
*/
|
*/
|
||||||
|
@ -18,12 +18,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.sleuthkit.autopsy.ingest;
|
package org.sleuthkit.autopsy.ingest;
|
||||||
|
|
||||||
/**
|
import org.sleuthkit.autopsy.coreutils.ExecUtil;
|
||||||
* An ExecUtil process terminator for data source ingest modules that checks for
|
|
||||||
* ingest job cancellation.
|
|
||||||
*/
|
|
||||||
public final class DataSourceIngestModuleProcessTerminator extends TimedProcessTerminator {
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A timed process terminator for data source ingest modules. Checks for
|
||||||
|
* ingest job cancellation as well.
|
||||||
|
*/
|
||||||
|
public final class DataSourceIngestModuleProcessTerminator extends ExecUtil.TimedProcessTerminator {
|
||||||
|
|
||||||
|
public final IngestJobContext context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a process terminator for a data source ingest module.
|
* Constructs a process terminator for a data source ingest module.
|
||||||
* Uses default process execution timeout value.
|
* Uses default process execution timeout value.
|
||||||
@ -31,7 +35,8 @@ public final class DataSourceIngestModuleProcessTerminator extends TimedProcessT
|
|||||||
* @param context The ingest job context for the ingest module.
|
* @param context The ingest job context for the ingest module.
|
||||||
*/
|
*/
|
||||||
public DataSourceIngestModuleProcessTerminator(IngestJobContext context) {
|
public DataSourceIngestModuleProcessTerminator(IngestJobContext context) {
|
||||||
super(context);
|
super();
|
||||||
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,7 +46,8 @@ public final class DataSourceIngestModuleProcessTerminator extends TimedProcessT
|
|||||||
* @param timeoutSec Process execution timeout value (seconds)
|
* @param timeoutSec Process execution timeout value (seconds)
|
||||||
*/
|
*/
|
||||||
public DataSourceIngestModuleProcessTerminator(IngestJobContext context, long timeoutSec) {
|
public DataSourceIngestModuleProcessTerminator(IngestJobContext context, long timeoutSec) {
|
||||||
super(context, timeoutSec);
|
super(timeoutSec);
|
||||||
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,13 +18,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.sleuthkit.autopsy.ingest;
|
package org.sleuthkit.autopsy.ingest;
|
||||||
|
|
||||||
|
import org.sleuthkit.autopsy.coreutils.ExecUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An ExecUtil process terminator for data source ingest modules that checks for
|
* A timed process terminator for data source ingest modules. Checks for
|
||||||
* ingest job cancellation.
|
* ingest job cancellation as well.
|
||||||
*/
|
*/
|
||||||
public final class FileIngestModuleProcessTerminator extends TimedProcessTerminator {
|
public final class FileIngestModuleProcessTerminator extends ExecUtil.TimedProcessTerminator {
|
||||||
|
|
||||||
|
|
||||||
|
public final IngestJobContext context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a process terminator for a file ingest module.
|
* Constructs a process terminator for a file ingest module.
|
||||||
* Uses default process execution timeout value.
|
* Uses default process execution timeout value.
|
||||||
@ -32,7 +35,8 @@ public final class FileIngestModuleProcessTerminator extends TimedProcessTermina
|
|||||||
* @param context The ingest job context for the ingest module.
|
* @param context The ingest job context for the ingest module.
|
||||||
*/
|
*/
|
||||||
public FileIngestModuleProcessTerminator(IngestJobContext context) {
|
public FileIngestModuleProcessTerminator(IngestJobContext context) {
|
||||||
super(context);
|
super();
|
||||||
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,7 +46,8 @@ public final class FileIngestModuleProcessTerminator extends TimedProcessTermina
|
|||||||
* @param timeoutSec Process execution timeout value (seconds)
|
* @param timeoutSec Process execution timeout value (seconds)
|
||||||
*/
|
*/
|
||||||
public FileIngestModuleProcessTerminator(IngestJobContext context, long timeoutSec) {
|
public FileIngestModuleProcessTerminator(IngestJobContext context, long timeoutSec) {
|
||||||
super(context, timeoutSec);
|
super(timeoutSec);
|
||||||
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
* Autopsy Forensic Browser
|
|
||||||
*
|
|
||||||
* Copyright 2014 Basis Technology Corp.
|
|
||||||
* Contact: carrier <at> sleuthkit <dot> org
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.sleuthkit.autopsy.ingest;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import org.sleuthkit.autopsy.coreutils.ExecUtil;
|
|
||||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An ExecUtil process terminator for data source ingest modules that checks for
|
|
||||||
* ingest job cancellation.
|
|
||||||
*/
|
|
||||||
public class TimedProcessTerminator implements ExecUtil.ProcessTerminator {
|
|
||||||
|
|
||||||
public final IngestJobContext context;
|
|
||||||
private static final Logger logger = Logger.getLogger(TimedProcessTerminator.class.getName());
|
|
||||||
private static long creationTimeSec; // time when TimedProcessTerminator was constructed
|
|
||||||
private static long timeoutSec; // time out value (seconds)
|
|
||||||
private static final long DEFAULT_TIMEOUT_SEC = 172800; // 48 hours
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a process terminator for an ingest module.
|
|
||||||
* Uses default process execution timeout value.
|
|
||||||
*
|
|
||||||
* @param context The ingest job context for the ingest module.
|
|
||||||
*/
|
|
||||||
public TimedProcessTerminator(IngestJobContext context) {
|
|
||||||
this.context = context;
|
|
||||||
|
|
||||||
TimedProcessTerminator.creationTimeSec = (new Date().getTime())/1000;
|
|
||||||
TimedProcessTerminator.timeoutSec = DEFAULT_TIMEOUT_SEC;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a process terminator for an ingest module.
|
|
||||||
*
|
|
||||||
* @param context The ingest job context for the ingest module.
|
|
||||||
* @param timeoutSec Process execution timeout value (seconds)
|
|
||||||
*/
|
|
||||||
public TimedProcessTerminator(IngestJobContext context, long timeoutSec) {
|
|
||||||
this.context = context;
|
|
||||||
|
|
||||||
TimedProcessTerminator.creationTimeSec = (new Date().getTime())/1000;
|
|
||||||
|
|
||||||
if (timeoutSec > 0)
|
|
||||||
TimedProcessTerminator.timeoutSec = timeoutSec;
|
|
||||||
else {
|
|
||||||
TimedProcessTerminator.logger.log(Level.WARNING, "Process time out value specified must be greater than zero"); // NON-NLS
|
|
||||||
TimedProcessTerminator.timeoutSec = DEFAULT_TIMEOUT_SEC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return true if process should be terminated, false otherwise
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean shouldTerminateProcess() {
|
|
||||||
|
|
||||||
// check if maximum execution time elapsed
|
|
||||||
long currentTimeSec = (new Date().getTime())/1000;
|
|
||||||
if (currentTimeSec - TimedProcessTerminator.creationTimeSec > TimedProcessTerminator.timeoutSec)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user