[CRIU] [PATCH] use #pragma once instead of #define guards

shawn at churchofgit.com shawn at churchofgit.com
Tue Dec 24 07:44:13 PST 2013


---- Original Message ----
 From: "Andrew Vagin" 
 To: "Shawn Landden" 
CC: criu at openvz.org
 Sent: Tue, Dec 24, 2013, 01:41 AM
 Subject: Re: [CRIU] [PATCH] use #pragma once instead of #define guards
Why do we need this?It makes the code cleaner. both systemd and kmod have done this. (inspired by my patch to systemd) 

On Fri, Dec 20, 2013 at 07:20:46PM -0800, Shawn Landden wrote:
---
include/bug.h              | 5 +----
include/compiler.h         | 5 +----
include/cpu.h              | 5 +----
include/cr-service.h       | 5 +----
include/cr-show.h          | 5 +----
include/cr_options.h       | 5 +----
include/crtools.h          | 5 +----
include/err.h              | 5 +----
include/errno.h            | 5 +----
include/eventfd.h          | 5 +----
include/eventpoll.h        | 5 +----
include/fcntl.h            | 5 +----
include/fdset.h            | 5 +----
include/fifo.h             | 5 +----
include/file-ids.h         | 5 +----
include/file-lock.h        | 5 +----
include/files-reg.h        | 5 +----
include/files.h            | 5 +----
include/fsnotify.h         | 5 +----
include/image-desc.h       | 5 +----
include/image.h            | 5 +----
include/inet_diag.h        | 5 +----
include/ipc_ns.h           | 5 +----
include/kcmp-ids.h         | 5 +----
include/kcmp.h             | 5 +----
include/kerndat.h          | 5 +----
include/libnetlink.h       | 6 +-----
include/list.h             | 5 +----
include/lock.h             | 5 +----
include/log-levels.h       | 5 +----
include/log.h              | 5 +----
include/magic.h            | 5 +----
include/mem.h              | 5 +----
include/mman.h             | 5 +----
include/mount.h            | 5 +----
include/namespaces.h       | 5 +----
include/net.h              | 5 +----
include/netfilter.h        | 5 +----
include/netlink_diag.h     | 5 +----
include/packet_diag.h      | 5 +----
include/page-pipe.h        | 5 +----
include/page-read.h        | 5 +----
include/page-xfer.h        | 5 +----
include/parasite-syscall.h | 5 +----
include/parasite.h         | 5 +----
include/pid.h              | 5 +----
include/pipes.h            | 5 +----
include/posix-timer.h      | 5 +----
include/prctl.h            | 5 +----
include/proc_parse.h       | 5 +----
include/protobuf-desc.h    | 5 +----
include/protobuf.h         | 5 +----
include/pstree.h           | 5 +----
include/ptrace.h           | 5 +----
include/rbtree.h           | 5 +----
include/restorer.h         | 5 +----
include/rst-malloc.h       | 5 +----
include/servicefd.h        | 5 +----
include/shmem.h            | 5 +----
include/signalfd.h         | 5 +----
include/sk-inet.h          | 5 +----
include/sk-packet.h        | 5 +----
include/sk-queue.h         | 5 +----
include/sockets.h          | 5 +----
include/stats.h            | 5 +----
include/string.h           | 5 +----
include/syscall-types.h    | 5 +----
include/sysctl.h           | 5 +----
include/tty.h              | 5 +----
include/tun.h              | 5 +----
include/unix_diag.h        | 5 +----
include/util-pie.h         | 5 +----
include/util.h             | 5 +----
include/uts_ns.h           | 5 +----
include/vdso.h             | 5 +----
include/vma.h              | 5 +----
include/xmalloc.h          | 5 +----
77 files changed, 77 insertions(+), 309 deletions(-)

diff --git a/include/bug.h b/include/bug.h
index 8330fed..4565e70 100644
--- a/include/bug.h
+++ b/include/bug.h
@@ -1,5 +1,4 @@
-#ifndef __CR_BUG_H__
-#define __CR_BUG_H__
+#pragma once

#include 

@@ -34,5 +33,3 @@

