]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/jcr.c
Fix cancel problem and implement run gnome dialog
[bacula/bacula] / bacula / src / lib / jcr.c
index 1ee2787d2290082dc0614a32318788a76187f1c8..caa59b4f5a1c640b61e58ad9df23b2c824267742 100755 (executable)
@@ -9,7 +9,7 @@
  *
  */
 /*
-   Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+   Copyright (C) 2000-2003 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -31,6 +31,8 @@
 #include "bacula.h"
 #include "jcr.h"
 
+extern void timeout_handler(int sig);
+
 struct s_last_job last_job;          /* last job run by this daemon */
 
 static JCR *jobs = NULL;             /* pointer to JCR chain */
@@ -45,9 +47,10 @@ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
 JCR *new_jcr(int size, JCR_free_HANDLER *daemon_free_jcr)
 {
    JCR *jcr;
+   struct sigaction sigtimer;
 
    Dmsg0(200, "Enter new_jcr\n");
-   jcr = (JCR *) malloc(size);
+   jcr = (JCR *)malloc(size);
    memset(jcr, 0, size);
    jcr->my_thread_id = pthread_self();
    jcr->sched_time = time(NULL);
@@ -60,6 +63,11 @@ JCR *new_jcr(int size, JCR_free_HANDLER *daemon_free_jcr)
    jcr->errmsg = get_pool_memory(PM_MESSAGE);
    jcr->errmsg[0] = 0;
 
+   sigtimer.sa_flags = 0;
+   sigtimer.sa_handler = timeout_handler;
+   sigfillset(&sigtimer.sa_mask);
+   sigaction(TIMEOUT_SIGNAL, &sigtimer, NULL);
+
    P(mutex);
    jcr->prev = NULL;
    jcr->next = jobs;
@@ -177,8 +185,14 @@ void free_jcr(JCR *jcr)
    remove_jcr(jcr);
    V(mutex);
 
-   jcr->daemon_free_jcr(jcr);        /* call daemon free routine */
+   if (jcr->daemon_free_jcr) {
+      jcr->daemon_free_jcr(jcr);      /* call daemon free routine */
+   }
    free_common_jcr(jcr);
+
+   P(mutex);
+   close_msg(NULL);                  /* flush any daemon messages */
+   V(mutex);
    Dmsg0(200, "Exit free_jcr\n");
 }
 
@@ -294,6 +308,24 @@ JCR *get_jcr_by_full_name(char *Job)
    return jcr; 
 }
 
+void set_jcr_job_status(JCR *jcr, int JobStatus)
+{
+   /*
+    * For a set of errors, ... keep the current status
+    *   so it isn't lost. For all others, set it.
+    */
+   switch (jcr->JobStatus) {
+   case JS_ErrorTerminated:
+   case JS_Error:
+   case JS_FatalError:
+   case JS_Differences:
+   case JS_Canceled:
+      break;
+   default:
+      jcr->JobStatus = JobStatus;
+   }
+}
+
 /* 
  * Lock the chain
  */