--- /dev/null
+Index: src/gnome2-console/console_conf.c
+===================================================================
+--- src/gnome2-console/console_conf.c (revision 7106)
++++ src/gnome2-console/console_conf.c (working copy)
+@@ -24,7 +24,7 @@
+ /*
+ Bacula® - The Network Backup Solution
+
+- Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
++ Copyright (C) 2000-2008 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.
+@@ -82,8 +82,8 @@
+ {"dirport", store_int, ITEM(dir_res.DIRport), 0, ITEM_DEFAULT, 9101},
+ {"address", store_str, ITEM(dir_res.address), 0, ITEM_REQUIRED, 0},
+ {"password", store_password, ITEM(dir_res.password), 0, 0, 0},
+- {"tlsenable", store_bit, ITEM(dir_res.tls_enable), 1, 0, 0},
+- {"tlsrequire", store_bit, ITEM(dir_res.tls_require), 1, 0, 0},
++ {"tlsenable", store_bool, ITEM(dir_res.tls_enable), 1, 0, 0},
++ {"tlsrequire", store_bool, ITEM(dir_res.tls_require), 1, 0, 0},
+ {"tlscacertificatefile", store_dir, ITEM(dir_res.tls_ca_certfile), 0, 0, 0},
+ {"tlscacertificatedir", store_dir, ITEM(dir_res.tls_ca_certdir), 0, 0, 0},
+ {"tlscertificate", store_dir, ITEM(dir_res.tls_certfile), 0, 0, 0},
+@@ -95,8 +95,8 @@
+ {"name", store_name, ITEM(con_res.hdr.name), 0, ITEM_REQUIRED, 0},
+ {"description", store_str, ITEM(con_res.hdr.desc), 0, 0, 0},
+ {"password", store_password, ITEM(con_res.password), 0, ITEM_REQUIRED, 0},
+- {"tlsenable", store_bit, ITEM(con_res.tls_enable), 1, 0, 0},
+- {"tlsrequire", store_bit, ITEM(con_res.tls_require), 1, 0, 0},
++ {"tlsenable", store_bool, ITEM(con_res.tls_enable), 1, 0, 0},
++ {"tlsrequire", store_bool, ITEM(con_res.tls_require), 1, 0, 0},
+ {"tlscacertificatefile", store_dir, ITEM(con_res.tls_ca_certfile), 0, 0, 0},
+ {"tlscacertificatedir", store_dir, ITEM(con_res.tls_ca_certdir), 0, 0, 0},
+ {"tlscertificate", store_dir, ITEM(con_res.tls_certfile), 0, 0, 0},
+Index: src/gnome2-console/console_conf.h
+===================================================================
+--- src/gnome2-console/console_conf.h (revision 7106)
++++ src/gnome2-console/console_conf.h (working copy)
+@@ -8,7 +8,7 @@
+ /*
+ Bacula® - The Network Backup Solution
+
+- Copyright (C) 2002-2006 Free Software Foundation Europe e.V.
++ Copyright (C) 2002-2008 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.
+@@ -66,8 +66,8 @@
+ int DIRport; /* UA server port */
+ char *address; /* UA server address */
+ char *password; /* UA server password */
+- int tls_enable; /* Enable TLS */
+- int tls_require; /* Require TLS */
++ bool tls_enable; /* Enable TLS */
++ bool tls_require; /* Require TLS */
+ char *tls_ca_certfile; /* TLS CA Certificate File */
+ char *tls_ca_certdir; /* TLS CA Certificate Directory */
+ char *tls_certfile; /* TLS Client Certificate File */
+@@ -84,8 +84,8 @@
+ struct CONRES {
+ RES hdr;
+ char *password; /* UA server password */
+- int tls_enable; /* Enable TLS on all connections */
+- int tls_require; /* Require TLS on all connections */
++ bool tls_enable; /* Enable TLS on all connections */
++ bool tls_require; /* Require TLS on all connections */
+ char *tls_ca_certfile; /* TLS CA Certificate File */
+ char *tls_ca_certdir; /* TLS CA Certificate Directory */
+ char *tls_certfile; /* TLS Client Certificate File */
+Index: src/wx-console/console_conf.c
+===================================================================
+--- src/wx-console/console_conf.c (revision 7106)
++++ src/wx-console/console_conf.c (working copy)
+@@ -100,12 +100,12 @@
+ {"rcfile", store_dir, ITEM(res_cons.rc_file), 0, 0, 0},
+ {"historyfile", store_dir, ITEM(res_cons.hist_file), 0, 0, 0},
+ {"password", store_password, ITEM(res_cons.password), 0, ITEM_REQUIRED, 0},
+- {"tlsenable", store_bit, ITEM(res_cons.tls_enable), 1, 0, 0},
+- {"tlsrequire", store_bit, ITEM(res_cons.tls_require), 1, 0, 0},
+ {"tlscacertificatefile", store_dir, ITEM(res_cons.tls_ca_certfile), 0, 0, 0},
+ {"tlscacertificatedir", store_dir, ITEM(res_cons.tls_ca_certdir), 0, 0, 0},
+ {"tlscertificate", store_dir, ITEM(res_cons.tls_certfile), 0, 0, 0},
+ {"tlskey", store_dir, ITEM(res_cons.tls_keyfile), 0, 0, 0},
++ {"tlsenable", store_bool, ITEM(res_cons.tls_enable), 1, 0, 0},
++ {"tlsrequire", store_bool, ITEM(res_cons.tls_require), 1, 0, 0},
+ {NULL, NULL, {0}, 0, 0, 0}
+ };
+
+@@ -117,12 +117,12 @@
+ {"dirport", store_int, ITEM(res_dir.DIRport), 0, ITEM_DEFAULT, 9101},
+ {"address", store_str, ITEM(res_dir.address), 0, 0, 0},
+ {"password", store_password, ITEM(res_dir.password), 0, ITEM_REQUIRED, 0},
+- {"tlsenable", store_bit, ITEM(res_dir.tls_enable), 1, 0, 0},
+- {"tlsrequire", store_bit, ITEM(res_dir.tls_require), 1, 0, 0},
+ {"tlscacertificatefile", store_dir, ITEM(res_dir.tls_ca_certfile), 0, 0, 0},
+ {"tlscacertificatedir", store_dir, ITEM(res_dir.tls_ca_certdir), 0, 0, 0},
+ {"tlscertificate", store_dir, ITEM(res_dir.tls_certfile), 0, 0, 0},
+ {"tlskey", store_dir, ITEM(res_dir.tls_keyfile), 0, 0, 0},
++ {"tlsenable", store_bool, ITEM(res_dir.tls_enable), 1, 0, 0},
++ {"tlsrequire", store_bool, ITEM(res_dir.tls_require), 1, 0, 0},
+ {NULL, NULL, {0}, 0, 0, 0}
+ };
+
+Index: src/wx-console/console_conf.h
+===================================================================
+--- src/wx-console/console_conf.h (revision 7106)
++++ src/wx-console/console_conf.h (working copy)
+@@ -4,7 +4,7 @@
+ /*
+ Bacula® - The Network Backup Solution
+
+- Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
++ Copyright (C) 2000-2008 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.
+@@ -63,14 +63,13 @@
+ char *rc_file; /* startup file */
+ char *hist_file; /* command history file */
+ char *password; /* UA server password */
+- int tls_enable; /* Enable TLS on all connections */
+- int tls_require; /* Require TLS on all connections */
+ char *tls_ca_certfile; /* TLS CA Certificate File */
+ char *tls_ca_certdir; /* TLS CA Certificate Directory */
+ char *tls_certfile; /* TLS Client Certificate File */
+ char *tls_keyfile; /* TLS Client Key File */
+-
+ TLS_CONTEXT *tls_ctx; /* Shared TLS Context */
++ bool tls_enable; /* Enable TLS on all connections */
++ bool tls_require; /* Require TLS on all connections */
+ };
+
+ /* Director */
+@@ -79,14 +78,13 @@
+ int DIRport; /* UA server port */
+ char *address; /* UA server address */
+ char *password; /* UA server password */
+- int tls_enable; /* Enable TLS on all connections */
+- int tls_require; /* Require TLS on all connections */
+ char *tls_ca_certfile; /* TLS CA Certificate File */
+ char *tls_ca_certdir; /* TLS CA Certificate Directory */
+ char *tls_certfile; /* TLS Client Certificate File */
+ char *tls_keyfile; /* TLS Client Key File */
+-
+ TLS_CONTEXT *tls_ctx; /* Shared TLS Context */
++ bool tls_enable; /* Enable TLS on all connections */
++ bool tls_require; /* Require TLS on all connections */
+ };
+
+
+Index: src/stored/stored_conf.c
+===================================================================
+--- src/stored/stored_conf.c (revision 7106)
++++ src/stored/stored_conf.c (working copy)
+@@ -1,7 +1,7 @@
+ /*
+ Bacula® - The Network Backup Solution
+
+- Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
++ Copyright (C) 2000-2008 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.
+@@ -77,9 +77,9 @@
+ {"scriptsdirectory", store_dir, ITEM(res_store.scripts_directory), 0, 0, 0},
+ {"maximumconcurrentjobs", store_pint, ITEM(res_store.max_concurrent_jobs), 0, ITEM_DEFAULT, 20},
+ {"heartbeatinterval", store_time, ITEM(res_store.heartbeat_interval), 0, ITEM_DEFAULT, 0},
+- {"tlsenable", store_bit, ITEM(res_store.tls_enable), 1, 0, 0},
+- {"tlsrequire", store_bit, ITEM(res_store.tls_require), 1, 0, 0},
+- {"tlsverifypeer", store_bit, ITEM(res_store.tls_verify_peer), 1, ITEM_DEFAULT, 1},
++ {"tlsenable", store_bool, ITEM(res_store.tls_enable), 1, 0, 0},
++ {"tlsrequire", store_bool, ITEM(res_store.tls_require), 1, 0, 0},
++ {"tlsverifypeer", store_bool, ITEM(res_store.tls_verify_peer), 1, ITEM_DEFAULT, 1},
+ {"tlscacertificatefile", store_dir, ITEM(res_store.tls_ca_certfile), 0, 0, 0},
+ {"tlscacertificatedir", store_dir, ITEM(res_store.tls_ca_certdir), 0, 0, 0},
+ {"tlscertificate", store_dir, ITEM(res_store.tls_certfile), 0, 0, 0},
+@@ -96,10 +96,10 @@
+ {"name", store_name, ITEM(res_dir.hdr.name), 0, ITEM_REQUIRED, 0},
+ {"description", store_str, ITEM(res_dir.hdr.desc), 0, 0, 0},
+ {"password", store_password, ITEM(res_dir.password), 0, ITEM_REQUIRED, 0},
+- {"monitor", store_bit, ITEM(res_dir.monitor), 1, ITEM_DEFAULT, 0},
+- {"tlsenable", store_bit, ITEM(res_dir.tls_enable), 1, 0, 0},
+- {"tlsrequire", store_bit, ITEM(res_dir.tls_require), 1, 0, 0},
+- {"tlsverifypeer", store_bit, ITEM(res_dir.tls_verify_peer), 1, ITEM_DEFAULT, 1},
++ {"monitor", store_bool, ITEM(res_dir.monitor), 1, ITEM_DEFAULT, 0},
++ {"tlsenable", store_bool, ITEM(res_dir.tls_enable), 1, 0, 0},
++ {"tlsrequire", store_bool, ITEM(res_dir.tls_require), 1, 0, 0},
++ {"tlsverifypeer", store_bool, ITEM(res_dir.tls_verify_peer), 1, ITEM_DEFAULT, 1},
+ {"tlscacertificatefile", store_dir, ITEM(res_dir.tls_ca_certfile), 0, 0, 0},
+ {"tlscacertificatedir", store_dir, ITEM(res_dir.tls_ca_certdir), 0, 0, 0},
+ {"tlscertificate", store_dir, ITEM(res_dir.tls_certfile), 0, 0, 0},
+@@ -137,7 +137,7 @@
+ {"checklabels", store_bit, ITEM(res_dev.cap_bits), CAP_CHECKLABELS, ITEM_DEFAULT, 0},
+ {"requiresmount", store_bit, ITEM(res_dev.cap_bits), CAP_REQMOUNT, ITEM_DEFAULT, 0},
+ {"offlineonunmount", store_bit, ITEM(res_dev.cap_bits), CAP_OFFLINEUNMOUNT, ITEM_DEFAULT, 0},
+- {"autoselect", store_bit, ITEM(res_dev.autoselect), 1, ITEM_DEFAULT, 1},
++ {"autoselect", store_bool, ITEM(res_dev.autoselect), 1, ITEM_DEFAULT, 1},
+ {"changerdevice", store_strname,ITEM(res_dev.changer_name), 0, 0, 0},
+ {"changercommand", store_strname,ITEM(res_dev.changer_command), 0, 0, 0},
+ {"alertcommand", store_strname,ITEM(res_dev.alert_command), 0, 0, 0},
+@@ -177,9 +177,6 @@
+ };
+
+
+-// {"mountanonymousvolumes", store_bit, ITEM(res_dev.cap_bits), CAP_ANONVOLS, ITEM_DEFAULT, 0},
+-
+-
+ /* Message resource */
+ extern RES_ITEM msgs_items[];
+
+Index: src/stored/stored_conf.h
+===================================================================
+--- src/stored/stored_conf.h (revision 7106)
++++ src/stored/stored_conf.h (working copy)
+@@ -1,7 +1,7 @@
+ /*
+ Bacula® - The Network Backup Solution
+
+- Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
++ Copyright (C) 2000-2008 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.
+@@ -126,9 +126,9 @@
+ char *spool_directory; /* Spool file directory */
+ int dev_type; /* device type */
+ int label_type; /* label type */
+- int autoselect; /* Automatically select from AutoChanger */
++ bool autoselect; /* Automatically select from AutoChanger */
+ uint32_t drive_index; /* Autochanger drive index */
+- uint32_t cap_bits; /* Capabilities of this device */
++ int cap_bits; /* Capabilities of this device */
+ utime_t max_changer_wait; /* Changer timeout */
+ utime_t max_rewind_wait; /* maximum secs to wait for rewind */
+ utime_t max_open_wait; /* maximum secs to wait for open */
+Index: src/console/console_conf.c
+===================================================================
+--- src/console/console_conf.c (revision 7106)
++++ src/console/console_conf.c (working copy)
+@@ -1,7 +1,7 @@
+ /*
+ Bacula® - The Network Backup Solution
+
+- Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
++ Copyright (C) 2000-2008 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.
+@@ -88,8 +88,8 @@
+ {"rcfile", store_dir, ITEM(res_cons.rc_file), 0, 0, 0},
+ {"historyfile", store_dir, ITEM(res_cons.hist_file), 0, 0, 0},
+ {"password", store_password, ITEM(res_cons.password), 0, ITEM_REQUIRED, 0},
+- {"tlsenable", store_bit, ITEM(res_cons.tls_enable), 1, 0, 0},
+- {"tlsrequire", store_bit, ITEM(res_cons.tls_require), 1, 0, 0},
++ {"tlsenable", store_bool, ITEM(res_cons.tls_enable), 1, 0, 0},
++ {"tlsrequire", store_bool, ITEM(res_cons.tls_require), 1, 0, 0},
+ {"tlscacertificatefile", store_dir, ITEM(res_cons.tls_ca_certfile), 0, 0, 0},
+ {"tlscacertificatedir", store_dir, ITEM(res_cons.tls_ca_certdir), 0, 0, 0},
+ {"tlscertificate", store_dir, ITEM(res_cons.tls_certfile), 0, 0, 0},
+@@ -107,8 +107,8 @@
+ {"dirport", store_int, ITEM(res_dir.DIRport), 0, ITEM_DEFAULT, 9101},
+ {"address", store_str, ITEM(res_dir.address), 0, 0, 0},
+ {"password", store_password, ITEM(res_dir.password), 0, ITEM_REQUIRED, 0},
+- {"tlsenable", store_bit, ITEM(res_dir.tls_enable), 1, 0, 0},
+- {"tlsrequire", store_bit, ITEM(res_dir.tls_require), 1, 0, 0},
++ {"tlsenable", store_bool, ITEM(res_dir.tls_enable), 1, 0, 0},
++ {"tlsrequire", store_bool, ITEM(res_dir.tls_require), 1, 0, 0},
+ {"tlscacertificatefile", store_dir, ITEM(res_dir.tls_ca_certfile), 0, 0, 0},
+ {"tlscacertificatedir", store_dir, ITEM(res_dir.tls_ca_certdir), 0, 0, 0},
+ {"tlscertificate", store_dir, ITEM(res_dir.tls_certfile), 0, 0, 0},
+Index: src/console/console_conf.h
+===================================================================
+--- src/console/console_conf.h (revision 7106)
++++ src/console/console_conf.h (working copy)
+@@ -64,16 +64,15 @@
+ char *rc_file; /* startup file */
+ char *hist_file; /* command history file */
+ char *password; /* UA server password */
+- int tls_enable; /* Enable TLS on all connections */
+- int tls_require; /* Require TLS on all connections */
+ char *tls_ca_certfile; /* TLS CA Certificate File */
+ char *tls_ca_certdir; /* TLS CA Certificate Directory */
+ char *tls_certfile; /* TLS Client Certificate File */
+ char *tls_keyfile; /* TLS Client Key File */
+ char *director; /* bind to director */
+ utime_t heartbeat_interval; /* Interval to send heartbeats to Dir */
+-
+ TLS_CONTEXT *tls_ctx; /* Shared TLS Context */
++ bool tls_enable; /* Enable TLS on all connections */
++ bool tls_require; /* Require TLS on all connections */
+ };
+
+ /* Director */
+@@ -82,15 +81,14 @@
+ int DIRport; /* UA server port */
+ char *address; /* UA server address */
+ char *password; /* UA server password */
+- int tls_enable; /* Enable TLS */
+- int tls_require; /* Require TLS */
+ char *tls_ca_certfile; /* TLS CA Certificate File */
+ char *tls_ca_certdir; /* TLS CA Certificate Directory */
+ char *tls_certfile; /* TLS Client Certificate File */
+ char *tls_keyfile; /* TLS Client Key File */
+ utime_t heartbeat_interval; /* Interval to send heartbeats to Dir */
+-
+ TLS_CONTEXT *tls_ctx; /* Shared TLS Context */
++ bool tls_enable; /* Enable TLS */
++ bool tls_require; /* Require TLS */
+ };
+
+
+Index: src/tray-monitor/tray_conf.c
+===================================================================
+--- src/tray-monitor/tray_conf.c (revision 7106)
++++ src/tray-monitor/tray_conf.c (working copy)
+@@ -82,7 +82,7 @@
+ static RES_ITEM mon_items[] = {
+ {"name", store_name, ITEM(res_monitor.hdr.name), 0, ITEM_REQUIRED, 0},
+ {"description", store_str, ITEM(res_monitor.hdr.desc), 0, 0, 0},
+- {"requiressl", store_bit, ITEM(res_monitor.require_ssl), 1, ITEM_DEFAULT, 0},
++ {"requiressl", store_bool, ITEM(res_monitor.require_ssl), 1, ITEM_DEFAULT, 0},
+ {"password", store_password, ITEM(res_monitor.password), 0, ITEM_REQUIRED, 0},
+ {"refreshinterval", store_time,ITEM(res_monitor.RefreshInterval), 0, ITEM_DEFAULT, 5},
+ {"fdconnecttimeout", store_time,ITEM(res_monitor.FDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
+@@ -96,7 +96,7 @@
+ {"description", store_str, ITEM(res_dir.hdr.desc), 0, 0, 0},
+ {"dirport", store_int, ITEM(res_dir.DIRport), 0, ITEM_DEFAULT, 9101},
+ {"address", store_str, ITEM(res_dir.address), 0, 0, 0},
+- {"enablessl", store_bit, ITEM(res_dir.enable_ssl), 1, ITEM_DEFAULT, 0},
++ {"enablessl", store_bool, ITEM(res_dir.enable_ssl), 1, ITEM_DEFAULT, 0},
+ {NULL, NULL, {0}, 0, 0, 0}
+ };
+
+@@ -112,7 +112,7 @@
+ {"address", store_str, ITEM(res_client.address), 0, ITEM_REQUIRED, 0},
+ {"fdport", store_pint, ITEM(res_client.FDport), 0, ITEM_DEFAULT, 9102},
+ {"password", store_password, ITEM(res_client.password), 0, ITEM_REQUIRED, 0},
+- {"enablessl", store_bit, ITEM(res_client.enable_ssl), 1, ITEM_DEFAULT, 0},
++ {"enablessl", store_bool, ITEM(res_client.enable_ssl), 1, ITEM_DEFAULT, 0},
+ {NULL, NULL, {0}, 0, 0, 0}
+ };
+
+@@ -128,7 +128,7 @@
+ {"sdaddress", store_str, ITEM(res_store.address), 0, 0, 0},
+ {"password", store_password, ITEM(res_store.password), 0, ITEM_REQUIRED, 0},
+ {"sdpassword", store_password, ITEM(res_store.password), 0, 0, 0},
+- {"enablessl", store_bit, ITEM(res_store.enable_ssl), 1, ITEM_DEFAULT, 0},
++ {"enablessl", store_bool, ITEM(res_store.enable_ssl), 1, ITEM_DEFAULT, 0},
+ {NULL, NULL, {0}, 0, 0, 0}
+ };
+
+Index: src/tray-monitor/tray_conf.h
+===================================================================
+--- src/tray-monitor/tray_conf.h (revision 7106)
++++ src/tray-monitor/tray_conf.h (working copy)
+@@ -1,7 +1,7 @@
+ /*
+ Bacula® - The Network Backup Solution
+
+- Copyright (C) 2004-2007 Free Software Foundation Europe e.V.
++ Copyright (C) 2004-2008 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.
+@@ -67,7 +67,7 @@
+ RES hdr;
+ int DIRport; /* UA server port */
+ char *address; /* UA server address */
+- int enable_ssl; /* Use SSL */
++ bool enable_ssl; /* Use SSL */
+ };
+
+ /*
+@@ -95,7 +95,7 @@
+ int FDport; /* Where File daemon listens */
+ char *address;
+ char *password;
+- int enable_ssl; /* Use SSL */
++ bool enable_ssl; /* Use SSL */
+ };
+
+ /*
+@@ -108,7 +108,7 @@
+ int SDport; /* port where Directors connect */
+ char *address;
+ char *password;
+- int enable_ssl; /* Use SSL */
++ bool enable_ssl; /* Use SSL */
+ };
+
+ struct CONFONTRES {
--- /dev/null
+
+ This patch should fix bug #1094 where jobs that wrote bytes and are rescheduled
+ do not keep any Pool overrides that were specified in the Schedule Run
+ directives. The patch also simplifies the resource lock inc/dec.
+
+ Apply it to 2.4.0 with:
+
+ cd <bacula-source>
+ patch -p0 <2.4.0-reschedule.patch
+ ./configure <your options>
+ make
+ ...
+ make install
+
+
+Index: src/dird/jobq.c
+===================================================================
+--- src/dird/jobq.c (revision 7178)
++++ src/dird/jobq.c (working copy)
+@@ -1,7 +1,7 @@
+ /*
+ Bacula® - The Network Backup Solution
+
+- Copyright (C) 2003-2007 Free Software Foundation Europe e.V.
++ Copyright (C) 2003-2008 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.
+@@ -56,9 +56,10 @@
+
+ static int start_server(jobq_t *jq);
+ static bool acquire_resources(JCR *jcr);
++static bool reschedule_job(JCR *jcr, jobq_t *jq, jobq_item_t *je);
++static void dec_read_store(JCR *jcr);
++static void dec_write_store(JCR *jcr);
+
+-
+-
+ /*
+ * Initialize a job queue
+ *
+@@ -357,8 +358,8 @@
+ pthread_t id;
+
+ /*
+- * if any threads are idle, wake one --
+- * actually we do a broadcast because on /lib/tls
++ * if any threads are idle, wake one.
++ * Actually we do a broadcast because on /lib/tls
+ * these signals seem to get lost from time to time.
+ */
+ if (jq->idle_workers > 0) {
+@@ -477,87 +478,17 @@
+ * put into the ready queue.
+ */
+ if (jcr->acquired_resource_locks) {
+- if (jcr->rstore) {
+- jcr->rstore->NumConcurrentJobs--;
+- Dmsg1(200, "Dec rncj=%d\n", jcr->rstore->NumConcurrentJobs);
+- }
+- if (jcr->wstore) {
+- jcr->wstore->NumConcurrentJobs--;
+- Dmsg1(200, "Dec wncj=%d\n", jcr->wstore->NumConcurrentJobs);
+- }
++ dec_read_store(jcr);
++ dec_write_store(jcr);
+ jcr->client->NumConcurrentJobs--;
+ jcr->job->NumConcurrentJobs--;
+ jcr->acquired_resource_locks = false;
+ }
+
+- /*
+- * Reschedule the job if necessary and requested
+- */
+- if (jcr->job->RescheduleOnError &&
+- jcr->JobStatus != JS_Terminated &&
+- jcr->JobStatus != JS_Canceled &&
+- jcr->JobType == JT_BACKUP &&
+- (jcr->job->RescheduleTimes == 0 ||
+- jcr->reschedule_count < jcr->job->RescheduleTimes)) {
+- char dt[50], dt2[50];
++ if (reschedule_job(jcr, jq, je)) {
++ continue; /* go look for more work */
++ }
+
+- /*
+- * Reschedule this job by cleaning it up, but
+- * reuse the same JobId if possible.
+- */
+- time_t now = time(NULL);
+- jcr->reschedule_count++;
+- jcr->sched_time = now + jcr->job->RescheduleInterval;
+- bstrftime(dt, sizeof(dt), now);
+- bstrftime(dt2, sizeof(dt2), jcr->sched_time);
+- Dmsg4(2300, "Rescheduled Job %s to re-run in %d seconds.(now=%u,then=%u)\n", jcr->Job,
+- (int)jcr->job->RescheduleInterval, now, jcr->sched_time);
+- Jmsg(jcr, M_INFO, 0, _("Rescheduled Job %s at %s to re-run in %d seconds (%s).\n"),
+- jcr->Job, dt, (int)jcr->job->RescheduleInterval, dt2);
+- dird_free_jcr_pointers(jcr); /* partial cleanup old stuff */
+- jcr->JobStatus = -1;
+- set_jcr_job_status(jcr, JS_WaitStartTime);
+- jcr->SDJobStatus = 0;
+- if (jcr->JobBytes == 0) {
+- Dmsg2(2300, "Requeue job=%d use=%d\n", jcr->JobId, jcr->use_count());
+- V(jq->mutex);
+- jobq_add(jq, jcr); /* queue the job to run again */
+- P(jq->mutex);
+- free_jcr(jcr); /* release jcr */
+- free(je); /* free the job entry */
+- continue; /* look for another job to run */
+- }
+- /*
+- * Something was actually backed up, so we cannot reuse
+- * the old JobId or there will be database record
+- * conflicts. We now create a new job, copying the
+- * appropriate fields.
+- */
+- JCR *njcr = new_jcr(sizeof(JCR), dird_free_jcr);
+- set_jcr_defaults(njcr, jcr->job);
+- njcr->reschedule_count = jcr->reschedule_count;
+- njcr->sched_time = jcr->sched_time;
+- njcr->JobLevel = jcr->JobLevel;
+- njcr->JobStatus = -1;
+- set_jcr_job_status(njcr, jcr->JobStatus);
+- if (jcr->rstore) {
+- copy_rstorage(njcr, jcr->rstorage, _("previous Job"));
+- } else {
+- free_rstorage(njcr);
+- }
+- if (jcr->wstore) {
+- copy_wstorage(njcr, jcr->wstorage, _("previous Job"));
+- } else {
+- free_wstorage(njcr);
+- }
+- njcr->messages = jcr->messages;
+- Dmsg0(2300, "Call to run new job\n");
+- V(jq->mutex);
+- run_job(njcr); /* This creates a "new" job */
+- free_jcr(njcr); /* release "new" jcr */
+- P(jq->mutex);
+- Dmsg0(2300, "Back from running new job.\n");
+- }
+ /* Clean up and release old jcr */
+ Dmsg2(2300, "====== Termination job=%d use_cnt=%d\n", jcr->JobId, jcr->use_count());
+ jcr->SDJobStatus = 0;
+@@ -671,6 +602,91 @@
+ }
+
+ /*
++ * Returns true if cleanup done and we should look for more work
++ */
++static bool reschedule_job(JCR *jcr, jobq_t *jq, jobq_item_t *je)
++{
++ /*
++ * Reschedule the job if necessary and requested
++ */
++ if (jcr->job->RescheduleOnError &&
++ jcr->JobStatus != JS_Terminated &&
++ jcr->JobStatus != JS_Canceled &&
++ jcr->JobType == JT_BACKUP &&
++ (jcr->job->RescheduleTimes == 0 ||
++ jcr->reschedule_count < jcr->job->RescheduleTimes)) {
++ char dt[50], dt2[50];
++
++ /*
++ * Reschedule this job by cleaning it up, but
++ * reuse the same JobId if possible.
++ */
++ time_t now = time(NULL);
++ jcr->reschedule_count++;
++ jcr->sched_time = now + jcr->job->RescheduleInterval;
++ bstrftime(dt, sizeof(dt), now);
++ bstrftime(dt2, sizeof(dt2), jcr->sched_time);
++ Dmsg4(2300, "Rescheduled Job %s to re-run in %d seconds.(now=%u,then=%u)\n", jcr->Job,
++ (int)jcr->job->RescheduleInterval, now, jcr->sched_time);
++ Jmsg(jcr, M_INFO, 0, _("Rescheduled Job %s at %s to re-run in %d seconds (%s).\n"),
++ jcr->Job, dt, (int)jcr->job->RescheduleInterval, dt2);
++ dird_free_jcr_pointers(jcr); /* partial cleanup old stuff */
++ jcr->JobStatus = -1;
++ set_jcr_job_status(jcr, JS_WaitStartTime);
++ jcr->SDJobStatus = 0;
++ if (jcr->JobBytes == 0) {
++ Dmsg2(2300, "Requeue job=%d use=%d\n", jcr->JobId, jcr->use_count());
++ V(jq->mutex);
++ jobq_add(jq, jcr); /* queue the job to run again */
++ P(jq->mutex);
++ free_jcr(jcr); /* release jcr */
++ free(je); /* free the job entry */
++ return true; /* we already cleaned up */
++ }
++ /*
++ * Something was actually backed up, so we cannot reuse
++ * the old JobId or there will be database record
++ * conflicts. We now create a new job, copying the
++ * appropriate fields.
++ */
++ JCR *njcr = new_jcr(sizeof(JCR), dird_free_jcr);
++ set_jcr_defaults(njcr, jcr->job);
++ njcr->reschedule_count = jcr->reschedule_count;
++ njcr->sched_time = jcr->sched_time;
++ njcr->JobLevel = jcr->JobLevel;
++ njcr->pool = jcr->pool;
++ njcr->run_pool_override = jcr->run_pool_override;
++ njcr->full_pool = jcr->full_pool;
++ njcr->run_full_pool_override = jcr->run_full_pool_override;
++ njcr->inc_pool = jcr->inc_pool;
++ njcr->run_inc_pool_override = jcr->run_inc_pool_override;
++ njcr->diff_pool = jcr->diff_pool;
++ njcr->JobStatus = -1;
++ set_jcr_job_status(njcr, jcr->JobStatus);
++ if (jcr->rstore) {
++ copy_rstorage(njcr, jcr->rstorage, _("previous Job"));
++ } else {
++ free_rstorage(njcr);
++ }
++ if (jcr->wstore) {
++ copy_wstorage(njcr, jcr->wstorage, _("previous Job"));
++ } else {
++ free_wstorage(njcr);
++ }
++ njcr->messages = jcr->messages;
++ njcr->spool_data = jcr->spool_data;
++ njcr->write_part_after_job = jcr->write_part_after_job;
++ Dmsg0(2300, "Call to run new job\n");
++ V(jq->mutex);
++ run_job(njcr); /* This creates a "new" job */
++ free_jcr(njcr); /* release "new" jcr */
++ P(jq->mutex);
++ Dmsg0(2300, "Back from running new job.\n");
++ }
++ return false;
++}
++
++/*
+ * See if we can acquire all the necessary resources for the job (JCR)
+ *
+ * Returns: true if successful
+@@ -681,11 +697,19 @@
+ bool skip_this_jcr = false;
+
+ jcr->acquired_resource_locks = false;
++ if (jcr->rstore == jcr->wstore) { /* deadlock */
++ Jmsg(jcr, M_FATAL, 0, _("Job canceled. Attempt to read and write same device.\n"
++ " Read storage \"%s\" (From %s) -- Write storage \"%s\" (From %s)\n"),
++ jcr->rstore->name(), jcr->rstore_source, jcr->wstore->name(), jcr->wstore_source);
++ set_jcr_job_status(jcr, JS_Canceled);
++ return false;
++ }
+ if (jcr->rstore) {
+ Dmsg1(200, "Rstore=%s\n", jcr->rstore->name());
+ if (jcr->rstore->NumConcurrentJobs < jcr->rstore->MaxConcurrentJobs) {
++// jcr->rstore->NumConcurrentReadJobs++;
+ jcr->rstore->NumConcurrentJobs++;
+- Dmsg0(200, "Set rncj=1\n");
++ Dmsg1(200, "Inc rncj=%d\n", jcr->rstore->NumConcurrentJobs);
+ } else {
+ Dmsg1(200, "Fail rncj=%d\n", jcr->rstore->NumConcurrentJobs);
+ set_jcr_job_status(jcr, JS_WaitStoreRes);
+@@ -695,25 +719,11 @@
+
+ if (jcr->wstore) {
+ Dmsg1(200, "Wstore=%s\n", jcr->wstore->name());
+- if (jcr->rstore == jcr->wstore) { /* deadlock */
+- jcr->rstore->NumConcurrentJobs--; /* back out rstore */
+- Jmsg(jcr, M_FATAL, 0, _("Job canceled. Attempt to read and write same device.\n"
+- " Read storage \"%s\" (From %s) -- Write storage \"%s\" (From %s)\n"),
+- jcr->rstore->name(), jcr->rstore_source, jcr->wstore->name(), jcr->wstore_source);
+- set_jcr_job_status(jcr, JS_Canceled);
+- return false;
+- }
+- if (jcr->wstore->NumConcurrentJobs == 0 &&
+- jcr->wstore->NumConcurrentJobs < jcr->wstore->MaxConcurrentJobs) {
+- /* Simple case, first job */
+- jcr->wstore->NumConcurrentJobs = 1;
+- Dmsg0(200, "Set wncj=1\n");
+- } else if (jcr->wstore->NumConcurrentJobs < jcr->wstore->MaxConcurrentJobs) {
++ if (jcr->wstore->NumConcurrentJobs < jcr->wstore->MaxConcurrentJobs) {
+ jcr->wstore->NumConcurrentJobs++;
+ Dmsg1(200, "Inc wncj=%d\n", jcr->wstore->NumConcurrentJobs);
+ } else if (jcr->rstore) {
+- jcr->rstore->NumConcurrentJobs--; /* back out rstore */
+- Dmsg1(200, "Fail wncj=%d\n", jcr->wstore->NumConcurrentJobs);
++ dec_read_store(jcr);
+ skip_this_jcr = true;
+ } else {
+ Dmsg1(200, "Fail wncj=%d\n", jcr->wstore->NumConcurrentJobs);
+@@ -729,14 +739,8 @@
+ jcr->client->NumConcurrentJobs++;
+ } else {
+ /* Back out previous locks */
+- if (jcr->wstore) {
+- jcr->wstore->NumConcurrentJobs--;
+- Dmsg1(200, "Dec wncj=%d\n", jcr->wstore->NumConcurrentJobs);
+- }
+- if (jcr->rstore) {
+- jcr->rstore->NumConcurrentJobs--;
+- Dmsg1(200, "Dec rncj=%d\n", jcr->rstore->NumConcurrentJobs);
+- }
++ dec_write_store(jcr);
++ dec_read_store(jcr);
+ set_jcr_job_status(jcr, JS_WaitClientRes);
+ return false;
+ }
+@@ -744,14 +748,8 @@
+ jcr->job->NumConcurrentJobs++;
+ } else {
+ /* Back out previous locks */
+- if (jcr->wstore) {
+- jcr->wstore->NumConcurrentJobs--;
+- Dmsg1(200, "Dec wncj=%d\n", jcr->wstore->NumConcurrentJobs);
+- }
+- if (jcr->rstore) {
+- jcr->rstore->NumConcurrentJobs--;
+- Dmsg1(200, "Dec rncj=%d\n", jcr->rstore->NumConcurrentJobs);
+- }
++ dec_write_store(jcr);
++ dec_read_store(jcr);
+ jcr->client->NumConcurrentJobs--;
+ set_jcr_job_status(jcr, JS_WaitJobRes);
+ return false;
+@@ -760,3 +758,23 @@
+ jcr->acquired_resource_locks = true;
+ return true;
+ }
++
++static void dec_read_store(JCR *jcr)
++{
++ if (jcr->rstore) {
++// jcr->rstore->NumConcurrentReadJobs--; /* back out rstore */
++ jcr->rstore->NumConcurrentJobs--; /* back out rstore */
++ Dmsg1(200, "Dec rncj=%d\n", jcr->rstore->NumConcurrentJobs);
++// ASSERT(jcr->rstore->NumConcurrentReadJobs >= 0);
++ ASSERT(jcr->rstore->NumConcurrentJobs >= 0);
++ }
++}
++
++static void dec_write_store(JCR *jcr)
++{
++ if (jcr->wstore) {
++ jcr->wstore->NumConcurrentJobs--;
++ Dmsg1(200, "Dec wncj=%d\n", jcr->wstore->NumConcurrentJobs);
++ ASSERT(jcr->wstore->NumConcurrentJobs >= 0);
++ }
++}