Fix compilation warnings and modify the Makefiles to treat
warnings as errors.

Signed-off-by: Erez Zilber <erezzi.l...@gmail.com>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to open-iscsi@googlegroups.com
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/open-iscsi
-~----------~----~----~----~------~----~------~--~---

From 6c97d8d941fa9caaae42f01eeeed686465d8b49f Mon Sep 17 00:00:00 2001
From: Erez Zilber <erezzi.l...@gmail.com>
Date: Thu, 3 Sep 2009 14:12:27 +0300
Subject: [PATCH] Fix compilation warnings in usr/kernel code

Fix compilation warnings and modify the Makefiles to treat
warnings as errors.

Signed-off-by: Erez Zilber <erezzi.l...@gmail.com>
---
 kernel/2.6.14-23_compat.patch    |  106 ++++++++++++++++++++++++++------------
 kernel/Makefile                  |    2 +-
 kernel/libiscsi.c                |    3 +-
 usr/Makefile                     |    2 +-
 usr/auth.c                       |   34 +++++++++---
 usr/iface.c                      |   38 --------------
 usr/iscsid.c                     |   22 +++++++-
 usr/log.c                        |   34 ------------
 usr/mgmt_ipc.c                   |    9 +++-
 usr/strings.c                    |    2 +-
 usr/util.c                       |   26 ++++++++--
 utils/Makefile                   |    2 +-
 utils/fwparam_ibft/fwparam_ppc.c |    7 ++-
 utils/sysdeps/Makefile           |    2 +-
 14 files changed, 157 insertions(+), 132 deletions(-)

diff --git a/kernel/2.6.14-23_compat.patch b/kernel/2.6.14-23_compat.patch
index ab233bb..4b02d2e 100644
--- a/kernel/2.6.14-23_compat.patch
+++ b/kernel/2.6.14-23_compat.patch
@@ -1,8 +1,8 @@
 diff --git a/iscsi_tcp.c b/iscsi_tcp.c
-index caa116c..71df5b9 100644
+index bce1594..c46888d 100644
 --- a/iscsi_tcp.c
 +++ b/iscsi_tcp.c
