diff options
-rw-r--r-- | Assemble.c | 2 | ||||
-rw-r--r-- | Create.c | 4 | ||||
-rw-r--r-- | Detail.c | 2 | ||||
-rw-r--r-- | Examine.c | 8 | ||||
-rw-r--r-- | Grow.c | 2 | ||||
-rw-r--r-- | Incremental.c | 2 | ||||
-rw-r--r-- | Manage.c | 2 | ||||
-rw-r--r-- | Monitor.c | 4 | ||||
-rw-r--r-- | bitmap.c | 1 | ||||
-rw-r--r-- | config.c | 2 | ||||
-rw-r--r-- | lib.c | 2 | ||||
-rw-r--r-- | managemon.c | 2 | ||||
-rw-r--r-- | mapfile.c | 2 | ||||
-rw-r--r-- | mdadm.c | 2 | ||||
-rw-r--r-- | mdadm.h | 5 | ||||
-rw-r--r-- | mdmon.c | 1 | ||||
-rw-r--r-- | mdopen.c | 2 | ||||
-rw-r--r-- | mdstat.c | 2 | ||||
-rw-r--r-- | msg.c | 1 | ||||
-rw-r--r-- | platform-intel.c | 2 | ||||
-rw-r--r-- | policy.c | 2 | ||||
-rw-r--r-- | restripe.c | 2 | ||||
-rw-r--r-- | super-ddf.c | 2 | ||||
-rw-r--r-- | super-gpt.c | 1 | ||||
-rw-r--r-- | super-intel.c | 2 | ||||
-rw-r--r-- | super-mbr.c | 1 | ||||
-rw-r--r-- | super0.c | 2 | ||||
-rw-r--r-- | super1.c | 2 | ||||
-rw-r--r-- | sysfs.c | 4 | ||||
-rw-r--r-- | udev.c | 2 | ||||
-rw-r--r-- | util.c | 2 | ||||
-rw-r--r-- | xmalloc.c | 59 | ||||
-rw-r--r-- | xmalloc.h | 13 |
33 files changed, 100 insertions, 44 deletions
@@ -23,6 +23,8 @@ */ #include "mdadm.h" +#include "xmalloc.h" + #include <ctype.h> mapping_t assemble_statuses[] = { @@ -23,9 +23,11 @@ */ #include "mdadm.h" -#include "udev.h" #include "md_u.h" #include "md_p.h" +#include "udev.h" +#include "xmalloc.h" + #include <ctype.h> #include <fcntl.h> #include <signal.h> @@ -25,6 +25,8 @@ #include "mdadm.h" #include "md_p.h" #include "md_u.h" +#include "xmalloc.h" + #include <ctype.h> #include <dirent.h> @@ -22,14 +22,16 @@ * Email: <neilb@suse.de> */ -#include "mdadm.h" #include "dlink.h" +#include "mdadm.h" +#include "md_u.h" +#include "md_p.h" +#include "xmalloc.h" #if ! defined(__BIG_ENDIAN) && ! defined(__LITTLE_ENDIAN) #error no endian defined #endif -#include "md_u.h" -#include "md_p.h" + int Examine(struct mddev_dev *devlist, struct context *c, struct supertype *forcest) @@ -23,6 +23,8 @@ */ #include "mdadm.h" #include "dlink.h" +#include "xmalloc.h" + #include <sys/mman.h> #include <stddef.h> #include <stdint.h> diff --git a/Incremental.c b/Incremental.c index e7987d1d..8c915783 100644 --- a/Incremental.c +++ b/Incremental.c @@ -29,6 +29,8 @@ */ #include "mdadm.h" +#include "xmalloc.h" + #include <sys/wait.h> #include <dirent.h> #include <ctype.h> @@ -26,6 +26,8 @@ #include "md_u.h" #include "md_p.h" #include "udev.h" +#include "xmalloc.h" + #include <ctype.h> int Manage_ro(char *devname, int fd, int readonly) @@ -23,9 +23,11 @@ */ #include "mdadm.h" -#include "udev.h" #include "md_p.h" #include "md_u.h" +#include "udev.h" +#include "xmalloc.h" + #include <sys/wait.h> #include <limits.h> #include <syslog.h> @@ -19,6 +19,7 @@ */ #include "mdadm.h" +#include "xmalloc.h" static inline void sb_le_to_cpu(bitmap_super_t *sb) { @@ -24,6 +24,8 @@ #include "mdadm.h" #include "dlink.h" +#include "xmalloc.h" + #include <dirent.h> #include <glob.h> #include <fnmatch.h> @@ -24,6 +24,8 @@ #include "mdadm.h" #include "dlink.h" +#include "xmalloc.h" + #include <ctype.h> #include <limits.h> diff --git a/managemon.c b/managemon.c index 877e8605..6ca592b1 100644 --- a/managemon.c +++ b/managemon.c @@ -104,6 +104,8 @@ #endif #include "mdadm.h" #include "mdmon.h" +#include "xmalloc.h" + #include <sys/syscall.h> #include <sys/socket.h> @@ -43,6 +43,8 @@ * at compile time via MAP_DIR and MAP_FILE. */ #include "mdadm.h" +#include "xmalloc.h" + #include <sys/file.h> #include <ctype.h> @@ -27,6 +27,8 @@ #include "mdadm.h" #include "md_p.h" +#include "xmalloc.h" + #include <ctype.h> /** @@ -1937,11 +1937,6 @@ static inline int xasprintf(char **strp, const char *fmt, ...) { #define pr_vrb(fmt, arg...) ((void)(verbose && pr_err(fmt, ##arg))) -void *xmalloc(size_t len); -void *xrealloc(void *ptr, size_t len); -void *xcalloc(size_t num, size_t size); -char *xstrdup(const char *str); - #define LEVEL_MULTIPATH (-4) #define LEVEL_LINEAR (-1) #define LEVEL_FAULTY (-5) @@ -65,6 +65,7 @@ #include "mdadm.h" #include "mdmon.h" +#include "xmalloc.h" char const Name[] = "mdmon"; @@ -25,6 +25,8 @@ #include "mdadm.h" #include "udev.h" #include "md_p.h" +#include "xmalloc.h" + #include <ctype.h> void make_parts(char *dev, int cnt) @@ -80,6 +80,8 @@ #include "mdadm.h" #include "dlink.h" +#include "xmalloc.h" + #include <sys/select.h> #include <ctype.h> @@ -30,6 +30,7 @@ #include <sys/un.h> #include "mdadm.h" #include "mdmon.h" +#include "xmalloc.h" static const __u32 start_magic = 0x5a5aa5a5; static const __u32 end_magic = 0xa5a55a5a; diff --git a/platform-intel.c b/platform-intel.c index 21591317..95bc4929 100644 --- a/platform-intel.c +++ b/platform-intel.c @@ -19,6 +19,8 @@ #include "mdadm.h" #include "platform-intel.h" #include "probe_roms.h" +#include "xmalloc.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -23,6 +23,8 @@ */ #include "mdadm.h" +#include "xmalloc.h" + #include <dirent.h> #include <fnmatch.h> #include <ctype.h> @@ -23,6 +23,8 @@ */ #include "mdadm.h" +#include "xmalloc.h" + #include <stdint.h> /* To restripe, we read from old geometry to a buffer, and diff --git a/super-ddf.c b/super-ddf.c index d870102d..6cd099ab 100644 --- a/super-ddf.c +++ b/super-ddf.c @@ -29,6 +29,8 @@ #include "mdadm.h" #include "mdmon.h" #include "sha1.h" +#include "xmalloc.h" + #include <values.h> #include <stddef.h> diff --git a/super-gpt.c b/super-gpt.c index ec3cf53f..50c267f6 100644 --- a/super-gpt.c +++ b/super-gpt.c @@ -40,6 +40,7 @@ #include "mdadm.h" #include "part.h" +#include "xmalloc.h" static void free_gpt(struct supertype *st) { diff --git a/super-intel.c b/super-intel.c index 30c2939a..7c5119c5 100644 --- a/super-intel.c +++ b/super-intel.c @@ -23,6 +23,8 @@ #include "dlink.h" #include "sha1.h" #include "platform-intel.h" +#include "xmalloc.h" + #include <values.h> #include <scsi/sg.h> #include <ctype.h> diff --git a/super-mbr.c b/super-mbr.c index 839f0003..98810170 100644 --- a/super-mbr.c +++ b/super-mbr.c @@ -41,6 +41,7 @@ #include "mdadm.h" #include "part.h" +#include "xmalloc.h" static void free_mbr(struct supertype *st) { @@ -25,6 +25,8 @@ #define HAVE_STDINT_H 1 #include "mdadm.h" #include "sha1.h" +#include "xmalloc.h" + /* * All handling for the 0.90.0 version superblock is in * this file. @@ -24,6 +24,8 @@ #include <stddef.h> #include "mdadm.h" +#include "xmalloc.h" + /* * The version-1 superblock : * All numeric fields are little-endian. @@ -24,9 +24,11 @@ */ #include "mdadm.h" +#include "dlink.h" +#include "xmalloc.h" + #include <dirent.h> #include <ctype.h> -#include "dlink.h" #define MAX_SYSFS_PATH_LEN 120 @@ -22,6 +22,8 @@ #include "udev.h" #include "md_p.h" #include "md_u.h" +#include "xmalloc.h" + #include <sys/wait.h> #include <signal.h> #include <limits.h> @@ -24,6 +24,8 @@ #include "mdadm.h" #include "md_p.h" +#include "xmalloc.h" + #include <sys/socket.h> #include <sys/utsname.h> #include <sys/wait.h> @@ -21,64 +21,57 @@ * Email: <neilb@suse.de> */ -#include "mdadm.h" -/*#include <sys/socket.h> -#include <sys/utsname.h> -#include <sys/wait.h> -#include <sys/un.h> -#include <ctype.h> -#include <dirent.h> -#include <signal.h> -*/ +#include "xmalloc.h" + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +static void *exit_memory_alloc_failure(void) +{ + fprintf(stderr, "Memory allocation failure - aborting\n"); + + /* TODO: replace with MDADM_STATUS_MEM_FAIL */ + exit(1); +} void *xmalloc(size_t len) { void *rv = malloc(len); - char *msg; - int n; + if (rv) return rv; - msg = ": memory allocation failure - aborting\n"; - n = write(2, Name, strlen(Name)); - n += write(2, msg, strlen(msg)); - exit(4+!!n); + + return exit_memory_alloc_failure(); } void *xrealloc(void *ptr, size_t len) { void *rv = realloc(ptr, len); - char *msg; - int n; + if (rv) return rv; - msg = ": memory allocation failure - aborting\n"; - n = write(2, Name, strlen(Name)); - n += write(2, msg, strlen(msg)); - exit(4+!!n); + + return exit_memory_alloc_failure(); } void *xcalloc(size_t num, size_t size) { void *rv = calloc(num, size); - char *msg; - int n; + if (rv) return rv; - msg = ": memory allocation failure - aborting\n"; - n = write(2, Name, strlen(Name)); - n += write(2, msg, strlen(msg)); - exit(4+!!n); + + return exit_memory_alloc_failure(); } char *xstrdup(const char *str) { char *rv = strdup(str); - char *msg; - int n; + if (rv) return rv; - msg = ": memory allocation failure - aborting\n"; - n = write(2, Name, strlen(Name)); - n += write(2, msg, strlen(msg)); - exit(4+!!n); + + return exit_memory_alloc_failure(); } diff --git a/xmalloc.h b/xmalloc.h new file mode 100644 index 00000000..0904b0ab --- /dev/null +++ b/xmalloc.h @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#ifndef XMALLOC_H +#define XMALLOC_H + +#include <stddef.h> + +void *xmalloc(size_t len); +void *xrealloc(void *ptr, size_t len); +void *xcalloc(size_t num, size_t size); +char *xstrdup(const char *str); + +#endif |