AppLock

1. Overview

The AppLock module provides single-instance process locking for BastionGuard Backup. It creates, validates, and removes a process lock file so conflicting backup or restore sessions cannot run concurrently.

The implementation is written in Vala and uses GLib/GIO together with the application utility namespaces required by the file.


2. Dependencies and Integration

The module imports:

  • TeeJee.Logging
  • TeeJee.FileSystem
  • TeeJee.ProcessHelper
  • TeeJee.Misc

Key runtime integrations include:

  • GIO/GLib streams – filesystem and process I/O

3. Declared Types

3.1 AppLock

public class AppLock : GLib.Object

This class encapsulates the state and operations described by this source file.


4. State, Properties, Constants, and Signals

Public and protected state

  • public string lock_file – Path of the active process-lock file.
  • public string lock_message – Human-readable description stored with the owning process ID.

5. Public API and Operational Methods

5.1 create()

public bool create(string app_name, string message)

Creates the application lock directory and lock file, validates any existing PID against the running executable, rejects a live competing instance, and replaces stale locks.

  • Performs filesystem access and handles files or directories through GLib or TeeJee helpers.
  • Catches runtime errors locally and reports them through the logging layer or return value.

5.2 remove()

public void remove()

Deletes the current lock file when it exists and logs filesystem errors without propagating them.

  • Performs filesystem access and handles files or directories through GLib or TeeJee helpers.
  • Catches runtime errors locally and reports them through the logging layer or return value.

6. Internal Helpers

6.1 write_lock_file()

private void write_lock_file(string message)

Writes the current process ID and caller-supplied operation message to the lock file using a semicolon-separated format.


7. Filesystem Paths and Resource Locations

The source references the following absolute or template paths:

/var/run/lock/%s

Some values are templates completed at runtime with application names, process IDs, device identifiers, or file names.


8. Operational Flow

  1. Apply the requested operation and update runtime or persistent state.
  2. Finalize the operation and release files, mounts, child processes, widgets, or cached state.

9. Error Handling and Diagnostics

  • GLib and filesystem exceptions are caught locally in the operations that can fail.
  • The TeeJee logging layer records errors, debug state, generated commands, and operational messages.
  • Boolean, nullable, or empty-string return values communicate recoverable failures to callers.

10. Runtime and Security Considerations

  • Linux-specific paths: the module depends on Linux virtual filesystems or privileged system directories.

11. Licensing

The source is distributed under the GNU General Public License version 2 or any later version.

The source header identifies:

Copyright 2012-2018 Tony George <teejeetech@gmail.com>