trivial warn_unused_result squashing

Made the mistake of recompiling the F9 mdadm rpm which has a patch to
remove -Werror and add "-Wp,-D_FORTIFY_SOURCE -O2" which turns on lots
of errors:

config.c:568: warning: ignoring return value of asprintf
Assemble.c:411: warning: ignoring return value of asprintf
Assemble.c:413: warning: ignoring return value of asprintf
super0.c:549: warning: ignoring return value of posix_memalign
super0.c:742: warning: ignoring return value of posix_memalign
super0.c:812: warning: ignoring return value of posix_memalign
super1.c:692: warning: ignoring return value of posix_memalign
super1.c:1039: warning: ignoring return value of posix_memalign
super1.c:1155: warning: ignoring return value of posix_memalign
super-ddf.c:508: warning: ignoring return value of posix_memalign
super-ddf.c:645: warning: ignoring return value of posix_memalign
super-ddf.c:696: warning: ignoring return value of posix_memalign
super-ddf.c:715: warning: ignoring return value of posix_memalign
super-ddf.c:1476: warning: ignoring return value of posix_memalign
super-ddf.c:1603: warning: ignoring return value of posix_memalign
super-ddf.c:1614: warning: ignoring return value of posix_memalign
super-ddf.c:1842: warning: ignoring return value of posix_memalign
super-ddf.c:2013: warning: ignoring return value of posix_memalign
super-ddf.c:2140: warning: ignoring return value of write
super-ddf.c:2143: warning: ignoring return value of write
super-ddf.c:2147: warning: ignoring return value of write
super-ddf.c:2150: warning: ignoring return value of write
super-ddf.c:2162: warning: ignoring return value of write
super-ddf.c:2169: warning: ignoring return value of write
super-ddf.c:2172: warning: ignoring return value of write
super-ddf.c:2176: warning: ignoring return value of write
super-ddf.c:2181: warning: ignoring return value of write
super-ddf.c:2686: warning: ignoring return value of posix_memalign
super-ddf.c:2690: warning: ignoring return value of write
super-ddf.c:3070: warning: ignoring return value of posix_memalign
super-ddf.c:3254: warning: ignoring return value of posix_memalign
bitmap.c:128: warning: ignoring return value of posix_memalign
mdmon.c:94: warning: ignoring return value of write
mdmon.c:221: warning: ignoring return value of pipe
mdmon.c:327: warning: ignoring return value of write
mdmon.c:330: warning: ignoring return value of chdir
mdmon.c:335: warning: ignoring return value of dup
monitor.c:415: warning: rv may be used uninitialized in this function

...some of these like the write() ones are not so trivial so save those
fixes for the next patch.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
This commit is contained in:
Dan Williams 2008-09-28 12:12:07 -07:00
parent 3f6efecc4c
commit 3d2c4fc7b6
9 changed files with 142 additions and 45 deletions

View File

@ -396,6 +396,8 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
mdu_array_info_t inf;
char *c;
char nbuf[64];
int rc;
if (!st || !st->sb) {
return 2;
}
@ -408,10 +410,13 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
}
if (isdigit(*c) && ((ident->autof & 7)==4 || (ident->autof&7)==6))
/* /dev/md/d0 style for partitionable */
asprintf(&mddev, "/dev/md/d%s", c);
rc = asprintf(&mddev, "/dev/md/d%s", c);
else
asprintf(&mddev, "/dev/md/%s", c);
mdfd = open_mddev(mddev, ident->autof);
rc = asprintf(&mddev, "/dev/md/%s", c);
if (rc < 0)
mdfd = -1;
else
mdfd = open_mddev(mddev, ident->autof);
if (mdfd < 0) {
st->ss->free_super(st);
free(devices);

View File

@ -43,6 +43,9 @@ KLIBC_GCC = gcc -nostdinc -iwithprefix include -I$(KLIBC)/klibc/include -I$(KLIB
CC = $(CROSS_COMPILE)gcc
CXFLAGS = -ggdb
CWFLAGS = -Wall -Werror -Wstrict-prototypes
ifdef WARN_UNUSED
CWFLAGS += -Wp,-D_FORTIFY_SOURCE=2 -O
endif
ifdef DEBIAN
CPPFLAGS= -DDEBIAN

View File

@ -125,7 +125,10 @@ bitmap_info_t *bitmap_fd_read(int fd, int brief)
void *buf;
int n, skip;
posix_memalign(&buf, 512, 8192);
if (posix_memalign(&buf, 512, 8192) != 0) {
fprintf(stderr, Name ": failed to allocate 8192 bytes\n");
return NULL;
}
n = read(fd, buf, 8192);
info = malloc(sizeof(*info));

View File

@ -564,10 +564,12 @@ void mailfromline(char *line)
if (alert_mail_from == NULL)
alert_mail_from = strdup(w);
else {
char *t= NULL;
asprintf(&t, "%s %s", alert_mail_from, w);
free(alert_mail_from);
alert_mail_from = t;
char *t = NULL;
if (asprintf(&t, "%s %s", alert_mail_from, w) > 0) {
free(alert_mail_from);
alert_mail_from = t;
}
}
}
}

