Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions src/Core/Main.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1659,11 +1659,7 @@ public class Main : GLib.Object{
task.delete_extra = true;
task.delete_excluded = true;
task.delete_after = false;

if (app_mode.length > 0){
// console mode
task.io_nice = true;
}
task.io_nice = (app_mode.length > 0);

task.execute();

Expand Down Expand Up @@ -4020,10 +4016,7 @@ public class Main : GLib.Object{
task.delete_excluded = true;
task.delete_after = false;

if (app_mode.length > 0){
// console mode
task.io_nice = true;
}
task.io_nice = (app_mode.length > 0);

task.dry_run = true;

Expand Down
15 changes: 12 additions & 3 deletions src/Utility/AsyncTask.vala
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public abstract class AsyncTask : GLib.Object{
public int64 prg_count = 0;
public int64 prg_count_total = 0;

public bool io_nice = true; // renice child processes to IDlE PRIO

// signals
public signal void stdout_line_read(string line);
public signal void stderr_line_read(string line);
Expand Down Expand Up @@ -112,7 +114,7 @@ public abstract class AsyncTask : GLib.Object{
}

protected abstract string build_script();

protected virtual bool begin() {
status = AppStatus.RUNNING;

Expand All @@ -131,20 +133,27 @@ public abstract class AsyncTask : GLib.Object{
timer = new GLib.Timer();
timer.start();

GLib.SpawnChildSetupFunc? childsetup = null;

if(this.io_nice) {
// change io prio of process, right before it execs
childsetup = () => TeeJee.ProcessHelper.ioprio_set(0, IoPrio.prioValue(IoPrio.PrioClass.IDLE, 0));
}

// execute script file
Process.spawn_async_with_pipes(
working_dir, // working dir
spawn_args, // argv
spawn_env, // environment
SpawnFlags.SEARCH_PATH,
null, // child_setup
childsetup, // child_setup
out child_pid,
out input_fd,
out output_fd,
out error_fd);

log_debug("AsyncTask: child_pid: %d".printf(child_pid));

// create stream readers
UnixOutputStream uos_in = new UnixOutputStream(input_fd, true);
UnixInputStream uis_out = new UnixInputStream(output_fd, true);
Expand Down
5 changes: 0 additions & 5 deletions src/Utility/DeleteFileTask.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class DeleteFileTask : AsyncTask{
// settings
public string dest_path = "";
public bool verbose = true;
public bool io_nice = true;
public bool use_rsync = false;

//private
Expand Down Expand Up @@ -80,10 +79,6 @@ public class DeleteFileTask : AsyncTask{
protected override string build_script() {
var cmd = "";

if (io_nice){
//cmd += "ionice -c2 -n7 ";
}

if (use_rsync){

cmd += "rsync -aii";
Expand Down
5 changes: 0 additions & 5 deletions src/Utility/RsyncTask.vala
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public class RsyncTask : AsyncTask{
public string source_path = "";
public string dest_path = "";
public bool verbose = true;
public bool io_nice = true;
public bool dry_run = false;

// regex
Expand Down Expand Up @@ -186,10 +185,6 @@ public class RsyncTask : AsyncTask{

var cmd = "export LC_ALL=C.UTF-8\n";

if (io_nice){
//cmd += "ionice -c2 -n7 ";
}

cmd += "rsync -aii";

//if (!dry_run){
Expand Down
19 changes: 18 additions & 1 deletion src/Utility/TeeJee.Process.vala
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
string path = "/proc/%s/stat".printf(pidStr);
string stats = file_read(path);
string details = stats.split(")", 2)[1];
string[] splitted = details.split(" ", 3);

Check failure on line 309 in src/Utility/TeeJee.Process.vala

View workflow job for this annotation

GitHub Actions / build / build (mint22, linuxmintd/mint22-amd64, Mint 22, true) / Mint 22

splitted ==> split
if(splitted.length == 3) {
return int.parse(splitted[2]);
}
Expand Down Expand Up @@ -367,7 +367,9 @@

public Pid[] get_process_children (Pid parent_pid){

/* Returns the list of child processes owned by a given process */
/* Returns the list of child processes owned by a given process
This does not contain grand children
*/

// no explicit check for the existence of /proc/ as this might be a time-of-check-time-of-use bug.
File procfs = File.new_for_path("/proc/");
Expand Down Expand Up @@ -490,4 +492,19 @@

process_set_priority (procID, 5);
}

/*
Wrapper for the ioprio_set syscall (has no libc wrapper)
see: man 2 ioprio_set

pid may be 0 (self)
prio shall be constructed using IoPrio.prioValue
*/
public static bool ioprio_set(Pid pid, int prio) {
bool success = 0 == IoPrio.syscall(IoPrio.SYS_ioprio_set, IoPrio.IOPRIO_WHO_PROCESS, pid, prio);
if(!success) {
log_debug("ioprio failed with errno: %i".printf(Posix.errno));
}
return success;
}
}
11 changes: 9 additions & 2 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,25 @@ sources_app_gtk = files([
'AppGtk.vala',
])

vala_opts = [
'--vapidir=' + meson.current_source_dir() / 'vapi',
'--pkg', 'ioprio'
]

timeshift = executable('timeshift',
sources_app_console + sources_core + sources_utility,
config_header,
dependencies: dependencies,
install: true
install: true,
vala_args: vala_opts
)

timeshift_gtk = executable('timeshift-gtk',
sources_app_gtk + sources_core + sources_utility + sources_gtk,
config_header,
dependencies: dependencies,
install: true
install: true,
vala_args: vala_opts
)

install_data(
Expand Down
33 changes: 33 additions & 0 deletions src/vapi/ioprio.vapi
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

// iorpio syscalls

[CCode (cprefix = "", lower_case_cprefix = "")]
namespace IoPrio {
[CCode (cheader_filename = "unistd.h", sentinel = "", feature_test_macro = "_DEFAULT_SOURCE")]
extern long syscall (long number, ...);

[CCode (cheader_filename = "sys/syscall.h")]
public const int SYS_ioprio_get;

[CCode (cheader_filename = "sys/syscall.h")]
public const int SYS_ioprio_set;

[CCode (cheader_filename = "linux/ioprio.h")]
public const int IOPRIO_WHO_PROCESS;

[CCode (cheader_filename = "linux/ioprio.h", cname = "int", cprefix = "IOPRIO_CLASS_")]
public enum PrioClass {
NONE,
RT,
BE,
IDLE,
INVALID,
}

/*
construct a prio value using a PrioClass and a class specific data attribute
See man 2 ioprio_set for details
*/
[CCode (cheader_filename = "linux/ioprio.h", cname = "IOPRIO_PRIO_VALUE")]
extern int prioValue(PrioClass clas, int data);
}
Loading