]> git.sur5r.net Git - bacula/docs/blob - docs/developers/generaldevel.tex
- Write install/uninstall of new manpages. There are now a
[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 {\bf
599 ***FIXME***}, where there are three asterisks (*) before and after the word
600 FIXME (in capitals) and no intervening spaces. This is important as it allows
601 new programmers to easily recognize where things are partially implemented. 
602
603 \subsubsection*{Bacula Source File Structure}
604 \index{Structure!Bacula Source File}
605 \index{Bacula Source File Structure}
606 \addcontentsline{toc}{subsubsection}{Bacula Source File Structure}
607
608 The distribution generally comes as a tar file of the form {\bf
609 bacula.x.y.z.tar.gz} where x, y, and z are the version, release, and update
610 numbers respectively. 
611
612 Once you detar this file, you will have a directory structure as follows: 
613
614 \footnotesize
615 \begin{verbatim}
616 |
617 Tar file:
618 |- depkgs
619    |- mtx              (autochanger control program + tape drive info)
620    |- sqlite           (SQLite database program)
621
622 Tar file:
623 |- depkgs-win32
624    |- pthreads         (Native win32 pthreads library -- dll)
625    |- zlib             (Native win32 zlib library)
626    |- wx               (wxWidgets source code)
627
628 Project bacula:
629 |- bacula              (main source directory containing configuration
630    |                    and installation files)
631    |- autoconf         (automatic configuration files, not normally used
632    |                    by users)
633    |- intl             (programs used to translate)
634    |- platforms        (OS specific installation files)
635       |- redhat        (Red Hat installation)
636       |- solaris       (Sun installation)
637       |- freebsd       (FreeBSD installation)
638       |- irix          (Irix installation -- not tested)
639       |- unknown       (Default if system not identified)
640    |- po               (translations of source strings)
641    |- src              (source directory; contains global header files)
642       |- cats          (SQL catalog database interface directory)
643       |- console       (bacula user agent directory)
644       |- dird          (Director daemon)
645       |- filed         (Unix File daemon)
646          |- win32      (Win32 files to make bacula-fd be a service)
647       |- findlib       (Unix file find library for File daemon)
648       |- gnome-console (GNOME version of console program)
649       |- lib           (General Bacula library)
650       |- stored        (Storage daemon)
651       |- tconsole      (Tcl/tk console program -- not yet working)
652       |- testprogs     (test programs -- normally only in Kern's tree)
653       |- tools         (Various tool programs)
654       |- win32         (Native Win32 File daemon)
655          |- baculafd   (Visual Studio project file)
656          |- compat     (compatibility interface library)
657          |- filed      (links to src/filed)
658          |- findlib    (links to src/findlib)
659          |- lib        (links to src/lib)
660          |- console    (beginning of native console program)
661          |- wx-console (wxWidget console Win32 specific parts)
662      |- wx-console     (wxWidgets console main source program)
663
664 Project regress:
665 |- regress             (Regression scripts)
666    |- bin              (temporary directory to hold Bacula installed binaries)
667    |- build            (temporary directory to hold Bacula source)
668    |- scripts          (scripts and .conf files)
669    |- tests            (test scripts)
670    |- tmp              (temporary directory for temp files)
671
672 Project docs:
673 |- docs                (documentation directory)
674    |- developers       (Developer's guide)
675    |- home-page        (Bacula's home page source)
676    |- manual           (html document directory)
677    |- manual-fr        (French translation) 
678    |- manual-de        (German translation) 
679    |- techlogs         (Technical development notes);
680
681 Project rescue:
682 |- rescue              (Bacula rescue CDROM)
683    |- linux            (Linux rescue CDROM)
684       |- cdrom         (Linux rescue CDROM code)
685         ...
686    |- solaris          (Solaris rescue -- incomplete) 
687    |- freebsd          (FreeBSD rescue -- incomplete)
688
689 Project gui:
690 |- gui                 (Bacula GUI projects)
691   |- bacula-web        (Bacula web php management code)
692   |- bimagemgr         (Web application for burning CDROMs)
693
694
695 \end{verbatim}
696 \normalsize
697
698 \subsubsection*{Header Files}
699 \index{Header Files}
700 \index{Files!Header}
701 \addcontentsline{toc}{subsubsection}{Header Files}
702
703 Please carefully follow the scheme defined below as it permits in general only
704 two header file includes per C file, and thus vastly simplifies programming.
705 With a large complex project like Bacula, it isn't always easy to ensure that
706 the right headers are invoked in the right order (there are a few kludges to
707 make this happen -- i.e. in a few include files because of the chicken and egg
708 problem, certain references to typedefs had to be replaced with {\bf void} ). 
709
710 Every file should include {\bf bacula.h}. It pulls in just about everything,
711 with very few exceptions. If you have system dependent ifdefing, please do it
712 in {\bf baconfig.h}. The version number and date are kept in {\bf version.h}. 
713
714 Each of the subdirectories (console, cats, dird, filed, findlib, lib, stored,
715 ...) contains a single directory dependent include file generally the name of
716 the directory, which should be included just after the include of {\bf
717 bacula.h}. This file (for example, for the dird directory, it is {\bf dird.h})
718 contains either definitions of things generally needed in this directory, or
719 it includes the appropriate header files. It always includes {\bf protos.h}.
720 See below. 
721
722 Each subdirectory contains a header file named {\bf protos.h}, which contains
723 the prototypes for subroutines exported by files in that directory. {\bf
724 protos.h} is always included by the main directory dependent include file. 
725
726 \subsubsection*{Programming Standards}
727 \index{Standards!Programming}
728 \index{Programming Standards}
729 \addcontentsline{toc}{subsubsection}{Programming Standards}
730
731 For the most part, all code should be written in C unless there is a burning
732 reason to use C++, and then only the simplest C++ constructs will be used.
733 Note, Bacula is slowly evolving to use more and more C++. 
734
735 Code should have some documentation -- not a lot, but enough so that I can
736 understand it. Look at the current code, and you will see that I document more
737 than most, but am definitely not a fanatic. 
738
739 I prefer simple linear code where possible. Gotos are strongly discouraged
740 except for handling an error to either bail out or to retry some code, and
741 such use of gotos can vastly simplify the program. 
742
743 Remember this is a C program that is migrating to a {\bf tiny} subset of C++,
744 so be conservative in your use of C++ features. 
745
746 \subsubsection*{Do Not Use}
747 \index{Use!Do Not}
748 \index{Do Not Use}
749 \addcontentsline{toc}{subsubsection}{Do Not Use}
750
751 \begin{itemize}
752 \item STL -- it is totally incomprehensible. 
753    \end{itemize}
754
755 \subsubsection*{Avoid if Possible}
756 \index{Possible!Avoid if}
757 \index{Avoid if Possible}
758 \addcontentsline{toc}{subsubsection}{Avoid if Possible}
759
760 \begin{itemize}
761 \item Returning a malloc'ed buffer from a subroutine --  someone will forget
762    to release it. 
763 \item Using reference variables -- it allows subroutines to  create side
764    effects. 
765 \item Heap allocation (malloc) unless needed -- it is expensive. 
766 \item Templates -- they can create portability problems. 
767 \item Fancy or tricky C or C++ code, unless you give a  good explanation of
768    why you used it. 
769 \item Too much inheritance -- it can complicate the code,  and make reading it
770    difficult (unless you are in love  with colons) 
771    \end{itemize}
772
773 \subsubsection*{Do Use Whenever Possible}
774 \index{Possible!Do Use Whenever}
775 \index{Do Use Whenever Possible}
776 \addcontentsline{toc}{subsubsection}{Do Use Whenever Possible}
777
778 \begin{itemize}
779 \item Locking and unlocking within a single subroutine.  
780 \item Malloc and free within a single subroutine.  
781 \item Comments and global explanations on what your code or  algorithm does. 
782    \end{itemize}
783
784 \subsubsection*{Indenting Standards}
785 \index{Standards!Indenting}
786 \index{Indenting Standards}
787 \addcontentsline{toc}{subsubsection}{Indenting Standards}
788
789 I cannot stand code indented 8 columns at a time. This makes the code
790 unreadable. Even 4 at a time uses a lot of space, so I have adopted indenting
791 3 spaces at every level. Note, indention is the visual appearance of the
792 source on the page, while tabbing is replacing a series of up to 8 spaces from
793 a tab character. 
794
795 The closest set of parameters for the Linux {\bf indent} program that will
796 produce reasonably indented code are: 
797
798 \footnotesize
799 \begin{verbatim}
800 -nbad -bap -bbo -nbc -br -brs -c36 -cd36 -ncdb -ce -ci3 -cli0
801 -cp36 -d0 -di1 -ndj -nfc1 -nfca -hnl -i3 -ip0 -l85 -lp -npcs
802 -nprs -npsl -saf -sai -saw -nsob -nss -nbc -ncs -nbfda
803 \end{verbatim}
804 \normalsize
805
806 You can put the above in your .indent.pro file, and then just invoke indent on
807 your file. However, be warned. This does not produce perfect indenting, and it
808 will mess up C++ class statements pretty badly. 
809
810 Braces are required in all if statements (missing in some very old code). To
811 avoid generating too many lines, the first brace appears on the first line
812 (e.g. of an if), and the closing brace is on a line by itself. E.g. 
813
814 \footnotesize
815 \begin{verbatim}
816    if (abc) {
817       some_code;
818   }
819 \end{verbatim}
820 \normalsize
821
822 Just follow the convention in the code. Originally I indented case clauses
823 under a switch(), but now I prefer non-indented cases. 
824
825 \footnotesize
826 \begin{verbatim}
827    switch (code) {
828    case 'A':
829       do something
830       break;
831    case 'B':
832       again();
833       break;
834    default:
835       break;
836   }
837 \end{verbatim}
838 \normalsize
839
840 Avoid using // style comments except for temporary code or turning off debug
841 code. Standard C comments are preferred (this also keeps the code closer to
842 C). 
843
844 Attempt to keep all lines less than 85 characters long so that the whole line
845 of code is readable at one time. This is not a rigid requirement. 
846
847 Always put a brief description at the top of any new file created describing
848 what it does and including your name and the date it was first written. Please
849 don't forget any Copyrights and acknowledgments if it isn't 100\% your code.
850 Also, include the Bacula copyright notice that is in {\bf src/c}. 
851
852 In general you should have two includes at the top of the an include for the
853 particular directory the code is in, for includes are needed, but this should
854 be rare. 
855
856 In general (except for self-contained packages), prototypes should all be put
857 in {\bf protos.h} in each directory. 
858
859 Always put space around assignment and comparison operators. 
860
861 \footnotesize
862 \begin{verbatim}
863    a = 1;
864    if (b >= 2) {
865      cleanup();
866   }
867 \end{verbatim}
868 \normalsize
869
870 but your can compress things in a {\bf for} statement: 
871
872 \footnotesize
873 \begin{verbatim}
874    for (i=0; i < del.num_ids; i++) {
875     ...
876 \end{verbatim}
877 \normalsize
878
879 Don't overuse the inline if (?:). A full {\bf if} is preferred, except in a
880 print statement, e.g.: 
881
882 \footnotesize
883 \begin{verbatim}
884    if (ua->verbose \&& del.num_del != 0) {
885       bsendmsg(ua, _("Pruned %d %s on Volume %s from catalog.\n"), del.num_del,
886          del.num_del == 1 ? "Job" : "Jobs", mr->VolumeName);
887   }
888 \end{verbatim}
889 \normalsize
890
891 Leave a certain amount of debug code (Dmsg) in code you submit, so that future
892 problems can be identified. This is particularly true for complicated code
893 likely to break. However, try to keep the debug code to a minimum to avoid
894 bloating the program and above all to keep the code readable. 
895
896 Please keep the same style in all new code you develop. If you include code
897 previously written, you have the option of leaving it with the old indenting
898 or re-indenting it. If the old code is indented with 8 spaces, then please
899 re-indent it to Bacula standards. 
900
901 If you are using {\bf vim}, simply set your tabstop to 8 and your shiftwidth
902 to 3. 
903
904 \subsubsection*{Tabbing}
905 \index{Tabbing}
906 \addcontentsline{toc}{subsubsection}{Tabbing}
907
908 Tabbing (inserting the tab character in place of spaces) is as normal on all
909 Unix systems -- a tab is converted space up to the next column multiple of 8.
910 My editor converts strings of spaces to tabs automatically -- this results in
911 significant compression of the files. Thus, you can remove tabs by replacing
912 them with spaces if you wish. Please don't confuse tabbing (use of tab
913 characters) with indenting (visual alignment of the code). 
914
915 \subsubsection*{Don'ts}
916 \index{Don'ts}
917 \addcontentsline{toc}{subsubsection}{Don'ts}
918
919 Please don't use: 
920
921 \footnotesize
922 \begin{verbatim}
923 strcpy()
924 strcat()
925 strncpy()
926 strncat();
927 sprintf()
928 snprintf()
929 \end{verbatim}
930 \normalsize
931
932 They are system dependent and un-safe. These should be replaced by the Bacula
933 safe equivalents: 
934
935 \footnotesize
936 \begin{verbatim}
937 char *bstrncpy(char *dest, char *source, int dest_size);
938 char *bstrncat(char *dest, char *source, int dest_size);
939 int bsnprintf(char *buf, int32_t buf_len, const char *fmt, ...);
940 int bvsnprintf(char *str, int32_t size, const char  *format, va_list ap);
941 \end{verbatim}
942 \normalsize
943
944 See src/lib/bsys.c for more details on these routines. 
945
946 Don't use the {\bf \%lld} or the {\bf \%q} printf format editing types to edit
947 64 bit integers -- they are not portable. Instead, use {\bf \%s} with {\bf
948 edit\_uint64()}. For example: 
949
950 \footnotesize
951 \begin{verbatim}
952    char buf[100];
953    uint64_t num = something;
954    char ed1[50];
955    bsnprintf(buf, sizeof(buf), "Num=%s\n", edit_uint64(num, ed1));
956 \end{verbatim}
957 \normalsize
958
959 The edit buffer {\bf ed1} must be at least 27 bytes long to avoid overflow.
960 See src/lib/edit.c for more details. If you look at the code, don't start
961 screaming that I use {\bf lld}. I actually use subtle trick taught to me by
962 John Walker. The {\bf lld} that appears in the editing routine is actually
963 {\bf \#define} to a what is needed on your OS (usually ``lld'' or ``q'') and
964 is defined in autoconf/configure.in for each OS. C string concatenation causes
965 the appropriate string to be concatenated to the ``\%''. 
966
967 Also please don't use the STL or Templates or any complicated C++ code. 
968
969 \subsubsection*{Message Classes}
970 \index{Classes!Message}
971 \index{Message Classes}
972 \addcontentsline{toc}{subsubsection}{Message Classes}
973
974 Currently, there are five classes of messages: Debug, Error, Job, Memory, 
975 and Queued.
976
977 \subsubsection*{Debug Messages}
978 \index{Messages!Debug}
979 \index{Debug Messages}
980 \addcontentsline{toc}{subsubsection}{Debug Messages}
981
982 Debug messages are designed to be turned on at a specified debug level and are
983 always sent to STDOUT. There are designed to only be used in the development
984 debug process. They are coded as: 
985
986 DmsgN(level, message, arg1, ...) where the N is a number indicating how many
987 arguments are to be substituted into the message (i.e. it is a count of the
988 number arguments you have in your message -- generally the number of percent
989 signs (\%)). {\bf level} is the debug level at which you wish the message to
990 be printed. message is the debug message to be printed, and arg1, ... are the
991 arguments to be substituted. Since not all compilers support \#defines with
992 varargs, you must explicitly specify how many arguments you have. 
993
994 When the debug message is printed, it will automatically be prefixed by the
995 name of the daemon which is running, the filename where the Dmsg is, and the
996 line number within the file. 
997
998 Some actual examples are: 
999
1000 Dmsg2(20, ``MD5len=\%d MD5=\%s\textbackslash{}n'', strlen(buf), buf); 
1001
1002 Dmsg1(9, ``Created client \%s record\textbackslash{}n'', client->hdr.name); 
1003
1004 \subsubsection*{Error Messages}
1005 \index{Messages!Error}
1006 \index{Error Messages}
1007 \addcontentsline{toc}{subsubsection}{Error Messages}
1008
1009 Error messages are messages that are related to the daemon as a whole rather
1010 than a particular job. For example, an out of memory condition my generate an
1011 error message. They should be very rarely needed. In general, you should be
1012 using Job and Job Queued messages (Jmsg and Qmsg). They are coded as: 
1013
1014 EmsgN(error-code, level, message, arg1, ...) As with debug messages, you must
1015 explicitly code the of arguments to be substituted in the message. error-code
1016 indicates the severity or class of error, and it may be one of the following: 
1017
1018 \addcontentsline{lot}{table}{Message Error Code Classes}
1019 \begin{longtable}{lp{3in}}
1020 {{\bf M\_ABORT} } & {Causes the daemon to immediately abort. This should be
1021 used only  in extreme cases. It attempts to produce a  traceback. } \\
1022 {{\bf M\_ERROR\_TERM} } & {Causes the daemon to immediately terminate. This
1023 should be used only  in extreme cases. It does not produce a  traceback. } \\
1024 {{\bf M\_FATAL} } & {Causes the daemon to terminate the current job, but the
1025 daemon keeps running } \\
1026 {{\bf M\_ERROR} } & {Reports the error. The daemon and the job continue
1027 running } \\
1028 {{\bf M\_WARNING} } & {Reports an warning message. The daemon and the job
1029 continue running } \\
1030 {{\bf M\_INFO} } & {Reports an informational message.}
1031
1032 \end{longtable}
1033
1034 There are other error message classes, but they are in a state of being
1035 redesigned or deprecated, so please do not use them. Some actual examples are:
1036
1037
1038 Emsg1(M\_ABORT, 0, ``Cannot create message thread: \%s\textbackslash{}n'',
1039 strerror(status)); 
1040
1041 Emsg3(M\_WARNING, 0, ``Connect to File daemon \%s at \%s:\%d failed. Retrying
1042 ...\textbackslash{}n'',  client-\gt{}hdr.name, client-\gt{}address,
1043 client-\gt{}port); 
1044
1045 Emsg3(M\_FATAL, 0, ``bdird\lt{}filed: bad response from Filed to \%s command:
1046 \%d \%s\textbackslash{}n'',  cmd, n, strerror(errno)); 
1047
1048 \subsubsection*{Job Messages}
1049 \index{Job Messages}
1050 \index{Messages!Job}
1051 \addcontentsline{toc}{subsubsection}{Job Messages}
1052
1053 Job messages are messages that pertain to a particular job such as a file that
1054 could not be saved, or the number of files and bytes that were saved. They
1055 Are coded as:
1056 \begin{verbatim}
1057 Jmsg(jcr, M\_FATAL, 0, "Text of message");
1058 \end{verbatim}
1059 A Jmsg with M\_FATAL will fail the job. The Jmsg() takes varargs so can
1060 have any number of arguments for substituted in a printf like format.
1061 Output from the Jmsg() will go to the Job report.
1062 <br>
1063 If the Jmsg is followed with a number such as Jmsg1(...), the number
1064 indicates the number of arguments to be substituted (varargs is not
1065 standard for \#defines), and what is more important is that the file and
1066 line number will be prefixed to the message. This permits a sort of debug
1067 from user's output.
1068
1069 \subsubsection*{Queued Job Messages}
1070 \index{Queued Job Messages}
1071 \index{Messages!Job}
1072 \addcontentsline{toc}{subsubsection}{Queued Job Messages}
1073 Queued Job messages are similar to Jmsg()s except that the message is
1074 Queued rather than immediately dispatched. This is necessary within the
1075 network subroutines and in the message editing routines. This is to prevent
1076 recursive loops, and to ensure that messages can be delivered even in the
1077 event of a network error.
1078
1079
1080 \subsubsection*{Memory Messages}
1081 \index{Messages!Memory}
1082 \index{Memory Messages}
1083 \addcontentsline{toc}{subsubsection}{Memory Messages}
1084
1085 Memory messages are messages that are edited into a memory buffer. Generally
1086 they are used in low level routines such as the low level device file dev.c in
1087 the Storage daemon or in the low level Catalog routines. These routines do not
1088 generally have access to the Job Control Record and so they return error
1089 messages reformatted in a memory buffer. Mmsg() is the way to do this.