-@@ -456,11 +456,9 @@ static int iscsi_sw_tcp_pdu_init(struct iscsi_task *task,
+@@ -460,11 +460,9 @@ static int iscsi_sw_tcp_pdu_init(struct iscsi_task *task,
  	if (!task->sc)
  		iscsi_sw_tcp_send_linear_data_prep(conn, task->data, count);
  	else {
@@ -17,7 +17,7 @@ index caa116c..71df5b9 100644
  	}
  
  	if (err) {
-@@ -793,7 +791,11 @@ iscsi_sw_tcp_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
+@@ -797,7 +795,11 @@ iscsi_sw_tcp_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
  	shost->max_lun = iscsi_max_lun;
  	shost->max_id = 0;
  	shost->max_channel = 0;
@@ -29,7 +29,7 @@ index caa116c..71df5b9 100644
  
  	if (iscsi_host_add(shost, NULL))
  		goto free_host;
-@@ -832,12 +834,6 @@ static void iscsi_sw_tcp_session_destroy(struct iscsi_cls_session *cls_session)
+@@ -836,12 +838,6 @@ static void iscsi_sw_tcp_session_destroy(struct iscsi_cls_session *cls_session)
  	iscsi_host_free(shost);
  }
  
@@ -42,7 +42,7 @@ index caa116c..71df5b9 100644
  static int iscsi_sw_tcp_slave_configure(struct scsi_device *sdev)
  {
  	blk_queue_bounce_limit(sdev->request_queue, BLK_BOUNCE_ANY);
-@@ -846,6 +842,9 @@ static int iscsi_sw_tcp_slave_configure(struct scsi_device *sdev)
+@@ -850,6 +846,9 @@ static int iscsi_sw_tcp_slave_configure(struct scsi_device *sdev)
  }
  
  static struct scsi_host_template iscsi_sw_tcp_sht = {
@@ -52,7 +52,7 @@ index caa116c..71df5b9 100644
  	.module			= THIS_MODULE,
  	.name			= "iSCSI Initiator over TCP/IP",
  	.queuecommand           = iscsi_queuecommand,
-@@ -856,9 +855,8 @@ static struct scsi_host_template iscsi_sw_tcp_sht = {
+@@ -860,9 +859,8 @@ static struct scsi_host_template iscsi_sw_tcp_sht = {
  	.cmd_per_lun		= ISCSI_DEF_CMD_PER_LUN,
  	.eh_abort_handler       = iscsi_eh_abort,
  	.eh_device_reset_handler= iscsi_eh_device_reset,
@@ -77,7 +77,7 @@ index f9a4044..ab20530 100644
  #include "libiscsi_tcp.h"
  
 diff --git a/libiscsi.c b/libiscsi.c
-index fe4b66e..6217f76 100644
+index 223a5b8..161c971 100644
 --- a/libiscsi.c
 +++ b/libiscsi.c
 @@ -24,7 +24,10 @@
@@ -91,7 +91,7 @@ index fe4b66e..6217f76 100644
  #include <asm/unaligned.h>
  #include <net/tcp.h>
  #include <scsi/scsi_cmnd.h>
-@@ -60,6 +63,8 @@ MODULE_PARM_DESC(debug_libiscsi, "Turn on debugging for libiscsi module. "
+@@ -83,6 +86,8 @@ MODULE_PARM_DESC(debug_libiscsi_eh,
  					     __func__, ##arg);		\
  	} while (0);
  
@@ -100,7 +100,7 @@ index fe4b66e..6217f76 100644
  /* Serial Number Arithmetic, 32 bits, less than, RFC1982 */
  #define SNA32_CHECK 2147483648UL
  
-@@ -229,7 +234,7 @@ static int iscsi_prep_bidi_ahs(struct iscsi_task *task)
+@@ -252,7 +257,7 @@ static int iscsi_prep_bidi_ahs(struct iscsi_task *task)
  						  sizeof(rlen_ahdr->reserved));
  	rlen_ahdr->ahstype = ISCSI_AHSTYPE_RLENGTH;
  	rlen_ahdr->reserved = 0;
@@ -109,7 +109,7 @@ index fe4b66e..6217f76 100644
  
  	ISCSI_DBG_SESSION(task->conn->session,
  			  "bidi-in rlen_ahdr->read_length(%d) "
-@@ -300,7 +305,7 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)
+@@ -323,7 +328,7 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)
  			return rc;
  	}
  	if (sc->sc_data_direction == DMA_TO_DEVICE) {
@@ -118,7 +118,7 @@ index fe4b66e..6217f76 100644
  		struct iscsi_r2t_info *r2t = &task->unsol_r2t;
  
  		hdr->data_length = cpu_to_be32(out_len);
-@@ -346,7 +351,7 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)
+@@ -369,7 +374,7 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)
  	} else {
  		hdr->flags |= ISCSI_FLAG_CMD_FINAL;
  		zero_data(hdr->dlength);
@@ -127,7 +127,7 @@ index fe4b66e..6217f76 100644
  
  		if (sc->sc_data_direction == DMA_FROM_DEVICE)
  			hdr->flags |= ISCSI_FLAG_CMD_READ;
-@@ -373,7 +378,7 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)
+@@ -396,7 +401,7 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)
  			  sc->sc_data_direction == DMA_TO_DEVICE ?
  			  "write" : "read", conn->id, sc, sc->cmnd[0],
  			  task->itt, scsi_bufflen(sc),
@@ -136,7 +136,7 @@ index fe4b66e..6217f76 100644
  			  session->cmdsn,
  			  session->max_cmdsn - session->exp_cmdsn + 1);
  	return 0;
-@@ -510,12 +515,7 @@ static void fail_scsi_task(struct iscsi_task *task, int err)
+@@ -533,12 +538,7 @@ static void fail_scsi_task(struct iscsi_task *task, int err)
  		state = ISCSI_TASK_ABRT_TMF;
  
  	sc->result = err << 16;
