DEBUG add function to set debug fd

DPRINTF was blindly sending all debug output to fd 2 (stderr).
The new function iscsi_set_debug_fd() will set the debug fd.
In general debugging is completely disabled by default.
This commit is contained in:
Peter Lieven
2012-11-06 16:07:43 +01:00
parent 3e57a612db
commit ec46d6fa43
5 changed files with 26 additions and 5 deletions

View File

@@ -130,6 +130,7 @@ struct iscsi_context {
int no_auto_reconnect; int no_auto_reconnect;
int reconnect_deferred; int reconnect_deferred;
int debug; int debug;
int debug_fd;
int mallocs; int mallocs;
int reallocs; int reallocs;
int frees; int frees;
@@ -304,7 +305,7 @@ struct scsi_task *iscsi_scsi_get_task_from_pdu(struct iscsi_pdu *pdu);
void iscsi_set_noautoreconnect(struct iscsi_context *iscsi, int state); void iscsi_set_noautoreconnect(struct iscsi_context *iscsi, int state);
void iscsi_decrement_iface_rr(); void iscsi_decrement_iface_rr(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -971,12 +971,12 @@ iscsi_scsi_cancel_all_tasks(struct iscsi_context *iscsi);
#define DPRINTF(iscsi,level,fmt,args...) \ #define DPRINTF(iscsi,level,fmt,args...) \
do { \ do { \
if ((iscsi)->debug >= level) { \ if ((iscsi)->debug >= level) { \
fprintf(stderr,"libiscsi: "); \ dprintf((iscsi)->debug_fd,"libiscsi: "); \
fprintf(stderr, (fmt), ##args); \ dprintf((iscsi)->debug_fd, (fmt), ##args); \
if (iscsi->target_name[0]) { \ if (iscsi->target_name[0]) { \
fprintf(stderr," [%s]",iscsi->target_name); \ dprintf((iscsi)->debug_fd," [%s]",iscsi->target_name); \
} \ } \
fprintf(stderr,"\n"); \ dprintf((iscsi)->debug_fd,"\n"); \
} \ } \
} while (0); } while (0);
@@ -993,6 +993,12 @@ iscsi_scsi_cancel_all_tasks(struct iscsi_context *iscsi);
EXTERN void EXTERN void
iscsi_set_debug(struct iscsi_context *iscsi, int level); iscsi_set_debug(struct iscsi_context *iscsi, int level);
/*
* This function is to set fd where debugging info is sent to. default is stderr (2)
*/
EXTERN void
iscsi_set_debug_fd(struct iscsi_context *iscsi, int fd);
/* /*
* This function is to set the TCP_USER_TIMEOUT option. It has to be called after iscsi * This function is to set the TCP_USER_TIMEOUT option. It has to be called after iscsi
* context creation. The value given in ms is then applied each time a new socket is created. * context creation. The value given in ms is then applied each time a new socket is created.

View File

@@ -87,6 +87,7 @@ iscsi_create_context(const char *initiator_name)
strncpy(iscsi->initiator_name,initiator_name,MAX_STRING_SIZE); strncpy(iscsi->initiator_name,initiator_name,MAX_STRING_SIZE);
iscsi->fd = -1; iscsi->fd = -1;
iscsi->debug_fd = 2;
srand(time(NULL) ^ getpid() ^ (u_int32_t) iscsi); srand(time(NULL) ^ getpid() ^ (u_int32_t) iscsi);
@@ -112,6 +113,10 @@ iscsi_create_context(const char *initiator_name)
iscsi->tcp_keepintvl=30; iscsi->tcp_keepintvl=30;
iscsi->tcp_keepidle=30; iscsi->tcp_keepidle=30;
if (getenv("LIBISCSI_DEBUG_FD") != NULL) {
iscsi_set_debug_fd(iscsi,atoi(getenv("LIBISCSI_DEBUG_FD")));
}
if (getenv("LIBISCSI_DEBUG") != NULL) { if (getenv("LIBISCSI_DEBUG") != NULL) {
iscsi_set_debug(iscsi,atoi(getenv("LIBISCSI_DEBUG"))); iscsi_set_debug(iscsi,atoi(getenv("LIBISCSI_DEBUG")));
} }
@@ -315,6 +320,13 @@ iscsi_set_debug(struct iscsi_context *iscsi, int level)
DPRINTF(iscsi,2,"set debug level to %d",level); DPRINTF(iscsi,2,"set debug level to %d",level);
} }
void
iscsi_set_debug_fd(struct iscsi_context *iscsi, int fd)
{
iscsi->debug_fd = fd;
DPRINTF(iscsi,2,"set debug fd to %d",fd);
}
const char * const char *
iscsi_get_error(struct iscsi_context *iscsi) iscsi_get_error(struct iscsi_context *iscsi)
{ {

View File

@@ -65,6 +65,7 @@ iscsi_scsi_task_cancel
iscsi_service iscsi_service
iscsi_set_alias iscsi_set_alias
iscsi_set_debug iscsi_set_debug
iscsi_set_debug_fd
iscsi_set_header_digest iscsi_set_header_digest
iscsi_set_initiator_username_pwd iscsi_set_initiator_username_pwd
iscsi_set_isid_en iscsi_set_isid_en

View File

@@ -63,6 +63,7 @@ iscsi_scsi_task_cancel
iscsi_service iscsi_service
iscsi_set_alias iscsi_set_alias
iscsi_set_debug iscsi_set_debug
iscsi_set_debug_fd
iscsi_set_header_digest iscsi_set_header_digest
iscsi_set_initiator_username_pwd iscsi_set_initiator_username_pwd
iscsi_set_isid_en iscsi_set_isid_en