From b102348e988e4abc5d579ce13c067ce2c885aaf7 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 26 Jul 2006 13:32:44 +0000 Subject: Fix declared with attribute warn_unused_result errors --- alsa/pcm_a2dp.c | 4 ++-- cups/hcrp.c | 6 +++--- cups/spp.c | 4 ++-- dund/dun.c | 6 +++++- dund/main.c | 15 +++------------ hidd/fakehid.c | 3 ++- hidd/main.c | 21 ++++++++------------- pand/main.c | 21 ++++++--------------- test/attest.c | 2 +- test/hciemu.c | 37 ++++++++++++++----------------------- test/hstest.c | 4 ++-- tools/csr_bcsp.c | 3 ++- tools/dfutool.c | 14 ++++++++++---- 13 files changed, 60 insertions(+), 80 deletions(-) diff --git a/alsa/pcm_a2dp.c b/alsa/pcm_a2dp.c index 89a53211..fef13941 100644 --- a/alsa/pcm_a2dp.c +++ b/alsa/pcm_a2dp.c @@ -110,7 +110,7 @@ static snd_pcm_sframes_t a2dp_transfer(snd_pcm_ioplug_t *io, { snd_pcm_a2dp_t *a2dp = io->private_data; unsigned char *buf; - int len; + int err, len; buf = (unsigned char *) areas->addr + (areas->first + areas->step * offset) / 8; @@ -119,7 +119,7 @@ static snd_pcm_sframes_t a2dp_transfer(snd_pcm_ioplug_t *io, return len; if (a2dp->len + a2dp->sbc.len > sizeof(a2dp->buf)) { - write(a2dp->sk, a2dp->buf, a2dp->len); + err = write(a2dp->sk, a2dp->buf, a2dp->len); a2dp->len = 0; } diff --git a/cups/hcrp.c b/cups/hcrp.c index c613b4fc..c70945be 100644 --- a/cups/hcrp.c +++ b/cups/hcrp.c @@ -89,7 +89,7 @@ static int hcrp_credit_grant(int sk, uint16_t tid, uint32_t credit) cp.credit = credit; memcpy(buf, &hdr, HCRP_PDU_HDR_SIZE); memcpy(buf + HCRP_PDU_HDR_SIZE, &cp, HCRP_CREDIT_GRANT_CP_SIZE); - write(sk, buf, HCRP_PDU_HDR_SIZE + HCRP_CREDIT_GRANT_CP_SIZE); + len = write(sk, buf, HCRP_PDU_HDR_SIZE + HCRP_CREDIT_GRANT_CP_SIZE); len = read(sk, buf, sizeof(buf)); memcpy(&hdr, buf, HCRP_PDU_HDR_SIZE); @@ -114,7 +114,7 @@ static int hcrp_credit_request(int sk, uint16_t tid, uint32_t *credit) hdr.tid = htons(tid); hdr.plen = htons(0); memcpy(buf, &hdr, HCRP_PDU_HDR_SIZE); - write(sk, buf, HCRP_PDU_HDR_SIZE); + len = write(sk, buf, HCRP_PDU_HDR_SIZE); len = read(sk, buf, sizeof(buf)); memcpy(&hdr, buf, HCRP_PDU_HDR_SIZE); @@ -142,7 +142,7 @@ static int hcrp_get_lpt_status(int sk, uint16_t tid, uint8_t *lpt_status) hdr.tid = htons(tid); hdr.plen = htons(0); memcpy(buf, &hdr, HCRP_PDU_HDR_SIZE); - write(sk, buf, HCRP_PDU_HDR_SIZE); + len = write(sk, buf, HCRP_PDU_HDR_SIZE); len = read(sk, buf, sizeof(buf)); memcpy(&hdr, buf, HCRP_PDU_HDR_SIZE); diff --git a/cups/spp.c b/cups/spp.c index 968cd61e..0350280b 100644 --- a/cups/spp.c +++ b/cups/spp.c @@ -38,7 +38,7 @@ int spp_print(bdaddr_t *src, bdaddr_t *dst, uint8_t channel, int fd, int copies) { struct sockaddr_rc addr; unsigned char buf[2048]; - int i, sk, len; + int i, sk, err, len; if ((sk = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0) { perror("ERROR: Can't create socket"); @@ -87,7 +87,7 @@ int spp_print(bdaddr_t *src, bdaddr_t *dst, uint8_t channel, int fd, int copies) } while ((len = read(fd, buf, sizeof(buf))) > 0) { - write(sk, buf, len); + err = write(sk, buf, len); } } diff --git a/dund/dun.c b/dund/dun.c index 4fbbad69..718da7ec 100644 --- a/dund/dun.c +++ b/dund/dun.c @@ -98,7 +98,9 @@ static int uses_rfcomm(char *path, char *dev) dir = opendir(path); if (!dir) return 0; - chdir(path); + + if (chdir(path) < 0) + return 0; while ((de = readdir(dir)) != NULL) { char link[PATH_MAX + 1]; @@ -109,7 +111,9 @@ static int uses_rfcomm(char *path, char *dev) return 1; } } + closedir(dir); + return 0; } diff --git a/dund/main.c b/dund/main.c index 249d6d7c..bb96d639 100644 --- a/dund/main.c +++ b/dund/main.c @@ -598,18 +598,9 @@ int main(int argc, char *argv[]) sa.sa_handler = sig_hup; sigaction(SIGHUP, &sa, NULL); - if (detach) { - int fd; - - if (fork()) exit(0); - - /* Direct stdin,stdout,stderr to '/dev/null' */ - fd = open("/dev/null", O_RDWR); - dup2(fd, 0); dup2(fd, 1); dup2(fd, 2); - close(fd); - - setsid(); - chdir("/"); + if (detach && daemon(0, 0)) { + perror("Can't start daemon"); + exit(1); } openlog("dund", LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_DAEMON); diff --git a/hidd/fakehid.c b/hidd/fakehid.c index 0d87335b..138d2b48 100644 --- a/hidd/fakehid.c +++ b/hidd/fakehid.c @@ -47,6 +47,7 @@ static void event(int fd, uint16_t type, uint16_t code, int32_t value) { struct uinput_event event; + int len; if (fd <= fileno(stderr)) return; @@ -56,7 +57,7 @@ static void event(int fd, uint16_t type, uint16_t code, int32_t value) event.code = code; event.value = value; - write(fd, &event, sizeof(event)); + len = write(fd, &event, sizeof(event)); } static void func(int fd) diff --git a/hidd/main.c b/hidd/main.c index 6ccbf0bc..b684cac7 100644 --- a/hidd/main.c +++ b/hidd/main.c @@ -638,8 +638,8 @@ int main(int argc, char *argv[]) uint8_t subclass = 0x00; char addr[18]; int log_option = LOG_NDELAY | LOG_PID; - int opt, fd, ctl, csk, isk; - int mode = SHOW, daemon = 1, nosdp = 0, nocheck = 0, bootonly = 0; + int opt, ctl, csk, isk; + int mode = SHOW, detach = 1, nosdp = 0, nocheck = 0, bootonly = 0; int fakehid = 1, encrypt = 0, timeout = 30, lm = 0; bacpy(&bdaddr, BDADDR_ANY); @@ -653,7 +653,7 @@ int main(int argc, char *argv[]) str2ba(optarg, &bdaddr); break; case 'n': - daemon = 0; + detach = 0; break; case 't': timeout = atoi(optarg); @@ -760,16 +760,11 @@ int main(int argc, char *argv[]) exit(0); } - if (daemon) { - if (fork()) - exit(0); - - fd = open("/dev/null", O_RDWR); - dup2(fd, 0); dup2(fd, 1); dup2(fd, 2); - close(fd); - - setsid(); - chdir("/"); + if (detach) { + if (daemon(0, 0)) { + perror("Can't start daemon"); + exit(1); + } } else log_option |= LOG_PERROR; diff --git a/pand/main.c b/pand/main.c index 50b355b6..fd77e4ab 100644 --- a/pand/main.c +++ b/pand/main.c @@ -443,7 +443,7 @@ static int write_pidfile(void) if (fd == -1) { /* Try to open the file for read. */ fd = open(pidfile, O_RDONLY); - if(fd == -1) { + if (fd < 0) { syslog(LOG_ERR, "Could not read old pidfile: %s(%d)", strerror(errno), errno); return -1; @@ -464,7 +464,8 @@ static int write_pidfile(void) } pid = 0; - fscanf(f, "%d", &pid); + if (fscanf(f, "%d", &pid) != 1) + pid = 0; fclose(f); if (pid) { @@ -706,19 +707,9 @@ int main(int argc, char *argv[]) sigaction(SIGTERM, &sa, NULL); sigaction(SIGINT, &sa, NULL); - if (detach) { - if (fork()) - exit(0); - - /* Direct stdin,stdout,stderr to '/dev/null' */ - { - int fd = open("/dev/null", O_RDWR); - dup2(fd, 0); dup2(fd, 1); dup2(fd, 2); - close(fd); - } - - setsid(); - chdir("/"); + if (detach && daemon(0, 0)) { + perror("Can't start daemon"); + exit(1); } openlog("pand", LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_DAEMON); diff --git a/test/attest.c b/test/attest.c index 59ab1d29..98fdf5e7 100644 --- a/test/attest.c +++ b/test/attest.c @@ -45,7 +45,7 @@ static int at_command(int fd, char *cmd, int to) char buf[1024]; int sel, len, i, n; - write(fd, cmd, strlen(cmd)); + len = write(fd, cmd, strlen(cmd)); for (i = 0; i < 100; i++) { diff --git a/test/hciemu.c b/test/hciemu.c index d6996a3e..213ca78c 100644 --- a/test/hciemu.c +++ b/test/hciemu.c @@ -219,6 +219,7 @@ static int write_snoop(int fd, int type, int incoming, unsigned char *buf, int l struct timeval tv; uint32_t size = len; uint64_t ts; + int err; if (fd < 0) return -1; @@ -236,8 +237,8 @@ static int write_snoop(int fd, int type, int incoming, unsigned char *buf, int l if (type == HCI_COMMAND_PKT || type == HCI_EVENT_PKT) pkt.flags |= ntohl(0x02); - write(fd, &pkt, BTSNOOP_PKT_SIZE); - write(fd, buf, size); + err = write(fd, &pkt, BTSNOOP_PKT_SIZE); + err = write(fd, buf, size); return 0; } @@ -872,7 +873,7 @@ static gboolean io_acl_data(GIOChannel *chan, GIOCondition cond, gpointer data) unsigned char buf[HCI_MAX_FRAME_SIZE], *ptr; hci_acl_hdr *ah; uint16_t flags; - int len, fd; + int fd, err, len; if (cond & G_IO_NVAL) return FALSE; @@ -907,7 +908,7 @@ static gboolean io_acl_data(GIOChannel *chan, GIOCondition cond, gpointer data) write_snoop(vdev.dd, HCI_ACLDATA_PKT, 1, buf, len); - write(vdev.fd, buf, len); + err = write(vdev.fd, buf, len); return TRUE; } @@ -1137,7 +1138,7 @@ static int run_proxy(int fd, int dev, bdaddr_t *bdaddr) len = read(fd, buf, sizeof(buf)); if (len > 0) { rewrite_bdaddr(buf, len, bdaddr); - write(dd, buf, len); + err = write(dd, buf, len); } } @@ -1145,7 +1146,7 @@ static int run_proxy(int fd, int dev, bdaddr_t *bdaddr) len = read(dd, buf, sizeof(buf)); if (len > 0) { rewrite_bdaddr(buf, len, bdaddr); - write(fd, buf, len); + err = write(fd, buf, len); } } } @@ -1185,13 +1186,10 @@ int main(int argc, char *argv[]) GIOChannel *dev_io; char *device = NULL, *snoop = NULL; bdaddr_t bdaddr; - int fd, dd, opt, daemon, dofork, dev = -1; + int fd, dd, opt, detach = 1, dev = -1; bacpy(&bdaddr, BDADDR_ANY); - /* Configure default settings */ - daemon = 1; dofork = 1; - while ((opt=getopt_long(argc, argv, "d:b:s:nh", main_options, NULL)) != EOF) { switch(opt) { case 'd': @@ -1207,7 +1205,7 @@ int main(int argc, char *argv[]) break; case 'n': - daemon = 0; + detach = 0; break; case 'h': @@ -1237,18 +1235,11 @@ int main(int argc, char *argv[]) exit(1); } - if (daemon) { - if (dofork && fork()) - exit(0); - - /* Direct stdin,stdout,stderr to '/dev/null' */ - fd = open("/dev/null", O_RDWR); - dup2(fd, 0); dup2(fd, 1); dup2(fd, 2); - close(fd); - - setsid(); - - chdir("/"); + if (detach) { + if (daemon(0, 0)) { + perror("Can't start daemon"); + exit(1); + } } /* Start logging to syslog and stderr */ diff --git a/test/hstest.c b/test/hstest.c index cda9101c..d94ade20 100644 --- a/test/hstest.c +++ b/test/hstest.c @@ -159,7 +159,7 @@ int main(int argc, char *argv[]) char *filename; mode_t filemode; - int mode = 0; + int err, mode = 0; int dd, rd, sd, fd; uint16_t sco_handle, sco_mtu, vs; @@ -245,7 +245,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "SCO audio channel connected (handle %d, mtu %d)\n", sco_handle, sco_mtu); if (mode == RECORD) - write(rd, "RING\r\n", 6); + err = write(rd, "RING\r\n", 6); maxfd = (rd > sd) ? rd : sd; diff --git a/tools/csr_bcsp.c b/tools/csr_bcsp.c index 77766114..29a60bf9 100644 --- a/tools/csr_bcsp.c +++ b/tools/csr_bcsp.c @@ -136,7 +136,8 @@ int csr_open_bcsp(char *device) void put_uart(uint8_t ch) { - write(fd, &ch, 1); + if (write(fd, &ch, 1) < 0) + fprintf(stderr, "UART write error\n"); } uint8_t get_uart(uint8_t *ch) diff --git a/tools/dfutool.c b/tools/dfutool.c index 8d5e9194..6bf65639 100644 --- a/tools/dfutool.c +++ b/tools/dfutool.c @@ -166,7 +166,8 @@ static struct usb_dev_handle *open_device(char *device, struct dfu_suffix *suffi printf("\rSelect device (abort with 0): "); fflush(stdout); memset(str, 0, sizeof(str)); - fgets(str, sizeof(str) - 1, stdin); + if (!fgets(str, sizeof(str) - 1, stdin)) + continue; sel = atoi(str); } while (!isdigit(str[0]) || sel < 0 || sel > num ); @@ -666,8 +667,12 @@ static void cmd_archive(char *device, int argc, char **argv) for (i = 0; i < len; i++) crc = crc32_byte(crc, buf[i]); - if (len > 0) - write(fd, buf, len); + if (len > 0) { + if (write(fd, buf, len) < 0) { + printf("\rCan't write next block: %s (%d)\n", strerror(errno), errno); + goto done; + } + } n++; if (len != 1023) @@ -687,7 +692,8 @@ static void cmd_archive(char *device, int argc, char **argv) suffix.dwCRC = cpu_to_le32(crc); - write(fd, &suffix, DFU_SUFFIX_SIZE); + if (write(fd, &suffix, DFU_SUFFIX_SIZE) < 0) + printf("Can't write suffix block: %s (%d)\n", strerror(errno), errno); done: close(fd); -- cgit