Guard #inclusion of config.h in examples.
[libguestfs.git] / HACKING
1 PLEASE LOOK AT THE TOP OF EACH FILE BEFORE EDITING TO SEE WHETHER IT
2 IS AUTOMATICALLY GENERATED OR NOT.
3
4 Adding a new action
5 ----------------------------------------------------------------------
6
7 All action functions are generated automatically, so there are only
8 two files you need to edit:
9
10 (1) src/generator.ml: Add your new action, parameters, description,
11 etc. to the big list called 'functions' at the top of this file.
12
13 (2) Edit/create a C file in daemon/ subdirectory which implements your
14 'do_action' function.  Take a look at one of the numerous examples
15 there.
16
17 Formatting
18 ----------------------------------------------------------------------
19
20 Try to use GNU / Emacs default formatting, following the convention
21 used elsewhere in the source.
22
23 Please make sure that the code compiles without warnings.
24
25 Please test any changes.
26
27 Directories
28 ----------------------------------------------------------------------
29
30 appliance/
31         The qemu appliance, build scripts and so on.
32
33 cat/
34         The virt-cat tool.
35
36 capitests/
37         Automated tests of the C API.
38
39 contrib/
40         Outside contributions, experimental parts.
41
42 daemon/
43         The daemon that runs inside the guest and carries out actions.
44
45 df/
46         The virt-df tool.
47
48 examples/
49         The examples.
50
51 fish/
52         Guestfish (the command-line program / shell)
53
54 haskell/
55         Haskell bindings.
56
57 images/
58         Some guest images to test against.  These are gzipped to save
59         space.  You have to unzip them before use.
60
61         Also contains some files used by the test suite.
62
63 inspector/
64         Virtual machine image inspector (virt-inspector).
65
66 java/
67         Java bindings.
68
69 m4/
70         M4 macros used by autoconf.
71
72 ocaml/
73         OCaml bindings.
74
75 po/
76         Translations.
77
78 perl/
79         Perl bindings.
80
81 python/
82         Python bindings.
83
84 regressions/
85         Regression tests.
86
87 ruby/
88         Ruby bindings.
89
90 src/
91         Source code to the C library.
92         Also contains the crucial generator program.
93
94 test-tool/
95         Interactive qemu/kernel test tool.
96
97 v2v/
98         Xen to KVM (V2V) conversion tool.
99
100 Debugging
101 ----------------------------------------------------------------------
102
103 It's a good idea to use guestfish to try out new commands.
104
105 Debugging the daemon is a problem because it runs inside a minimal
106 qemu environment.  However you can print messages from the daemon, and
107 they will show up if you use 'guestfish -v'.
108
109 Patches
110 ----------------------------------------------------------------------
111
112 Submit patches to the mailing list:
113 http://www.redhat.com/mailman/listinfo/libguestfs
114 and CC to rjones@redhat.com
115
116 I18N
117 ----------------------------------------------------------------------
118
119 We support i18n (gettext anyhow) in the library.
120
121 However many messages come from the daemon, and we don't translate
122 those at the moment.  One reason is that the appliance generally has
123 all locale files removed from it, because they take up a lot of space.
124 So we'd have to readd some of those, as well as copying our PO files
125 into the appliance.
126
127 Debugging messages are never translated, since they are intended for
128 the programmers.
129
130 Extended printf
131 ----------------------------------------------------------------------
132
133 In the daemon code we have created custom printf formatters %Q and %R,
134 which are used to do shell quoting.
135
136 %Q => Simple shell quoted string.  Any spaces or other shell characters
137       are escaped for you.
138
139 %R => Same as %Q except the string is treated as a path which is prefixed
140       by the sysroot.
141
142 eg.
143
144 asprintf (&cmd, "cat %R", path);
145 ==> "cat /sysroot/some\ path\ with\ spaces"
146
147 Note: Do NOT use these when you are passing parameters to the
148 command{,r,v,rv}() functions.  These parameters do NOT need to be
149 quoted because they are not passed via the shell (instead, straight to
150 exec).  You probably want to use the sysroot_path() function however.