Change in osmo-remsim[master]: logging: Replace remaining fprintf() calls with libosmocore logging

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Thu Dec 9 10:15:30 UTC 2021


laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-remsim/+/26475 )

Change subject: logging: Replace remaining fprintf() calls with libosmocore logging
......................................................................

logging: Replace remaining fprintf() calls with libosmocore logging

Change-Id: I2a772b3180131923d4e2ee7311670b938cb50fe0
---
M src/bankd/bankd_pcsc.c
M src/bankd/driver_core.c
M src/bankd/driver_pcsc.c
M src/client/remsim_client.c
M src/client/remsim_client_main.c
M src/client/user_simtrace2.c
M src/rspro_util.c
7 files changed, 25 insertions(+), 19 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved



diff --git a/src/bankd/bankd_pcsc.c b/src/bankd/bankd_pcsc.c
index 91eeadd..8202504 100644
--- a/src/bankd/bankd_pcsc.c
+++ b/src/bankd/bankd_pcsc.c
@@ -102,14 +102,16 @@
 	regex_t compiled_name;
 	int rc;
 
-	printf("PC/SC slot name: %u/%u -> regex '%s'\n", sn->slot.bank_id, sn->slot.slot_nr, sn->name_regex);
+	LOGP(DMAIN, LOGL_INFO, "PC/SC slot name: %u/%u -> regex '%s'\n",
+	     sn->slot.bank_id, sn->slot.slot_nr, sn->name_regex);
 
 	memset(&compiled_name, 0, sizeof(compiled_name));
 
 	rc = regcomp(&compiled_name, sn->name_regex, REG_EXTENDED);
 	if (rc != 0) {
 		char *errmsg = get_regerror(sn, rc, &compiled_name);
-		fprintf(stderr, "Error compiling regex '%s': %s - Ignoring\n", sn->name_regex, errmsg);
+		LOGP(DMAIN, LOGL_ERROR, "Error compiling regex '%s': %s - Ignoring\n",
+		     sn->name_regex, errmsg);
 		talloc_free(errmsg);
 		talloc_free(sn);
 	} else {
@@ -141,7 +143,8 @@
 
 	while ((bytes_read = fread(buf, 1, sizeof(buf), fp)) > 0) {
 		if (csv_parse(&p, buf, bytes_read, cb1, cb2, &ps) != bytes_read) {
-			fprintf(stderr, "Error parsing CSV: %s\n", csv_strerror(csv_error(&p)));
+			LOGP(DMAIN, LOGL_FATAL, "Error parsing bankd PC/SC CSV: %s\n",
+			     csv_strerror(csv_error(&p)));
 			fclose(fp);
 			return -1;
 		}
diff --git a/src/bankd/driver_core.c b/src/bankd/driver_core.c
index dbdf23f..57ae3cd 100644
--- a/src/bankd/driver_core.c
+++ b/src/bankd/driver_core.c
@@ -28,6 +28,7 @@
 #include <osmocom/core/linuxlist.h>
 
 #include "internal.h"
+#include "debug.h"
 
 static LLIST_HEAD(g_card_reader_drivers);
 static LLIST_HEAD(g_card_readers);
@@ -46,7 +47,7 @@
 
 	llist_add(&cr->list, &g_card_readers);
 
-	printf("allocated reader '%s'\n", cr->name);
+	LOGP(DMAIN, LOGL_INFO, "allocated reader '%s'\n", cr->name);
 
 	return cr;
 }
@@ -78,7 +79,7 @@
 	struct card_reader_driver *drv;
 
 	llist_for_each_entry(drv, &g_card_reader_drivers, list) {
-		printf("probing driver '%s' for drivers\n", drv->name);
+		LOGP(DMAIN, LOGL_INFO, "probing driver '%s' for drivers\n", drv->name);
 		drv->ops->probe(ctx);
 	}
 }
diff --git a/src/bankd/driver_pcsc.c b/src/bankd/driver_pcsc.c
index 03a7f32..4279c2f 100644
--- a/src/bankd/driver_pcsc.c
+++ b/src/bankd/driver_pcsc.c
@@ -36,13 +36,14 @@
 #include <winscard.h>
 
 #include "internal.h"
+#include "debug.h"
 
 #define PCSC_ERROR(rv, text) \
 if (rv != SCARD_S_SUCCESS) { \
-	fprintf(stderr, text ": %s (0x%lX)\n", pcsc_stringify_error(rv), rv); \
+	LOGP(DMAIN, LOGL_ERROR, text ": %s (0x%lX)\n", pcsc_stringify_error(rv), rv); \
 	goto end; \
 } else { \
-        printf(text ": OK\n\n"); \
+	LOGP(DMAIN, LOGL_DEBUG, ": OK\n\n"); \
 }
 
 static void pcsc_readers_probe(void *ctx)
@@ -73,7 +74,7 @@
 		num_readers++;
 	}
 
-	printf("num_readers=%d\n", num_readers);
+	LOGP(DMAIN, LOGL_DEBUG, "num_readers=%d\n", num_readers);
 
 end:
 	if (mszReaders)
diff --git a/src/client/remsim_client.c b/src/client/remsim_client.c
index 182894f..388aa26 100644
--- a/src/client/remsim_client.c
+++ b/src/client/remsim_client.c
@@ -140,7 +140,7 @@
 
 	bc->main_fi = main_fsm_alloc(bc, bc);
 	if (!bc->main_fi) {
-		fprintf(stderr, "Unable to create main client FSM: %s\n", strerror(errno));
+		LOGP(DMAIN, LOGL_FATAL, "Unable to create main client FSM: %s\n", strerror(errno));
 		exit(1);
 	}
 