#define BUG_ON(condition)   BUG_ON_HANDLER((condition))
#define BUG()         BUG_ON(true)
-
-#endif /* __CR_BUG_H__ */
diff --git a/include/compiler.h b/include/compiler.h
index 3f3e6d6..5a837fc 100644
--- a/include/compiler.h
+++ b/include/compiler.h
@@ -1,5 +1,4 @@
-#ifndef __CR_COMPILER_H__
-#define __CR_COMPILER_H__
+#pragma once

/*
* Various definitions for success build,
@@ -67,5 +66,3 @@
   _max1 > _max2 ? _max1 : _max2; })

#define is_log2(v)      (((v) & ((v) - 1)) == 0)
-
-#endif /* __CR_COMPILER_H__ */
diff --git a/include/cpu.h b/include/cpu.h
index 08220cf..eb54ce4 100644
--- a/include/cpu.h
+++ b/include/cpu.h
@@ -1,10 +1,7 @@
-#ifndef __CR_CPU_H__
-#define __CR_CPU_H__
+#pragma once

#include "asm/cpu.h"

extern void cpu_set_feature(unsigned int feature);
extern bool cpu_has_feature(unsigned int feature);
extern int cpu_init(void);
-
-#endif /* __CR_CPU_H__ */
diff --git a/include/cr-service.h b/include/cr-service.h
index 5c38ac3..4a3791a 100644
--- a/include/cr-service.h
+++ b/include/cr-service.h
@@ -1,5 +1,4 @@
-#ifndef __CR_SERVICE_H__
-#define __CR_SERVICE_H__
+#pragma once

#include "protobuf/rpc.pb-c.h"

@@ -12,5 +11,3 @@ extern int send_criu_dump_resp(int socket_fd, bool success, bool restored);

extern struct _cr_service_client *cr_service_client;
extern unsigned int service_sk_ino;
-
-#endif /* __CR_SERVICE_H__ */
diff --git a/include/cr-show.h b/include/cr-show.h
index 165f87a..e206d3b 100644
--- a/include/cr-show.h
+++ b/include/cr-show.h
@@ -1,5 +1,4 @@
-#ifndef __CR_SHOW_H__
-#define __CR_SHOW_H__
+#pragma once

#include 
#include "asm/types.h"
@@ -19,5 +18,3 @@ extern void ipc_msg_handler(int fd, void *obj);
extern void ipc_sem_handler(int fd, void *obj);
extern int cr_parse_fd(int fd, u32 magic);
extern void show_tcp_stream(int fd, void *obj);
-
-#endif /* __CR_SHOW_H__ */
diff --git a/include/cr_options.h b/include/cr_options.h
index b90b4e1..4db07b1 100644
--- a/include/cr_options.h
+++ b/include/cr_options.h
@@ -1,5 +1,4 @@
-#ifndef __CR_OPTIONS_H__
-#define __CR_OPTIONS_H__
+#pragma once

#include 

@@ -39,5 +38,3 @@ struct cr_options {
extern struct cr_options opts;

extern void init_opts(void);
-
-#endif /* __CR_OPTIONS_H__ */
diff --git a/include/crtools.h b/include/crtools.h
index 7c08fd6..ec89d84 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -1,5 +1,4 @@
-#ifndef __CR_CRTOOLS_H__
-#define __CR_CRTOOLS_H__
+#pragma once

#include 

@@ -28,5 +27,3 @@ struct proc_status_creds;
extern bool may_dump(struct proc_status_creds *);
struct _CredsEntry;
extern bool may_restore(struct _CredsEntry *);
-
-#endif /* __CR_CRTOOLS_H__ */
diff --git a/include/err.h b/include/err.h
index c5b6165..38f3965 100644
--- a/include/err.h
+++ b/include/err.h
@@ -1,8 +1,7 @@
/*
* Adopted from linux kernel
*/
-#ifndef __CR_ERR_H__
-#define __CR_ERR_H__
+#pragma once

#include "compiler.h"

@@ -49,5 +48,3 @@ static inline int PTR_RET(const void *ptr)
   else
      return 0;
}
-
-#endif /* __CR_ERR_H__ */
diff --git a/include/errno.h b/include/errno.h
index 5c2322e..f8ff9d3 100644
--- a/include/errno.h
+++ b/include/errno.h
@@ -1,9 +1,6 @@
-#ifndef __CR_ERRNO_H__
-#define __CR_ERRNO_H__
+#pragma once

