[CRIU] [PATCH] dump: add const qualifiers where possible
Kinsbursky Stanislav
skinsbursky at openvz.org
Tue Mar 6 05:20:41 EST 2012
Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
cr-dump.c | 77 +++++++++++++++++++++++++++++------------------------
include/crtools.h | 2 +
include/util.h | 8 +++---
util.c | 8 +++---
uts_ns.c | 2 +
5 files changed, 52 insertions(+), 45 deletions(-)
diff --git a/cr-dump.c b/cr-dump.c
index c4d62fe..60b37cc 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -97,8 +97,8 @@ struct fd_parms {
pid_t pid;
};
-static int dump_one_reg_file(struct fd_parms *p, int lfd,
- struct cr_fdset *cr_fdset,
+static int dump_one_reg_file(const struct fd_parms *p, int lfd,
+ const struct cr_fdset *cr_fdset,
bool do_close_lfd)
{
struct fdinfo_entry e;
@@ -157,7 +157,7 @@ err:
return ret;
}
-static int dump_task_special_files(pid_t pid, struct cr_fdset *cr_fdset)
+static int dump_task_special_files(pid_t pid, const struct cr_fdset *cr_fdset)
{
struct fd_parms params;
int fd, ret;
@@ -194,7 +194,7 @@ static int dump_task_special_files(pid_t pid, struct cr_fdset *cr_fdset)
}
static int dump_pipe_and_data(int lfd, struct pipe_entry *e,
- struct cr_fdset *cr_fdset)
+ const struct cr_fdset *cr_fdset)
{
int fd_pipes;
int steal_pipe[2];
@@ -248,8 +248,8 @@ err:
return ret;
}
-static int dump_one_pipe(struct fd_parms *p, unsigned int id, int lfd,
- struct cr_fdset *cr_fdset)
+static int dump_one_pipe(const struct fd_parms *p, unsigned int id, int lfd,
+ const struct cr_fdset *cr_fdset)
{
struct pipe_entry e;
int ret = -1;
@@ -287,7 +287,7 @@ err:
return ret;
}
-static int read_fd_params(pid_t pid, char *fd, struct fd_parms *p)
+static int read_fd_params(pid_t pid, const char *fd, struct fd_parms *p)
{
FILE *file;
int ret;
@@ -314,7 +314,8 @@ static int read_fd_params(pid_t pid, char *fd, struct fd_parms *p)
return 0;
}
-static int dump_one_fd(pid_t pid, int pid_fd_dir, char *d_name, struct cr_fdset *cr_fdset,
+static int dump_one_fd(pid_t pid, int pid_fd_dir, const char *d_name,
+ const struct cr_fdset *cr_fdset,
struct sk_queue *sk_queue)
{
struct stat fd_stat;
@@ -374,7 +375,7 @@ out_close:
return err;
}
-static int dump_task_files(pid_t pid, struct cr_fdset *cr_fdset,
+static int dump_task_files(pid_t pid, const struct cr_fdset *cr_fdset,
struct sk_queue *sk_queue)
{
struct dirent *de;
@@ -416,7 +417,8 @@ static int dump_task_files(pid_t pid, struct cr_fdset *cr_fdset,
return 0;
}
-static int dump_task_mappings(pid_t pid, struct list_head *vma_area_list, struct cr_fdset *cr_fdset)
+static int dump_task_mappings(pid_t pid, const struct list_head *vma_area_list,
+ const struct cr_fdset *cr_fdset)
{
struct vma_area *vma_area;
int ret = -1;
@@ -475,8 +477,8 @@ err:
return ret;
}
-static int dump_task_creds(pid_t pid,
- struct parasite_dump_misc *misc, struct cr_fdset *fds)
+static int dump_task_creds(pid_t pid, const struct parasite_dump_misc *misc,
+ const struct cr_fdset *fds)
{
int ret, i;
struct proc_status_creds cr;
@@ -571,7 +573,7 @@ err:
return ret;
}
-static int get_task_regs(pid_t pid, struct core_entry *core, struct parasite_ctl *ctl)
+static int get_task_regs(pid_t pid, struct core_entry *core, const struct parasite_ctl *ctl)
{
user_fpregs_struct_t fpregs = {-1};
user_regs_struct_t regs = {-1};
@@ -655,7 +657,7 @@ err:
return ret;
}
-static int dump_task_core(struct core_entry *core, struct cr_fdset *fdset)
+static int dump_task_core(struct core_entry *core, const struct cr_fdset *fdset)
{
int fd_core = fdset->fds[CR_FD_CORE];
int ret;
@@ -674,9 +676,9 @@ static int dump_task_core(struct core_entry *core, struct cr_fdset *fdset)
return ret;
}
-static int dump_task_core_all(pid_t pid, struct proc_pid_stat *stat,
- struct parasite_dump_misc *misc, struct parasite_ctl *ctl,
- struct cr_fdset *cr_fdset)
+static int dump_task_core_all(pid_t pid, const struct proc_pid_stat *stat,
+ const struct parasite_dump_misc *misc, const struct parasite_ctl *ctl,
+ const struct cr_fdset *cr_fdset)
{
struct core_entry *core = xzalloc(sizeof(*core));
int ret = -1;
@@ -739,7 +741,7 @@ err:
return ret;
}
-static int parse_threads(struct pstree_item *item, u32 **_t, int *_n)
+static int parse_threads(const struct pstree_item *item, u32 **_t, int *_n)
{
struct dirent *de;
DIR *dir;
@@ -780,7 +782,7 @@ static int get_threads(struct pstree_item *item)
return parse_threads(item, &item->threads, &item->nr_threads);
}
-static int check_threads(struct pstree_item *item)
+static int check_threads(const struct pstree_item *item)
{
u32 *t;
int nr, ret;
@@ -800,7 +802,7 @@ static int check_threads(struct pstree_item *item)
return 0;
}
-static int parse_children(struct pstree_item *item, u32 **_c, int *_n)
+static int parse_children(const struct pstree_item *item, u32 **_c, int *_n)
{
FILE *file;
char *tok;
@@ -846,7 +848,7 @@ static int get_children(struct pstree_item *item)
return parse_children(item, &item->children, &item->nr_children);
}
-static void unseize_task_and_threads(struct pstree_item *item, int st)
+static void unseize_task_and_threads(const struct pstree_item *item, int st)
{
int i;
@@ -854,7 +856,8 @@ static void unseize_task_and_threads(struct pstree_item *item, int st)
unseize_task(item->threads[i], st); /* item->pid will be here */
}
-static void pstree_switch_state(struct list_head *list, struct cr_options *opts)
+static void pstree_switch_state(const struct list_head *list,
+ const struct cr_options *opts)
{
struct pstree_item *item;
@@ -865,7 +868,7 @@ static void pstree_switch_state(struct list_head *list, struct cr_options *opts)
}
}
-static int seize_threads(struct pstree_item *item)
+static int seize_threads(const struct pstree_item *item)
{
int i = 0, ret;
@@ -967,7 +970,7 @@ err:
return NULL;
}
-static int check_subtree(struct pstree_item *item)
+static int check_subtree(const struct pstree_item *item)
{
u32 *ch;
int nr, ret;
@@ -1012,7 +1015,7 @@ static int collect_subtree(pid_t pid, pid_t ppid, struct list_head *pstree_list,
}
static int collect_pstree(pid_t pid, struct list_head *pstree_list,
- struct cr_options *opts)
+ const struct cr_options *opts)
{
int ret, attempts = 5;
@@ -1072,9 +1075,10 @@ try_again:
return ret;
}
-static int dump_pstree(pid_t pid, struct list_head *pstree_list, struct cr_fdset *cr_fdset)
+static int dump_pstree(pid_t pid, const struct list_head *pstree_list,
+ const struct cr_fdset *cr_fdset)
{
- struct pstree_item *item;
+ const struct pstree_item *item;
struct pstree_entry e;
unsigned long i;
int ret = -1;
@@ -1120,7 +1124,8 @@ err:
return ret;
}
-static struct vma_area *find_vma_by_addr(struct list_head *vma_area_list, unsigned long addr)
+static struct vma_area *find_vma_by_addr(const struct list_head *vma_area_list,
+ unsigned long addr)
{
struct vma_area *vma_area;
@@ -1133,7 +1138,8 @@ static struct vma_area *find_vma_by_addr(struct list_head *vma_area_list, unsign
}
/* kernel expects a special format in core file */
-static int finalize_core(pid_t pid, struct list_head *vma_area_list, struct cr_fdset *cr_fdset)
+static int finalize_core(pid_t pid, const struct list_head *vma_area_list,
+ const struct cr_fdset *cr_fdset)
{
int fd_core;
unsigned long num;
@@ -1179,7 +1185,7 @@ err:
}
static int dump_task_thread(struct parasite_ctl *parasite_ctl,
- pid_t pid, struct cr_fdset *cr_fdset)
+ pid_t pid, const struct cr_fdset *cr_fdset)
{
struct core_entry *core = xzalloc(sizeof(*core));
int ret = -1;
@@ -1221,8 +1227,9 @@ err:
return ret;
}
-static int dump_one_zombie(struct pstree_item *item, struct proc_pid_stat *pps,
- struct cr_fdset *cr_fdset)
+static int dump_one_zombie(const struct pstree_item *item,
+ const struct proc_pid_stat *pps,
+ struct cr_fdset *cr_fdset)
{
struct core_entry *core;
@@ -1243,7 +1250,7 @@ static int dump_one_zombie(struct pstree_item *item, struct proc_pid_stat *pps,
static struct proc_pid_stat pps_buf;
static int dump_task_threads(struct parasite_ctl *parasite_ctl,
- struct pstree_item *item)
+ const struct pstree_item *item)
{
int i;
struct cr_fdset *cr_fdset_thread = NULL;
@@ -1274,7 +1281,7 @@ err:
return -1;
}
-static int dump_one_task(struct pstree_item *item, struct cr_fdset *cr_fdset)
+static int dump_one_task(const struct pstree_item *item, struct cr_fdset *cr_fdset)
{
pid_t pid = item->pid;
LIST_HEAD(vma_area_list);
@@ -1397,7 +1404,7 @@ err_free:
return ret;
}
-int cr_dump_tasks(pid_t pid, struct cr_options *opts)
+int cr_dump_tasks(pid_t pid, const struct cr_options *opts)
{
LIST_HEAD(pstree_list);
struct cr_fdset *cr_fdset = NULL;
diff --git a/include/crtools.h b/include/crtools.h
index 795626f..ee35cc7 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -121,7 +121,7 @@ struct cr_fdset {
CR_FD_DESC_USE(CR_FD_IPCNS_SHM) )
#define CR_FD_DESC_NONE (0)
-int cr_dump_tasks(pid_t pid, struct cr_options *opts);
+int cr_dump_tasks(pid_t pid, const struct cr_options *opts);
int cr_restore_tasks(pid_t pid, struct cr_options *opts);
int cr_show(unsigned long pid, struct cr_options *opts);
int convert_to_elf(char *elf_path, int fd_core);
diff --git a/include/util.h b/include/util.h
index 9d74953..915a3b5 100644
--- a/include/util.h
+++ b/include/util.h
@@ -66,7 +66,7 @@
* 0 on success
* -1 on error (error message is printed)
*/
-static inline int write_img_buf(int fd, void *ptr, int size)
+static inline int write_img_buf(int fd, const void *ptr, int size)
{
int ret;
ret = write(fd, ptr, size);
@@ -131,12 +131,12 @@ static inline int read_img_buf(int fd, void *ptr, int size)
#define memzero_p(p) memset(p, 0, sizeof(*p))
#define memzero(p, size) memset(p, 0, size)
-extern void pr_info_siginfo(siginfo_t *siginfo);
+extern void pr_info_siginfo(const siginfo_t *siginfo);
struct vma_area;
struct list_head;
-extern void pr_vma(unsigned int loglevel, struct vma_area *vma_area);
+extern void pr_vma(unsigned int loglevel, const struct vma_area *vma_area);
#define pr_info_vma(vma_area) pr_vma(LOG_INFO, vma_area)
#define pr_msg_vma(vma_area) pr_vma(LOG_MSG, vma_area)
@@ -171,7 +171,7 @@ extern int reopen_fd_as_safe(int new_fd, int old_fd, bool allow_reuse_fd);
#define reopen_fd_as(new_fd, old_fd) reopen_fd_as_safe(new_fd, old_fd, false)
#define reopen_fd_as_nocheck(new_fd, old_fd) reopen_fd_as_safe(new_fd, old_fd, true)
-extern void hex_dump(void *addr, unsigned long len);
+extern void hex_dump(const void *addr, unsigned long len);
int open_pid_proc(pid_t pid);
int close_pid_proc(void);
diff --git a/util.c b/util.c
index dce38c6..72c2c8f 100644
--- a/util.c
+++ b/util.c
@@ -37,9 +37,9 @@
#include "crtools.h"
-void hex_dump(void *addr, unsigned long len)
+void hex_dump(const void *addr, unsigned long len)
{
- unsigned char *p = addr;
+ const unsigned char *p = addr;
unsigned long i;
len = (len + 8) & ~7;
@@ -51,13 +51,13 @@ void hex_dump(void *addr, unsigned long len)
}
}
-void pr_info_siginfo(siginfo_t *siginfo)
+void pr_info_siginfo(const siginfo_t *siginfo)
{
pr_info("si_signo %d si_errno %d si_code %d\n",
siginfo->si_signo, siginfo->si_errno, siginfo->si_code);
}
-void pr_vma(unsigned int loglevel, struct vma_area *vma_area)
+void pr_vma(unsigned int loglevel, const struct vma_area *vma_area)
{
if (!vma_area)
return;
diff --git a/uts_ns.c b/uts_ns.c
index dfb4276..65789fd 100644
--- a/uts_ns.c
+++ b/uts_ns.c
@@ -8,7 +8,7 @@
#include "namespaces.h"
#include "sysctl.h"
-static int dump_uts_string(int fd, char *str)
+static int dump_uts_string(int fd, const char *str)
{
int ret;
u32 len;
More information about the CRIU
mailing list