Skip to contentSkip to conversation

tools/libs/ctrl: Save errno only once in *PRINTF() and *ERROR()

PATCH In review Juergen Gross 3 participants 3 messages Dec 9, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tools/libs/ctrl: Save errno only once in *PRINTF() and *ERROR()

All *PRINTF() and *ERROR() macros are based on xc_reportv() which is saving and restoring errno in order to not modify it. There is no need to save and restore in those macros, too.

---
V2:
- style corrections (Jan Beulich)

---
 tools/libs/ctrl/xc_private.h | 34 ++++++++++++----------------------
 1 file changed, 12 insertions(+), 22 deletions(-)
tools/libs/ctrl/xc_private.h +12 -22
index 2e483590e6..abac9072a0 100644
@@ -122,28 +122,18 @@ void xc_report_progress_step(xc_interface *xch,
 
 /* anamorphic macros:  struct xc_interface *xch  must be in scope */
 
-#define IPRINTF(_f, _a...)  do { int IPRINTF_errno = errno; \
-        xc_report(xch, xch->error_handler, XTL_INFO,0, _f , ## _a); \
-        errno = IPRINTF_errno; \
-        } while (0)
-#define DPRINTF(_f, _a...) do { int DPRINTF_errno = errno; \
-        xc_report(xch, xch->error_handler, XTL_DETAIL,0, _f , ## _a); \
-        errno = DPRINTF_errno; \
-        } while (0)
-#define DBGPRINTF(_f, _a...)  do { int DBGPRINTF_errno = errno; \
-        xc_report(xch, xch->error_handler, XTL_DEBUG,0, _f , ## _a); \
-        errno = DBGPRINTF_errno; \
-        } while (0)
-
-#define ERROR(_m, _a...)  do { int ERROR_errno = errno; \
-        xc_report_error(xch,XC_INTERNAL_ERROR,_m , ## _a ); \
-        errno = ERROR_errno; \
-        } while (0)
-#define PERROR(_m, _a...) do { int PERROR_errno = errno; \
-        xc_report_error(xch,XC_INTERNAL_ERROR,_m " (%d = %s)", \
-        ## _a , errno, xc_strerror(xch, errno)); \
-        errno = PERROR_errno; \
-        } while (0)
+#define IPRINTF(_f, _a...) \
+        xc_report(xch, xch->error_handler, XTL_INFO, 0, _f, ## _a)
+#define DPRINTF(_f, _a...) \
+        xc_report(xch, xch->error_handler, XTL_DETAIL, 0, _f, ## _a)
+#define DBGPRINTF(_f, _a...) \
+        xc_report(xch, xch->error_handler, XTL_DEBUG, 0, _f, ## _a)
+
+#define ERROR(_m, _a...) \
+        xc_report_error(xch, XC_INTERNAL_ERROR, _m, ## _a )
+#define PERROR(_m, _a...) \
+        xc_report_error(xch, XC_INTERNAL_ERROR, _m " (%d = %s)", \
+                        ## _a, errno, xc_strerror(xch, errno))
 
 /*
  * HYPERCALL ARGUMENT BUFFERS
Signature · 1 line
2.26.2
#1 lore raw
Quoted 9 lines · Juergen Gross

All *PRINTF() and *ERROR() macros are based on xc_reportv() which is saving and restoring errno in order to not modify it. There is no need to save and restore in those macros, too.

---
V2:
- style corrections (Jan Beulich)

Thanks. Sadly there still is ...

Quoted 27 lines
tools/libs/ctrl/xc_private.h +0 -21
@@ -122,28 +122,18 @@ void xc_report_progress_step(xc_interface *xch,
 
 /* anamorphic macros:  struct xc_interface *xch  must be in scope */
 
-#define IPRINTF(_f, _a...)  do { int IPRINTF_errno = errno; \
-        xc_report(xch, xch->error_handler, XTL_INFO,0, _f , ## _a); \
-        errno = IPRINTF_errno; \
-        } while (0)
-#define DPRINTF(_f, _a...) do { int DPRINTF_errno = errno; \
-        xc_report(xch, xch->error_handler, XTL_DETAIL,0, _f , ## _a); \
-        errno = DPRINTF_errno; \
-        } while (0)
-#define DBGPRINTF(_f, _a...)  do { int DBGPRINTF_errno = errno; \
-        xc_report(xch, xch->error_handler, XTL_DEBUG,0, _f , ## _a); \
-        errno = DBGPRINTF_errno; \
-        } while (0)
-
-#define ERROR(_m, _a...)  do { int ERROR_errno = errno; \
-        xc_report_error(xch,XC_INTERNAL_ERROR,_m , ## _a ); \
-        errno = ERROR_errno; \
-        } while (0)
-#define PERROR(_m, _a...) do { int PERROR_errno = errno; \
-        xc_report_error(xch,XC_INTERNAL_ERROR,_m " (%d = %s)", \
-        ## _a , errno, xc_strerror(xch, errno)); \
-        errno = PERROR_errno; \

tools/libs/ctrl/xc_private.h void xc_report_progress_step(xc_interface *xch, · line 133

Quoted 10 lines
tools/libs/ctrl/xc_private.h +9 -1
-        } while (0)
+#define IPRINTF(_f, _a...) \
+        xc_report(xch, xch->error_handler, XTL_INFO, 0, _f, ## _a)
+#define DPRINTF(_f, _a...) \
+        xc_report(xch, xch->error_handler, XTL_DETAIL, 0, _f, ## _a)
+#define DBGPRINTF(_f, _a...) \
+        xc_report(xch, xch->error_handler, XTL_DEBUG, 0, _f, ## _a)
+
+#define ERROR(_m, _a...) \
+        xc_report_error(xch, XC_INTERNAL_ERROR, _m, ## _a )

... a stray blank ahead of the closing parenthesis here; I'm sure this can be taken care of while committing.

Jan

Quoted 7 lines
tools/libs/ctrl/xc_private.h +3 -0
+#define PERROR(_m, _a...) \
+        xc_report_error(xch, XC_INTERNAL_ERROR, _m " (%d = %s)", \
+                        ## _a, errno, xc_strerror(xch, errno))
 
 /*
  * HYPERCALL ARGUMENT BUFFERS
#2 lore raw
Quoted 43 lines · Jan Beulich
Quoted 9 lines · Juergen Gross

All *PRINTF() and *ERROR() macros are based on xc_reportv() which is saving and restoring errno in order to not modify it. There is no need to save and restore in those macros, too.

---
V2:
- style corrections (Jan Beulich)

Thanks. Sadly there still is ...

Quoted 31 lines
tools/libs/ctrl/xc_private.h +3 -22
@@ -122,28 +122,18 @@ void xc_report_progress_step(xc_interface *xch,
 
 /* anamorphic macros:  struct xc_interface *xch  must be in scope */
 
-#define IPRINTF(_f, _a...)  do { int IPRINTF_errno = errno; \
-        xc_report(xch, xch->error_handler, XTL_INFO,0, _f , ## _a); \
-        errno = IPRINTF_errno; \
-        } while (0)
-#define DPRINTF(_f, _a...) do { int DPRINTF_errno = errno; \
-        xc_report(xch, xch->error_handler, XTL_DETAIL,0, _f , ## _a); \
-        errno = DPRINTF_errno; \
-        } while (0)
-#define DBGPRINTF(_f, _a...)  do { int DBGPRINTF_errno = errno; \
-        xc_report(xch, xch->error_handler, XTL_DEBUG,0, _f , ## _a); \
-        errno = DBGPRINTF_errno; \
-        } while (0)
-
-#define ERROR(_m, _a...)  do { int ERROR_errno = errno; \
-        xc_report_error(xch,XC_INTERNAL_ERROR,_m , ## _a ); \
-        errno = ERROR_errno; \
-        } while (0)
-#define PERROR(_m, _a...) do { int PERROR_errno = errno; \
-        xc_report_error(xch,XC_INTERNAL_ERROR,_m " (%d = %s)", \
-        ## _a , errno, xc_strerror(xch, errno)); \
-        errno = PERROR_errno; \
-        } while (0)
+#define IPRINTF(_f, _a...) \
+        xc_report(xch, xch->error_handler, XTL_INFO, 0, _f, ## _a)
+#define DPRINTF(_f, _a...) \
Quoted 8 lines

tools/libs/ctrl/xc_private.h void xc_report_progress_step(xc_interface *xch, · line 133

Quoted 6 lines
tools/libs/ctrl/xc_private.h +6 -0
+        xc_report(xch, xch->error_handler, XTL_DETAIL, 0, _f, ## _a)
+#define DBGPRINTF(_f, _a...) \
+        xc_report(xch, xch->error_handler, XTL_DEBUG, 0, _f, ## _a)
+
+#define ERROR(_m, _a...) \
+        xc_report_error(xch, XC_INTERNAL_ERROR, _m, ## _a )

... a stray blank ahead of the closing parenthesis here; I'm sure this can be taken care of while committing.

Yeah - I'll fix on commit seeing as I'm doing a sweep right now.

~Andrew