lib: add pr_debug() macro
Add the pr_debug() macro so that:
#ifdef DEBUG
printf("foo");
#endif
can be replaced by:
pr_debug("foo");
Apply the pr_debug() macro wherever relevant.
Currently, there is no consensus whether debug messages should be
printed on stdout or stderr. Most of the modules: canbusload.c,
candump.c and canlogserver.c use stdout but
mcp251xfd/mcp251xfd-dev-coredump.c uses stderr. Harmonize the behavior
by following the major trend and make
mcp251xfd/mcp251xfd-dev-coredump.c also output to stdout.
slcanpty.c does a #define DEBUG, meaning that debug is always turned
on for this file. Remove this and make debug an option like every
other files.
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://lore.kernel.org/all/20221114163848.3398-5-mailhol.vincent@wanadoo.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
pull/387/head
parent
21fb43532e
commit
0cfd56d613
1
Makefile
1
Makefile
|
|
@ -46,6 +46,7 @@ MAKEFLAGS := -k
|
|||
CFLAGS := -O2 -Wall -Wno-parentheses
|
||||
|
||||
CPPFLAGS += \
|
||||
-I. \
|
||||
-Iinclude \
|
||||
-DAF_CAN=PF_CAN \
|
||||
-DPF_CAN=29 \
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@
|
|||
#include <linux/can.h>
|
||||
#include <linux/can/raw.h>
|
||||
|
||||
#include "lib.h"
|
||||
#include "terminal.h"
|
||||
#include "canframelen.h"
|
||||
|
||||
|
|
@ -310,9 +311,7 @@ int main(int argc, char **argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("open %d '%s'.\n", i, ptr);
|
||||
#endif
|
||||
pr_debug("open %d '%s'.\n", i, ptr);
|
||||
|
||||
s[i] = socket(PF_CAN, SOCK_RAW, CAN_RAW);
|
||||
if (s[i] < 0) {
|
||||
|
|
@ -358,10 +357,8 @@ int main(int argc, char **argv)
|
|||
if (nbytes > max_bitrate_len)
|
||||
max_bitrate_len = nbytes; /* for nice printing */
|
||||
|
||||
pr_debug("using interface name '%s'.\n", ifr.ifr_name);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("using interface name '%s'.\n", ifr.ifr_name);
|
||||
#endif
|
||||
/* try to switch the socket into CAN FD mode */
|
||||
const int canfd_on = 1;
|
||||
setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &canfd_on, sizeof(canfd_on));
|
||||
|
|
|
|||
16
candump.c
16
candump.c
|
|
@ -216,9 +216,7 @@ static int idx2dindex(int ifidx, int socket)
|
|||
|
||||
strcpy(devname[i], ifr.ifr_name);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("new index %d (%s)\n", i, devname[i]);
|
||||
#endif
|
||||
pr_debug("new index %d (%s)\n", i, devname[i]);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
|
@ -477,9 +475,7 @@ int main(int argc, char **argv)
|
|||
ptr = argv[optind+i];
|
||||
nptr = strchr(ptr, ',');
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("open %d '%s'.\n", i, ptr);
|
||||
#endif
|
||||
pr_debug("open %d '%s'.\n", i, ptr);
|
||||
|
||||
obj->s = socket(PF_CAN, SOCK_RAW, CAN_RAW);
|
||||
if (obj->s < 0) {
|
||||
|
|
@ -513,9 +509,7 @@ int main(int argc, char **argv)
|
|||
memset(&ifr.ifr_name, 0, sizeof(ifr.ifr_name));
|
||||
strncpy(ifr.ifr_name, ptr, nbytes);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("using interface name '%s'.\n", ifr.ifr_name);
|
||||
#endif
|
||||
pr_debug("using interface name '%s'.\n", ifr.ifr_name);
|
||||
|
||||
if (strcmp(ANYDEV, ifr.ifr_name) != 0) {
|
||||
if (ioctl(obj->s, SIOCGIFINDEX, &ifr) < 0) {
|
||||
|
|
@ -605,9 +599,7 @@ int main(int argc, char **argv)
|
|||
/* try SO_RCVBUFFORCE first, if we run with CAP_NET_ADMIN */
|
||||
if (setsockopt(obj->s, SOL_SOCKET, SO_RCVBUFFORCE,
|
||||
&rcvbuf_size, sizeof(rcvbuf_size)) < 0) {
|
||||
#ifdef DEBUG
|
||||
printf("SO_RCVBUFFORCE failed so try SO_RCVBUF ...\n");
|
||||
#endif
|
||||
pr_debug("SO_RCVBUFFORCE failed so try SO_RCVBUF ...\n");
|
||||
if (setsockopt(obj->s, SOL_SOCKET, SO_RCVBUF,
|
||||
&rcvbuf_size, sizeof(rcvbuf_size)) < 0) {
|
||||
perror("setsockopt SO_RCVBUF");
|
||||
|
|
|
|||
|
|
@ -145,9 +145,7 @@ int idx2dindex(int ifidx, int socket)
|
|||
|
||||
strcpy(devname[i], ifr.ifr_name);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("new index %d (%s)\n", i, devname[i]);
|
||||
#endif
|
||||
pr_debug("new index %d (%s)\n", i, devname[i]);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
|
@ -310,11 +308,9 @@ int main(int argc, char **argv)
|
|||
|
||||
for (i=0; i<currmax; i++) {
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("open %d '%s' m%08X v%08X i%d e%d.\n",
|
||||
i, argv[optind+i], mask[i], value[i],
|
||||
inv_filter[i], err_mask[i]);
|
||||
#endif
|
||||
pr_debug("open %d '%s' m%08X v%08X i%d e%d.\n",
|
||||
i, argv[optind+i], mask[i], value[i],
|
||||
inv_filter[i], err_mask[i]);
|
||||
|
||||
if ((s[i] = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
|
||||
perror("socket");
|
||||
|
|
|
|||
7
lib.h
7
lib.h
|
|
@ -47,6 +47,13 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef DEBUG
|
||||
#define pr_debug(fmt, args...) printf(fmt, ##args)
|
||||
#else
|
||||
__attribute__((format (printf, 1, 2)))
|
||||
static inline int pr_debug(const char* fmt, ...) {return 0;}
|
||||
#endif
|
||||
|
||||
/* buffer sizes for CAN frame string representations */
|
||||
|
||||
#define CL_ID (sizeof("12345678##1"))
|
||||
|
|
|
|||
|
|
@ -17,18 +17,10 @@
|
|||
|
||||
#include <linux/kernel.h>
|
||||
|
||||
#include "lib.h"
|
||||
#include "mcp251xfd.h"
|
||||
#include "mcp251xfd-dump-userspace.h"
|
||||
|
||||
#define pr_err(fmt, args...) fprintf(stderr, fmt, ##args)
|
||||
#define pr_no(fmt, args...) while (0) { fprintf(stdout, fmt, ##args); }
|
||||
|
||||
#ifdef DEBUG
|
||||
#define pr_debug(fmt, args...) pr_err(fmt, ##args)
|
||||
#else
|
||||
#define pr_debug(fmt, args...) pr_no(fmt, ##args)
|
||||
#endif
|
||||
|
||||
|
||||
struct mcp251xfd_dump_iter {
|
||||
const void *start;
|
||||
|
|
|
|||
10
slcanpty.c
10
slcanpty.c
|
|
@ -49,8 +49,6 @@
|
|||
#define SLC_MTU (sizeof("T1111222281122334455667788EA5F\r")+1)
|
||||
#define DEVICE_NAME_PTMX "/dev/ptmx"
|
||||
|
||||
#define DEBUG
|
||||
|
||||
/* read data from pty, send CAN frames to CAN socket and answer commands */
|
||||
int pty2can(int pty, int socket, struct can_filter *fi,
|
||||
int *is_open, int *tstamp)
|
||||
|
|
@ -106,14 +104,12 @@ rx_restart:
|
|||
cmd = buf[0];
|
||||
buf[nbytes] = 0;
|
||||
|
||||
#ifdef DEBUG
|
||||
for (tmp = 0; tmp < nbytes; tmp++)
|
||||
if (buf[tmp] == '\r')
|
||||
putchar('@');
|
||||
pr_debug("@");
|
||||
else
|
||||
putchar(buf[tmp]);
|
||||
printf("\n");
|
||||
#endif
|
||||
pr_debug("%c", buf[tmp]);
|
||||
pr_debug("\n");
|
||||
|
||||
/* check for filter configuration commands */
|
||||
if (cmd == 'm' || cmd == 'M') {
|
||||
|
|
|
|||
Loading…
Reference in New Issue