]> git.sur5r.net Git - bacula/docs/blob - docs/developers/generaldevel.tex
Update licenses
[bacula/docs] / docs / developers / generaldevel.tex
1 %%
2 %%
3
4 \section*{Bacula Developer Notes}
5 \label{_ChapterStart10}
6 \index{Bacula Developer Notes}
7 \index{Notes!Bacula Developer}
8 \addcontentsline{toc}{section}{Bacula Developer Notes}
9
10 \subsection*{General}
11 \index{General}
12 \addcontentsline{toc}{subsection}{General}
13
14 This document is intended mostly for developers and describes the the general
15 framework of making Bacula source changes. 
16
17 \subsubsection*{Contributions}
18 \index{Contributions}
19 \addcontentsline{toc}{subsubsection}{Contributions}
20
21 Contributions from programmers are broken into two groups. The first are
22 contributions that are aids and not essential to Bacula. In general, these
23 will be scripts or will go into and examples or contributions directory. 
24 For these kinds of non-essential contributions there is no obligation to do
25 a copyright assignment as described below. However, a copyright assignment
26 would still be appreciated.
27
28 The second class of contributions are those which will be integrated with
29 Bacula and become an essential part. Within this class of contributions, there
30 are two hurdles to surmount. One is getting your patch accepted, and two is
31 dealing with copyright issues. The following text describes some of the
32 requirements for such code. 
33
34 \subsubsection*{Patches}
35 \index{Patches}
36 \addcontentsline{toc}{subsubsection}{Patches}
37
38 Subject to the copyright assignment described below, your patches should be
39 sent in {\bf diff -u} format relative to the current contents of the Source
40 Forge CVS, which is the easiest to understand and integrate.
41 If you have checked out the source with CVS, you can get a diff using:
42
43 \begin{verbatim}
44 cvs diff -u > change.patch
45 \end{verbatim}
46      
47 If you plan on doing significant development work over a period of time,
48 after having your first patch reviewed and approved, you will be eligible
49 for having developer CVS access so that you can commit your changes
50 directly to the CVS repository.  To do so, you will need a userid on Source
51 Forge.
52
53 \subsubsection*{Copyrights}
54 \index{Copyrights}
55 \addcontentsline{toc}{subsubsection}{Copyrights}
56
57 To avoid future problems concerning changing licensing or copyrights, all
58 code contributions more than a hand full of lines must be in the Public
59 Domain or have the copyright assigned to Kern Sibbald as in the current
60 code.  Note, prior to November 2004, the code was copyrighted by Kern
61 Sibbald and John Walker.
62
63 Your name should be clearly indicated as the author of the code, and you
64 must be extremely careful not to violate any copyrights or use other
65 people's code without acknowledging it.  The purpose of this requirement is
66 to avoid future copyright, patent, or intellectual property problems.  To
67 understand on possible source of future problems, please examine the
68 difficulties Mozilla is (was?) having finding previous contributors at
69 \elink{ http://www.mozilla.org/MPL/missing.html}
70 {http://www.mozilla.org/MPL/missing.html}. The other important issue is to
71 avoid copyright, patent, or intellectual property violations as are currently
72 (May 2003) being claimed by SCO against IBM. 
73
74 Although the copyright will be held by Kern, each developer is expected to
75 indicate that he wrote and/or modified a particular module (or file) and
76 any other sources.  The copyright assignment may seem a bit unusual, but in
77 reality, it is not.  Most large projects require this.  In fact, the
78 paperwork associated with making contributions to the Free Software
79 Foundation, was for me unsurmountable, so hopefully the rather
80 simplified procedure we have will not create any difficulties for
81 you.
82
83 If you have any doubts about this, please don't hesitate to ask.  The
84 objective is to assure the long term servival of the Bacula project.  There
85 is no consideration of personal gain in this request.  Our (John and my)
86 track records with Autodesk are easily available; early
87 programmers/founders/contributors and later employees had substantial
88 shares of the company, and no one founder had a controlling part of the
89 company.  Even though Microsoft created many millionaires among early
90 employees, the politics of Autodesk (during our time at the helm) is in
91 stark contrast to Microsoft where the majority of the company is still
92 tightly held among a few.
93
94 Items not needing a copyright assignment are: most small changes,
95 enhancements, or bug fixes of 5-10 lines of code, and documentation. 
96
97 \subsubsection*{Copyright Assignment}
98 \index{Copyright Assignment}
99 \index{Assignment!Copyright}
100 \addcontentsline{toc}{subsubsection}{Copyright Assignment}
101
102 Since this is not a commercial enterprise, and I prefer to believe in
103 everyone's good faith, developers can assign the copyright by explicitly
104 acknowledging that they do so in their first submission.  This is
105 sufficient if the developer is independent, or an employee of a
106 not-for-profit organization or a university.  Any developer who wants to
107 contribute and is employed by a company must get a copyright assignment
108 from his employer.  This is to avoid misunderstandings between the
109 employee, the company, and the Bacula project. A good number of
110 companies have already followed this procedure.  
111
112 \subsubsection*{Corporate Assignment Statement}
113 \index{Statement!Corporate Assignment}
114 \index{Corporate Assignment Statement}
115 \addcontentsline{toc}{subsubsection}{Corporate Assignment Statement}
116
117 The following statement must be filled out by the employer, signed, and mailed
118 to my address (please ask me for my address and I will email it -- I'd prefer
119 not to include it here). 
120
121 \footnotesize
122 \begin{verbatim}
123 Copyright release and transfer statement.
124    <On company letter head>
125
126    To: Kern Sibbald
127    Concerning: Copyright release and transfer
128
129    <Company, Inc> is hereby agrees that <names-of-developers> and
130    other employees of <Company, Inc> are authorized to develop
131    code for and contribute code to the Bacula project for an
132    undetermined period of time.  The copyright as well as all
133    other rights to and interests in such contributed code are
134    hereby transferred to Kern Sibbald.
135
136    Signed in <City, Country> on <Date>:
137
138    <Name of Person>, <Position in Company, Inc>
139
140 \end{verbatim}
141 \normalsize
142
143 This release/transfer statement must be sent to:
144 Kern Sibbald
145 Address-to-be-given
146
147 If you wish to retain the full rights to use the software you
148 have contributed in different projects, this is not a problem. Just
149 request a perpetual non-exclusive license before sending in your
150 copyright assignment.
151
152 \subsection*{Basic CVS Usage}
153 \index{Basic CVS Usage}
154 \index{CVS}
155 \addcontentsline{toc}{subsection}{Basic CVS Usage}
156
157 The Bacula CVS is kept at Source Forge. If you are not a developer,
158 you only be able to access the public CVS, which runs about 6 hours behind
159 the developer's CVS.  If you are a developer, then you will have immediate
160 access to "the" CVS and any changes ("commit") that you make will be
161 immediately seen by other developers.
162
163 For developer access to the CVS, go to the Bacula page on Source Forge
164 and click on the CVS menu item.  Then follow the instructions for
165 installing your SSH public key.  It may take a few hours until the
166 key is actually installed, and then you will have access to the CVS.
167
168 The Bacula CVS is divided into the following CVS "projects" or "modules".
169
170 \begin{verbatim}
171
172   bacula              (Bacula source code)
173   docs                (Bacula documentation)
174   gui                 (Some of the GUI programs that do not use
175                        the Bacula core code)
176   rescue              (Bacula CDROM rescue code)
177   regress             (Bacula regression scripts)
178   ryol                (Roll your own Linux -- incomplete project)
179
180 \end{verbatim}
181
182 Most of you will want either the Bacula source (bacula) and/or the
183 documents (docs).
184
185 To get the source for a project, you must check it out ("checkout"), which
186 you do usually once.
187
188 \subsubsection*{Public CVS Access}
189 \index{Public CVS Access}
190 \addcontentsline{toc}{subsubsection}{Public CVS Access}
191
192 The first time you checkout the code for each project, you will need to
193 tell the cvs program where the CVS repository is.  The procedure for
194 checking out code from the public CVS is:
195
196 \begin{verbatim}
197 cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/bacula login 
198 \end{verbatim}
199 Then when it prompts for the password for {\bf anonymous}, simply
200 press the Enter key.  The above command is necessary only once
201 the very first time you login. Then enter the following command:
202
203 \begin{verbatim}
204 cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/bacula co -P bacula
205 \end{verbatim}
206
207 The above will place the contents of the bacula module in a directory
208 named {\bf bacula} in the current directory.  This data will come
209 from the public CVS, which typically runs 6 hours to a day behind the
210 developer's CVS. Once you have created a copy of the CVS, you can use 
211 the commands listed below under the title CVS Usage.
212
213 \subsubsection*{Developer CVS Access}
214 \index{Developer CVS Access}
215 \addcontentsline{toc}{subsubsection}{Developer CVS Access}
216
217 If you are registered as a Bacula developer (contact Kern about this),
218 you may access the developer's CVS using:
219
220 \begin{verbatim}
221 export CVS_RSH=ssh
222 export CVSROOT=:ext:<nnnn>@cvs.bacula.sourceforge.net:/cvsroot/bacula
223 \end{verbatim}
224
225 where you replace \lt{}nnnn\gt{} by your Source Forge user name.
226
227 Then do:
228
229 \begin{verbatim}
230 cvs -z3 checkout -d <directory> bacula
231 \end{verbatim}
232
233 where you replace \lt{}directory\gt{} by the name of the directory you want
234 to contain the Bacula source code.  If you want the docs, replace the
235 word "bacula" on the above line by "docs" and be sure to put it in
236 a different directory.  The -z3 just tells CVS to use compression during
237 the transmission, which makes things go faster. There is no need to
238 do the anonymous login as is the case for non-developers.
239
240 The above command should generate output that looks a bit like the
241 following:
242
243 \begin{verbatim}
244 cvs checkout: Updating bacula
245 U bacula/Makefile
246 U bacula/bar.c
247 U bacula/foo.c
248 U bacula/main.c
249 ...
250 \end{verbatim}
251
252 \subsubsection*{CVS Usage}
253 \index{CVS Usage}
254 \addcontentsline{toc}{subsubsection}{CVS Usage}
255
256 The commands that follow with the exception of the {\bf commit} 
257 work the same whether you are accessing the public CVS or
258 the developer's CVS.
259
260 Let's assume you used the name "bacula" for the directory, so your
261 command was:
262
263 \begin{verbatim}
264 cvs -z3 checkout -d bacula bacula
265 \end{verbatim}
266
267 When the command is done, simply do:
268
269 \begin{verbatim}
270 cd bacula
271 \end{verbatim}
272
273
274 and then build Bacula.  You will notice a lot of extra CVS directories
275 in the source code.  Don't ever change or delete them, or you will mess up
276 your copy of the project. Also, do not rename or delete any of the files
277 in your copy of the repository or you may have problems.  Any files that
278 you change will remain only on your system until you do a "commit", which
279 is explained later.
280
281 Let's say you are working in the directory scripts.  You would then do:
282
283 \begin{verbatim}
284 cd scripts
285 (edit some files)
286 \end{verbatim}
287
288 when you are happy with your changes, you can do the following:
289
290 \begin{verbatim}
291 cd bacula   (to your top level directory)
292 cvs diff -u >my-changes.patch
293 \end{verbatim}
294
295 When the command is done, you can look in the file my-changes.patch
296 and you will see all the changes you have made to your copy of the
297 repository.  Make sure that you understand all the changes that
298 it reports before proceeding.  If you modified files that you do
299 do not want to commit to the main repository, you can simply delete
300 them from your local directory, and they will be restored from the
301 repository with the "cvs update" that is shown below.  Normally, you
302 should not find changes to files that you do not want to commit, and
303 if you find yourself in that position a lot, you are probably doing
304 something wrong.
305
306 Let's assume that now you want to commit your changes to the main CVS
307 repository.
308
309 First do:
310
311 \begin{verbatim}
312 cvs bacula
313 cvs update
314 \end{verbatim}
315
316 When you do this, it will pull any changes made by other developers into
317 your local copy of the repository, and it will check for conflicts. If there
318 are any, it will tell you, and you will need to resolve them.  The problems
319 of resolving conflicts are a bit more than this document can cover, but
320 you can examine the files it claims have conflicts and look for \lt{}\lt{}\lt{}\lt{}
321 or look in the .rej files that it creates.  If you have problems, just ask
322 on the developer's list.
323
324 Note, doing the above "cvs update" is not absolutely necessary.  There are
325 times when you may be working on code and you want to commit it, but you
326 explicitly do not want to move up to the latest version of the code in
327 the CVS.  If that is the case, you can simply skip the "cvs update" and
328 do the commit shown below.  If the commit fails because of a conflict, it
329 will tell you, and you must resolve the conflict before it will permit
330 you to do the commit.
331
332 Once your local copy of the repository has been updated, you can now
333 commit your changes:
334
335 \begin{verbatim}
336 cvs commit -m "Some comment about what you changed"
337 \end{verbatim}
338
339 or if you really only want to commit a single file, you can
340 do:
341
342 \begin{verbatim}
343 cvs commit -m "comment" scripts/file-I-edited
344 \end{verbatim}
345
346 Note, if you have done a build in your directory, or you have added
347 other new files, the commit will update only the files that are
348 actually in the repository.  For example, none of the object files
349 are stored in the repository, so when you do a commit, those object
350 files will simply be ignored.
351
352 If you want to add new files or remove files from the main CVS
353 repository, and you are not experienced with CVS, please ask Kern
354 to do it.  If you follow the simple steps above, it is unlikely that
355 you will do any damage to the repository, and if you do, it is always
356 possible for us to recover, but it can be painful.
357
358 If you are only working in one subdirectory of say the bacula project,
359 for example, the scripts directory, you can do your commit from
360 that subdirectory, and only the changes in that directory and all its
361 subdirectories will be committed.  This can be helpful for translators.
362 If you are doing a French translation, you will be working in
363 docs/manual-fr, and if you are always cd'ed into that directory when
364 doing your commits, your commit will effect only that directory.  As
365 long as you are careful only to change files that you want changed,
366 you have little to worry about.
367
368 \subsection*{The Development Cycle}
369 \index{Developement Cycle}
370 \index{Cycle!Developement}
371 \addcontentsline{toc}{subsubsection}{Development Cycle}
372
373 As I noted in the 1.38 ReleaseNotes, version 1.38 was different from prior
374 versions because it had a lot more contributions.  I expect that this trend
375 will continue.  As a consequence, I am going to modify how I normally do
376 development, and instead of making a list of all the features that I will
377 implement in the next version, I will personally sign up for one (maybe
378 two) projects at a time, and when they are complete, I will release a new
379 version.
380
381 The difference is that I will have more time to review the new code that is
382 being contributed, and will be able to devote more time to a smaller number
383 of projects (1.38 had too many new features for me to handle correctly).
384
385 I expect that future release schedules will be much the same, and the
386 number of new features will also be much the same providing that the
387 contributions continue to come -- and they show no signs of let up :-)
388
389 \index{Feature Requests}
390 {\bf Feature Requests:} \\
391 In addition, I would like to "formalize" the feature requests a bit.
392
393 Instead of me maintaining an informal list of everything I run into 
394 (kernstodo), I would like to maintain a "formal" list of projects.  This 
395 means that all new feature requests, including those recently discussed on 
396 the email lists, must be formally submitted and approved. 
397
398 Formal submission of feature requests will take two forms: \\
399 1. non-mandatory, but highly recommended is to discuss proposed new features
400 on the mailing list.\\
401 2.  Formal submission of an Feature Request in a special format.
402 I'll give an example of this below, but you can also find it on the web
403 site under "Support -\gt{} Feature Requests".  Since it takes a bit of time to
404 properly fill out a Feature Request form, you probably should check on the email list
405 first.
406
407 Once I receive the Feature Request, I will either accept it, send it back
408 asking for clarification, send it to the email list asking for opinions, or
409 reject it.
410
411 If it is accepted, it will go in the "projects" file (a simple ASCII file) 
412 maintained in the main Bacula source directory.
413
414 {\bf Implementation of Feature Requests:}\\
415 Any qualified developer can sign up for a project.  The project must have
416 an entry in the projects file, and the developer's name will appear in the
417 Status field.
418
419 {\bf How Feature Requests are accepted:}\\
420 Acceptance of Feature Requests depends on several things: \\
421 1.  feedback from users.  If it is negative, the Feature Request will probably not be
422 accepted.  \\
423 2.  the difficulty of the project.  A project that is so
424 difficult that I cannot imagine finding someone to implement probably won't
425 be accepted. \\
426  3.  whether or not the Feature Request fits within the
427 current stategy of Bacula (for example an Feature Request that requests changing the
428 tape to tar format would not be accepted, ...)
429
430 {\bf How Feature Requests are prioritized:}\\
431 Once an Feature Request is accepted, it needs to be implemented.  If you
432 can find a developer for it, or one signs up for implementing it, then the
433 Feature Request becomes top priority (at least for that developer).
434
435 Between releases of Bacula, I will generally solicit Feature Request input
436 for the next version, and by way of this email, I suggest that you send
437 discuss and send in your Feature Requests for the next release.  Please
438 verify that the Feature Request is not in the current list (attached to this email).
439
440 Once users have had several weeks to submit Feature Requests, I will
441 organize them, and request users to vote on them.  This will allow fixing
442 prioritizing the Feature Requests.  Having a priority is one thing, but
443 getting it implement is another thing -- I am hoping that the Bacula
444 community will take more responsibility for assuring the implementation of
445 accepted Feature Requests.
446
447 Feature Request format:
448 \begin{verbatim}
449 ============= Empty Feature Request form ===========
450 Item n:   One line summary ...
451   Date:   Date submitted
452   Origin: Name and email of originator.
453   Status:
454
455   What:   More detailed explanation ...
456
457   Why:    Why it is important ...
458
459   Notes:  Additional notes or features (omit if not used)
460 ============== End Feature Request form ==============
461 \end{verbatim}
462
463 \begin{verbatim}
464 ============= Example Completed  Feature Request form ===========
465 Item 1:   Implement a Migration job type that will move the job
466           data from one device to another.
467   Origin: Sponsored by Riege Sofware International GmbH. Contact:
468           Daniel Holtkamp <holtkamp at riege dot com>
469   Date:   28 October 2005
470   Status: Partially coded in 1.37 -- much more to do. Assigned to
471           Kern.
472
473   What:   The ability to copy, move, or archive data that is on a
474           device to another device is very important.
475
476   Why:    An ISP might want to backup to disk, but after 30 days
477           migrate the data to tape backup and delete it from
478           disk.  Bacula should be able to handle this
479           automatically.  It needs to know what was put where,
480           and when, and what to migrate -- it is a bit like
481           retention periods.  Doing so would allow space to be
482           freed up for current backups while maintaining older
483           data on tape drives.
484
485   Notes:  Migration could be triggered by:
486            Number of Jobs
487            Number of Volumes
488            Age of Jobs
489            Highwater size (keep total size)
490            Lowwater mark
491 =================================================
492 \end{verbatim}
493
494
495 \subsection*{Developing Bacula}
496 \index{Developing Bacula}
497 \index{Bacula!Developing}
498 \addcontentsline{toc}{subsubsection}{Developing Bacula}
499
500 Typically the simplest way to develop Bacula is to open one xterm window
501 pointing to the source directory you wish to update; a second xterm window at
502 the top source directory level, and a third xterm window at the bacula
503 directory \lt{}top\gt{}/src/bacula. After making source changes in one of the
504 directories, in the top source directory xterm, build the source, and start
505 the daemons by entering: 
506
507 make and 
508
509 ./startit then in the enter: 
510
511 ./console or 
512
513 ./gnome-console to start the Console program. Enter any commands for testing.
514 For example: run kernsverify full. 
515
516 Note, the instructions here to use {\bf ./startit} are different from using a
517 production system where the administrator starts Bacula by entering {\bf
518 ./bacula start}. This difference allows a development version of {\bf Bacula}
519 to be run on a computer at the same time that a production system is running.
520 The {\bf ./startit} strip starts {\bf Bacula} using a different set of
521 configuration files, and thus permits avoiding conflicts with any production
522 system. 
523
524 To make additional source changes, exit from the Console program, and in the
525 top source directory, stop the daemons by entering: 
526
527 ./stopit then repeat the process. 
528
529 \subsubsection*{Debugging}
530 \index{Debugging}
531 \addcontentsline{toc}{subsubsection}{Debugging}
532
533 Probably the first thing to do is to turn on debug output. 
534
535 A good place to start is with a debug level of 20 as in {\bf ./startit -d20}.
536 The startit command starts all the daemons with the same debug level.
537 Alternatively, you can start the appropriate daemon with the debug level you
538 want. If you really need more info, a debug level of 60 is not bad, and for
539 just about everything a level of 200. 
540
541 \subsubsection*{Using a Debugger}
542 \index{Using a Debugger}
543 \index{Debugger!Using a}
544 \addcontentsline{toc}{subsubsection}{Using a Debugger}
545
546 If you have a serious problem such as a segmentation fault, it can usually be
547 found quickly using a good multiple thread debugger such as {\bf gdb}. For
548 example, suppose you get a segmentation violation in {\bf bacula-dir}. You
549 might use the following to find the problem: 
550
551 \lt{}start the Storage and File daemons\gt{}
552 cd dird
553 gdb ./bacula-dir
554 run -f -s -c ./dird.conf
555 \lt{}it dies with a segmentation fault\gt{}
556 where
557 The {\bf -f} option is specified on the {\bf run} command to inhibit {\bf
558 dird} from going into the background. You may also want to add the {\bf -s}
559 option to the run command to disable signals which can potentially interfere
560 with the debugging. 
561
562 As an alternative to using the debugger, each {\bf Bacula} daemon has a built
563 in back trace feature when a serious error is encountered. It calls the
564 debugger on itself, produces a back trace, and emails the report to the
565 developer. For more details on this, please see the chapter in the main Bacula
566 manual entitled ``What To Do When Bacula Crashes (Kaboom)''. 
567
568 \subsubsection*{Memory Leaks}
569 \index{Leaks!Memory}
570 \index{Memory Leaks}
571 \addcontentsline{toc}{subsubsection}{Memory Leaks}
572
573 Because Bacula runs routinely and unattended on client and server machines, it
574 may run for a long time. As a consequence, from the very beginning, Bacula
575 uses SmartAlloc to ensure that there are no memory leaks. To make detection of
576 memory leaks effective, all Bacula code that dynamically allocates memory MUST
577 have a way to release it. In general when the memory is no longer needed, it
578 should be immediately released, but in some cases, the memory will be held
579 during the entire time that Bacula is executing. In that case, there MUST be a
580 routine that can be called at termination time that releases the memory. In
581 this way, we will be able to detect memory leaks. Be sure to immediately
582 correct any and all memory leaks that are printed at the termination of the
583 daemons. 
584
585 \subsubsection*{Special Files}
586 \index{Files!Special}
587 \index{Special Files}
588 \addcontentsline{toc}{subsubsection}{Special Files}
589
590 Kern uses files named 1, 2, ... 9 with any extension as scratch files. Thus
591 any files with these names are subject to being rudely deleted at any time. 
592
593 \subsubsection*{When Implementing Incomplete Code}
594 \index{Code!When Implementing Incomplete}
595 \index{When Implementing Incomplete Code}
596 \addcontentsline{toc}{subsubsection}{When Implementing Incomplete Code}
597
598 Please identify all incomplete code with a comment that contains 
599
600 \begin{verbatim}
601 ***FIXME***
602 \end{verbatim} 
603
604 where there are three asterisks (*) before and after the word
605 FIXME (in capitals) and no intervening spaces. This is important as it allows
606 new programmers to easily recognize where things are partially implemented. 
607
608 \subsubsection*{Bacula Source File Structure}
609 \index{Structure!Bacula Source File}
610 \index{Bacula Source File Structure}
611 \addcontentsline{toc}{subsubsection}{Bacula Source File Structure}
612
613 The distribution generally comes as a tar file of the form {\bf
614 bacula.x.y.z.tar.gz} where x, y, and z are the version, release, and update
615 numbers respectively. 
616
617 Once you detar this file, you will have a directory structure as follows: 
618
619 \footnotesize
620 \begin{verbatim}
621 |
622 Tar file:
623 |- depkgs
624    |- mtx              (autochanger control program + tape drive info)
625    |- sqlite           (SQLite database program)
626
627 Tar file:
628 |- depkgs-win32
629    |- pthreads         (Native win32 pthreads library -- dll)
630    |- zlib             (Native win32 zlib library)
631    |- wx               (wxWidgets source code)
632
633 Project bacula:
634 |- bacula              (main source directory containing configuration
635    |                    and installation files)
636    |- autoconf         (automatic configuration files, not normally used
637    |                    by users)
638    |- intl             (programs used to translate)
639    |- platforms        (OS specific installation files)
640       |- redhat        (Red Hat installation)
641       |- solaris       (Sun installation)
642       |- freebsd       (FreeBSD installation)
643       |- irix          (Irix installation -- not tested)
644       |- unknown       (Default if system not identified)
645    |- po               (translations of source strings)
646    |- src              (source directory; contains global header files)
647       |- cats          (SQL catalog database interface directory)
648       |- console       (bacula user agent directory)
649       |- dird          (Director daemon)
650       |- filed         (Unix File daemon)
651          |- win32      (Win32 files to make bacula-fd be a service)
652       |- findlib       (Unix file find library for File daemon)
653       |- gnome-console (GNOME version of console program)
654       |- lib           (General Bacula library)
655       |- stored        (Storage daemon)
656       |- tconsole      (Tcl/tk console program -- not yet working)
657       |- testprogs     (test programs -- normally only in Kern's tree)
658       |- tools         (Various tool programs)
659       |- win32         (Native Win32 File daemon)
660          |- baculafd   (Visual Studio project file)
661          |- compat     (compatibility interface library)
662          |- filed      (links to src/filed)
663          |- findlib    (links to src/findlib)
664          |- lib        (links to src/lib)
665          |- console    (beginning of native console program)
666          |- wx-console (wxWidget console Win32 specific parts)
667      |- wx-console     (wxWidgets console main source program)
668
669 Project regress:
670 |- regress             (Regression scripts)
671    |- bin              (temporary directory to hold Bacula installed binaries)
672    |- build            (temporary directory to hold Bacula source)
673    |- scripts          (scripts and .conf files)
674    |- tests            (test scripts)
675    |- tmp              (temporary directory for temp files)
676
677 Project docs:
678 |- docs                (documentation directory)
679    |- developers       (Developer's guide)
680    |- home-page        (Bacula's home page source)
681    |- manual           (html document directory)
682    |- manual-fr        (French translation) 
683    |- manual-de        (German translation) 
684    |- techlogs         (Technical development notes);
685
686 Project rescue:
687 |- rescue              (Bacula rescue CDROM)
688    |- linux            (Linux rescue CDROM)
689       |- cdrom         (Linux rescue CDROM code)
690         ...
691    |- solaris          (Solaris rescue -- incomplete) 
692    |- freebsd          (FreeBSD rescue -- incomplete)
693
694 Project gui:
695 |- gui                 (Bacula GUI projects)
696   |- bacula-web        (Bacula web php management code)
697   |- bimagemgr         (Web application for burning CDROMs)
698
699
700 \end{verbatim}
701 \normalsize
702
703 \subsubsection*{Header Files}
704 \index{Header Files}
705 \index{Files!Header}
706 \addcontentsline{toc}{subsubsection}{Header Files}
707
708 Please carefully follow the scheme defined below as it permits in general only
709 two header file includes per C file, and thus vastly simplifies programming.
710 With a large complex project like Bacula, it isn't always easy to ensure that
711 the right headers are invoked in the right order (there are a few kludges to
712 make this happen -- i.e. in a few include files because of the chicken and egg
713 problem, certain references to typedefs had to be replaced with {\bf void} ). 
714
715 Every file should include {\bf bacula.h}. It pulls in just about everything,
716 with very few exceptions. If you have system dependent ifdefing, please do it
717 in {\bf baconfig.h}. The version number and date are kept in {\bf version.h}. 
718
719 Each of the subdirectories (console, cats, dird, filed, findlib, lib, stored,
720 ...) contains a single directory dependent include file generally the name of
721 the directory, which should be included just after the include of {\bf
722 bacula.h}. This file (for example, for the dird directory, it is {\bf dird.h})
723 contains either definitions of things generally needed in this directory, or
724 it includes the appropriate header files. It always includes {\bf protos.h}.
725 See below. 
726
727 Each subdirectory contains a header file named {\bf protos.h}, which contains
728 the prototypes for subroutines exported by files in that directory. {\bf
729 protos.h} is always included by the main directory dependent include file. 
730
731 \subsubsection*{Programming Standards}
732 \index{Standards!Programming}
733 \index{Programming Standards}
734 \addcontentsline{toc}{subsubsection}{Programming Standards}
735
736 For the most part, all code should be written in C unless there is a burning
737 reason to use C++, and then only the simplest C++ constructs will be used.
738 Note, Bacula is slowly evolving to use more and more C++. 
739
740 Code should have some documentation -- not a lot, but enough so that I can
741 understand it. Look at the current code, and you will see that I document more
742 than most, but am definitely not a fanatic. 
743
744 I prefer simple linear code where possible. Gotos are strongly discouraged
745 except for handling an error to either bail out or to retry some code, and
746 such use of gotos can vastly simplify the program. 
747
748 Remember this is a C program that is migrating to a {\bf tiny} subset of C++,
749 so be conservative in your use of C++ features. 
750
751 \subsubsection*{Do Not Use}
752 \index{Use!Do Not}
753 \index{Do Not Use}
754 \addcontentsline{toc}{subsubsection}{Do Not Use}
755
756 \begin{itemize}
757 \item STL -- it is totally incomprehensible. 
758    \end{itemize}
759
760 \subsubsection*{Avoid if Possible}
761 \index{Possible!Avoid if}
762 \index{Avoid if Possible}
763 \addcontentsline{toc}{subsubsection}{Avoid if Possible}
764
765 \begin{itemize}
766 \item Using {\bf void *} because this generally means that one must
767    using casting, and in C++ casting is rather ugly.  It is OK to use
768    void * to pass structure address where the structure is not known  
769    to the routines accepting the packet (typically callback routines).
770    However, declaring "void *buf" is a bad idea.  Please use the
771    correct types whenever possible.
772 \item Using undefined storage specifications such as (short, int, long,
773    long long, size_t ...).  The problem with all these is that the number of bytes
774    they allocate depends on the compiler and the system.  Instead use
775    Bacula's types (int8_t, uint8_t, int32_t, uint32_t, int64_t, and 
776    uint64_t).  This guarantees that the variables are given exactly the
777    size you want. Please try at all possible to avoid using size_t ssize_t
778    and the such. They are very system dependent.  However, some system
779    routines may need them, so their use is often unavoidable.
780 \item Returning a malloc'ed buffer from a subroutine --  someone will forget
781    to release it. 
782 \item Using reference variables -- it allows subroutines to  create side
783    effects. Reference variables are OK, if you are sure the variable 
784    *always* exists, and you are sure you can handle the side effects of
785    a subroutine changing the "pointer".
786 \item Heap allocation (malloc) unless needed -- it is expensive. 
787 \item Templates -- they can create portability problems. 
788 \item Fancy or tricky C or C++ code, unless you give a  good explanation of
789    why you used it. 
790 \item Too much inheritance -- it can complicate the code,  and make reading it
791    difficult (unless you are in love  with colons) 
792    \end{itemize}
793
794 \subsubsection*{Do Use Whenever Possible}
795 \index{Possible!Do Use Whenever}
796 \index{Do Use Whenever Possible}
797 \addcontentsline{toc}{subsubsection}{Do Use Whenever Possible}
798
799 \begin{itemize}
800 \item Locking and unlocking within a single subroutine.  
801 \item Malloc and free within a single subroutine.  
802 \item Comments and global explanations on what your code or  algorithm does. 
803    \end{itemize}
804
805 \subsubsection*{Indenting Standards}
806 \index{Standards!Indenting}
807 \index{Indenting Standards}
808 \addcontentsline{toc}{subsubsection}{Indenting Standards}
809
810 I cannot stand code indented 8 columns at a time. This makes the code
811 unreadable. Even 4 at a time uses a lot of space, so I have adopted indenting
812 3 spaces at every level. Note, indention is the visual appearance of the
813 source on the page, while tabbing is replacing a series of up to 8 spaces from
814 a tab character. 
815
816 The closest set of parameters for the Linux {\bf indent} program that will
817 produce reasonably indented code are: 
818
819 \footnotesize
820 \begin{verbatim}
821 -nbad -bap -bbo -nbc -br -brs -c36 -cd36 -ncdb -ce -ci3 -cli0
822 -cp36 -d0 -di1 -ndj -nfc1 -nfca -hnl -i3 -ip0 -l85 -lp -npcs
823 -nprs -npsl -saf -sai -saw -nsob -nss -nbc -ncs -nbfda
824 \end{verbatim}
825 \normalsize
826
827 You can put the above in your .indent.pro file, and then just invoke indent on
828 your file. However, be warned. This does not produce perfect indenting, and it
829 will mess up C++ class statements pretty badly. 
830
831 Braces are required in all if statements (missing in some very old code). To
832 avoid generating too many lines, the first brace appears on the first line
833 (e.g. of an if), and the closing brace is on a line by itself. E.g. 
834
835 \footnotesize
836 \begin{verbatim}
837    if (abc) {
838       some_code;
839   }
840 \end{verbatim}
841 \normalsize
842
843 Just follow the convention in the code. Originally I indented case clauses
844 under a switch(), but now I prefer non-indented cases. 
845
846 \footnotesize
847 \begin{verbatim}
848    switch (code) {
849    case 'A':
850       do something
851       break;
852    case 'B':
853       again();
854       break;
855    default:
856       break;
857   }
858 \end{verbatim}
859 \normalsize
860
861 Avoid using // style comments except for temporary code or turning off debug
862 code. Standard C comments are preferred (this also keeps the code closer to
863 C). 
864
865 Attempt to keep all lines less than 85 characters long so that the whole line
866 of code is readable at one time. This is not a rigid requirement. 
867
868 Always put a brief description at the top of any new file created describing
869 what it does and including your name and the date it was first written. Please
870 don't forget any Copyrights and acknowledgments if it isn't 100\% your code.
871 Also, include the Bacula copyright notice that is in {\bf src/c}. 
872
873 In general you should have two includes at the top of the an include for the
874 particular directory the code is in, for includes are needed, but this should
875 be rare. 
876
877 In general (except for self-contained packages), prototypes should all be put
878 in {\bf protos.h} in each directory. 
879
880 Always put space around assignment and comparison operators. 
881
882 \footnotesize
883 \begin{verbatim}
884    a = 1;
885    if (b >= 2) {
886      cleanup();
887   }
888 \end{verbatim}
889 \normalsize
890
891 but your can compress things in a {\bf for} statement: 
892
893 \footnotesize
894 \begin{verbatim}
895    for (i=0; i < del.num_ids; i++) {
896     ...
897 \end{verbatim}
898 \normalsize
899
900 Don't overuse the inline if (?:). A full {\bf if} is preferred, except in a
901 print statement, e.g.: 
902
903 \footnotesize
904 \begin{verbatim}
905    if (ua->verbose \&& del.num_del != 0) {
906       bsendmsg(ua, _("Pruned %d %s on Volume %s from catalog.\n"), del.num_del,
907          del.num_del == 1 ? "Job" : "Jobs", mr->VolumeName);
908   }
909 \end{verbatim}
910 \normalsize
911
912 Leave a certain amount of debug code (Dmsg) in code you submit, so that future
913 problems can be identified. This is particularly true for complicated code
914 likely to break. However, try to keep the debug code to a minimum to avoid
915 bloating the program and above all to keep the code readable. 
916
917 Please keep the same style in all new code you develop. If you include code
918 previously written, you have the option of leaving it with the old indenting
919 or re-indenting it. If the old code is indented with 8 spaces, then please
920 re-indent it to Bacula standards. 
921
922 If you are using {\bf vim}, simply set your tabstop to 8 and your shiftwidth
923 to 3. 
924
925 \subsubsection*{Tabbing}
926 \index{Tabbing}
927 \addcontentsline{toc}{subsubsection}{Tabbing}
928
929 Tabbing (inserting the tab character in place of spaces) is as normal on all
930 Unix systems -- a tab is converted space up to the next column multiple of 8.
931 My editor converts strings of spaces to tabs automatically -- this results in
932 significant compression of the files. Thus, you can remove tabs by replacing
933 them with spaces if you wish. Please don't confuse tabbing (use of tab
934 characters) with indenting (visual alignment of the code). 
935
936 \subsubsection*{Don'ts}
937 \index{Don'ts}
938 \addcontentsline{toc}{subsubsection}{Don'ts}
939
940 Please don't use: 
941
942 \footnotesize
943 \begin{verbatim}
944 strcpy()
945 strcat()
946 strncpy()
947 strncat();
948 sprintf()
949 snprintf()
950 \end{verbatim}
951 \normalsize
952
953 They are system dependent and un-safe. These should be replaced by the Bacula
954 safe equivalents: 
955
956 \footnotesize
957 \begin{verbatim}
958 char *bstrncpy(char *dest, char *source, int dest_size);
959 char *bstrncat(char *dest, char *source, int dest_size);
960 int bsnprintf(char *buf, int32_t buf_len, const char *fmt, ...);
961 int bvsnprintf(char *str, int32_t size, const char  *format, va_list ap);
962 \end{verbatim}
963 \normalsize
964
965 See src/lib/bsys.c for more details on these routines. 
966
967 Don't use the {\bf \%lld} or the {\bf \%q} printf format editing types to edit
968 64 bit integers -- they are not portable. Instead, use {\bf \%s} with {\bf
969 edit\_uint64()}. For example: 
970
971 \footnotesize
972 \begin{verbatim}
973    char buf[100];
974    uint64_t num = something;
975    char ed1[50];
976    bsnprintf(buf, sizeof(buf), "Num=%s\n", edit_uint64(num, ed1));
977 \end{verbatim}
978 \normalsize
979
980 The edit buffer {\bf ed1} must be at least 27 bytes long to avoid overflow.
981 See src/lib/edit.c for more details. If you look at the code, don't start
982 screaming that I use {\bf lld}. I actually use subtle trick taught to me by
983 John Walker. The {\bf lld} that appears in the editing routine is actually
984 {\bf \#define} to a what is needed on your OS (usually ``lld'' or ``q'') and
985 is defined in autoconf/configure.in for each OS. C string concatenation causes
986 the appropriate string to be concatenated to the ``\%''. 
987
988 Also please don't use the STL or Templates or any complicated C++ code. 
989
990 \subsubsection*{Message Classes}
991 \index{Classes!Message}
992 \index{Message Classes}
993 \addcontentsline{toc}{subsubsection}{Message Classes}
994
995 Currently, there are five classes of messages: Debug, Error, Job, Memory, 
996 and Queued.
997
998 \subsubsection*{Debug Messages}
999 \index{Messages!Debug}
1000 \index{Debug Messages}
1001 \addcontentsline{toc}{subsubsection}{Debug Messages}
1002
1003 Debug messages are designed to be turned on at a specified debug level and are
1004 always sent to STDOUT. There are designed to only be used in the development
1005 debug process. They are coded as: 
1006
1007 DmsgN(level, message, arg1, ...) where the N is a number indicating how many
1008 arguments are to be substituted into the message (i.e. it is a count of the
1009 number arguments you have in your message -- generally the number of percent
1010 signs (\%)). {\bf level} is the debug level at which you wish the message to
1011 be printed. message is the debug message to be printed, and arg1, ... are the
1012 arguments to be substituted. Since not all compilers support \#defines with
1013 varargs, you must explicitly specify how many arguments you have. 
1014
1015 When the debug message is printed, it will automatically be prefixed by the
1016 name of the daemon which is running, the filename where the Dmsg is, and the
1017 line number within the file. 
1018
1019 Some actual examples are: 
1020
1021 Dmsg2(20, ``MD5len=\%d MD5=\%s\textbackslash{}n'', strlen(buf), buf); 
1022
1023 Dmsg1(9, ``Created client \%s record\textbackslash{}n'', client->hdr.name); 
1024
1025 \subsubsection*{Error Messages}
1026 \index{Messages!Error}
1027 \index{Error Messages}
1028 \addcontentsline{toc}{subsubsection}{Error Messages}
1029
1030 Error messages are messages that are related to the daemon as a whole rather
1031 than a particular job. For example, an out of memory condition my generate an
1032 error message. They should be very rarely needed. In general, you should be
1033 using Job and Job Queued messages (Jmsg and Qmsg). They are coded as: 
1034
1035 EmsgN(error-code, level, message, arg1, ...) As with debug messages, you must
1036 explicitly code the of arguments to be substituted in the message. error-code
1037 indicates the severity or class of error, and it may be one of the following: 
1038
1039 \addcontentsline{lot}{table}{Message Error Code Classes}
1040 \begin{longtable}{lp{3in}}
1041 {{\bf M\_ABORT} } & {Causes the daemon to immediately abort. This should be
1042 used only  in extreme cases. It attempts to produce a  traceback. } \\
1043 {{\bf M\_ERROR\_TERM} } & {Causes the daemon to immediately terminate. This
1044 should be used only  in extreme cases. It does not produce a  traceback. } \\
1045 {{\bf M\_FATAL} } & {Causes the daemon to terminate the current job, but the
1046 daemon keeps running } \\
1047 {{\bf M\_ERROR} } & {Reports the error. The daemon and the job continue
1048 running } \\
1049 {{\bf M\_WARNING} } & {Reports an warning message. The daemon and the job
1050 continue running } \\
1051 {{\bf M\_INFO} } & {Reports an informational message.}
1052
1053 \end{longtable}
1054
1055 There are other error message classes, but they are in a state of being
1056 redesigned or deprecated, so please do not use them. Some actual examples are:
1057
1058
1059 Emsg1(M\_ABORT, 0, ``Cannot create message thread: \%s\textbackslash{}n'',
1060 strerror(status)); 
1061
1062 Emsg3(M\_WARNING, 0, ``Connect to File daemon \%s at \%s:\%d failed. Retrying
1063 ...\textbackslash{}n'',  client-\gt{}hdr.name, client-\gt{}address,
1064 client-\gt{}port); 
1065
1066 Emsg3(M\_FATAL, 0, ``bdird\lt{}filed: bad response from Filed to \%s command:
1067 \%d \%s\textbackslash{}n'',  cmd, n, strerror(errno)); 
1068
1069 \subsubsection*{Job Messages}
1070 \index{Job Messages}
1071 \index{Messages!Job}
1072 \addcontentsline{toc}{subsubsection}{Job Messages}
1073
1074 Job messages are messages that pertain to a particular job such as a file that
1075 could not be saved, or the number of files and bytes that were saved. They
1076 Are coded as:
1077 \begin{verbatim}
1078 Jmsg(jcr, M\_FATAL, 0, "Text of message");
1079 \end{verbatim}
1080 A Jmsg with M\_FATAL will fail the job. The Jmsg() takes varargs so can
1081 have any number of arguments for substituted in a printf like format.
1082 Output from the Jmsg() will go to the Job report.
1083 <br>
1084 If the Jmsg is followed with a number such as Jmsg1(...), the number
1085 indicates the number of arguments to be substituted (varargs is not
1086 standard for \#defines), and what is more important is that the file and
1087 line number will be prefixed to the message. This permits a sort of debug
1088 from user's output.
1089
1090 \subsubsection*{Queued Job Messages}
1091 \index{Queued Job Messages}
1092 \index{Messages!Job}
1093 \addcontentsline{toc}{subsubsection}{Queued Job Messages}
1094 Queued Job messages are similar to Jmsg()s except that the message is
1095 Queued rather than immediately dispatched. This is necessary within the
1096 network subroutines and in the message editing routines. This is to prevent
1097 recursive loops, and to ensure that messages can be delivered even in the
1098 event of a network error.
1099
1100
1101 \subsubsection*{Memory Messages}
1102 \index{Messages!Memory}
1103 \index{Memory Messages}
1104 \addcontentsline{toc}{subsubsection}{Memory Messages}
1105
1106 Memory messages are messages that are edited into a memory buffer. Generally
1107 they are used in low level routines such as the low level device file dev.c in
1108 the Storage daemon or in the low level Catalog routines. These routines do not
1109 generally have access to the Job Control Record and so they return error
1110 messages reformatted in a memory buffer. Mmsg() is the way to do this.