diff options
author | Wu Fengguang <fengguang.wu@intel.com> | 2009-10-07 19:32:29 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-10-08 10:36:39 -0400 |
commit | 31bbf66eaaaf50ba79e50ab7d3c89531b31c0614 (patch) | |
tree | bb96b311a4293649f2f0c9e0870330a94ee7e419 /Documentation/vm | |
parent | 0c57effe27eb6544eb44d5fac563b7334e3bc771 (diff) |
page-types: introduce checked_open()
This helps merge duplicate code (now and future) and outstand the main
logic.
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
Cc: Andi Kleen <andi@firstfloor.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'Documentation/vm')
-rw-r--r-- | Documentation/vm/page-types.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/Documentation/vm/page-types.c b/Documentation/vm/page-types.c index e46fb5b2107d..6bdcc0632c24 100644 --- a/Documentation/vm/page-types.c +++ b/Documentation/vm/page-types.c | |||
@@ -214,6 +214,18 @@ static void fatal(const char *x, ...) | |||
214 | exit(EXIT_FAILURE); | 214 | exit(EXIT_FAILURE); |
215 | } | 215 | } |
216 | 216 | ||
217 | int checked_open(const char *pathname, int flags) | ||
218 | { | ||
219 | int fd = open(pathname, flags); | ||
220 | |||
221 | if (fd < 0) { | ||
222 | perror(pathname); | ||
223 | exit(EXIT_FAILURE); | ||
224 | } | ||
225 | |||
226 | return fd; | ||
227 | } | ||
228 | |||
217 | 229 | ||
218 | /* | 230 | /* |
219 | * page flag names | 231 | * page flag names |
@@ -534,11 +546,7 @@ static void walk_addr_ranges(void) | |||
534 | { | 546 | { |
535 | int i; | 547 | int i; |
536 | 548 | ||
537 | kpageflags_fd = open(PROC_KPAGEFLAGS, O_RDONLY); | 549 | kpageflags_fd = checked_open(PROC_KPAGEFLAGS, O_RDONLY); |
538 | if (kpageflags_fd < 0) { | ||
539 | perror(PROC_KPAGEFLAGS); | ||
540 | exit(EXIT_FAILURE); | ||
541 | } | ||
542 | 550 | ||
543 | if (!nr_addr_ranges) | 551 | if (!nr_addr_ranges) |
544 | add_addr_range(0, ULONG_MAX); | 552 | add_addr_range(0, ULONG_MAX); |
@@ -631,11 +639,7 @@ static void parse_pid(const char *str) | |||
631 | opt_pid = parse_number(str); | 639 | opt_pid = parse_number(str); |
632 | 640 | ||
633 | sprintf(buf, "/proc/%d/pagemap", opt_pid); | 641 | sprintf(buf, "/proc/%d/pagemap", opt_pid); |
634 | pagemap_fd = open(buf, O_RDONLY); | 642 | pagemap_fd = checked_open(buf, O_RDONLY); |
635 | if (pagemap_fd < 0) { | ||
636 | perror(buf); | ||
637 | exit(EXIT_FAILURE); | ||
638 | } | ||
639 | 643 | ||
640 | sprintf(buf, "/proc/%d/maps", opt_pid); | 644 | sprintf(buf, "/proc/%d/maps", opt_pid); |
641 | file = fopen(buf, "r"); | 645 | file = fopen(buf, "r"); |