#define ERESTARTSYS      512
#define ERESTARTNOINTR      513
#define ERESTARTNOHAND      514
#define ERESTART_RESTARTBLOCK   516
-
-#endif /* __CR_ERRNO_H__ */
diff --git a/include/eventfd.h b/include/eventfd.h
index 22a62a0..b66d677 100644
--- a/include/eventfd.h
+++ b/include/eventfd.h
@@ -1,10 +1,7 @@
-#ifndef __CR_EVENTFD_H__
-#define __CR_EVENTFD_H__
+#pragma once

#include "files.h"

extern int is_eventfd_link(int lfd);
extern const struct fdtype_ops eventfd_dump_ops;
extern struct collect_image_info eventfd_cinfo;
-
-#endif /* __CR_EVENTFD_H__ */
diff --git a/include/eventpoll.h b/include/eventpoll.h
index 4e6c112..5f4ba88 100644
--- a/include/eventpoll.h
+++ b/include/eventpoll.h
@@ -1,5 +1,4 @@
-#ifndef __CR_EVENTPOLL_H__
-#define __CR_EVENTPOLL_H__
+#pragma once

#include "files.h"

@@ -7,5 +6,3 @@ extern int is_eventpoll_link(int lfd);
extern const struct fdtype_ops eventpoll_dump_ops;
extern struct collect_image_info epoll_tfd_cinfo;
extern struct collect_image_info epoll_cinfo;
-
-#endif /* __CR_EVENTPOLL_H__ */
diff --git a/include/fcntl.h b/include/fcntl.h
index 65ba2bf..f53c387 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -1,5 +1,4 @@
-#ifndef __CR_ASM_GENERIC_FCNTL_H__
-#define __CR_ASM_GENERIC_FCNTL_H__
+#pragma once