@@ -150,7 +150,7 @@ index fe4b66e..6217f76 100644
  
  	iscsi_complete_task(task, state);
  }
-@@ -706,7 +706,7 @@ invalid_datalen:
+@@ -729,7 +729,7 @@ invalid_datalen:
  			goto out;
  		}
  
@@ -159,7 +159,7 @@ index fe4b66e..6217f76 100644
  		if (datalen < senselen)
  			goto invalid_datalen;
  
-@@ -723,8 +723,8 @@ invalid_datalen:
+@@ -746,8 +746,8 @@ invalid_datalen:
  
  		if (scsi_bidi_cmnd(sc) && res_count > 0 &&
  				(rhdr->flags & ISCSI_FLAG_CMD_BIDI_OVERFLOW ||
@@ -170,7 +170,7 @@ index fe4b66e..6217f76 100644
  		else
  			sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
  	}
-@@ -773,8 +773,8 @@ iscsi_data_in_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
+@@ -796,8 +796,8 @@ iscsi_data_in_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
  
  		if (res_count > 0 &&
  		    (rhdr->flags & ISCSI_FLAG_CMD_OVERFLOW ||
@@ -181,7 +181,7 @@ index fe4b66e..6217f76 100644
  		else
  			sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
  	}
-@@ -1498,12 +1498,7 @@ fault:
+@@ -1527,12 +1527,7 @@ fault:
  	spin_unlock(&session->lock);
  	ISCSI_DBG_SESSION(session, "iscsi: cmd 0x%x is not queued (%d)\n",
  			  sc->cmnd[0], reason);
@@ -196,7 +196,7 @@ index fe4b66e..6217f76 100644
  	spin_lock(host->host_lock);
  	return 0;
 diff --git a/libiscsi.h b/libiscsi.h
-index 1798fbe..c9174ec 100644
+index 04463c1..fa45dff 100644
 --- a/libiscsi.h
 +++ b/libiscsi.h
 @@ -32,6 +32,8 @@
@@ -209,10 +209,22 @@ index 1798fbe..c9174ec 100644
  struct scsi_host_template;
  struct scsi_device;
 diff --git a/libiscsi_tcp.c b/libiscsi_tcp.c
-index c2b535b..76ead4b 100644
+index 4051e62..d357331 100644
 --- a/libiscsi_tcp.c
 +++ b/libiscsi_tcp.c
-@@ -360,6 +360,16 @@ iscsi_segment_seek_sg(struct iscsi_segment *segment,
+@@ -302,7 +302,11 @@ iscsi_tcp_dgst_header(struct hash_desc *hash, const void *hdr, size_t hdrlen,
+ {
+ 	struct scatterlist sg;
+ 
++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
++	sg_init_one(&sg, (void *)hdr, hdrlen);
++#else
+ 	sg_init_one(&sg, hdr, hdrlen);
++#endif
+ 	crypto_hash_digest(hash, &sg, hdrlen, digest);
+ }
+ EXPORT_SYMBOL_GPL(iscsi_tcp_dgst_header);
+@@ -360,6 +364,16 @@ iscsi_segment_seek_sg(struct iscsi_segment *segment,
  	struct scatterlist *sg;
  	unsigned int i;
  
@@ -229,7 +241,7 @@ index c2b535b..76ead4b 100644
  	__iscsi_segment_init(segment, size, done, hash);
  	for_each_sg(sg_list, sg, sg_count, i) {
  		if (offset < sg->length) {
-@@ -471,7 +481,7 @@ static int iscsi_tcp_data_in(struct iscsi_conn *conn, struct iscsi_task *task)
+@@ -471,7 +485,7 @@ static int iscsi_tcp_data_in(struct iscsi_conn *conn, struct iscsi_task *task)
  	struct iscsi_tcp_task *tcp_task = task->dd_data;
  	struct iscsi_data_rsp *rhdr = (struct iscsi_data_rsp *)tcp_conn->in.hdr;
  	int datasn = be32_to_cpu(rhdr->datasn);
@@ -238,7 +250,7 @@ index c2b535b..76ead4b 100644
  
  	/*
  	 * lib iscsi will update this in the completion handling if there
-@@ -565,11 +575,11 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task)
+@@ -565,11 +579,11 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task)
  			      r2t->data_length, session->max_burst);
  
  	r2t->data_offset = be32_to_cpu(rhdr->data_offset);
@@ -252,7 +264,7 @@ index c2b535b..76ead4b 100644
  		__kfifo_put(tcp_task->r2tpool.queue, (void*)&r2t,
  			    sizeof(void*));
  		return ISCSI_ERR_DATALEN;
-@@ -668,7 +678,6 @@ iscsi_tcp_hdr_dissect(struct iscsi_conn *conn, struct iscsi_hdr *hdr)
+@@ -668,7 +682,6 @@ iscsi_tcp_hdr_dissect(struct iscsi_conn *conn, struct iscsi_hdr *hdr)
  		if (tcp_conn->in.datalen) {
  			struct iscsi_tcp_task *tcp_task = task->dd_data;
  			struct hash_desc *rx_hash = NULL;
@@ -260,9 +272,9 @@ index c2b535b..76ead4b 100644
  
  			/*
  			 * Setup copy of Data-In into the Scsi_Cmnd
-@@ -687,8 +696,8 @@ iscsi_tcp_hdr_dissect(struct iscsi_conn *conn, struct iscsi_hdr *hdr)
- 				      tcp_task->data_offset,
+@@ -688,8 +701,8 @@ iscsi_tcp_hdr_dissect(struct iscsi_conn *conn, struct iscsi_hdr *hdr)
  				      tcp_conn->in.datalen);
+ 			task->last_xfer = jiffies;
  			rc = iscsi_segment_seek_sg(&tcp_conn->in.segment,
 -						   sdb->table.sgl,
 -						   sdb->table.nents,
@@ -288,7 +300,7 @@ new file mode 100644
 index 0000000..763d07a
 --- /dev/null
 +++ b/open_iscsi_compat.h
-@@ -0,0 +1,321 @@
+@@ -0,0 +1,327 @@
 +#ifndef OPEN_ISCSI_COMPAT
 +#define OPEN_ISCSI_COMPAT
 +
@@ -331,9 +343,15 @@ index 0000000..763d07a
 +	INIT_WORK(work, func, work);
 +}
 +
++int queue_delayed_work_compat(struct workqueue_struct *wq, struct delayed_work *work, unsigned long delay)
++{
++       return queue_delayed_work(wq, &(work)->work, delay);
++}
 +#undef INIT_WORK
 +#define INIT_WORK(_work, _func) INIT_WORK_compat(_work, _func)
 +#define INIT_DELAYED_WORK(_work,_func) INIT_WORK(&(_work)->work, _func)
++#undef queue_delayed_work
++#define queue_delayed_work(wq, work, delay) queue_delayed_work_compat(wq, work, delay)
 +
 +#endif
 +
@@ -611,7 +629,7 @@ index 0000000..763d07a
 +
 +#endif
 diff --git a/scsi_transport_iscsi.c b/scsi_transport_iscsi.c
-index c9e95e7..79436c4 100644
+index 5434f5b..4262048 100644
 --- a/scsi_transport_iscsi.c
 +++ b/scsi_transport_iscsi.c
 @@ -41,13 +41,13 @@ struct iscsi_internal {
@@ -712,7 +730,16 @@ index c9e95e7..79436c4 100644
  {
  	struct Scsi_Host *shost = dev_to_shost(dev);
  	struct iscsi_cls_host *ihost = shost->shost_data;
-@@ -545,15 +545,6 @@ static void __iscsi_unblock_session(struct work_struct *work)
+@@ -531,8 +531,6 @@ static void __iscsi_unblock_session(struct work_struct *work)
+ 	struct iscsi_cls_session *session =
+ 			container_of(work, struct iscsi_cls_session,
+ 				     unblock_work);
+-	struct Scsi_Host *shost = iscsi_session_to_shost(session);
+-	struct iscsi_cls_host *ihost = shost->shost_data;
+ 	unsigned long flags;
+ 
+ 	/*
+@@ -545,15 +543,6 @@ static void __iscsi_unblock_session(struct work_struct *work)
  	spin_unlock_irqrestore(&session->lock, flags);
  	/* start IO */
  	scsi_target_unblock(&session->dev);
@@ -728,7 +755,7 @@ index c9e95e7..79436c4 100644
  }
  
  /**
-@@ -698,7 +689,8 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
+@@ -698,7 +687,8 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
  	}
  	session->target_id = id;
  
@@ -738,7 +765,7 @@ index c9e95e7..79436c4 100644
  	err = device_add(&session->dev);
  	if (err) {
  		iscsi_cls_session_printk(KERN_ERR, session,
-@@ -870,7 +862,8 @@ iscsi_create_conn(struct iscsi_cls_session *session, int dd_size, uint32_t cid)
+@@ -870,7 +860,8 @@ iscsi_create_conn(struct iscsi_cls_session *session, int dd_size, uint32_t cid)
  	if (!get_device(&session->dev))
  		goto free_conn;
  
@@ -748,7 +775,21 @@ index c9e95e7..79436c4 100644
  	conn->dev.parent = &session->dev;
  	conn->dev.release = iscsi_conn_release;
  	err = device_register(&conn->dev);
-@@ -1309,6 +1302,8 @@ static int
+@@ -1268,6 +1259,7 @@ iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev)
+ 	return err;
+ }
+ 
++#if 0
+ static int iscsi_if_ep_connect(struct iscsi_transport *transport,
+ 			       struct iscsi_uevent *ev, int msg_type)
+ {
+@@ -1304,11 +1296,14 @@ release_host:
+ 		scsi_host_put(shost);
+ 	return err;
+ }
++#endif
+ 
+ static int
  iscsi_if_transport_ep(struct iscsi_transport *transport,
  		      struct iscsi_uevent *ev, int msg_type)
  {
@@ -1097,6 +1138,3 @@ index 6beea23..d509d17 100644
  struct scsi_transport_template;
  struct iscsi_transport;
  struct iscsi_endpoint;
--- 
-1.5.2.1
-
diff --git a/kernel/Makefile b/kernel/Makefile
index a97c52f..539ea71 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -8,7 +8,7 @@
 
 # Kbuild stuff, the following is the only part of this file that KBuild
 # actually uses itself.
-EXTRA_CFLAGS += -I$(obj) -I$(obj)/../include 
+EXTRA_CFLAGS += -I$(obj) -I$(obj)/../include -Werror
 
 ifeq ($(DEBUG_SCSI), 1)
 EXTRA_CFLAGS += -DDEBUG_SCSI=1
diff --git a/kernel/libiscsi.c b/kernel/libiscsi.c
index 73c4231..223a5b8 100644
--- a/kernel/libiscsi.c
+++ b/kernel/libiscsi.c
@@ -1548,10 +1548,9 @@ EXPORT_SYMBOL_GPL(iscsi_change_queue_depth);
 
 int iscsi_target_alloc(struct scsi_target *starget)
 {
+#if 0
 	struct iscsi_cls_session *cls_session = starget_to_session(starget);
 	struct iscsi_session *session = cls_session->dd_data;
-
-#if 0
 	starget->can_queue = session->scsi_cmds_max;
 #endif
 	return 0;
diff --git a/usr/Makefile b/usr/Makefile
index 4d3c71f..31cdecc 100644
--- a/usr/Makefile
+++ b/usr/Makefile
@@ -29,7 +29,7 @@ endif
 endif
 
 OPTFLAGS ?= -O2 -g
-WARNFLAGS ?= -Wall -Wstrict-prototypes
+WARNFLAGS ?= -Wall -Wstrict-prototypes -Werror
 CFLAGS += $(OPTFLAGS) $(WARNFLAGS) -I../include -I. -D$(OSNAME) $(IPC_CFLAGS)
 PROGRAMS = iscsid iscsiadm iscsistart
 
diff --git a/usr/auth.c b/usr/auth.c
index 4b9afb5..e7f8831 100644
--- a/usr/auth.c
+++ b/usr/auth.c
@@ -190,29 +190,45 @@ get_random_bytes(unsigned char *data, unsigned int length)
 	long r;
         unsigned n;
 	int fd;
+	int rc;
 
 	fd = open("/dev/urandom", O_RDONLY);
         while (length > 0) {
 
-		if (fd)
-			read(fd, &r, sizeof(long));
-		else
+		if (fd) {
+			rc = read(fd, &r, sizeof(long));
+			if (rc == -1) {
+				log_error("read failed");
+				close(fd);
+				return;
+			}
+		} else
 			r = rand();
                 r = r ^ (r >> 8);
                 r = r ^ (r >> 4);
                 n = r & 0x7;
 
-		if (fd)
-			read(fd, &r, sizeof(long));
-		else
+		if (fd) {
+			rc = read(fd, &r, sizeof(long));
+			if (rc == -1) {
+				log_error("read failed");
+				close(fd);
+				return;
+			}
+		} else
 			r = rand();
                 r = r ^ (r >> 8);
                 r = r ^ (r >> 5);
                 n = (n << 3) | (r & 0x7);
 
-		if (fd)
-			read(fd, &r, sizeof(long));
-		else
+		if (fd) {
+			rc = read(fd, &r, sizeof(long));
+			if (rc == -1) {
+				log_error("read failed");
+				close(fd);
+				return;
+			}
+		} else
 			r = rand();
 
                 r = r ^ (r >> 8);
diff --git a/usr/iface.c b/usr/iface.c
index 0684644..3f6cc6f 100644
--- a/usr/iface.c
+++ b/usr/iface.c
@@ -308,44 +308,6 @@ free_info:
 	return rc;
 }
 
-static int iface_get_next_id(void)
-{
-	struct stat statb;
-	char *iface_conf;
-	int i, rc = ENOSPC;
-
-	iface_conf = calloc(1, PATH_MAX);
-	if (!iface_conf)
-		return ENOMEM;
-
-	for (i = 0; i < INT_MAX; i++) {
-		memset(iface_conf, 0, PATH_MAX);
-		/* check len */
-		snprintf(iface_conf, PATH_MAX, "iface%d", i);
-		if (strlen(iface_conf) > ISCSI_MAX_IFACE_LEN - 1) {
-			log_error("iface namespace is full. Remove unused "
-				  "iface definitions from %s or send mail "
-				  "to open-iscsi@googlegroups.com to report "
-				  "the problem", IFACE_CONFIG_DIR);
-			rc = ENOSPC;
-			break;
-		}
-		memset(iface_conf, 0, PATH_MAX);
-		snprintf(iface_conf, PATH_MAX, "%s/iface%d", IFACE_CONFIG_DIR,
-			i);
-
-		if (!stat(iface_conf, &statb))
-			continue;
-		if (errno == ENOENT) {
-			rc = i;
-			break;
-		}
-	}
-
-	free(iface_conf);
-        return rc;
-}
-
 struct iface_search {
 	struct iface_rec *pattern;
 	struct iface_rec *found;
diff --git a/usr/iscsid.c b/usr/iscsid.c
index 6f27be8..8fbca5a 100644
--- a/usr/iscsid.c
+++ b/usr/iscsid.c
@@ -337,6 +337,7 @@ int main(int argc, char *argv[])
 	struct sigaction sa_old;
 	struct sigaction sa_new;
 	pid_t pid;
+	int rc;
 
 	/* do not allow ctrl-c for now... */
 	sa_new.sa_handler = catch_signal;
@@ -441,15 +442,30 @@ int main(int argc, char *argv[])
 			exit(1);
 		}
 
-		chdir("/");
+		rc = chdir("/");
+		if (!rc) {
+			log_error("Could not chdir (%d)", rc);
+			log_close(log_pid);
+			exit(1);
+		}
 		if (lockf(fd, F_TLOCK, 0) < 0) {
 			log_error("Unable to lock pid file");
 			log_close(log_pid);
 			exit(1);
 		}
-		ftruncate(fd, 0);
+		rc = ftruncate(fd, 0);
+		if (!rc) {
+			log_error("ftruncate failed (%d)", rc);
+			log_close(log_pid);
+			exit(1);
+		}
 		sprintf(buf, "%d\n", getpid());
-		write(fd, buf, strlen(buf));
+		rc = write(fd, buf, strlen(buf));
+		if (rc == -1) {
+			log_error("write failed");
+			log_close(log_pid);
+			exit(1);
+		}
 
 		daemon_init();
 	} else {
diff --git a/usr/log.c b/usr/log.c
index 4351456..ff7149e 100644
--- a/usr/log.c
+++ b/usr/log.c
@@ -308,40 +308,6 @@ void log_debug(int level, const char *fmt, ...)
 	}
 }
 
-static void __dump_line(int level, unsigned char *buf, int *cp)
-{
-	char line[16*3+5], *lp = line;
-	int i, cnt;
-
-	cnt = *cp;
-	if (!cnt)
-		return;
-	for (i = 0; i < 16; i++) {
-		if (i < cnt)
-			lp += sprintf(lp, " %02x", buf[i]);
-		else
-			lp += sprintf(lp, "   ");
-		if ((i % 4) == 3)
-			lp += sprintf(lp, " |");
-		if (i >= cnt || !isprint(buf[i]))
-			buf[i] =  ' ';
-	}
-	log_debug(level, "%s %.16s |", line, buf);
-	*cp = 0;
-}
-
-static void __dump_char(int level, unsigned char *buf, int *cp, int ch)
-{
-	int cnt = (*cp)++;
-
-	buf[cnt] = ch;
-	if (cnt == 15)
-		__dump_line(level, buf, cp);
-}
-
-#define dump_line() __dump_line(level, char_buf, &char_cnt)
-#define dump_char(ch) __dump_char(level, char_buf, &char_cnt, ch)
-
 static void log_flush(void)
 {
 	int msglen;
diff --git a/usr/mgmt_ipc.c b/usr/mgmt_ipc.c
index e784bca..7092c62 100644
--- a/usr/mgmt_ipc.c
+++ b/usr/mgmt_ipc.c
@@ -443,6 +443,8 @@ mgmt_ipc_destroy_queue_task(queue_task_t *qtask)
 void
 mgmt_ipc_write_rsp(queue_task_t *qtask, mgmt_ipc_err_e err)
 {
+	int rc;
+
 	if (!qtask)
 		return;
 	log_debug(4, "%s: rsp to fd %d", __FUNCTION__,
@@ -454,7 +456,12 @@ mgmt_ipc_write_rsp(queue_task_t *qtask, mgmt_ipc_err_e err)
 	}
 
 	qtask->rsp.err = err;
-	write(qtask->mgmt_ipc_fd, &qtask->rsp, sizeof(qtask->rsp));
+	rc = write(qtask->mgmt_ipc_fd, &qtask->rsp, sizeof(qtask->rsp));
+	if (rc == -1) {
+		log_error("write failed");
+		close(qtask->mgmt_ipc_fd);
+		return;
+	}
 	close(qtask->mgmt_ipc_fd);
 	mgmt_ipc_destroy_queue_task(qtask);
 }
diff --git a/usr/strings.c b/usr/strings.c
index aee1de3..a4e3bdb 100644
--- a/usr/strings.c
+++ b/usr/strings.c
@@ -79,7 +79,7 @@ enlarge_data(struct string_buffer *s, int length)
 	if (s) {
 		s->data_length += length;
 		if (s->data_length > s->allocated_length) {
-			log_debug(7, "enlarge buffer from %lu to %lu\n",
+			log_debug(7, "enlarge buffer from %zu to %zu\n",
 				  s->allocated_length, s->data_length);
 			new_buf = realloc(s->buffer, s->data_length);
 			if (!new_buf) {
diff --git a/usr/util.c b/usr/util.c
index 5b31e89..ba50c2b 100644
--- a/usr/util.c
+++ b/usr/util.c
@@ -26,6 +26,7 @@
 void daemon_init(void)
 {
 	int fd;
+	int rc;
 
 	fd = open("/dev/null", O_RDWR);
 	if (fd == -1) {
@@ -36,22 +37,39 @@ void daemon_init(void)
 	dup2(fd, 1);
 	dup2(fd, 2);
 	setsid();
-	chdir("/");
+	rc = chdir("/");
+	if (!rc)
+		log_error("Could not chdir (%d)", rc);
 }
 
 int oom_adjust(void)
 {
 	int fd;
+	int rc;
 	char path[48];
 
-	nice(-10);
+	rc = nice(-10);
+	if (rc == -1) {
+		log_error("nice failed");
+		return rc;
+	}
 	sprintf(path, "/proc/%d/oom_adj", getpid());
 	fd = open(path, O_WRONLY);
 	if (fd < 0) {
 		return -1;
 	}
-	write(fd, "-16\n", 3); /* for 2.6.11 */
-	write(fd, "-17\n", 3); /* for Andrea's patch */
+	rc = write(fd, "-16\n", 3); /* for 2.6.11 */
+	if (rc == -1) {
+		log_error("writing -16 failed");
+		close(fd);
+		return rc;
+	}
+	rc = write(fd, "-17\n", 3); /* for Andrea's patch */
+	if (rc == -1) {
+		log_error("writing -17 failed");
+		close(fd);
+		return rc;
+	}
 	close(fd);
 
 	return 0;
diff --git a/utils/Makefile b/utils/Makefile
index 2c7e891..358c54c 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -1,6 +1,6 @@
 # This Makefile will work only with GNU make.
 
-CFLAGS += $(OPTFLAGS) -O2 -fno-inline -Wall -Wstrict-prototypes -g
+CFLAGS += $(OPTFLAGS) -O2 -fno-inline -Wall -Wstrict-prototypes -g -Werror
 PROGRAMS = iscsi-iname
 
 all: $(PROGRAMS)
diff --git a/utils/fwparam_ibft/fwparam_ppc.c b/utils/fwparam_ibft/fwparam_ppc.c
index 7dc337a..b94d18a 100644
--- a/utils/fwparam_ibft/fwparam_ppc.c
+++ b/utils/fwparam_ibft/fwparam_ppc.c
@@ -318,9 +318,12 @@ static int find_nics(const char *fpath, const struct stat *sb, int tflag,
 	return 0;
 }
 
-int nic_cmp(const char **a, const char **b)
+int nic_cmp(const void *a, const void *b)
 {
-	return strcmp(*a, *b);
+	const char **ca = (const char **)a;
+	const char **cb = (const char **)b;
+
+	return strcmp(*ca, *cb);
 }
 
 static int find_initiator(const char *fpath, const struct stat *sb, int tflag,
diff --git a/utils/sysdeps/Makefile b/utils/sysdeps/Makefile
index 53c10e5..e24ec52 100644
--- a/utils/sysdeps/Makefile
+++ b/utils/sysdeps/Makefile
@@ -1,6 +1,6 @@
 # This Makefile will work only with GNU make.
 
-CFLAGS += $(OPTFLAGS) $(WARNFLAGS) -O2 -fno-inline -Wall -Wstrict-prototypes -g
+CFLAGS += $(OPTFLAGS) $(WARNFLAGS) -O2 -fno-inline -Wall -Wstrict-prototypes -g -Werror
 
 SYSDEPS_OBJS=sysdeps.o
 
-- 
1.5.5.6

Reply via email to