@@ -158,7 +158,7 @@
 
 	rc = server_conn_fsm_alloc(bc, srvc);
 	if (rc < 0) {
-		fprintf(stderr, "Unable to create Server conn FSM: %s\n", strerror(errno));
+		LOGP(DMAIN, LOGL_FATAL, "Unable to create Server conn FSM: %s\n", strerror(errno));
 		exit(1);
 	}
 	osmo_fsm_inst_change_parent(srvc->fi, bc->main_fi, MF_E_SRVC_LOST);
@@ -171,7 +171,7 @@
 	memcpy(&bankdc->own_comp_id, &srvc->own_comp_id, sizeof(bankdc->own_comp_id));
 	rc = server_conn_fsm_alloc(bc, bankdc);
 	if (rc < 0) {
-		fprintf(stderr, "Unable to connect bankd conn FSM: %s\n", strerror(errno));
+		LOGP(DMAIN, LOGL_FATAL, "Unable to connect bankd conn FSM: %s\n", strerror(errno));
 		exit(1);
 	}
 	osmo_fsm_inst_update_id(bankdc->fi, "bankd");
diff --git a/src/client/remsim_client_main.c b/src/client/remsim_client_main.c
index f064960..47ec8ac 100644
--- a/src/client/remsim_client_main.c
+++ b/src/client/remsim_client_main.c
@@ -188,7 +188,7 @@
 
 	/* Silently (and portably) reap children. */
 	if (avoid_zombies() < 0) {
-		fprintf(stderr, "Unable to silently reap children: %s\n", strerror(errno));
+		LOGP(DMAIN, LOGL_FATAL, "Unable to silently reap children: %s\n", strerror(errno));
 		exit(1);
 	}
 
diff --git a/src/client/user_simtrace2.c b/src/client/user_simtrace2.c
index 8d8a6c9..100d55b 100644
--- a/src/client/user_simtrace2.c
+++ b/src/client/user_simtrace2.c
@@ -404,7 +404,7 @@
 
 	rc = osmo_libusb_init(NULL);
 	if (rc < 0) {
-		fprintf(stderr, "libusb initialization failed\n");
+		LOGP(DMAIN, LOGL_ERROR, "libusb initialization failed\n");
 		return rc;
 	}
 
@@ -427,7 +427,7 @@
 	transp->usb_async = true;
 	transp->usb_devh = osmo_libusb_open_claim_interface(NULL, NULL, ifm);
 	if (!transp->usb_devh) {
-		fprintf(stderr, "can't open USB device\n");
+		LOGP(DMAIN, LOGL_ERROR, "can't open USB device\n");
 		return -1;
 	}
 
@@ -437,14 +437,14 @@
 
 	rc = libusb_claim_interface(transp->usb_devh, cfg->usb.if_num);
 	if (rc < 0) {
-		fprintf(stderr, "can't claim interface %d; rc=%d\n", cfg->usb.if_num, rc);
+		LOGP(DMAIN, LOGL_ERROR, "can't claim interface %d; rc=%d\n", cfg->usb.if_num, rc);
 		goto close_exit;
 	}
 
 	rc = osmo_libusb_get_ep_addrs(transp->usb_devh, cfg->usb.if_num, &transp->usb_ep.out,
 					&transp->usb_ep.in, &transp->usb_ep.irq_in);
 	if (rc < 0) {
-		fprintf(stderr, "can't obtain EP addrs; rc=%d\n", rc);
+		LOGP(DMAIN, LOGL_ERROR, "can't obtain EP addrs; rc=%d\n", rc);
 		goto close_exit;
 	}
 
diff --git a/src/rspro_util.c b/src/rspro_util.c
index ab748f6..a7476dc 100644
--- a/src/rspro_util.c
+++ b/src/rspro_util.c
@@ -33,6 +33,7 @@
 #include <osmocom/rspro/RsproPDU.h>
 
 #include "rspro_util.h"
+#include "debug.h"
 
 #define ASN_ALLOC_COPY(out, in) \
 do {						\
@@ -69,7 +70,7 @@
 	msg->l2h = msg->data;
 	rval = der_encode_to_buffer(&asn_DEF_RsproPDU, pdu, msgb_data(msg), msgb_tailroom(msg));
 	if (rval.encoded < 0) {
-		fprintf(stderr, "Failed to encode %s\n", rval.failed_type->name);
+		LOGP(DRSPRO, LOGL_ERROR, "Failed to encode %s\n", rval.failed_type->name);
 		msgb_free(msg);
 		return NULL;
 	}
@@ -86,10 +87,10 @@
 	RsproPDU_t *pdu = NULL;
 	asn_dec_rval_t rval;
 
-	//printf("decoding %s\n", msgb_hexdump(msg));
+	LOGP(DRSPRO, LOGL_DEBUG, "decoding %s\n", msgb_hexdump(msg));
 	rval = ber_decode(NULL, &asn_DEF_RsproPDU, (void **) &pdu, msgb_l2(msg), msgb_l2len(msg));
 	if (rval.code != RC_OK) {
-		fprintf(stderr, "Failed to decode: %d. Consumed %zu of %u bytes\n",
+		LOGP(DRSPRO, LOGL_ERROR, "Failed to decode: %d. Consumed %zu of %u bytes\n",
 			rval.code, rval.consumed, msgb_length(msg));
 		return NULL;
 	}

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-remsim/+/26475
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-remsim
Gerrit-Branch: master
Gerrit-Change-Id: I2a772b3180131923d4e2ee7311670b938cb50fe0
Gerrit-Change-Number: 26475
Gerrit-PatchSet: 2
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: lynxis lazus <lynxis at fe80.eu>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20211209/1bf8b590/attachment.htm>


More information about the gerrit-log mailing list