#include 
#include 
@@ -28,5 +27,3 @@ struct f_owner_ex {
#ifndef F_GETPIPE_SZ
# define F_GETPIPE_SZ   (F_LINUX_SPECIFIC_BASE + 8)
#endif
-
-#endif /* __CR_ASM_GENERIC_FCNTL_H__ */
diff --git a/include/fdset.h b/include/fdset.h
index ad62d5e..b5a0ce2 100644
--- a/include/fdset.h
+++ b/include/fdset.h
@@ -1,5 +1,4 @@
-#ifndef __CR_FDSET_H__
-#define __CR_FDSET_H__
+#pragma once

#include "image-desc.h"
#include "bug.h"
@@ -32,5 +31,3 @@ extern struct cr_fdset *cr_fdset_open_range(int pid, int from, int to,
extern struct cr_fdset *cr_glob_fdset_open(int mode);

extern void close_cr_fdset(struct cr_fdset **cr_fdset);
-
-#endif /* __CR_FDSET_H__ */
diff --git a/include/fifo.h b/include/fifo.h
index 1824346..edeb308 100644
--- a/include/fifo.h
+++ b/include/fifo.h
@@ -1,5 +1,4 @@
-#ifndef __CR_FIFO_H__
-#define __CR_FIFO_H__
+#pragma once

struct fd_parms;
struct cr_fdset;
@@ -7,5 +6,3 @@ struct cr_fdset;
extern const struct fdtype_ops fifo_dump_ops;
extern struct collect_image_info fifo_cinfo;
extern int collect_fifo(void);
-
-#endif /* __CR_FIFO_H__ */
diff --git a/include/file-ids.h b/include/file-ids.h
index ce9029d..2d901a7 100644
--- a/include/file-ids.h
+++ b/include/file-ids.h
@@ -1,5 +1,4 @@
-#ifndef __CR_FILE_IDS_H__
-#define __CR_FILE_IDS_H__
+#pragma once

#include "compiler.h"
#include "asm/types.h"
@@ -14,5 +13,3 @@ struct fdinfo_entry;
extern int fd_id_generate(pid_t pid, FdinfoEntry *fe);
extern u32 fd_id_generate_special(void);
extern void fd_id_show_tree(void);
-
-#endif /* __CR_FILE_IDS_H__ */
diff --git a/include/file-lock.h b/include/file-lock.h
index 56de975..a0ba993 100644
--- a/include/file-lock.h
+++ b/include/file-lock.h
@@ -1,5 +1,4 @@
-#ifndef __FILE_LOCK_H__
-#define __FILE_LOCK_H__
+#pragma once

#include "list.h"

@@ -55,5 +54,3 @@ extern int dump_task_file_locks(struct parasite_ctl *ctl,
extern int prepare_file_locks(int pid);

#define OPT_FILE_LOCKS   "file-locks"
-
-#endif /* __FILE_LOCK_H__ */
diff --git a/include/files-reg.h b/include/files-reg.h
index d3bd4f0..711d734 100644
--- a/include/files-reg.h
+++ b/include/files-reg.h
@@ -1,5 +1,4 @@
-#ifndef __CR_FILES_REG_H__
-#define __CR_FILES_REG_H__
+#pragma once

#include "asm/types.h"
#include "files.h"
@@ -40,5 +39,3 @@ extern struct collect_image_info remap_cinfo;

extern void delete_link_remaps(void);
extern void free_link_remaps(void);
-
-#endif /* __CR_FILES_REG_H__ */
diff --git a/include/files.h b/include/files.h
index d491cf1..51615c4 100644
--- a/include/files.h
+++ b/include/files.h
@@ -1,5 +1,4 @@
-#ifndef __CR_FILES_H__
-#define __CR_FILES_H__
+#pragma once

#include "compiler.h"
#include "asm/types.h"
@@ -146,5 +145,3 @@ extern int close_old_fds(struct pstree_item *me);
#define LREMAP_PARAM   "link-remap"

extern int shared_fdt_prepare(struct pstree_item *item);
-
-#endif /* __CR_FILES_H__ */
diff --git a/include/fsnotify.h b/include/fsnotify.h
index a882fd9..fbd4667 100644
--- a/include/fsnotify.h
+++ b/include/fsnotify.h
@@ -1,5 +1,4 @@
-#ifndef __CR_FSNOTIFY_H__
-#define __CR_FSNOTIFY_H__
+#pragma once

#include "asm/types.h"
#include "files.h"
@@ -18,5 +17,3 @@ extern struct collect_image_info inotify_cinfo;
extern struct collect_image_info inotify_mark_cinfo;
extern struct collect_image_info fanotify_cinfo;
extern struct collect_image_info fanotify_mark_cinfo;
-
-#endif /* __CR_FSNOTIFY_H__ */
diff --git a/include/image-desc.h b/include/image-desc.h
index a38368b..fce0247 100644
--- a/include/image-desc.h
+++ b/include/image-desc.h
@@ -1,5 +1,4 @@
-#ifndef __CR_IMAGE_DESC_H__
-#define __CR_IMAGE_DESC_H__
+#pragma once

#include "asm/int.h"

@@ -96,5 +95,3 @@ struct cr_fd_desc_tmpl {
};

extern struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX];
-
-#endif /* __CR_IMAGE_DESC_H__ */
diff --git a/include/image.h b/include/image.h
index 099f510..052661a 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1,5 +1,4 @@
-#ifndef __CR_IMAGE_H__
-#define __CR_IMAGE_H__
+#pragma once

#include 

@@ -76,5 +75,3 @@ extern int open_image_at(int dfd, int type, unsigned long flags, ...);
extern int open_pages_image(unsigned long flags, int pm_fd);
extern int open_pages_image_at(int dfd, unsigned long flags, int pm_fd);
extern void up_page_ids_base(void);
-
-#endif /* __CR_IMAGE_H__ */
diff --git a/include/inet_diag.h b/include/inet_diag.h
index 95be2c1..d22b0b1 100644
--- a/include/inet_diag.h
+++ b/include/inet_diag.h
@@ -1,5 +1,4 @@
-#ifndef __CR_INET_DIAG_H__
-#define __CR_INET_DIAG_H__
+#pragma once

#include 

@@ -132,5 +131,3 @@ struct tcpvegas_info {
   __u32   tcpv_rtt;
   __u32   tcpv_minrtt;
};
-
-#endif /* __CR_INET_DIAG_H__ */
diff --git a/include/ipc_ns.h b/include/ipc_ns.h
index a50281f..84c2eab 100644
--- a/include/ipc_ns.h
+++ b/include/ipc_ns.h
@@ -1,9 +1,6 @@
-#ifndef __CR_IPC_NS_H__
-#define __CR_IPC_NS_H__
+#pragma once

extern int dump_ipc_ns(int ns_pid, int ns_id);
extern int prepare_ipc_ns(int pid);

extern struct ns_desc ipc_ns_desc;
-
-#endif /* __CR_IPC_NS_H__ */
diff --git a/include/kcmp-ids.h b/include/kcmp-ids.h
index e9e9101..c26d986 100644
--- a/include/kcmp-ids.h
+++ b/include/kcmp-ids.h
@@ -1,5 +1,4 @@
-#ifndef __CR_KCMP_IDS_H__
-#define __CR_KCMP_IDS_H__
+#pragma once

#include "kcmp.h"

@@ -26,5 +25,3 @@ struct kid_elem {
extern u32 kid_generate_gen(struct kid_tree *tree,
             struct kid_elem *elem, int *new_id);
extern void kid_show_tree(struct kid_tree *tree);
-
-#endif /* __CR_KCMP_IDS_H__ */
diff --git a/include/kcmp.h b/include/kcmp.h
index 76f557b..f275619 100644
--- a/include/kcmp.h
+++ b/include/kcmp.h
@@ -1,5 +1,4 @@
-#ifndef __CR_KCMP_H__
-#define __CR_KCMP_H__
+#pragma once

enum kcmp_type {
   KCMP_FILE,
@@ -12,5 +11,3 @@ enum kcmp_type {

   KCMP_TYPES,
};
-
-#endif /* __CR_KCMP_H__ */
diff --git a/include/kerndat.h b/include/kerndat.h
index 738ad04..64f9f0b 100644
--- a/include/kerndat.h
+++ b/include/kerndat.h
@@ -1,5 +1,4 @@
-#ifndef __CR_KERNDAT_H__
-#define __CR_KERNDAT_H__
+#pragma once

#include "asm/types.h"

@@ -19,5 +18,3 @@ extern int tcp_max_wshare;
extern int tcp_max_rshare;

extern int kern_last_cap;
-
-#endif /* __CR_KERNDAT_H__ */
diff --git a/include/libnetlink.h b/include/libnetlink.h
index 616a111..03679e9 100644
--- a/include/libnetlink.h
+++ b/include/libnetlink.h
@@ -1,5 +1,4 @@
-#ifndef __CR_LIBNETLINK_H__
-#define __CR_LIBNETLINK_H__
+#pragma once

#define CR_NLMSG_SEQ      24680   /* arbitrary chosen */

@@ -14,6 +13,3 @@ extern int addattr_l(struct nlmsghdr *n, int maxlen, int type,

#define NLMSG_TAIL(nmsg) 
   ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
-
-
-#endif /* __CR_LIBNETLINK_H__ */
diff --git a/include/list.h b/include/list.h
index 32d8edd..28508c4 100644
--- a/include/list.h
+++ b/include/list.h
@@ -1,5 +1,4 @@
-#ifndef __CR_LIST_H__
-#define __CR_LIST_H__
+#pragma once

/*
* Double linked lists.
@@ -419,5 +418,3 @@ static inline void hlist_move_list(struct hlist_head *old,
   for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);   
        pos && ({ n = pos->member.next; 1; });            
        pos = hlist_entry_safe(n, typeof(*pos), member))
-
-#endif /* __CR_LIST_H__ */
diff --git a/include/lock.h b/include/lock.h
index 89d71b1..adde3da 100644
--- a/include/lock.h
+++ b/include/lock.h
@@ -1,5 +1,4 @@
-#ifndef __CR_LOCK_H__
-#define __CR_LOCK_H__
+#pragma once

#include 
#include 
@@ -135,5 +134,3 @@ static inline void mutex_unlock(mutex_t *m)
   atomic_set(&m->raw, (int)c);
   BUG_ON(sys_futex((u32 *)&m->raw.counter, FUTEX_WAKE, 1, NULL, NULL, 0) < 0);
}
-
-#endif /* __CR_LOCK_H__ */
diff --git a/include/log-levels.h b/include/log-levels.h
index 3e6753f..6a1aa2f 100644
--- a/include/log-levels.h
+++ b/include/log-levels.h
@@ -1,5 +1,4 @@
-#ifndef __CR_LOG_LEVELS_H__
-#define __CR_LOG_LEVELS_H__
+#pragma once

#define LOG_MSG      (0) /* Print message regardless of log level */
#define LOG_ERROR   (1) /* Errors only, when we're in trouble */
@@ -8,5 +7,3 @@
#define LOG_DEBUG   (4) /* Debug only */

#define DEFAULT_LOGLEVEL   LOG_WARN
-
-#endif /* __CR_LOG_LEVELS_H__ */
diff --git a/include/log.h b/include/log.h
index 1060254..ebd035f 100644
--- a/include/log.h
+++ b/include/log.h
@@ -1,5 +1,4 @@
-#ifndef __CR_LOG_H__
-#define __CR_LOG_H__
+#pragma once

#include "log-levels.h"

@@ -63,5 +62,3 @@ extern int write_pidfile(int pid);

extern void print_data(unsigned long addr, unsigned char *data, size_t size);
extern void print_image_data(int fd, unsigned int length, int show);
-
-#endif /* __CR_LOG_H__ */
diff --git a/include/magic.h b/include/magic.h
index f17a191..cfdf8c8 100644
--- a/include/magic.h
+++ b/include/magic.h
@@ -1,5 +1,4 @@
-#ifndef __CR_MAGIC_H__
-#define __CR_MAGIC_H__
+#pragma once

/*
* Basic multi-file images
@@ -79,5 +78,3 @@

#define PAGES_OLD_MAGIC      PAGEMAP_MAGIC
#define SHM_PAGES_OLD_MAGIC   PAGEMAP_MAGIC
-
-#endif /* __CR_MAGIC_H__ */
diff --git a/include/mem.h b/include/mem.h
index 6cfd2e3..f596632 100644
--- a/include/mem.h
+++ b/include/mem.h
@@ -1,5 +1,4 @@
-#ifndef __CR_MEM_H__
-#define __CR_MEM_H__
+#pragma once

struct parasite_ctl;
struct vm_area_list;
@@ -21,5 +20,3 @@ extern int parasite_dump_pages_seized(struct parasite_ctl *ctl,
#define PME_PSHIFT_OFFSET   (PME_STATUS_OFFSET - PME_PSHIFT_BITS)
#define PME_PFRAME_MASK      ((1ULL vma.start &&
      addr < (unsigned long)vma->vma.end;
}
-
-#endif /* __CR_VMA_H__ */
diff --git a/include/xmalloc.h b/include/xmalloc.h
index a5cc608..753a450 100644
--- a/include/xmalloc.h
+++ b/include/xmalloc.h
@@ -1,5 +1,4 @@
-#ifndef __CR_XMALLOC_H__
-#define __CR_XMALLOC_H__
+#pragma once

#include 
#include 
@@ -35,5 +34,3 @@

#define memzero_p(p)      memset(p, 0, sizeof(*p))
#define memzero(p, size)   memset(p, 0, size)
-
-#endif /* __CR_XMALLOC_H__ */
-- 
1.8.5.2

_______________________________________________
CRIU mailing list
CRIU at openvz.org (mailto:CRIU at openvz.org)
https://lists.openvz.org/mailman/listinfo/criu (https://lists.openvz.org/mailman/listinfo/criu)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvz.org/pipermail/criu/attachments/20131224/e7ee7faf/attachment-0001.html>


More information about the CRIU mailing list