22
mdmon.c
View File

@ -85,14 +85,18 @@ int make_pidfile(char *devname, int o_excl)
char path[100];
char pid[10];
int fd;
int n;
sprintf(path, "/var/run/mdadm/%s.pid", devname);
fd = open(path, O_RDWR|O_CREAT|o_excl, 0600);
if (fd < 0)
return -errno;
sprintf(pid, "%d\n", getpid());
write(fd, pid, strlen(pid));
n = write(fd, pid, strlen(pid));
close(fd);
if (n < 0)
return -errno;
return 0;
}
@ -199,6 +203,7 @@ int main(int argc, char *argv[])
struct sigaction act;
int pfd[2];
int status;
int ignore;
if (argc != 2) {
fprintf(stderr, "Usage: md-manage /device/name/for/container\n");
@ -218,7 +223,10 @@ int main(int argc, char *argv[])
/* Fork, and have the child tell us when they are ready */
if (do_fork()) {
pipe(pfd);
if (pipe(pfd) != 0) {
fprintf(stderr, "mdmon: failed to create pipe\n");
exit(1);
}
switch(fork()) {
case -1:
fprintf(stderr, "mdmon: failed to fork: %s\n",
@ -324,18 +332,20 @@ int main(int argc, char *argv[])
/* Ok, this is close enough. We can say goodbye to our parent now.
*/
status = 0;
write(pfd[1], &status, sizeof(status));
if (write(pfd[1], &status, sizeof(status)) < 0)
fprintf(stderr, "mdmon: failed to notify our parent: %d\n",
getppid());
close(pfd[1]);
chdir("/");
ignore = chdir("/");
setsid();
close(0);
open("/dev/null", O_RDWR);
close(1);
dup(0);
ignore = dup(0);
#ifndef DEBUG
close(2);
dup(0);
ignore = dup(0);
#endif
mlockall(MCL_FUTURE);

View File

@ -486,6 +486,7 @@ static int wait_and_act(struct supertype *container, int nowait)
container->ss->sync_metadata(container);
}
rv = 0;
for (a = *aap; a ; a = a->next) {
if (a->replaces && !discard_this) {
struct active_array **ap;

View File

@ -504,9 +504,8 @@ static void *load_section(int fd, struct ddf_super *super, void *buf,
/* All pre-allocated sections are a single block */
if (len != 1)
return NULL;
} else {
posix_memalign(&buf, 512, len<<9);
}
} else if (posix_memalign(&buf, 512, len<<9) != 0)
buf = NULL;
if (!buf)
return NULL;
@ -642,9 +641,13 @@ static int load_ddf_local(int fd, struct ddf_super *super,
unsigned long long dsize;
/* First the local disk info */
posix_memalign((void**)&dl, 512,
if (posix_memalign((void**)&dl, 512,
sizeof(*dl) +
(super->max_part) * sizeof(dl->vlist[0]));
(super->max_part) * sizeof(dl->vlist[0])) != 0) {
fprintf(stderr, Name ": %s could not allocate disk info buffer\n",
__func__);
return 1;
}
load_section(fd, super, &dl->disk,
super->active->data_section_offset,
@ -693,8 +696,14 @@ static int load_ddf_local(int fd, struct ddf_super *super,
if (vd->magic == DDF_SPARE_ASSIGN_MAGIC) {
if (dl->spare)
continue;
posix_memalign((void**)&dl->spare, 512,
super->conf_rec_len*512);
if (posix_memalign((void**)&dl->spare, 512,
super->conf_rec_len*512) != 0) {
fprintf(stderr, Name
": %s could not allocate spare info buf\n",
__func__);
return 1;
}
memcpy(dl->spare, vd, super->conf_rec_len*512);
continue;
}
@ -712,9 +721,14 @@ static int load_ddf_local(int fd, struct ddf_super *super,
__be32_to_cpu(vcl->conf.seqnum))
continue;
} else {
posix_memalign((void**)&vcl, 512,
if (posix_memalign((void**)&vcl, 512,
(super->conf_rec_len*512 +
offsetof(struct vcl, conf)));
offsetof(struct vcl, conf))) != 0) {
fprintf(stderr, Name
": %s could not allocate vcl buf\n",
__func__);
return 1;
}
vcl->next = super->conflist;
vcl->block_sizes = NULL; /* FIXME not for CONCAT */
super->conflist = vcl;
@ -804,7 +818,16 @@ static int load_super_ddf(struct supertype *st, int fd,
return rv;
}
load_ddf_local(fd, super, devname, 0);
rv = load_ddf_local(fd, super, devname, 0);
if (rv) {
if (devname)
fprintf(stderr,
Name ": Failed to load all information "
"sections on %s\n", devname);
free(super);
return rv;
}
/* Should possibly check the sections .... */
@ -1473,7 +1496,10 @@ static int init_super_ddf(struct supertype *st,
return init_super_ddf_bvd(st, info, size, name, homehost,
uuid);
posix_memalign((void**)&ddf, 512, sizeof(*ddf));
if (posix_memalign((void**)&ddf, 512, sizeof(*ddf)) != 0) {
fprintf(stderr, Name ": %s could not allocate superblock\n", __func__);
return 0;
}
memset(ddf, 0, sizeof(*ddf));
ddf->dlist = NULL; /* no physical disks yet */
ddf->conflist = NULL; /* No virtual disks yet */
@ -1600,7 +1626,10 @@ static int init_super_ddf(struct supertype *st,
memset(ddf->controller.pad, 0xff, 8);
memset(ddf->controller.vendor_data, 0xff, 448);
posix_memalign((void**)&pd, 512, pdsize);
if (posix_memalign((void**)&pd, 512, pdsize) != 0) {
fprintf(stderr, Name ": %s could not allocate pd\n", __func__);
return 0;
}
ddf->phys = pd;
ddf->pdsize = pdsize;
@ -1611,7 +1640,10 @@ static int init_super_ddf(struct supertype *st,
pd->max_pdes = __cpu_to_be16(max_phys_disks);
memset(pd->pad, 0xff, 52);
posix_memalign((void**)&vd, 512, vdsize);
if (posix_memalign((void**)&vd, 512, vdsize) != 0) {
fprintf(stderr, Name ": %s could not allocate vd\n", __func__);
return 0;
}
ddf->virt = vd;
ddf->vdsize = vdsize;
memset(vd, 0, vdsize);
@ -1839,8 +1871,11 @@ static int init_super_ddf_bvd(struct supertype *st,
__cpu_to_be16(__be16_to_cpu(ddf->virt->populated_vdes)+1);
/* Now create a new vd_config */
posix_memalign((void**)&vcl, 512,
(offsetof(struct vcl, conf) + ddf->conf_rec_len * 512));
if (posix_memalign((void**)&vcl, 512,
(offsetof(struct vcl, conf) + ddf->conf_rec_len * 512)) != 0) {
fprintf(stderr, Name ": %s could not allocate vd_config\n", __func__);
return 0;
}
vcl->lba_offset = (__u64*) &vcl->conf.phys_refnum[ddf->mppe];
vcl->vcnum = venum;
sprintf(st->subarray, "%d", venum);
@ -2010,8 +2045,13 @@ static void add_to_super_ddf(struct supertype *st,
* a phys_disk entry and a more detailed disk_data entry.
*/
fstat(fd, &stb);
posix_memalign((void**)&dd, 512,
sizeof(*dd) + sizeof(dd->vlist[0]) * ddf->max_part);
if (posix_memalign((void**)&dd, 512,
sizeof(*dd) + sizeof(dd->vlist[0]) * ddf->max_part) != 0) {
fprintf(stderr, Name
": %s could allocate buffer for new disk, aborting\n",
__func__);
abort();
}
dd->major = major(stb.st_rdev);
dd->minor = minor(stb.st_rdev);
dd->devname = devname;
@ -2547,13 +2587,18 @@ static int load_super_ddf_all(struct supertype *st, int fd,
close(dfd);
/* Now we need the device-local bits */
for (sd = sra->devs ; sd ; sd = sd->next) {
int rv;
sprintf(nm, "%d:%d", sd->disk.major, sd->disk.minor);
dfd = dev_open(nm, keep_fd? O_RDWR : O_RDONLY);
if (dfd < 0)
return 2;
load_ddf_headers(dfd, super, NULL);
seq = load_ddf_local(dfd, super, NULL, keep_fd);
rv = load_ddf_headers(dfd, super, NULL);
if (rv == 0)
rv = load_ddf_local(dfd, super, NULL, keep_fd);
if (!keep_fd) close(dfd);
if (rv)
return 1;
}
if (st->subarray[0]) {
struct vcl *v;
@ -2679,16 +2724,20 @@ static int store_zero_ddf(struct supertype *st, int fd)
{
unsigned long long dsize;
void *buf;
int rc;
if (!get_dev_size(fd, NULL, &dsize))
return 1;
posix_memalign(&buf, 512, 512);
if (posix_memalign(&buf, 512, 512) != 0)
return 1;
memset(buf, 0, 512);
lseek64(fd, dsize-512, 0);
write(fd, buf, 512);
rc = write(fd, buf, 512);
free(buf);
if (rc < 0)
return 1;
return 0;
}

View File

@ -546,7 +546,10 @@ static int init_super0(struct supertype *st, mdu_array_info_t *info,
mdp_super_t *sb;
int spares;
posix_memalign((void**)&sb, 512, MD_SB_BYTES + sizeof(bitmap_super_t));
if (posix_memalign((void**)&sb, 512, MD_SB_BYTES + sizeof(bitmap_super_t)) != 0) {
fprintf(stderr, Name ": %s could not allocate superblock\n", __func__);
return 0;
}
memset(sb, 0, MD_SB_BYTES + sizeof(bitmap_super_t));
st->sb = sb;
@ -739,8 +742,12 @@ static int compare_super0(struct supertype *st, struct supertype *tst)
if (second->md_magic != MD_SB_MAGIC)
return 1;
if (!first) {
posix_memalign((void**)&first, 512,
MD_SB_BYTES + sizeof(struct bitmap_super_s));
if (posix_memalign((void**)&first, 512,
MD_SB_BYTES + sizeof(struct bitmap_super_s)) != 0) {
fprintf(stderr, Name
": %s could not allocate superblock\n", __func__);
return 1;
}
memcpy(first, second, MD_SB_BYTES + sizeof(struct bitmap_super_s));
st->sb = first;
return 0;
@ -809,7 +816,12 @@ static int load_super0(struct supertype *st, int fd, char *devname)
return 1;
}
posix_memalign((void**)&super, 512, MD_SB_BYTES + sizeof(bitmap_super_t)+512);
if (posix_memalign((void**)&super, 512,
MD_SB_BYTES + sizeof(bitmap_super_t)+512) != 0) {
fprintf(stderr, Name
": %s could not allocate superblock\n", __func__);
return 1;
}
if (read(fd, super, sizeof(*super)) != MD_SB_BYTES) {
if (devname)

View File

@ -689,8 +689,12 @@ static int init_super1(struct supertype *st, mdu_array_info_t *info,
int rfd;
char defname[10];
posix_memalign((void**)&sb, 512, (1024 + 512 +
sizeof(struct misc_dev_info)));
if (posix_memalign((void**)&sb, 512, (1024 + 512 +
sizeof(struct misc_dev_info))) != 0) {
fprintf(stderr, Name
": %s could not allocate superblock\n", __func__);
return 0;
}
memset(sb, 0, 1024);
st->sb = sb;
@ -1036,9 +1040,13 @@ static int compare_super1(struct supertype *st, struct supertype *tst)
return 1;
if (!first) {
posix_memalign((void**)&first, 512,
if (posix_memalign((void**)&first, 512,
1024 + 512 +
sizeof(struct misc_dev_info));
sizeof(struct misc_dev_info)) != 0) {
fprintf(stderr, Name
": %s could not allocate superblock\n", __func__);
return 1;
}
memcpy(first, second, 1024 + 512 +
sizeof(struct misc_dev_info));
st->sb = first;
@ -1152,9 +1160,13 @@ static int load_super1(struct supertype *st, int fd, char *devname)
return 1;
}
posix_memalign((void**)&super, 512,
if (posix_memalign((void**)&super, 512,
1024 + 512 +
sizeof(struct misc_dev_info));
sizeof(struct misc_dev_info)) != 0) {
fprintf(stderr, Name ": %s could not allocate superblock\n",
__func__);
return 1;
}
if (read(fd, super, 1024) != 1024) {
if (devname)