Skip to content
API Documentation
BastionGuard™
AppLock Class Reference
Inheritance diagram for AppLock:

Public Member Functions

bool create (string app_name, string message)
void remove ()

Public Attributes

string lock_file = ""
string lock_message = ""

Private Member Functions

void write_lock_file (string message)

Detailed Description

Definition at line 29 of file AppLock.vala.

Member Function Documentation

◆ create()

bool AppLock.create ( string app_name,
string message )
inline

Definition at line 33 of file AppLock.vala.

33 {
34
35 var lock_dir = "/var/run/lock/%s".printf(app_name);
36 dir_create(lock_dir);
37 lock_file = path_combine(lock_dir, "lock");
38
39 try{
40 var file = File.new_for_path(lock_file);
41 if (file.query_exists()) {
42
43 string txt = file_read(lock_file);
44 string process_id = txt.split(";")[0].strip();
45 lock_message = txt.split(";")[1].strip();
46 long pid = long.parse(process_id);
47
48 if (get_process_exe_name(pid).contains("bastionguard-backup")){
49 log_msg(_("Another instance of this application is running")
50 + " (PID=%ld)".printf(pid));
51 return false;
52 }
53 else{
54 log_msg(_("[Warning] Deleted invalid lock"));
55 file.delete();
56 write_lock_file(message);
57 return true;
58 }
59 }
60 else{
61 write_lock_file(message);
62 return true;
63 }
64 }
65 catch (Error e) {
66 log_error (e.message);
67 return false;
68 }
69 }
#define _(s)
void write_lock_file(string message)
Definition AppLock.vala:71
string lock_file
Definition AppLock.vala:30
string lock_message
Definition AppLock.vala:31
string? file_read(string file_path)
string path_combine(string path1, string path2)
bool dir_create(string dir_path, bool show_message=false)
void log_error(string message, bool highlight=false, bool is_warning=false)
void log_msg(string message, bool highlight=false)
string get_process_exe_name(long pid=-1)

References _, TeeJee.FileSystem.dir_create(), Error, TeeJee.FileSystem.file_read(), TeeJee.ProcessHelper.get_process_exe_name(), lock_file, lock_message, TeeJee.Logging.log_error(), TeeJee.Logging.log_msg(), TeeJee.FileSystem.path_combine(), and write_lock_file().

Referenced by Main.Main().

◆ remove()

void AppLock.remove ( )
inline

Definition at line 76 of file AppLock.vala.

76 {
77 try{
78 var file = File.new_for_path (lock_file);
79 if (file.query_exists()) {
80 file.delete();
81 }
82 }
83 catch (Error e) {
84 log_error (e.message);
85 }
86 }

References Error, lock_file, and TeeJee.Logging.log_error().

Referenced by Main.exit_app().

◆ write_lock_file()

void AppLock.write_lock_file ( string message)
inlineprivate

Definition at line 71 of file AppLock.vala.

71 {
72 string current_pid = ((long) Posix.getpid()).to_string();
73 file_write(lock_file, "%s;%s".printf(current_pid, message));
74 }
bool file_write(string file_path, string contents)

References TeeJee.FileSystem.file_write(), and lock_file.

Referenced by create().

Member Data Documentation

◆ lock_file

string AppLock.lock_file = ""

Definition at line 30 of file AppLock.vala.

Referenced by create(), remove(), and write_lock_file().

◆ lock_message

string AppLock.lock_message = ""

Definition at line 31 of file AppLock.vala.

Referenced by create(), and Main.Main().


The documentation for this class was generated from the following file:
  • BastionGuard/thirdparty/bastionguard-backup/src/Utility/AppLock.vala