[lxc-devel] [lxc/master] CODING_STYLE: update

brauner on Github lxc-bot at linuxcontainers.org
Fri Mar 1 20:24:58 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190301/55734fdb/attachment.bin>
-------------- next part --------------
From 874563c376dea07f0520c1a7088565c218775300 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Fri, 1 Mar 2019 21:24:31 +0100
Subject: [PATCH] CODING_STYLE: update

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 CODING_STYLE.md | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/CODING_STYLE.md b/CODING_STYLE.md
index 54ac6d4ad0..4599c4ed85 100644
--- a/CODING_STYLE.md
+++ b/CODING_STYLE.md
@@ -662,3 +662,35 @@ int lxc_attach_run_command(void *payload)
 	return ret;
 }
 ```
+
+## 24) Never use `fgets()`
+
+LXC does not allow the use of `fgets()`. Use `getline()` or other methods
+instead.
+
+## 25) Never allocate memory on the stack
+
+This specifically forbids any usage of `alloca()` in the codebase.
+
+## 26) Use cleanup macros supported by `gcc` and `clang`
+
+LXC has switched from manually cleaning up resources to using cleanup macros
+supported by `gcc` and `clang`:
+```c
+__attribute__((__cleanup__(<my-cleanup-function-wrapper>)))
+```
+We do not allow manually cleanups anymore if there are appropriate macros.
+Currently the following macros are supported:
+```c
+/* close file descriptor */
+#define __do_close_prot_errno
+
+/* free allocated memory */
+#define __do_free __attribute__((__cleanup__(__auto_free__)))
+
+/* close FILEs */
+#define __do_fclose __attribute__((__cleanup__(__auto_fclose__)))
+
+/* close DIRs */
+#define __do_closedir __attribute__((__cleanup__(__auto_closedir__)))
+```


More information about the lxc-devel mailing list