#include #include #include #include #include #include static XfceSMClient *sm_client = NULL; pid_t pid; int timeout=10; void alarm_handler(int sig) { g_print("Timeout! killing child\n"); kill(pid,9); } static gboolean session_die(gpointer user_data) { char * args[] = {NULL}; int pts; pid = fork(); if(pid==0) { /* CHILD */ execv("/usr/bin/xfce-moving-profile-stop.py",args); } else { if(pid>0) { /* FATHER */ g_print("Succesfully spawned child process: %d\n",pid); alarm(timeout); wait(&pts); g_print("Child process terminated\n"); signal(SIGALRM,SIG_IGN); } else { /* ERROR */ g_printerr("session_die():Cannot spawn child process\n"); } } //gtk_main_quit(); return FALSE; } void session_init() { pid_t pid_init; char * args[]={NULL}; pid_init=fork(); if(pid_init==0) { /* CHILD */ execv("/usr/bin/xfce-moving-profile-start.py",args); } else { if(pid_init>0) { /* FATHER */ g_print("Succesfully spawned child process: %d\n",pid_init); } else { /* ERROR */ g_printerr("session_init():Cannot spawn child process\n"); } } } int main(int argc, char **argv) { GError *error = NULL; g_type_init(); sm_client = xfce_sm_client_get(); xfce_sm_client_set_restart_style(sm_client, XFCE_SM_CLIENT_RESTART_IMMEDIATELY); xfce_sm_client_set_priority(sm_client, XFCE_SM_CLIENT_PRIORITY_DESKTOP); g_set_prgname("xfce-moving-profile"); g_signal_connect(sm_client, "quit-requested", G_CALLBACK(session_die), NULL); if(!xfce_sm_client_connect(sm_client, &error) && error) { g_printerr("Failed to connect to session manager: %s\n", error->message); g_clear_error(&error); } if(argc>1) { int tmp =atoi(argv[1]); if(tmp>0 && tmp<30) { g_print("Using custom timeout:%d\n",tmp); timeout=tmp; } else { g_printerr("Invalid timeout value:%s\n",argv[1]); } } session_init(); signal(SIGALRM,alarm_handler); gtk_main(); return 0; }