Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/sandbox:master commit in: src/, libsbutil/
Date: Fri, 05 Nov 2021 21:40:26
Message-Id: 1636145788.2f99599214eeb36b329ddc90559c17210312f7d1.vapier@gentoo
1 commit: 2f99599214eeb36b329ddc90559c17210312f7d1
2 Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
3 AuthorDate: Fri Nov 5 20:56:28 2021 +0000
4 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
5 CommitDate: Fri Nov 5 20:56:28 2021 +0000
6 URL: https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=2f995992
7
8 sandbox: move xasprintf helper here
9
10 Since this is only used by sandbox, and is not usable by libsandbox,
11 move it out of libsbutil. Leave a note behind for possible future
12 macros too.
13
14 Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>
15
16 libsbutil/sbutil.h | 17 ++++++++---------
17 src/sandbox.h | 8 ++++++++
18 2 files changed, 16 insertions(+), 9 deletions(-)
19
20 diff --git a/libsbutil/sbutil.h b/libsbutil/sbutil.h
21 index cf97179..c146b80 100644
22 --- a/libsbutil/sbutil.h
23 +++ b/libsbutil/sbutil.h
24 @@ -140,7 +140,14 @@ void sb_maybe_gdb(void);
25 #define sb_fprintf(fp, ...) sb_fdprintf(fileno(fp), __VA_ARGS__)
26 #define sb_vfprintf(fp, ...) sb_vfdprintf(fileno(fp), __VA_ARGS__)
27
28 -/* Memory functions */
29 +/*
30 + * Memory functions.
31 + *
32 + * NB: These are wrappers around libsbutil functions that build off memory calls that we
33 + * implement directly (see libsandbox/memory.c). Do not add any helpers here that cannot
34 + * be mirrored in libsandbox as attempts to pass memory between the two allocators will
35 + * lead to corruption & crashes.
36 + */
37 void *__xcalloc(size_t nmemb, size_t size, const char *file, const char *func, size_t line);
38 void *__xmalloc(size_t size, const char *file, const char *func, size_t line);
39 void *__xzalloc(size_t size /*, const char *file, const char *func, size_t line */);
40 @@ -155,14 +162,6 @@ char *__xstrndup(const char *str, size_t size, const char *file, const char *fun
41 #define xstrndup(_str, _size) __xstrndup(_str, _size, __FILE__, __func__, __LINE__)
42 #define xalloc_die() __sb_ebort(__FILE__, __func__, __LINE__, "out of memory")
43
44 -#define xasprintf(fmt, ...) \
45 -({ \
46 - int _ret = asprintf(fmt, __VA_ARGS__); \
47 - if (_ret == 0) \
48 - sb_perr("asprintf(%s) failed", #fmt); \
49 - _ret; \
50 -})
51 -
52 /* string helpers */
53 #define streq(s1, s2) (strcmp(s1, s2) == 0)
54
55
56 diff --git a/src/sandbox.h b/src/sandbox.h
57 index 28961f5..477973a 100644
58 --- a/src/sandbox.h
59 +++ b/src/sandbox.h
60 @@ -40,6 +40,14 @@ extern pid_t setup_namespaces(void);
61 #define sb_err(fmt, args...) _sb_err(warn, fmt, ## args)
62 #define sb_perr(fmt, args...) _sb_err(pwarn, fmt, ## args)
63
64 +#define xasprintf(fmt, ...) \
65 +({ \
66 + int _ret = asprintf(fmt, __VA_ARGS__); \
67 + if (_ret == 0) \
68 + sb_perr("asprintf(%s) failed", #fmt); \
69 + _ret; \
70 +})
71 +
72 /* Option parsing related code */
73 extern void parseargs(int argc, char *argv[]);
74 extern int opt_use_namespaces;