mirror of
http://galexander.org/git/simplesshd.git
synced 2024-12-28 17:08:08 +00:00
when creating the Service, we check for a pid file for an orphaned daemon
process, and if it exists, we kill it.
This commit is contained in:
parent
e77351edd4
commit
5c01b97345
@ -4,6 +4,9 @@ import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.content.Context;
|
||||
import android.os.IBinder;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
public class SimpleSSHDService extends Service {
|
||||
public static int sshd_pid = 0;
|
||||
@ -11,7 +14,15 @@ public class SimpleSSHDService extends Service {
|
||||
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
Prefs.init(this);
|
||||
|
||||
read_pidfile();
|
||||
if (is_started()) {
|
||||
/* would prefer to restart the daemon process rather
|
||||
* than leave the stale one around.. */
|
||||
stop_sshd();
|
||||
}
|
||||
}
|
||||
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
@ -81,6 +92,22 @@ public class SimpleSSHDService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
private static void read_pidfile() {
|
||||
try {
|
||||
File f = new File(Prefs.get_path(), "dropbear.pid");
|
||||
if (f.exists()) {
|
||||
BufferedReader r = new BufferedReader(
|
||||
new FileReader(f));
|
||||
try {
|
||||
sshd_pid =
|
||||
Integer.valueOf(r.readLine());
|
||||
} finally {
|
||||
r.close();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) { /* *shrug* */ }
|
||||
}
|
||||
|
||||
private native void start_sshd(int port, String path,
|
||||
String shell, String home);
|
||||
private native void stop_sshd();
|
||||
|
Loading…
Reference in New Issue
Block a user