summaryrefslogtreecommitdiffstats
path: root/twin/client.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-02-20 02:24:32 -0600
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-02-20 02:24:32 -0600
commitd160a6fc0101dd094195f8d0782e8aefcf94d376 (patch)
treebf7ebde63e93fb2f54b2bcaf5b0427b7f8de845f /twin/client.cpp
parenta515552a21960aeffbe12e24c6d64da32c646829 (diff)
downloadtdebase-d160a6fc0101dd094195f8d0782e8aefcf94d376.tar.gz
tdebase-d160a6fc0101dd094195f8d0782e8aefcf94d376.zip
Update twin with initial framework for application suspend/resume
This needs some additional work before it can be enabled
Diffstat (limited to 'twin/client.cpp')
-rw-r--r--twin/client.cpp118
1 files changed, 118 insertions, 0 deletions
diff --git a/twin/client.cpp b/twin/client.cpp
index c09df53fa..ff890404e 100644
--- a/twin/client.cpp
+++ b/twin/client.cpp
@@ -1834,6 +1834,124 @@ void Client::killProcess( bool ask, Time timestamp )
}
}
+bool Client::isSuspendable() const
+ {
+ TQCString machine = wmClientMachine( true );
+ pid_t pid = info->pid();
+ if( pid <= 0 || machine.isEmpty()) // needed properties missing
+ return false;
+ kdDebug( 1212 ) << "Suspend process:" << pid << "(" << machine << ")" << endl;
+ if( machine != "localhost" )
+ {
+ return false;
+ }
+ else
+ {
+ FILE *procfile;
+ if(chdir(TQString("/proc/%1").arg(pid).ascii()) == 0)
+ {
+ procfile = fopen("stat", "r");
+ }
+ if(!procfile)
+ {
+ return false;
+ }
+ else
+ {
+ long long int procpid;
+ char tcomm[PATH_MAX];
+ char state;
+ fscanf(procfile, "%lld ", &procpid);
+ fscanf(procfile, "%s ", tcomm);
+ fscanf(procfile, "%c ", &state);
+ if( state != 'T' )
+ {
+ fclose(procfile);
+ return true;
+ }
+ else
+ {
+ fclose(procfile);
+ return false;
+ }
+ }
+ }
+ }
+
+bool Client::isResumeable() const
+ {
+ TQCString machine = wmClientMachine( true );
+ pid_t pid = info->pid();
+ if( pid <= 0 || machine.isEmpty()) // needed properties missing
+ return false;
+ kdDebug( 1212 ) << "Suspend process:" << pid << "(" << machine << ")" << endl;
+ if( machine != "localhost" )
+ {
+ return false;
+ }
+ else
+ {
+ FILE *procfile;
+ if(chdir(TQString("/proc/%1").arg(pid).ascii()) == 0)
+ {
+ procfile = fopen("stat", "r");
+ }
+ if(!procfile)
+ {
+ return false;
+ }
+ else
+ {
+ long long int procpid;
+ char tcomm[PATH_MAX];
+ char state;
+ fscanf(procfile, "%lld ", &procpid);
+ fscanf(procfile, "%s ", tcomm);
+ fscanf(procfile, "%c ", &state);
+ if( state == 'T' )
+ {
+ fclose(procfile);
+ return true;
+ }
+ else
+ {
+ fclose(procfile);
+ return false;
+ }
+ }
+ }
+ }
+
+void Client::suspendWindow()
+ {
+ TQCString machine = wmClientMachine( true );
+ pid_t pid = info->pid();
+ if( pid <= 0 || machine.isEmpty()) // needed properties missing
+ return;
+ kdDebug( 1212 ) << "Suspend process:" << pid << "(" << machine << ")" << endl;
+ if( machine != "localhost" )
+ {
+ return;
+ }
+ else
+ ::kill( pid, SIGSTOP );
+ }
+
+void Client::resumeWindow()
+ {
+ TQCString machine = wmClientMachine( true );
+ pid_t pid = info->pid();
+ if( pid <= 0 || machine.isEmpty()) // needed properties missing
+ return;
+ kdDebug( 1212 ) << "Resume process:" << pid << "(" << machine << ")" << endl;
+ if( machine != "localhost" )
+ {
+ return;
+ }
+ else
+ ::kill( pid, SIGCONT );
+ }
+
void Client::processKillerExited()
{
kdDebug( 1212 ) << "Killer exited" << endl;