[lxc-devel] [lxc/master] tree-wide: random macro cleanups
brauner on Github
lxc-bot at linuxcontainers.org
Tue Nov 29 06:30:55 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 470 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20161129/fb9408f0/attachment.bin>
-------------- next part --------------
From eab15c1ee61d4e71a57f8dd6d1cf85d0bf36b76f Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 29 Nov 2016 07:28:19 +0100
Subject: [PATCH] tree-wide: random macro cleanups
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/attach.c | 4 ++--
src/lxc/bdev/bdev.c | 2 +-
src/lxc/bdev/bdev.h | 2 +-
src/lxc/cgroups/cgfsng.c | 10 +++-------
src/lxc/commands.h | 6 +++---
src/lxc/conf.c | 8 +++-----
src/lxc/genl.c | 6 +++---
src/lxc/log.c | 8 ++++----
src/lxc/monitor.c | 7 +++----
src/lxc/nl.h | 3 +--
src/lxc/tools/lxc_checkpoint.c | 2 +-
src/lxc/tools/lxc_init.c | 2 +-
src/lxc/tools/lxc_ls.c | 1 -
src/lxc/tools/lxc_start.c | 6 +++---
src/lxc/tools/lxc_stop.c | 4 ++--
src/lxc/tools/lxc_usernsexec.c | 2 +-
src/lxc/utils.c | 17 ++++++++---------
src/lxc/utils.h | 3 ++-
src/tests/concurrent.c | 2 +-
src/tests/lxc-test-utils.c | 2 +-
20 files changed, 44 insertions(+), 53 deletions(-)
diff --git a/src/lxc/attach.c b/src/lxc/attach.c
index c84c696..094495f 100644
--- a/src/lxc/attach.c
+++ b/src/lxc/attach.c
@@ -86,7 +86,7 @@
lxc_log_define(lxc_attach, lxc);
/* /proc/pid-to-str/current\0 = (5 + 21 + 7 + 1) */
-#define __LSMATTRLEN (5 + 21 + 7 + 1)
+#define __LSMATTRLEN (5 + (LXC_NUMSTRLEN64) + 7 + 1)
static int lsm_openat(int procfd, pid_t pid, int on_exec)
{
int ret = -1;
@@ -182,7 +182,7 @@ static int lsm_set_label_at(int lsm_labelfd, int on_exec, char *lsm_label)
}
/* /proc/pid-to-str/status\0 = (5 + 21 + 7 + 1) */
-#define __PROC_STATUS_LEN (5 + 21 + 7 + 1)
+#define __PROC_STATUS_LEN (5 + (LXC_NUMSTRLEN64) + 7 + 1)
static struct lxc_proc_context_info *lxc_proc_get_context_info(pid_t pid)
{
FILE *proc_file;
diff --git a/src/lxc/bdev/bdev.c b/src/lxc/bdev/bdev.c
index 1534cc9..3526ed5 100644
--- a/src/lxc/bdev/bdev.c
+++ b/src/lxc/bdev/bdev.c
@@ -68,7 +68,7 @@
#include "utils.h"
#ifndef BLKGETSIZE64
-#define BLKGETSIZE64 _IOR(0x12,114,size_t)
+#define BLKGETSIZE64 _IOR(0x12, 114, size_t)
#endif
lxc_log_define(bdev, lxc);
diff --git a/src/lxc/bdev/bdev.h b/src/lxc/bdev/bdev.h
index 3f21e84..d8083cb 100644
--- a/src/lxc/bdev/bdev.h
+++ b/src/lxc/bdev/bdev.h
@@ -47,7 +47,7 @@
#endif
#ifndef MS_SLAVE
-#define MS_SLAVE (1<<19)
+#define MS_SLAVE (1 << 19)
#endif
#ifndef MS_RELATIME
diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index d3215d7..2b772e2 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -357,22 +357,18 @@ static uint32_t *lxc_cpumask(char *buf, size_t nbits)
return bitarr;
}
-/* The largest integer that can fit into long int is 2^64. This is a
- * 20-digit number.
- */
-#define __IN_TO_STR_LEN 21
/* Turn cpumask into simple, comma-separated cpulist. */
static char *lxc_cpumask_to_cpulist(uint32_t *bitarr, size_t nbits)
{
size_t i;
int ret;
- char numstr[__IN_TO_STR_LEN] = {0};
+ char numstr[LXC_NUMSTRLEN64] = {0};
char **cpulist = NULL;
for (i = 0; i <= nbits; i++) {
if (is_set(i, bitarr)) {
- ret = snprintf(numstr, __IN_TO_STR_LEN, "%zu", i);
- if (ret < 0 || (size_t)ret >= __IN_TO_STR_LEN) {
+ ret = snprintf(numstr, LXC_NUMSTRLEN64, "%zu", i);
+ if (ret < 0 || (size_t)ret >= LXC_NUMSTRLEN64) {
lxc_free_array((void **)cpulist, free);
return NULL;
}
diff --git a/src/lxc/commands.h b/src/lxc/commands.h
index e11a139..184eefa 100644
--- a/src/lxc/commands.h
+++ b/src/lxc/commands.h
@@ -26,11 +26,11 @@
#include "state.h"
-#define LXC_CMD_DATA_MAX (MAXPATHLEN*2)
+#define LXC_CMD_DATA_MAX (MAXPATHLEN * 2)
/* https://developer.gnome.org/glib/2.28/glib-Type-Conversion-Macros.html */
-#define INT_TO_PTR(n) ((void *) (long) (n))
-#define PTR_TO_INT(p) ((int) (long) (p))
+#define INT_TO_PTR(n) ((void *)(long)(n))
+#define PTR_TO_INT(p) ((int)(long)(p))
typedef enum {
LXC_CMD_CONSOLE,
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index fb080aa..8173b4f 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -99,8 +99,6 @@
lxc_log_define(lxc_conf, lxc);
-#define LINELEN 4096
-
#if HAVE_SYS_CAPABILITY_H
#ifndef CAP_SETFCAP
#define CAP_SETFCAP 31
@@ -1281,7 +1279,7 @@ static int setup_rootfs(struct lxc_conf *conf)
int prepare_ramfs_root(char *root)
{
- char buf[LINELEN], *p;
+ char buf[LXC_LINELEN], *p;
char nroot[PATH_MAX];
FILE *f;
int i;
@@ -1326,7 +1324,7 @@ int prepare_ramfs_root(char *root)
SYSERROR("Unable to open /proc/self/mountinfo");
return -1;
}
- while (fgets(buf, LINELEN, f)) {
+ while (fgets(buf, LXC_LINELEN, f)) {
for (p = buf, i=0; p && i < 4; i++)
p = strchr(p+1, ' ');
if (!p)
@@ -3042,7 +3040,7 @@ bool lxc_delete_network(struct lxc_handler *handler)
#define LXC_USERNIC_PATH LIBEXECDIR "/lxc/lxc-user-nic"
/* lxc-user-nic returns "interface_name:interface_name\n" */
-#define MAX_BUFFER_SIZE IFNAMSIZ*2 + 2
+#define MAX_BUFFER_SIZE IFNAMSIZ * 2 + 2
static int unpriv_assign_nic(const char *lxcpath, char *lxcname,
struct lxc_netdev *netdev, pid_t pid)
{
diff --git a/src/lxc/genl.c b/src/lxc/genl.c
index b5a582e..6afaf40 100644
--- a/src/lxc/genl.c
+++ b/src/lxc/genl.c
@@ -44,7 +44,7 @@ static int genetlink_resolve_family(const char *family)
request = genlmsg_alloc(GENLMSG_GOOD_SIZE);
if (!request)
return -ENOMEM;
-
+
reply = genlmsg_alloc(GENLMSG_GOOD_SIZE);
if (!reply) {
genlmsg_free(request);
@@ -86,10 +86,10 @@ static int genetlink_resolve_family(const char *family)
len -= NLMSG_LENGTH(GENL_HDRLEN);
if (len < 0)
goto out_close;
-
+
attr = (struct nlattr *)GENLMSG_DATA(reply);
attr = (struct nlattr *)((char *)attr + NLA_ALIGN(attr->nla_len));
-
+
ret = -ENOMSG;
if (attr->nla_type != CTRL_ATTR_FAMILY_ID)
goto out_close;
diff --git a/src/lxc/log.c b/src/lxc/log.c
index 549a160..27aa2c4 100644
--- a/src/lxc/log.c
+++ b/src/lxc/log.c
@@ -50,7 +50,7 @@
* datatype is currently at maximum a 64bit integer, we have a date string that
* is of maximum length (2^64 - 1) * 2 = (21 + 21) = 42.
*/
-#define LXC_LOG_TIME_SIZE ((__LXC_NUMSTRLEN) * 2)
+#define LXC_LOG_TIME_SIZE ((LXC_NUMSTRLEN64)*2)
int lxc_log_fd = -1;
static int syslog_enable = 0;
@@ -145,7 +145,7 @@ int lxc_unix_epoch_to_utc(char *buf, size_t bufsize, const struct timespec *time
{
int64_t epoch_to_days, z, era, doe, yoe, year, doy, mp, day, month,
d_in_s, hours, h_in_s, minutes, seconds;
- char nanosec[__LXC_NUMSTRLEN];
+ char nanosec[LXC_NUMSTRLEN64];
int ret;
/* See https://howardhinnant.github.io/date_algorithms.html for an
@@ -217,8 +217,8 @@ int lxc_unix_epoch_to_utc(char *buf, size_t bufsize, const struct timespec *time
seconds = (time->tv_sec - d_in_s - h_in_s - (minutes * 60));
/* Make string from nanoseconds. */
- ret = snprintf(nanosec, __LXC_NUMSTRLEN, "%ld", time->tv_nsec);
- if (ret < 0 || ret >= __LXC_NUMSTRLEN)
+ ret = snprintf(nanosec, LXC_NUMSTRLEN64, "%ld", time->tv_nsec);
+ if (ret < 0 || ret >= LXC_NUMSTRLEN64)
return -1;
/* Create final timestamp for the log and shorten nanoseconds to 3
diff --git a/src/lxc/monitor.c b/src/lxc/monitor.c
index 793fbde..483e06b 100644
--- a/src/lxc/monitor.c
+++ b/src/lxc/monitor.c
@@ -284,12 +284,11 @@ int lxc_monitor_read(int fd, struct lxc_msg *msg)
/* Used to spawn a monitord either on startup of a daemon container, or when
* lxc-monitor starts.
*/
-#define __INT_LEN 21
int lxc_monitord_spawn(const char *lxcpath)
{
int ret;
int pipefd[2];
- char pipefd_str[__INT_LEN];
+ char pipefd_str[LXC_NUMSTRLEN64];
pid_t pid1, pid2;
char *const args[] = {
@@ -356,8 +355,8 @@ int lxc_monitord_spawn(const char *lxcpath)
close(pipefd[0]);
- ret = snprintf(pipefd_str, __INT_LEN, "%d", pipefd[1]);
- if (ret < 0 || ret >= __INT_LEN) {
+ ret = snprintf(pipefd_str, LXC_NUMSTRLEN64, "%d", pipefd[1]);
+ if (ret < 0 || ret >= LXC_NUMSTRLEN64) {
ERROR("Failed to create pid argument to pass to monitord.");
exit(EXIT_FAILURE);
}
diff --git a/src/lxc/nl.h b/src/lxc/nl.h
index d347835..0bf62d5 100644
--- a/src/lxc/nl.h
+++ b/src/lxc/nl.h
@@ -30,8 +30,7 @@
#define PAGE_SIZE 4096
#endif
#define NLMSG_GOOD_SIZE (2*PAGE_SIZE)
-#define NLMSG_TAIL(nmsg) \
- ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
+#define NLMSG_TAIL(nmsg) ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
#define NLA_DATA(na) ((void *)((char*)(na) + NLA_HDRLEN))
#define NLA_NEXT_ATTR(attr) ((void *)((char *)attr) + NLA_ALIGN(attr->nla_len))
diff --git a/src/lxc/tools/lxc_checkpoint.c b/src/lxc/tools/lxc_checkpoint.c
index eeddf59..c42cecd 100644
--- a/src/lxc/tools/lxc_checkpoint.c
+++ b/src/lxc/tools/lxc_checkpoint.c
@@ -39,7 +39,7 @@ static bool daemonize_set = false;
static bool pre_dump = false;
static char *predump_dir = NULL;
-#define OPT_PREDUMP_DIR OPT_USAGE+1
+#define OPT_PREDUMP_DIR OPT_USAGE + 1
static const struct option my_longopts[] = {
{"checkpoint-dir", required_argument, 0, 'D'},
diff --git a/src/lxc/tools/lxc_init.c b/src/lxc/tools/lxc_init.c
index 5dd29af..1aaa96c 100644
--- a/src/lxc/tools/lxc_init.c
+++ b/src/lxc/tools/lxc_init.c
@@ -21,6 +21,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
@@ -30,7 +31,6 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
-#define _GNU_SOURCE
#include <getopt.h>
#include "log.h"
diff --git a/src/lxc/tools/lxc_ls.c b/src/lxc/tools/lxc_ls.c
index b5ddeef..363d3d2 100644
--- a/src/lxc/tools/lxc_ls.c
+++ b/src/lxc/tools/lxc_ls.c
@@ -43,7 +43,6 @@
lxc_log_define(lxc_ls, lxc);
-#define LINELEN 1024
/* Per default we only allow five levels of recursion to protect the stack at
* least a little bit. */
#define MAX_NESTLVL 5
diff --git a/src/lxc/tools/lxc_start.c b/src/lxc/tools/lxc_start.c
index eaa8da4..984a28f 100644
--- a/src/lxc/tools/lxc_start.c
+++ b/src/lxc/tools/lxc_start.c
@@ -50,9 +50,9 @@
#include "confile.h"
#include "arguments.h"
-#define OPT_SHARE_NET OPT_USAGE+1
-#define OPT_SHARE_IPC OPT_USAGE+2
-#define OPT_SHARE_UTS OPT_USAGE+3
+#define OPT_SHARE_NET OPT_USAGE + 1
+#define OPT_SHARE_IPC OPT_USAGE + 2
+#define OPT_SHARE_UTS OPT_USAGE + 3
lxc_log_define(lxc_start_ui, lxc);
diff --git a/src/lxc/tools/lxc_stop.c b/src/lxc/tools/lxc_stop.c
index 64b742d..e2d64fb 100644
--- a/src/lxc/tools/lxc_stop.c
+++ b/src/lxc/tools/lxc_stop.c
@@ -33,8 +33,8 @@
#include "commands.h"
#include "utils.h"
-#define OPT_NO_LOCK OPT_USAGE+1
-#define OPT_NO_KILL OPT_USAGE+2
+#define OPT_NO_LOCK OPT_USAGE + 1
+#define OPT_NO_KILL OPT_USAGE + 2
lxc_log_define(lxc_stop_ui, lxc);
diff --git a/src/lxc/tools/lxc_usernsexec.c b/src/lxc/tools/lxc_usernsexec.c
index 9905d53..7fd2aca 100644
--- a/src/lxc/tools/lxc_usernsexec.c
+++ b/src/lxc/tools/lxc_usernsexec.c
@@ -50,7 +50,7 @@
#endif
#ifndef MS_SLAVE
-#define MS_SLAVE (1<<19)
+#define MS_SLAVE (1 << 19)
#endif
int unshare(int flags);
diff --git a/src/lxc/utils.c b/src/lxc/utils.c
index 7ddf1db..7c2098e 100644
--- a/src/lxc/utils.c
+++ b/src/lxc/utils.c
@@ -1093,10 +1093,9 @@ uint64_t fnv_64a_buf(void *buf, size_t len, uint64_t hval)
* is MS_SHARED, but not '/', then you're out of luck - figuring that
* out would be too much work to be worth it.
*/
-#define LINELEN 4096
int detect_shared_rootfs(void)
{
- char buf[LINELEN], *p;
+ char buf[LXC_LINELEN], *p;
FILE *f;
int i;
char *p2;
@@ -1104,18 +1103,18 @@ int detect_shared_rootfs(void)
f = fopen("/proc/self/mountinfo", "r");
if (!f)
return 0;
- while (fgets(buf, LINELEN, f)) {
- for (p = buf, i=0; p && i < 4; i++)
- p = strchr(p+1, ' ');
+ while (fgets(buf, LXC_LINELEN, f)) {
+ for (p = buf, i = 0; p && i < 4; i++)
+ p = strchr(p + 1, ' ');
if (!p)
continue;
- p2 = strchr(p+1, ' ');
+ p2 = strchr(p + 1, ' ');
if (!p2)
continue;
*p2 = '\0';
- if (strcmp(p+1, "/") == 0) {
+ if (strcmp(p + 1, "/") == 0) {
// this is '/'. is it shared?
- p = strchr(p2+1, ' ');
+ p = strchr(p2 + 1, ' ');
if (p && strstr(p, "shared:")) {
fclose(f);
return 1;
@@ -1897,7 +1896,7 @@ int lxc_strmunmap(void *addr, size_t length)
/* Check whether a signal is blocked by a process. */
/* /proc/pid-to-str/status\0 = (5 + 21 + 7 + 1) */
-#define __PROC_STATUS_LEN (5 + 21 + 7 + 1)
+#define __PROC_STATUS_LEN (5 + (LXC_NUMSTRLEN64) + 7 + 1)
bool task_blocking_signal(pid_t pid, int signal)
{
bool bret = false;
diff --git a/src/lxc/utils.h b/src/lxc/utils.h
index 3d1ecee..b7dcd5d 100644
--- a/src/lxc/utils.h
+++ b/src/lxc/utils.h
@@ -37,7 +37,8 @@
/* Useful macros */
/* Maximum number for 64 bit integer is a string with 21 digits: 2^64 - 1 = 21 */
-#define __LXC_NUMSTRLEN 21
+#define LXC_NUMSTRLEN64 21
+#define LXC_LINELEN 4096
/* returns 1 on success, 0 if there were any failures */
extern int lxc_rmdir_onedev(char *path, const char *exclude);
diff --git a/src/tests/concurrent.c b/src/tests/concurrent.c
index e6899ad..bfefa48 100644
--- a/src/tests/concurrent.c
+++ b/src/tests/concurrent.c
@@ -16,13 +16,13 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#define _GNU_SOURCE
#include <limits.h>
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
-#define _GNU_SOURCE
#include <getopt.h>
#include <lxc/lxccontainer.h>
diff --git a/src/tests/lxc-test-utils.c b/src/tests/lxc-test-utils.c
index 800c029..d4363b8 100644
--- a/src/tests/lxc-test-utils.c
+++ b/src/tests/lxc-test-utils.c
@@ -71,7 +71,7 @@ void test_lxc_deslashify(void)
}
/* /proc/int_as_str/ns/mnt\0 = (5 + 21 + 7 + 1) */
-#define __MNTNS_LEN (5 + 21 + 7 + 1)
+#define __MNTNS_LEN (5 + (LXC_NUMSTRLEN64) + 7 + 1)
void test_detect_ramfs_rootfs(void)
{
size_t i;
More information about the lxc-devel
mailing list