-
Notifications
You must be signed in to change notification settings - Fork 0
/
CODING
356 lines (275 loc) · 12.6 KB
/
CODING
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
Notes on Coding Standards/Requirements for OpenAFS Source
---------------------------------------------------------
We have an official style. Please use it. If you have gnu indent 2.2.9 or
later you can reformat for this style with the following option:
-npro -nbad -bap -nbc -bbo -br -ce -cdw -brs -ncdb -cp1 -ncs -di2 -ndj -nfc1
-nfca -i4 -lp -npcs -nprs -psl -sc -nsob -ts8
Do not use $< for non-pattern rules in any cross-platform dir as it
requires a reasonable make that is not available on all systems.
Do not have build rules that build multiple targets. Make doesn't seem able
to handle this, and it interferes with -j builds. (In particular, build the
rxgen targets individually and not using the flags for building all the files
in one shot.)
Try to test builds using gmake -j # MAKE="gmake -j #", it seems like a good
way to find missing or order-dependent dependency rules. (Is there a better
way to do this?)
-- Prototyping and Style --
Prototypes for all source files in a given dir DDD should be placed
in the file DDD/DDD_prototypes.h. All externally used (either API
or used by other source files) routines and variables should be
prototyped in this file.
The prototypes should be a full prototype, with argument and return
types. (Should not generate a warning with gcc -Wstrict-prototypes.)
Format of the prototype files should look like:
Standard Copyright Notice
#ifndef AFS_SRC_DDD_PROTO_H
#define AFS_SRC_DDD_PROTO_H
/* filename.c */
prototypes
/* filename.c */
prototypes
#endif /* AFS_SRC_DDD_PROTO_H */
In most of the existing prototypes, the define is DDD_PROTOTYPES_H, which is
probably ok as well.
The declaration of the routines should be done in ANSI style. If at some
later date, it is determined that prototypes don't work on some platform
properly, we can use ansi2knr during the compile.
rettype
routine(argtype arg)
{
}
All routines should have a return type specified, void if nothing returned,
and should have (void) if no arguments are taken.
Header files should not contain macros or other definitions unless they
are used across multiple source files.
All routines should be declared static if they are not used outside that
source file.
Compiles on gcc-using machines should strive to handle using
-Wstrict-prototypes -Werror. (this may take a while)
Routines shall be defined in source prior to use if possible, and
prototyped in block at top of file if static.
API documentation in the code should be done using Qt-style Doxygen
comments.
If you make a routine or variable static, be sure and remove it from
the AIX .exp files.
Suggested compiler flags:
gcc: -Wall -Wstrict-prototypes
Solaris Workshop CC: -fd -v
(You might not want the -fd, it isn't really useful, just complains about the
K&R style functions, but -v gives useful info.)
Multiple line comment blocks should begin with only /* on one line and end with
only */ on one line.
Example:
/*
* Multiple line comment blocks should be formatted
* like this example.
*/
Do not use braces on one-line if and loop statements.
Use:
if (some_condition)
do_some_action();
else
do_something_else();
while (some_condition)
do_something();
Instead of:
if (some_condition) {
do_some_action();
}
while (some_condition) {
do_something();
}
In switch statements, to fall through from one case statement to another, use
AFS_FALLTHROUGH to mark the intentional fall through. Do not use fall through
comments (e.g. /* fallthrough */), as some compilers do not recognize them and
will flag the case statement with an implied fallthrough warning.
Use:
switch (x) {
case 1:
do_something();
AFS_FALLTHROUGH;
case 2:
do_something_else();
AFS_FALLTHROUGH;
default:
do_some_action();
}
Instead of using fallthrough comments:
switch (x) {
case 1:
do_something();
/* fallthrough */
case 2:
do_something_else();
/* fallthrough */
default:
do_some_action();
}
Or not marking the fall through:
switch (x) {
case 1:
do_something();
case 2:
do_something_else();
default:
do_some_action();
}
Dependencies required to build OpenAFS from source
--------------------------------------------------
The following packages are required to build all of the OpenAFS code
from source on various operating systems:
On Debian:
- autoconf, automake, bison, comerr-dev, cpio, flex, libkrb5-dev,
libncurses5-dev, libpam0g-dev, libxml2-utils, perl, pkg-config;
- libfuse-dev (for the FUSE-based user-mode client);
- dblatex, docbook-xsl, doxygen, xsltproc (for documentation);
- debhelper, hardening-wrapper, dkms (to build the Debian packages)
On FreeBSD:
- autoconf, automake, libtool;
- fusefs-libs, pkgconf (for the FUSE-based user-mode client);
- perl, dblatex, docbook-xsl, libxslt, python, ruby, zip (for documentation)
In addition, FreeBSD systems require kernel sources and a configured kernel
build directory (see section "FreeBSD Notes" in the README file).
GIT Usage
=========
*WARNING* *WARNING* *WARNING* *WARNING* *WARNING* *WARNING* *WARNING*
The Git tree may not always have code which can currently be built.
While every effort is made to keep the head of the tree buildable,
you may at any time find yourself between commits and hence have a tree
which does not build, or worse, causes more serious problems!
Do not use the Git tree unless you know what you're doing.
Git checkouts do not include files generated by autoconf. You can
run regen.sh (at the top level) to create these files. You will need
to have autoconf and automake installed on your system.
Summary
-------
Browse: http://git.openafs.org/
Clone: git clone git://git.openafs.org/openafs.git
Step-by-step
------------
1. Obtain the Git software. If you are using a system with a standard
software repository, Git may already be available as a package named
something like git or git-core. Otherwise, go to http://git-scm.com/
2. Run the command:
% git clone git://git.openafs.org/openafs.git
This will download the full repository and leave a checked-out tree in
a subdirectory of the current directory named openafs. The repository
itself is in the .git subdirectory of that directory.
WARNING: The repository is approximately 60MiB currently and will only
grow, so it may take some time to download the first time over a slow
network connection.
3. Generate the additional required files:
% cd openafs
% ./regen.sh
The current development series is in the branch named master. The stable
releases are on separate branches named something like
openafs-stable_<version> with a separate branch for each major stable
release series. Use git branch -a to see a full list of branches.
OpenAFS uses the Gerrit code review system to review and merge all changes
to OpenAFS. More details are at:
http://wiki.openafs.org/GitDevelopers/
including more detailed Git instructions.
It's by far preferred to use Gerrit to submit code changes, but if you
can't for whatever reason, you can instead open a bug and submit a patch
that way. Do this by sending mail to [email protected] with the
patch attached. But please use Gerrit if you can; patches sent in as bugs
will have to be forwarded to Gerrit by someone else, and it's easier for
everyone if you can enter them into Gerrit yourself.
Backport policy
------------
All patches should land on master first, unless the patch fixes a bug
that only exists in the stable branch.
Once a patch has been accepted into master, anyone can propose
backports to stable branches.
When cherry-picking a commit from another branch, please append a
"cherry picked from" section in your commit message. You'll also need
a separate Change-ID for Gerrit to recognize this as a separate
change. One workflow to do this:
1) Use "git cherry-pick -ex" to pick your commits onto another branch.
The -x option will append the appropriate "cherry picked from"
message, and the -e option will open your editor for you to edit
the commit message.
2) In your editor, delete the existing Change-ID line. Save and quit.
3) Run "git commit --amend", saving and quitting again. Git will run
the commit hook and generate a new Change-ID for Gerrit.
Warnings
========
OpenAFS Warning detection
-------------------------
There's been a concerted effort over the last few years, by many developers,
to reduce the number of warnings in the OpenAFS tree. In an attempt to
prevent warnings from creeping back in, we now have the ability to break the
build when new warnings appear.
This is only available for systems with gcc 4.2 or later or clang 3.2 or
later, and is disabled unless the --enable-checking option is supplied to
configure. Because we can't remove all of the warnings, we permit file by
file (and warning by warning) disabling of specific warnings. The
--enable-checking=all option prevents
this, and errors for any file containing a warning.
Disabling warnings
------------------
If warnings are unavoidable in a particular part of the build, they may be
disabled in an number of ways.
You can disable a single warning type in a particular file by using GCC
pragmas. If a warning can be disabled with a pragma, then the switch to use
will be listed in the error message you receive from the compiler. Pragmas
should be wrapped in IGNORE_SOME_GCC_WARNINGS, so that they aren't used
with non-gcc compilers, and can be disabled if desired. For example:
#ifdef IGNORE_SOME_GCC_WARNINGS
# pragma GCC diagnostic warning "-Wold-style-definition"
#endif
It would appear that when built with -Werror, the llvm clang compiler will
still upgrade warnings that are suppresed in this way to errors. In this case,
the fix is to mark that warning as ignored, but only for clang. For example:
#ifdef IGNORE_SOME_GCC_WARNINGS
# ifdef __clang__
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
# else
# pragma GCC diagnostic warning "-Wdeprecated-declarations"
# endif
#endif
If the source cannot be changed to add a pragma, you might be able to use the
autoconf function AX_APPEND_COMPILE_FLAGS to create a new macro that disables
the warning and then use macro for the build options for that file. For an
example, see how the autoconf macro CFLAGS_NOIMPLICIT_FALLTHROUGH is defined and
used.
Finally, if there isn't a way to disable the specific warning, you will need to
disable all warnings for the file in question. You can do this by supplying
the autoconf macro @CFLAGS_NOERROR@ in the build options for the file. For
example:
lex.yy.o : lex.yy.c y.tab.c
${CC} -c ${CFLAGS} @CFLAGS_NOERROR@ lex.yy.c
If you add a new warning inhibition, please also add it to the list below.
Inhibited warnings
------------------
uss/lex.i : fallthrough : clang fallthrough, flex generated code
comerr/et_lex.lex.l : fallthrough : clang fallthrough, flex generated code
pragma set to ignored where included in
error_table.y
afs/afs_syscall.c : old-style
: strict-proto
: all (ukernel) : syscall pointer issues
afsd/afsd_kernel.c : deprecated : daemon() marked as deprecated on Darwin
bozo/bosserver.c : deprecated : daemon() marked as deprecated on Darwin
bucoord/ubik_db_if.c : strict-proto : ubik_Call_SingleServer
bucoord/commands.c : all : signed vs unsigned for dates
external/heimdal/hcrypto/validate.c: all: statement with empty body
external/heimdal/hcrypto/evp.c: cast-function-type
: Linux kernel build uses -Wcast-function-type
external/heimdal/hcrypto/evp-algs.c: cast-function-type
: Linux kernel build uses -Wcast-function-type
kauth/admin_tools.c : strict-proto : ubik_Call
kauth/authclient.c : strict-proto : ubik_Call nonsense
libadmin/kas/afs_kasAdmin.c: strict-proto : ubik_Call nonsense
libadmin/samples/rxstat_query_peer.c : all : util_RPCStatsStateGet types
libadmin/samples/rxstat_query_process.c : all : util_RPCStatsStateGet types
libadmin/test/client.c : all : util_RPCStatsStateGet types
ubik/ubikclient.c : strict-protos : ubik_Call
volser/vol-dump.c : format : afs_sfsize_t
rxkad/ticket5.c : format-truncation : inside included file v5der.c in the
function _heim_time2generalizedtime, the
two snprintf calls raise
format-truncation warnings due to the
arithmetic on tm_year and tm_mon fields
lwp/process.c : dangling-pointer : Ignore the legitimate use of saving
the address of a stack variable