Add contents of /proc/mounts to the debugging information.
[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 Code indentation
28 ----------------------------------------------------------------------
29 Our C source code generally adheres to some basic code-formatting
30 conventions.  The existing code base is not totally consistent on this
31 front, but we do prefer that contributed code be formatted similarly.
32 In short, use spaces-not-TABs for indentation, use 2 spaces for each
33 indentation level, and other than that, follow the K&R style.
34
35 If you use Emacs, add the following to one of one of your start-up files
36 (e.g., ~/.emacs), to help ensure that you get indentation right:
37
38   ;;; When editing C sources in libguestfs, use this style.
39   (defun libguestfs-c-mode ()
40     "C mode with adjusted defaults for use with libguestfs."
41     (interactive)
42     (c-set-style "K&R")
43     (setq indent-tabs-mode nil) ; indent using spaces, not TABs
44     (setq c-indent-level 2)
45     (setq c-basic-offset 2))
46   (add-hook 'c-mode-hook
47             '(lambda () (if (string-match "/libguestfs" (buffer-file-name))
48                             (libguestfs-c-mode))))
49
50 Directories
51 ----------------------------------------------------------------------
52
53 appliance/
54         The qemu appliance, build scripts and so on.
55
56 cat/
57         The virt-cat tool.
58
59 capitests/
60         Automated tests of the C API.
61
62 contrib/
63         Outside contributions, experimental parts.
64
65 daemon/
66         The daemon that runs inside the guest and carries out actions.
67
68 df/
69         The virt-df tool.
70
71 examples/
72         The examples.
73
74 fish/
75         Guestfish (the command-line program / shell)
76
77 haskell/
78         Haskell bindings.
79
80 images/
81         Some guest images to test against.  These are gzipped to save
82         space.  You have to unzip them before use.
83
84         Also contains some files used by the test suite.
85
86 inspector/
87         Virtual machine image inspector (virt-inspector).
88
89 java/
90         Java bindings.
91
92 m4/
93         M4 macros used by autoconf.
94
95 ocaml/
96         OCaml bindings.
97
98 po/
99         Translations.
100
101 perl/
102         Perl bindings.
103
104 python/
105         Python bindings.
106
107 regressions/
108         Regression tests.
109
110 ruby/
111         Ruby bindings.
112
113 src/
114         Source code to the C library.
115         Also contains the crucial generator program.
116
117 test-tool/
118         Interactive qemu/kernel test tool.
119
120 v2v/
121         Xen to KVM (V2V) conversion tool.
122
123 Debugging
124 ----------------------------------------------------------------------
125
126 It's a good idea to use guestfish to try out new commands.
127
128 Debugging the daemon is a problem because it runs inside a minimal
129 qemu environment.  However you can print messages from the daemon, and
130 they will show up if you use 'guestfish -v'.
131
132 Patches
133 ----------------------------------------------------------------------
134
135 Submit patches to the mailing list:
136 http://www.redhat.com/mailman/listinfo/libguestfs
137 and CC to rjones@redhat.com
138
139 I18N
140 ----------------------------------------------------------------------
141
142 We support i18n (gettext anyhow) in the library.
143
144 However many messages come from the daemon, and we don't translate
145 those at the moment.  One reason is that the appliance generally has
146 all locale files removed from it, because they take up a lot of space.
147 So we'd have to readd some of those, as well as copying our PO files
148 into the appliance.
149
150 Debugging messages are never translated, since they are intended for
151 the programmers.
152
153 Extended printf
154 ----------------------------------------------------------------------
155
156 In the daemon code we have created custom printf formatters %Q and %R,
157 which are used to do shell quoting.
158
159 %Q => Simple shell quoted string.  Any spaces or other shell characters
160       are escaped for you.
161
162 %R => Same as %Q except the string is treated as a path which is prefixed
163       by the sysroot.
164
165 eg.
166
167 asprintf (&cmd, "cat %R", path);
168 ==> "cat /sysroot/some\ path\ with\ spaces"
169
170 Note: Do NOT use these when you are passing parameters to the
171 command{,r,v,rv}() functions.  These parameters do NOT need to be
172 quoted because they are not passed via the shell (instead, straight to
173 exec).  You probably want to use the sysroot_path() function however.