530
530
process_set_priority (procID, 5);
533
public class TimeoutCounter : GLib.Object {
535
public bool active = false;
536
public string process_to_kill = "";
537
public int seconds_to_wait = 30;
538
public bool exit_app = false;
540
public void kill_process_on_timeout(
541
string process_to_kill, int seconds_to_wait = 20, bool exit_app = false){
543
this.process_to_kill = process_to_kill;
544
this.seconds_to_wait = seconds_to_wait;
545
this.exit_app = exit_app;
549
Thread.create<void> (start_counter_thread, true);
552
log_error (e.message);
556
public void exit_on_timeout(int seconds_to_wait = 20){
557
this.process_to_kill = "";
558
this.seconds_to_wait = seconds_to_wait;
559
this.exit_app = true;
563
Thread.create<void> (start_counter_thread, true);
566
log_error (e.message);
574
public void start_counter_thread(){
577
while (active && (secs < seconds_to_wait)){
578
Thread.usleep((ulong) GLib.TimeSpan.MILLISECOND * 1000);
586
if (process_to_kill.length > 0){
587
Posix.system("killall " + process_to_kill);
588
stderr.printf("\n[timeout] Killed process" + ": %s\n".printf(process_to_kill));
592
stderr.printf("\n[timeout] Exit application\n");
599
public class AppLock : GLib.Object {
600
public string lock_file = "";
601
public string lock_message = "";
603
public bool create(string app_name, string message){
605
var lock_dir = "/var/run/lock/%s".printf(app_name);
606
dir_create(lock_dir);
607
lock_file = path_combine(lock_dir, "lock");
610
var file = File.new_for_path(lock_file);
611
if (file.query_exists()) {
613
string txt = file_read(lock_file);
614
string process_id = txt.split(";")[0].strip();
615
lock_message = txt.split(";")[1].strip();
616
long pid = long.parse(process_id);
618
if (process_is_running(pid)){
619
log_msg(_("Another instance of this application is running")
620
+ " (PID=%ld)".printf(pid));
624
log_msg(_("[Warning] Deleted invalid lock"));
626
write_lock_file(message);
631
write_lock_file(message);
636
log_error (e.message);
641
private void write_lock_file(string message){
642
string current_pid = ((long) Posix.getpid()).to_string();
643
file_write(lock_file, "%s;%s".printf(current_pid, message));
646
public void remove(){
648
var file = File.new_for_path (lock_file);
649
if (file.query_exists()) {
654
log_error (e.message);