4 \chapter{Bacula Developer Notes}
5 \label{_ChapterStart10}
6 \index{Bacula Developer Notes}
7 \index{Notes!Bacula Developer}
8 \addcontentsline{toc}{section}{Bacula Developer Notes}
10 This document is intended mostly for developers and describes how you can
11 contribute to the Bacula project and the the general framework of making
12 Bacula source changes.
14 \subsection{Contributions}
16 \addcontentsline{toc}{subsubsection}{Contributions}
18 Contributions to the Bacula project come in many forms: ideas,
19 participation in helping people on the bacula-users email list, packaging
20 Bacula binaries for the community, helping improve the documentation, and
23 Contributions in the form of submissions for inclusion in the project are
24 broken into two groups. The first are contributions that are aids and not
25 essential to Bacula. In general, these will be scripts or will go into the
26 {\bf bacula/examples} directory. For these kinds of non-essential
27 contributions there is no obligation to do a copyright assignment as
28 described below. However, a copyright assignment would still be
31 The second class of contributions are those which will be integrated with
32 Bacula and become an essential part (code, scripts, documentation, ...)
33 Within this class of contributions, there are two hurdles to surmount. One
34 is getting your patch accepted, and two is dealing with copyright issues.
35 The following text describes some of the requirements for such code.
39 \addcontentsline{toc}{subsubsection}{Patches}
41 Subject to the copyright assignment described below, your patches should be
42 sent in {\bf git format-patch} format relative to the current contents of the
43 master branch of the Source Forge Git repository. Please attach the
44 output file or files generated by the {\bf git format-patch} to the email
45 rather than include them directory to avoid wrapping of the lines
46 in the patch. Please be sure to use the Bacula
47 indenting standard (see below) for source code. If you have checked out
48 the source with Git, you can get a diff using.
55 If you plan on doing significant development work over a period of time,
56 after having your first patch reviewed and approved, you will be eligible
57 for having developer Git write access so that you can commit your changes
58 directly to the Git repository. To do so, you will need a userid on Source
61 \subsection{Copyrights}
63 \addcontentsline{toc}{subsubsection}{Copyrights}
65 To avoid future problems concerning changing licensing or
66 copyrights, all code contributions more than a hand full of lines
67 must be in the Public Domain or have the copyright transferred to
68 the Free Software Foundation Europe e.V. with a Fiduciary License
69 Agreement (FLA) as the case for all the current code.
71 Prior to November 2004, all the code was copyrighted by Kern Sibbald and
72 John Walker. After November 2004, the code was copyrighted by Kern
73 Sibbald, then on the 15th of November 2006, Kern transferred the copyright
74 to the Free Software Foundation Europe e.V. In signing the FLA and
75 transferring the copyright, you retain the right to use the code you have
76 submitted as you want, and you ensure that Bacula will always remain Free
79 Your name should be clearly indicated as the author of the code, and you
80 must be extremely careful not to violate any copyrights or patents or use
81 other people's code without acknowledging it. The purpose of this
82 requirement is to avoid future copyright, patent, or intellectual property
83 problems. Please read the LICENSE agreement in the main Bacula source code
84 directory. When you sign the Fiduciary License Agreement (FLA) and send it
85 in, you are agreeing to the terms of that LICENSE file.
87 If you don't understand what we mean by future problems, please
88 examine the difficulties Mozilla was having finding
89 previous contributors at \elink{
90 http://www.mozilla.org/MPL/missing.html}
91 {http://www.mozilla.org/MPL/missing.html}. The other important issue is to
92 avoid copyright, patent, or intellectual property violations as was
93 (May 2003) claimed by SCO against IBM.
95 Although the copyright will be held by the Free Software
96 Foundation Europe e.V., each developer is expected to indicate
97 that he wrote and/or modified a particular module (or file) and
98 any other sources. The copyright assignment may seem a bit
99 unusual, but in reality, it is not. Most large projects require
102 If you have any doubts about this, please don't hesitate to ask. The
103 objective is to assure the long term survival of the Bacula project.
105 Items not needing a copyright assignment are: most small changes,
106 enhancements, or bug fixes of 5-10 lines of code, which amount to
107 less than 20% of any particular file.
109 \subsection{Copyright Assignment -- Fiduciary License Agreement}
110 \index{Copyright Assignment}
111 \index{Assignment!Copyright}
112 \addcontentsline{toc}{subsubsection}{Copyright Assignment -- Fiduciary License Agreement}
114 Since this is not a commercial enterprise, and we prefer to believe in
115 everyone's good faith, previously developers could assign the copyright by
116 explicitly acknowledging that they do so in their first submission. This
117 was sufficient if the developer is independent, or an employee of a
118 not-for-profit organization or a university. However, in an effort to
119 ensure that the Bacula code is really clean, beginning in August 2006, all
120 previous and future developers with SVN write access will be asked to submit a
121 copyright assignment (or Fiduciary License Agreement -- FLA),
122 which means you agree to the LICENSE in the main source
123 directory. It also means that you receive back the right to use
124 the code that you have submitted.
126 Any developer who wants to contribute and is employed by a company should
127 either list the employer as the owner of the code, or get explicit
128 permission from him to sign the copyright assignment. This is because in
129 many countries, all work that an employee does whether on company time or
130 in the employee's free time is considered to be Intellectual Property of
131 the company. Obtaining official approval or an FLA from the company will
132 avoid misunderstandings between the employee, the company, and the Bacula
133 project. A good number of companies have already followed this procedure.
135 The Fiduciary License Agreement is posted on the Bacula web site at:
136 \elink{http://www.bacula.org/en/FLA-bacula.en.pdf}{http://www.bacula.org/en/FLA-bacula.en.pdf}
138 The instructions for filling out this agreement are also at:
139 \elink{http://www.bacula.org/?page=fsfe}{http://www.bacula.org/?page=fsfe}
141 It should be filled out, then sent to:
145 Cotes-de-Montmoiret 9
150 Please note that the above address is different from the officially
151 registered office mentioned in the document. When you send in such a
152 complete document, please notify me: kern at sibbald dot com, and
153 please add your email address to the FLA so that I can contact you
154 to confirm reception of the signed FLA.
157 \section{The Development Cycle}
158 \index{Developement Cycle}
159 \index{Cycle!Developement}
160 \addcontentsline{toc}{subsubsection}{Development Cycle}
162 As discussed on the email lists, the number of contributions are
163 increasing significantly. We expect this positive trend
164 will continue. As a consequence, we have modified how we do
165 development, and instead of making a list of all the features that we will
166 implement in the next version, each developer signs up for one (maybe
167 two) projects at a time, and when they are complete, and the code
168 is stable, we will release a new version. The release cycle will probably
169 be roughly six months.
171 The difference is that with a shorter release cycle and fewer released
172 feature, we will have more time to review the new code that is being
173 contributed, and will be able to devote more time to a smaller number of
174 projects (some prior versions had too many new features for us to handle
177 Future release schedules will be much the same, and the
178 number of new features will also be much the same providing that the
179 contributions continue to come -- and they show no signs of let up :-)
181 \index{Feature Requests}
182 {\bf Feature Requests:} \\
183 In addition, we have "formalizee" the feature requests a bit.
185 Instead of me maintaining an informal list of everything I run into
186 (kernstodo), we now maintain a "formal" list of projects. This
187 means that all new feature requests, including those recently discussed on
188 the email lists, must be formally submitted and approved.
190 Formal submission of feature requests will take two forms: \\
191 1. non-mandatory, but highly recommended is to discuss proposed new features
192 on the mailing list.\\
193 2. Formal submission of an Feature Request in a special format. We'll
194 give an example of this below, but you can also find it on the web site
195 under "Support -\gt{} Feature Requests". Since it takes a bit of time to
196 properly fill out a Feature Request form, you probably should check on the
199 Once the Feature Request is received by the keeper of the projects list, it
200 will be sent to the Bacula project manager (Kern), and he will either
201 accept it (90% of the time), send it back asking for clarification (10% of
202 the time), send it to the email list asking for opinions, or reject it
205 If it is accepted, it will go in the "projects" file (a simple ASCII file)
206 maintained in the main Bacula source directory.
208 {\bf Implementation of Feature Requests:}\\
209 Any qualified developer can sign up for a project. The project must have
210 an entry in the projects file, and the developer's name will appear in the
213 {\bf How Feature Requests are accepted:}\\
214 Acceptance of Feature Requests depends on several things: \\
215 1. feedback from users. If it is negative, the Feature Request will probably not be
217 2. the difficulty of the project. A project that is so
218 difficult that we cannot imagine finding someone to implement probably won't
219 be accepted. Obviously if you know how to implement it, don't hesitate
220 to put it in your Feature Request \\
221 3. whether or not the Feature Request fits within the current strategy of
222 Bacula (for example an Feature Request that requests changing the tape to
223 tar format probably would not be accepted, ...).
225 {\bf How Feature Requests are prioritized:}\\
226 Once an Feature Request is accepted, it needs to be implemented. If you
227 can find a developer for it, or one signs up for implementing it, then the
228 Feature Request becomes top priority (at least for that developer).
230 Between releases of Bacula, we will generally solicit Feature Request input
231 for the next version, and by way of this email, we suggest that you send
232 discuss and send in your Feature Requests for the next release. Please
233 verify that the Feature Request is not in the current list (attached to this email).
235 Once users have had several weeks to submit Feature Requests, the keeper of
236 the projects list will organize them, and request users to vote on them.
237 This will allow fixing prioritizing the Feature Requests. Having a
238 priority is one thing, but getting it implement is another thing -- we are
239 hoping that the Bacula community will take more responsibility for assuring
240 the implementation of accepted Feature Requests.
242 Feature Request format:
244 ============= Empty Feature Request form ===========
245 Item n: One line summary ...
247 Origin: Name and email of originator.
250 What: More detailed explanation ...
252 Why: Why it is important ...
254 Notes: Additional notes or features (omit if not used)
255 ============== End Feature Request form ==============
259 ============= Example Completed Feature Request form ===========
260 Item 1: Implement a Migration job type that will move the job
261 data from one device to another.
262 Origin: Sponsored by Riege Sofware International GmbH. Contact:
263 Daniel Holtkamp <holtkamp at riege dot com>
264 Date: 28 October 2005
265 Status: Partially coded in 1.37 -- much more to do. Assigned to
268 What: The ability to copy, move, or archive data that is on a
269 device to another device is very important.
271 Why: An ISP might want to backup to disk, but after 30 days
272 migrate the data to tape backup and delete it from
273 disk. Bacula should be able to handle this
274 automatically. It needs to know what was put where,
275 and when, and what to migrate -- it is a bit like
276 retention periods. Doing so would allow space to be
277 freed up for current backups while maintaining older
280 Notes: Migration could be triggered by:
284 Highwater size (keep total size)
286 =================================================
290 \section{Bacula Code Submissions and Projects}
291 \index{Submissions and Projects}
292 \addcontentsline{toc}{subsection}{Code Submissions and Projects}
294 Getting code implemented in Bacula works roughly as follows:
298 \item Kern is the project manager, but prefers not to be a "gate keeper".
299 This means that the developers are expected to be self-motivated,
300 and once they have experience submit directly to the Git
301 repositories. However,
302 it is a good idea to have your patches reviewed prior to submitting,
303 and it is a bad idea to submit monster patches because no one will
304 be able to properly review them. See below for more details on this.
306 \item There are growing numbers of contributions (very good).
308 \item Some contributions come in the form of relatively small patches,
309 which Kern reviews, integrates, documents, tests, and maintains.
311 \item All Bacula developers take full
312 responsibility for writing the code, posting as patches so that we can
313 review it as time permits, integrating it at an appropriate time,
314 responding to our requests for tweaking it (name changes, ...),
315 document it in the code, document it in the manual (even though
316 their mother tongue is not English), test it, develop and commit
317 regression scripts, and answer in a timely fashion all bug reports --
318 even occasionally accepting additional bugs :-)
320 This is a sustainable way of going forward with Bacula, and the
321 direction that the project will be taking more and more. For
322 example, in the past, we have had some very dedicated programmers
323 who did major projects. However, some of these
324 programmers due to outside obligations (job responsibilities change of
325 job, school duties, ...) could not continue to maintain the code. In
326 those cases, the code suffers from lack of maintenance, sometimes we
327 patch it, sometimes not. In the end, if the code is not maintained, the
328 code gets dropped from the project (there are two such contributions
329 that are heading in that direction). When ever possible, we would like
330 to avoid this, and ensure a continuation of the code and a sharing of
331 the development, debugging, documentation, and maintenance
335 \section{Patches for Released Versions}
336 \index{Patches for Released Versions}
337 \addcontentsline{toc}{subsection}{Patches for Released Versions}
338 If you fix a bug in a released version, you should, unless it is
339 an absolutely trivial bug, create and release a patch file for the
340 bug. The procedure is as follows:
342 Fix the bug in the released branch and in the develpment master branch.
344 Make a patch file for the branch and add the branch patch to
345 the patches directory in both the branch and the trunk.
346 The name should be 2.2.4-xxx.patch where xxx is unique, in this case it can
347 be "restore", e.g. 2.2.4-restore.patch. Add to the top of the
348 file a brief description and instructions for applying it -- see for example
349 2.2.4-poll-mount.patch. The best way to create the patch file is as
353 (edit) 2.2.4-restore.patch
358 mv 0001-xxx 2.2.4-restore.patch
361 check to make sure no extra junk got put into the patch file (i.e.
362 it should have the patch for that bug only).
364 If there is not a bug report on the problem, create one, then add the
365 patch to the bug report.
367 Then upload it to the 2.2.x release of bacula-patches.
369 So, end the end, the patch file is:
371 \item Attached to the bug report
373 \item In Branch-2.2/bacula/patches/...
377 \item Loaded on Source Forge bacula-patches 2.2.x release. When
378 you add it, click on the check box to send an Email so that all the
379 users that are monitoring SF patches get notified.
383 \section{Developing Bacula}
384 \index{Developing Bacula}
385 \index{Bacula!Developing}
386 \addcontentsline{toc}{subsubsection}{Developing Bacula}
388 Typically the simplest way to develop Bacula is to open one xterm window
389 pointing to the source directory you wish to update; a second xterm window at
390 the top source directory level, and a third xterm window at the bacula
391 directory \lt{}top\gt{}/src/bacula. After making source changes in one of the
392 directories, in the top source directory xterm, build the source, and start
393 the daemons by entering:
397 ./startit then in the enter:
401 ./gnome-console to start the Console program. Enter any commands for testing.
402 For example: run kernsverify full.
404 Note, the instructions here to use {\bf ./startit} are different from using a
405 production system where the administrator starts Bacula by entering {\bf
406 ./bacula start}. This difference allows a development version of {\bf Bacula}
407 to be run on a computer at the same time that a production system is running.
408 The {\bf ./startit} strip starts {\bf Bacula} using a different set of
409 configuration files, and thus permits avoiding conflicts with any production
412 To make additional source changes, exit from the Console program, and in the
413 top source directory, stop the daemons by entering:
415 ./stopit then repeat the process.
417 \subsection{Debugging}
419 \addcontentsline{toc}{subsubsection}{Debugging}
421 Probably the first thing to do is to turn on debug output.
423 A good place to start is with a debug level of 20 as in {\bf ./startit -d20}.
424 The startit command starts all the daemons with the same debug level.
425 Alternatively, you can start the appropriate daemon with the debug level you
426 want. If you really need more info, a debug level of 60 is not bad, and for
427 just about everything a level of 200.
429 \subsection{Using a Debugger}
430 \index{Using a Debugger}
431 \index{Debugger!Using a}
432 \addcontentsline{toc}{subsubsection}{Using a Debugger}
434 If you have a serious problem such as a segmentation fault, it can usually be
435 found quickly using a good multiple thread debugger such as {\bf gdb}. For
436 example, suppose you get a segmentation violation in {\bf bacula-dir}. You
437 might use the following to find the problem:
439 \lt{}start the Storage and File daemons\gt{}
442 run -f -s -c ./dird.conf
443 \lt{}it dies with a segmentation fault\gt{}
445 The {\bf -f} option is specified on the {\bf run} command to inhibit {\bf
446 dird} from going into the background. You may also want to add the {\bf -s}
447 option to the run command to disable signals which can potentially interfere
450 As an alternative to using the debugger, each {\bf Bacula} daemon has a built
451 in back trace feature when a serious error is encountered. It calls the
452 debugger on itself, produces a back trace, and emails the report to the
453 developer. For more details on this, please see the chapter in the main Bacula
454 manual entitled ``What To Do When Bacula Crashes (Kaboom)''.
456 \subsection{Memory Leaks}
459 \addcontentsline{toc}{subsubsection}{Memory Leaks}
461 Because Bacula runs routinely and unattended on client and server machines, it
462 may run for a long time. As a consequence, from the very beginning, Bacula
463 uses SmartAlloc to ensure that there are no memory leaks. To make detection of
464 memory leaks effective, all Bacula code that dynamically allocates memory MUST
465 have a way to release it. In general when the memory is no longer needed, it
466 should be immediately released, but in some cases, the memory will be held
467 during the entire time that Bacula is executing. In that case, there MUST be a
468 routine that can be called at termination time that releases the memory. In
469 this way, we will be able to detect memory leaks. Be sure to immediately
470 correct any and all memory leaks that are printed at the termination of the
473 \subsection{Special Files}
474 \index{Files!Special}
475 \index{Special Files}
476 \addcontentsline{toc}{subsubsection}{Special Files}
478 Kern uses files named 1, 2, ... 9 with any extension as scratch files. Thus
479 any files with these names are subject to being rudely deleted at any time.
481 \subsection{When Implementing Incomplete Code}
482 \index{Code!When Implementing Incomplete}
483 \index{When Implementing Incomplete Code}
484 \addcontentsline{toc}{subsubsection}{When Implementing Incomplete Code}
486 Please identify all incomplete code with a comment that contains
492 where there are three asterisks (*) before and after the word
493 FIXME (in capitals) and no intervening spaces. This is important as it allows
494 new programmers to easily recognize where things are partially implemented.
496 \subsection{Bacula Source File Structure}
497 \index{Structure!Bacula Source File}
498 \index{Bacula Source File Structure}
499 \addcontentsline{toc}{subsubsection}{Bacula Source File Structure}
501 The distribution generally comes as a tar file of the form {\bf
502 bacula.x.y.z.tar.gz} where x, y, and z are the version, release, and update
503 numbers respectively.
505 Once you detar this file, you will have a directory structure as follows:
512 |- mtx (autochanger control program + tape drive info)
513 |- sqlite (SQLite database program)
517 |- pthreads (Native win32 pthreads library -- dll)
518 |- zlib (Native win32 zlib library)
519 |- wx (wxWidgets source code)
522 |- bacula (main source directory containing configuration
523 | and installation files)
524 |- autoconf (automatic configuration files, not normally used
526 |- intl (programs used to translate)
527 |- platforms (OS specific installation files)
528 |- redhat (Red Hat installation)
529 |- solaris (Sun installation)
530 |- freebsd (FreeBSD installation)
531 |- irix (Irix installation -- not tested)
532 |- unknown (Default if system not identified)
533 |- po (translations of source strings)
534 |- src (source directory; contains global header files)
535 |- cats (SQL catalog database interface directory)
536 |- console (bacula user agent directory)
537 |- dird (Director daemon)
538 |- filed (Unix File daemon)
539 |- win32 (Win32 files to make bacula-fd be a service)
540 |- findlib (Unix file find library for File daemon)
541 |- gnome-console (GNOME version of console program)
542 |- lib (General Bacula library)
543 |- stored (Storage daemon)
544 |- tconsole (Tcl/tk console program -- not yet working)
545 |- testprogs (test programs -- normally only in Kern's tree)
546 |- tools (Various tool programs)
547 |- win32 (Native Win32 File daemon)
548 |- baculafd (Visual Studio project file)
549 |- compat (compatibility interface library)
550 |- filed (links to src/filed)
551 |- findlib (links to src/findlib)
552 |- lib (links to src/lib)
553 |- console (beginning of native console program)
554 |- wx-console (wxWidget console Win32 specific parts)
555 |- wx-console (wxWidgets console main source program)
558 |- regress (Regression scripts)
559 |- bin (temporary directory to hold Bacula installed binaries)
560 |- build (temporary directory to hold Bacula source)
561 |- scripts (scripts and .conf files)
562 |- tests (test scripts)
563 |- tmp (temporary directory for temp files)
564 |- working (temporary working directory for Bacula daemons)
567 |- docs (documentation directory)
568 |- developers (Developer's guide)
569 |- home-page (Bacula's home page source)
570 |- manual (html document directory)
571 |- manual-fr (French translation)
572 |- manual-de (German translation)
573 |- techlogs (Technical development notes);
576 |- rescue (Bacula rescue CDROM)
577 |- linux (Linux rescue CDROM)
578 |- cdrom (Linux rescue CDROM code)
580 |- solaris (Solaris rescue -- incomplete)
581 |- freebsd (FreeBSD rescue -- incomplete)
584 |- gui (Bacula GUI projects)
585 |- bacula-web (Bacula web php management code)
586 |- bimagemgr (Web application for burning CDROMs)
592 \subsection{Header Files}
595 \addcontentsline{toc}{subsubsection}{Header Files}
597 Please carefully follow the scheme defined below as it permits in general only
598 two header file includes per C file, and thus vastly simplifies programming.
599 With a large complex project like Bacula, it isn't always easy to ensure that
600 the right headers are invoked in the right order (there are a few kludges to
601 make this happen -- i.e. in a few include files because of the chicken and egg
602 problem, certain references to typedefs had to be replaced with {\bf void} ).
604 Every file should include {\bf bacula.h}. It pulls in just about everything,
605 with very few exceptions. If you have system dependent ifdefing, please do it
606 in {\bf baconfig.h}. The version number and date are kept in {\bf version.h}.
608 Each of the subdirectories (console, cats, dird, filed, findlib, lib, stored,
609 ...) contains a single directory dependent include file generally the name of
610 the directory, which should be included just after the include of {\bf
611 bacula.h}. This file (for example, for the dird directory, it is {\bf dird.h})
612 contains either definitions of things generally needed in this directory, or
613 it includes the appropriate header files. It always includes {\bf protos.h}.
616 Each subdirectory contains a header file named {\bf protos.h}, which contains
617 the prototypes for subroutines exported by files in that directory. {\bf
618 protos.h} is always included by the main directory dependent include file.
620 \subsection{Programming Standards}
621 \index{Standards!Programming}
622 \index{Programming Standards}
623 \addcontentsline{toc}{subsubsection}{Programming Standards}
625 For the most part, all code should be written in C unless there is a burning
626 reason to use C++, and then only the simplest C++ constructs will be used.
627 Note, Bacula is slowly evolving to use more and more C++.
629 Code should have some documentation -- not a lot, but enough so that I can
630 understand it. Look at the current code, and you will see that I document more
631 than most, but am definitely not a fanatic.
633 We prefer simple linear code where possible. Gotos are strongly discouraged
634 except for handling an error to either bail out or to retry some code, and
635 such use of gotos can vastly simplify the program.
637 Remember this is a C program that is migrating to a {\bf tiny} subset of C++,
638 so be conservative in your use of C++ features.
640 \subsection{Do Not Use}
643 \addcontentsline{toc}{subsubsection}{Do Not Use}
646 \item STL -- it is totally incomprehensible.
649 \subsection{Avoid if Possible}
650 \index{Possible!Avoid if}
651 \index{Avoid if Possible}
652 \addcontentsline{toc}{subsubsection}{Avoid if Possible}
655 \item Using {\bf void *} because this generally means that one must
656 using casting, and in C++ casting is rather ugly. It is OK to use
657 void * to pass structure address where the structure is not known
658 to the routines accepting the packet (typically callback routines).
659 However, declaring "void *buf" is a bad idea. Please use the
660 correct types whenever possible.
662 \item Using undefined storage specifications such as (short, int, long,
663 long long, size\_t ...). The problem with all these is that the number of bytes
664 they allocate depends on the compiler and the system. Instead use
665 Bacula's types (int8\_t, uint8\_t, int32\_t, uint32\_t, int64\_t, and
666 uint64\_t). This guarantees that the variables are given exactly the
667 size you want. Please try at all possible to avoid using size\_t ssize\_t
668 and the such. They are very system dependent. However, some system
669 routines may need them, so their use is often unavoidable.
671 \item Returning a malloc'ed buffer from a subroutine -- someone will forget
674 \item Heap allocation (malloc) unless needed -- it is expensive. Use
677 \item Templates -- they can create portability problems.
679 \item Fancy or tricky C or C++ code, unless you give a good explanation of
682 \item Too much inheritance -- it can complicate the code, and make reading it
683 difficult (unless you are in love with colons)
687 \subsection{Do Use Whenever Possible}
688 \index{Possible!Do Use Whenever}
689 \index{Do Use Whenever Possible}
690 \addcontentsline{toc}{subsubsection}{Do Use Whenever Possible}
693 \item Locking and unlocking within a single subroutine.
695 \item A single point of exit from all subroutines. A goto is
696 perfectly OK to use to get out early, but only to a label
697 named bail\_out, and possibly an ok\_out. See current code
700 \item malloc and free within a single subroutine.
702 \item Comments and global explanations on what your code or algorithm does.
704 \item When committing a fix for a bug, make the comment of the
708 Reason for bug fix or other message. Fixes bug #1234
711 It is important to write the {\bf bug #1234} like
712 that because our program that automatically pulls messages
713 from the git repository to make the ChangeLog looks for that
714 pattern. Obviously the {\bf 1234} should be replaced with
715 the number of the bug you actually fixed.
717 Providing the commit comment line has one of the following
718 keywords (or phrases), it will be ignored:
743 \item Use the following keywords at the beginning of
749 \subsection{Indenting Standards}
750 \index{Standards!Indenting}
751 \index{Indenting Standards}
752 \addcontentsline{toc}{subsubsection}{Indenting Standards}
754 We find it very hard to read code indented 8 columns at a time.
755 Even 4 at a time uses a lot of space, so we have adopted indenting
756 3 spaces at every level. Note, indention is the visual appearance of the
757 source on the page, while tabbing is replacing a series of up to 8 spaces from
760 The closest set of parameters for the Linux {\bf indent} program that will
761 produce reasonably indented code are:
765 -nbad -bap -bbo -nbc -br -brs -c36 -cd36 -ncdb -ce -ci3 -cli0
766 -cp36 -d0 -di1 -ndj -nfc1 -nfca -hnl -i3 -ip0 -l85 -lp -npcs
767 -nprs -npsl -saf -sai -saw -nsob -nss -nbc -ncs -nbfda
771 You can put the above in your .indent.pro file, and then just invoke indent on
772 your file. However, be warned. This does not produce perfect indenting, and it
773 will mess up C++ class statements pretty badly.
775 Braces are required in all if statements (missing in some very old code). To
776 avoid generating too many lines, the first brace appears on the first line
777 (e.g. of an if), and the closing brace is on a line by itself. E.g.
787 Just follow the convention in the code. For example we I prefer non-indented cases.
804 Avoid using // style comments except for temporary code or turning off debug
805 code. Standard C comments are preferred (this also keeps the code closer to
808 Attempt to keep all lines less than 85 characters long so that the whole line
809 of code is readable at one time. This is not a rigid requirement.
811 Always put a brief description at the top of any new file created describing
812 what it does and including your name and the date it was first written. Please
813 don't forget any Copyrights and acknowledgments if it isn't 100\% your code.
814 Also, include the Bacula copyright notice that is in {\bf src/c}.
816 In general you should have two includes at the top of the an include for the
817 particular directory the code is in, for includes are needed, but this should
820 In general (except for self-contained packages), prototypes should all be put
821 in {\bf protos.h} in each directory.
823 Always put space around assignment and comparison operators.
834 but your can compress things in a {\bf for} statement:
838 for (i=0; i < del.num_ids; i++) {
843 Don't overuse the inline if (?:). A full {\bf if} is preferred, except in a
844 print statement, e.g.:
848 if (ua->verbose \&& del.num_del != 0) {
849 bsendmsg(ua, _("Pruned %d %s on Volume %s from catalog.\n"), del.num_del,
850 del.num_del == 1 ? "Job" : "Jobs", mr->VolumeName);
855 Leave a certain amount of debug code (Dmsg) in code you submit, so that future
856 problems can be identified. This is particularly true for complicated code
857 likely to break. However, try to keep the debug code to a minimum to avoid
858 bloating the program and above all to keep the code readable.
860 Please keep the same style in all new code you develop. If you include code
861 previously written, you have the option of leaving it with the old indenting
862 or re-indenting it. If the old code is indented with 8 spaces, then please
863 re-indent it to Bacula standards.
865 If you are using {\bf vim}, simply set your tabstop to 8 and your shiftwidth
870 \addcontentsline{toc}{subsubsection}{Tabbing}
872 Tabbing (inserting the tab character in place of spaces) is as normal on all
873 Unix systems -- a tab is converted space up to the next column multiple of 8.
874 My editor converts strings of spaces to tabs automatically -- this results in
875 significant compression of the files. Thus, you can remove tabs by replacing
876 them with spaces if you wish. Please don't confuse tabbing (use of tab
877 characters) with indenting (visual alignment of the code).
881 \addcontentsline{toc}{subsubsection}{Don'ts}
896 They are system dependent and un-safe. These should be replaced by the Bacula
901 char *bstrncpy(char *dest, char *source, int dest_size);
902 char *bstrncat(char *dest, char *source, int dest_size);
903 int bsnprintf(char *buf, int32_t buf_len, const char *fmt, ...);
904 int bvsnprintf(char *str, int32_t size, const char *format, va_list ap);
908 See src/lib/bsys.c for more details on these routines.
910 Don't use the {\bf \%lld} or the {\bf \%q} printf format editing types to edit
911 64 bit integers -- they are not portable. Instead, use {\bf \%s} with {\bf
912 edit\_uint64()}. For example:
917 uint64_t num = something;
919 bsnprintf(buf, sizeof(buf), "Num=%s\n", edit_uint64(num, ed1));
923 Note: {\bf \%lld} is now permitted in Bacula code -- we have our
924 own printf routines which handle it correctly. The edit\_uint64() subroutine
925 can still be used if you wish, but over time, most of that old style will
928 The edit buffer {\bf ed1} must be at least 27 bytes long to avoid overflow.
929 See src/lib/edit.c for more details. If you look at the code, don't start
930 screaming that I use {\bf lld}. I actually use subtle trick taught to me by
931 John Walker. The {\bf lld} that appears in the editing routine is actually
932 {\bf \#define} to a what is needed on your OS (usually ``lld'' or ``q'') and
933 is defined in autoconf/configure.in for each OS. C string concatenation causes
934 the appropriate string to be concatenated to the ``\%''.
936 Also please don't use the STL or Templates or any complicated C++ code.
938 \subsection{Message Classes}
939 \index{Classes!Message}
940 \index{Message Classes}
941 \addcontentsline{toc}{subsubsection}{Message Classes}
943 Currently, there are five classes of messages: Debug, Error, Job, Memory,
946 \subsection{Debug Messages}
947 \index{Messages!Debug}
948 \index{Debug Messages}
949 \addcontentsline{toc}{subsubsection}{Debug Messages}
951 Debug messages are designed to be turned on at a specified debug level and are
952 always sent to STDOUT. There are designed to only be used in the development
953 debug process. They are coded as:
955 DmsgN(level, message, arg1, ...) where the N is a number indicating how many
956 arguments are to be substituted into the message (i.e. it is a count of the
957 number arguments you have in your message -- generally the number of percent
958 signs (\%)). {\bf level} is the debug level at which you wish the message to
959 be printed. message is the debug message to be printed, and arg1, ... are the
960 arguments to be substituted. Since not all compilers support \#defines with
961 varargs, you must explicitly specify how many arguments you have.
963 When the debug message is printed, it will automatically be prefixed by the
964 name of the daemon which is running, the filename where the Dmsg is, and the
965 line number within the file.
967 Some actual examples are:
969 Dmsg2(20, ``MD5len=\%d MD5=\%s\textbackslash{}n'', strlen(buf), buf);
971 Dmsg1(9, ``Created client \%s record\textbackslash{}n'', client->hdr.name);
973 \subsection{Error Messages}
974 \index{Messages!Error}
975 \index{Error Messages}
976 \addcontentsline{toc}{subsubsection}{Error Messages}
978 Error messages are messages that are related to the daemon as a whole rather
979 than a particular job. For example, an out of memory condition my generate an
980 error message. They should be very rarely needed. In general, you should be
981 using Job and Job Queued messages (Jmsg and Qmsg). They are coded as:
983 EmsgN(error-code, level, message, arg1, ...) As with debug messages, you must
984 explicitly code the of arguments to be substituted in the message. error-code
985 indicates the severity or class of error, and it may be one of the following:
987 \addcontentsline{lot}{table}{Message Error Code Classes}
988 \begin{longtable}{lp{3in}}
989 {{\bf M\_ABORT} } & {Causes the daemon to immediately abort. This should be
990 used only in extreme cases. It attempts to produce a traceback. } \\
991 {{\bf M\_ERROR\_TERM} } & {Causes the daemon to immediately terminate. This
992 should be used only in extreme cases. It does not produce a traceback. } \\
993 {{\bf M\_FATAL} } & {Causes the daemon to terminate the current job, but the
994 daemon keeps running } \\
995 {{\bf M\_ERROR} } & {Reports the error. The daemon and the job continue
997 {{\bf M\_WARNING} } & {Reports an warning message. The daemon and the job
998 continue running } \\
999 {{\bf M\_INFO} } & {Reports an informational message.}
1003 There are other error message classes, but they are in a state of being
1004 redesigned or deprecated, so please do not use them. Some actual examples are:
1007 Emsg1(M\_ABORT, 0, ``Cannot create message thread: \%s\textbackslash{}n'',
1010 Emsg3(M\_WARNING, 0, ``Connect to File daemon \%s at \%s:\%d failed. Retrying
1011 ...\textbackslash{}n'', client-\gt{}hdr.name, client-\gt{}address,
1014 Emsg3(M\_FATAL, 0, ``bdird\lt{}filed: bad response from Filed to \%s command:
1015 \%d \%s\textbackslash{}n'', cmd, n, strerror(errno));
1017 \subsection{Job Messages}
1018 \index{Job Messages}
1019 \index{Messages!Job}
1020 \addcontentsline{toc}{subsubsection}{Job Messages}
1022 Job messages are messages that pertain to a particular job such as a file that
1023 could not be saved, or the number of files and bytes that were saved. They
1026 Jmsg(jcr, M\_FATAL, 0, "Text of message");
1028 A Jmsg with M\_FATAL will fail the job. The Jmsg() takes varargs so can
1029 have any number of arguments for substituted in a printf like format.
1030 Output from the Jmsg() will go to the Job report.
1032 If the Jmsg is followed with a number such as Jmsg1(...), the number
1033 indicates the number of arguments to be substituted (varargs is not
1034 standard for \#defines), and what is more important is that the file and
1035 line number will be prefixed to the message. This permits a sort of debug
1038 \subsection{Queued Job Messages}
1039 \index{Queued Job Messages}
1040 \index{Messages!Job}
1041 \addcontentsline{toc}{subsubsection}{Queued Job Messages}
1042 Queued Job messages are similar to Jmsg()s except that the message is
1043 Queued rather than immediately dispatched. This is necessary within the
1044 network subroutines and in the message editing routines. This is to prevent
1045 recursive loops, and to ensure that messages can be delivered even in the
1046 event of a network error.
1049 \subsection{Memory Messages}
1050 \index{Messages!Memory}
1051 \index{Memory Messages}
1052 \addcontentsline{toc}{subsubsection}{Memory Messages}
1054 Memory messages are messages that are edited into a memory buffer. Generally
1055 they are used in low level routines such as the low level device file dev.c in
1056 the Storage daemon or in the low level Catalog routines. These routines do not
1057 generally have access to the Job Control Record and so they return error
1058 essages reformatted in a memory buffer. Mmsg() is the way to do this.
1060 \subsection{Bugs Database}
1061 \index{Database!Bugs}
1062 \index{Bugs Database}
1063 \addcontentsline{toc}{subsubsection}{Bugs Database}
1064 We have a bugs database which is at:
1065 \elink{http://bugs.bacula.org}{http://bugs.bacula.org}, and as
1066 a developer you will need to respond to bugs, perhaps bugs in general
1067 if you have time, otherwise just bugs that correspond to code that
1070 If you need to answer bugs, please be sure to ask the Project Manager
1071 (currently Kern) to give you Developer access to the bugs database. This
1072 allows you to modify statuses and close bugs.
1074 The first thing is if you want to take over a bug, rather than just make a
1075 note, you should assign the bug to yourself. This helps other developers
1076 know that you are the principal person to deal with the bug. You can do so
1077 by going into the bug and clicking on the {\bf Update Issue} button. Then
1078 you simply go to the {\bf Assigned To} box and select your name from the
1079 drop down box. To actually update it you must click on the {\bf Update
1080 Information} button a bit further down on the screen, but if you have other
1081 things to do such as add a Note, you might wait before clicking on the {\bf
1082 Update Information} button.
1084 Generally, we set the {\bf Status} field to either acknowledged, confirmed,
1085 or feedback when we first start working on the bug. Feedback is set when
1086 we expect that the user should give us more information.
1088 Normally, once you are reasonably sure that the bug is fixed, and a patch
1089 is made and attached to the bug report, and/or in the SVN, you can close
1090 the bug. If you want the user to test the patch, then leave the bug open,
1091 otherwise close it and set {\bf Resolution} to {\bf Fixed}. We generally
1092 close bug reports rather quickly, even without confirmation, especially if
1093 we have run tests and can see that for us the problem is fixed. However,
1094 in doing so, it avoids misunderstandings if you leave a note while you are
1095 closing the bug that says something to the following effect:
1096 We are closing this bug because ... If for some reason, it does not fix
1097 your problem, please feel free to reopen it, or to open a new bug report
1098 describing the problem".
1100 We do not recommend that you attempt to edit any of the bug notes that have
1101 been submitted, nor to delete them or make them private. In fact, if
1102 someone accidentally makes a bug note private, you should ask the reason
1103 and if at all possible (with his agreement) make the bug note public.
1105 If the user has not properly filled in most of the important fields
1106 (platorm, OS, Product Version, ...) please do not hesitate to politely ask
1107 him. Also, if the bug report is a request for a new feature, please
1108 politely send the user to the Feature Request menu item on www.bacula.org.
1109 The same applies to a support request (we answer only bugs), you might give
1110 the user a tip, but please politely refer him to the manual and the
1111 Getting Support page of www.bacula.org.