From 00a9d4d78a9e8d8a4d3f7256818e3fbc2bb31058 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 26 Sep 2007 13:34:34 +0000 Subject: [PATCH] Add jcr to timer packets so if killed message can be sent to job. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@5654 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/filed/backup.c | 2 +- bacula/src/findlib/create_file.c | 2 +- bacula/src/lib/bpipe.c | 2 +- bacula/src/lib/bsock.c | 2 +- bacula/src/lib/btimers.c | 9 +++++++-- bacula/src/lib/btimers.h | 1 + bacula/src/lib/message.c | 2 +- bacula/src/lib/protos.h | 16 ++++++++-------- bacula/src/stored/dev.c | 2 +- bacula/technotes-2.3 | 1 + 10 files changed, 23 insertions(+), 16 deletions(-) diff --git a/bacula/src/filed/backup.c b/bacula/src/filed/backup.c index db9193e716..f5fbd25ef2 100644 --- a/bacula/src/filed/backup.c +++ b/bacula/src/filed/backup.c @@ -450,7 +450,7 @@ static int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level) if (do_read) { btimer_t *tid; if (ff_pkt->type == FT_FIFO) { - tid = start_thread_timer(pthread_self(), 60); + tid = start_thread_timer(jcr, pthread_self(), 60); } else { tid = NULL; } diff --git a/bacula/src/findlib/create_file.c b/bacula/src/findlib/create_file.c index cd032b9817..ea329d8d87 100644 --- a/bacula/src/findlib/create_file.c +++ b/bacula/src/findlib/create_file.c @@ -269,7 +269,7 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace) /* Timeout open() in 60 seconds */ if (attr->type == FT_FIFO) { Dmsg0(400, "Set FIFO timer\n"); - tid = start_thread_timer(pthread_self(), 60); + tid = start_thread_timer(jcr, pthread_self(), 60); } else { tid = NULL; } diff --git a/bacula/src/lib/bpipe.c b/bacula/src/lib/bpipe.c index d95236d794..03640a5fb1 100644 --- a/bacula/src/lib/bpipe.c +++ b/bacula/src/lib/bpipe.c @@ -163,7 +163,7 @@ BPIPE *open_bpipe(char *prog, int wait, const char *mode) bpipe->worker_stime = time(NULL); bpipe->wait = wait; if (wait > 0) { - bpipe->timer_id = start_child_timer(bpipe->worker_pid, wait); + bpipe->timer_id = start_child_timer(NULL, bpipe->worker_pid, wait); } return bpipe; } diff --git a/bacula/src/lib/bsock.c b/bacula/src/lib/bsock.c index 32a163acc8..560d6233c3 100644 --- a/bacula/src/lib/bsock.c +++ b/bacula/src/lib/bsock.c @@ -104,7 +104,7 @@ bool BSOCK::connect(JCR * jcr, int retry_interval, utime_t max_retry_time, /* Try to trap out of OS call when time expires */ if (max_retry_time) { - tid = start_thread_timer(pthread_self(), (uint32_t)max_retry_time); + tid = start_thread_timer(jcr, pthread_self(), (uint32_t)max_retry_time); } for (i = 0; !open(jcr, name, host, service, port, heart_beat, &fatal); diff --git a/bacula/src/lib/btimers.c b/bacula/src/lib/btimers.c index 2e59cf0f7e..4c44922f38 100644 --- a/bacula/src/lib/btimers.c +++ b/bacula/src/lib/btimers.c @@ -53,7 +53,7 @@ static void destructor_child_timer(watchdog_t *self); * Returns: btimer_t *(pointer to btimer_t struct) on success * NULL on failure */ -btimer_t *start_child_timer(pid_t pid, uint32_t wait) +btimer_t *start_child_timer(JCR *jcr, pid_t pid, uint32_t wait) { btimer_t *wid; @@ -64,6 +64,7 @@ btimer_t *start_child_timer(pid_t pid, uint32_t wait) wid->type = TYPE_CHILD; wid->pid = pid; wid->killed = false; + wid->jcr = jcr; wid->wd->callback = callback_child_timer; wid->wd->one_shot = false; @@ -124,6 +125,7 @@ static void callback_child_timer(watchdog_t *self) */ self->one_shot = true; } + Jmsg(wid->jcr, M_INFO, 0, _("Child timer expired. Child process killed.\n")); } /* @@ -132,7 +134,7 @@ static void callback_child_timer(watchdog_t *self) * Returns: btimer_t *(pointer to btimer_t struct) on success * NULL on failure */ -btimer_t *start_thread_timer(pthread_t tid, uint32_t wait) +btimer_t *start_thread_timer(JCR *jcr, pthread_t tid, uint32_t wait) { btimer_t *wid; wid = btimer_start_common(wait); @@ -142,6 +144,7 @@ btimer_t *start_thread_timer(pthread_t tid, uint32_t wait) } wid->type = TYPE_PTHREAD; wid->tid = tid; + wid->jcr = jcr; wid->wd->callback = callback_thread_timer; wid->wd->one_shot = true; @@ -169,6 +172,7 @@ btimer_t *start_bsock_timer(BSOCK *bsock, uint32_t wait) wid->type = TYPE_BSOCK; wid->tid = pthread_self(); wid->bsock = bsock; + wid->jcr = bsock->jcr(); wid->wd->callback = callback_thread_timer; wid->wd->one_shot = true; @@ -228,6 +232,7 @@ static void callback_thread_timer(watchdog_t *self) wid->bsock->set_timed_out(); } pthread_kill(wid->tid, TIMEOUT_SIGNAL); + Jmsg(wid->jcr, M_INFO, 0, _("Thread timer expired. Thread interrupted.\n")); } static btimer_t *btimer_start_common(uint32_t wait) diff --git a/bacula/src/lib/btimers.h b/bacula/src/lib/btimers.h index 33e3ed5994..7d9eca00cd 100644 --- a/bacula/src/lib/btimers.h +++ b/bacula/src/lib/btimers.h @@ -42,6 +42,7 @@ struct btimer_t { pid_t pid; /* process id if TYPE_CHILD */ pthread_t tid; /* thread id if TYPE_PTHREAD */ BSOCK *bsock; /* Pointer to BSOCK */ + JCR *jcr; /* Pointer to job control record */ }; #endif /* __BTIMERS_H_ */ diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index b231e62298..8cccb87339 100644 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -849,7 +849,7 @@ d_msg(const char *file, int line, int level, const char *fmt,...) if (level <= debug_level) { #ifdef FULL_LOCATION if (details) { - len = bsnprintf(buf, sizeof(buf), "%s: %s:%d jid=%u", + len = bsnprintf(buf, sizeof(buf), "%s: %s:%d jid=%u ", my_name, get_basename(file), line, get_jobid_from_tid()); } else { len = 0; diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h index c1ed9ead16..043a40a6b9 100644 --- a/bacula/src/lib/protos.h +++ b/bacula/src/lib/protos.h @@ -1,12 +1,7 @@ -/* - * Prototypes for lib directory of Bacula - * - * Version $Id$ - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. + Copyright (C) 2000-2007 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -30,6 +25,11 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * Prototypes for lib directory of Bacula + * + * Version $Id$ + */ class JCR; @@ -330,9 +330,9 @@ bool register_watchdog(watchdog_t *wd); bool unregister_watchdog(watchdog_t *wd); /* timers.c */ -btimer_t *start_child_timer(pid_t pid, uint32_t wait); +btimer_t *start_child_timer(JCR *jcr, pid_t pid, uint32_t wait); void stop_child_timer(btimer_t *wid); -btimer_t *start_thread_timer(pthread_t tid, uint32_t wait); +btimer_t *start_thread_timer(JCR *jcr, pthread_t tid, uint32_t wait); void stop_thread_timer(btimer_t *wid); btimer_t *start_bsock_timer(BSOCK *bs, uint32_t wait); void stop_bsock_timer(btimer_t *wid); diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 6a5eb392ec..50b4dd4a63 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -363,7 +363,7 @@ void DEVICE::open_tape_device(DCR *dcr, int omode) errno = 0; if (is_fifo() && timeout) { /* Set open timer */ - tid = start_thread_timer(pthread_self(), timeout); + tid = start_thread_timer(dcr->jcr, pthread_self(), timeout); } Dmsg2(100, "Try open %s mode=%s\n", print_name(), mode_to_str(omode)); #if defined(HAVE_WIN32) diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index 446df2df65..812dc78379 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -2,6 +2,7 @@ General: 26Sep07 +kes Add jcr to timer packets so if killed message can be sent to job. kes Add JobId to all Dmsg() output. kes Put some FD auth code on dbglvl rather than fixed. kes Return insert attributes error message in db msg buffer to avoid -- 2.39.5