summaryrefslogtreecommitdiff
path: root/Monitor.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2012-07-09 17:14:16 +1000
committerNeilBrown <neilb@suse.de>2012-07-09 17:14:16 +1000
commit503975b9d5f0696b5d2ee20ea903b859e3f60662 (patch)
tree171c9f9b9db109325fad7f81ba07671d84a085a5 /Monitor.c
parentc8e1a230b73c44aff5beeeb74d32e36219bed12d (diff)
Remove scattered checks for malloc success.
malloc should never fail, and if it does it is unlikely that anything else useful can be done. Best approach is to abort and let some super-daemon restart. So define xmalloc, xcalloc, xrealloc, xstrdup which don't fail but just print a message and exit. Then use those removing all the tests for failure. Also replace all "malloc;memset" sequences with 'xcalloc'. Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'Monitor.c')
-rw-r--r--Monitor.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/Monitor.c b/Monitor.c
index 35a984f8..27d448b7 100644
--- a/Monitor.c
+++ b/Monitor.c
@@ -166,13 +166,11 @@ int Monitor(struct mddev_dev *devlist,
continue;
if (strcasecmp(mdlist->devname, "<ignore>") == 0)
continue;
- st = calloc(1, sizeof *st);
- if (st == NULL)
- continue;
+ st = xcalloc(1, sizeof *st);
if (mdlist->devname[0] == '/')
- st->devname = strdup(mdlist->devname);
+ st->devname = xstrdup(mdlist->devname);
else {
- st->devname = malloc(8+strlen(mdlist->devname)+1);
+ st->devname = xmalloc(8+strlen(mdlist->devname)+1);
strcpy(strcpy(st->devname, "/dev/md/"),
mdlist->devname);
}
@@ -181,17 +179,15 @@ int Monitor(struct mddev_dev *devlist,
st->percent = RESYNC_UNKNOWN;
st->expected_spares = mdlist->spare_disks;
if (mdlist->spare_group)
- st->spare_group = strdup(mdlist->spare_group);
+ st->spare_group = xstrdup(mdlist->spare_group);
statelist = st;
}
} else {
struct mddev_dev *dv;
for (dv=devlist ; dv; dv=dv->next) {
struct mddev_ident *mdlist = conf_get_ident(dv->devname);
- struct state *st = calloc(1, sizeof *st);
- if (st == NULL)
- continue;
- st->devname = strdup(dv->devname);
+ struct state *st = xcalloc(1, sizeof *st);
+ st->devname = xstrdup(dv->devname);
st->next = statelist;
st->devnum = INT_MAX;
st->percent = RESYNC_UNKNOWN;
@@ -199,7 +195,7 @@ int Monitor(struct mddev_dev *devlist,
if (mdlist) {
st->expected_spares = mdlist->spare_disks;
if (mdlist->spare_group)
- st->spare_group = strdup(mdlist->spare_group);
+ st->spare_group = xstrdup(mdlist->spare_group);
}
statelist = st;
}
@@ -670,12 +666,10 @@ static int add_new_arrays(struct mdstat_ent *mdstat, struct state **statelist,
(strcmp(mse->level, "raid0") != 0 &&
strcmp(mse->level, "linear") != 0))
) {
- struct state *st = calloc(1, sizeof *st);
+ struct state *st = xcalloc(1, sizeof *st);
mdu_array_info_t array;
int fd;
- if (st == NULL)
- continue;
- st->devname = strdup(get_md_name(mse->devnum));
+ st->devname = xstrdup(get_md_name(mse->devnum));
if ((fd = open(st->devname, O_RDONLY)) < 0 ||
ioctl(fd, GET_ARRAY_INFO, &array)< 0) {
/* no such array */