From b7e38303089ea22944cc065f07750b0214cf93f1 Mon Sep 17 00:00:00 2001 From: Leanid Astrakou Date: Thu, 3 Aug 2023 16:29:11 -0400 Subject: [PATCH 1/6] Move WTO code from metal.c to zos.c Signed-off-by: Leanid Astrakou --- c/zos.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/c/zos.c b/c/zos.c index da926e628..dbff8b321 100644 --- a/c/zos.c +++ b/c/zos.c @@ -1469,6 +1469,87 @@ int safStat(int options, char *safClass, char *copy, int copyLength, int *racfSt get current TCB AC */ +/* begin WTO SECTION + +TODO(?): This is code duplication from metalio.c but the following works for LE & metal */ + +typedef struct WTO2Common31_tag{ + char replyBufferLength; /* 31-bit WTOR only, else 0 */ + char length; /* message length +4 */ + char mcsFlags1; + char mcsFlags2; +} WTO2Common31; + +void message(char *message){ + + ALLOC_STRUCT31( + STRUCT31_NAME(below2G), + STRUCT31_FIELDS( + WTO2Common31 common; + char text[126]; /* Maximum length of WTO text is 126 - ABEND D23-xxxx0005 if longer than 126 */ + ) + ); + + int len = strlen(message); + if (len>sizeof(below2G->text)) + len=sizeof(below2G->text); + + below2G->common.length = len+sizeof(below2G->common); /* +4 for header */ + memcpy(below2G->text,message,len); + + __asm(ASM_PREFIX + " WTO MF=(E,(%[wtobuf])) \n" + : + :[wtobuf]"NR:r1"(&below2G->common) + :"r0","r1","r15"); + + FREE_STRUCT31( + STRUCT31_NAME(below2G) + ); +} + +#define WTO_MAX_SIZE 126 +void wtoPrintf(char *formatString, ...){ + char text[WTO_MAX_SIZE+1]; /* Allow for trailing null character */ + va_list argPointer; + int cnt; + + for (int pass=0; pass<2; pass++){ + + /* The resulting text string from vsnprintf is unpredictable if + there is an error in the format string or arguments. In that + case we will set the output text area to null, repeat the + vsnprintf, and then find the length of the null terminated + string. This avoids initializing the output text area prior + to every successful request. + */ + + va_start(argPointer,formatString); + cnt = vsnprintf(text,sizeof(text),formatString,argPointer); + va_end(argPointer); + + if (cnt<0){ + if (pass==0) + memset(text,0,sizeof(text)); /* Clear the text buffer before retrying the vsnprint request */ + else { + text[WTO_MAX_SIZE] = 0; /* Ensure strlen stops at the end of the text buffer */ + cnt = strlen(text); /* Find the end of the text string */ + } + } else + break; /* vsnprintf did not return an error - cnt was set */ + } + if (cnt>WTO_MAX_SIZE) /* If more data to format than the text buffer length */ + cnt = WTO_MAX_SIZE; /* Truncate the formatted length to the text buffer length */ + + /* We never want to include a final \n character in the WTO text */ + + if (cnt>0 && text[cnt-1] == '\n') /* If text ends with \n */ + text[cnt-1] = 0; /* Change it into a null character */ + + message(text); +} + +/* end WTO SECTION */ /* LOCATE/CAMLIST */ From 52f3a4c84f5f3685d6e6ce74d17462c90f5cf21b Mon Sep 17 00:00:00 2001 From: Leanid Astrakou Date: Wed, 9 Aug 2023 12:38:05 -0400 Subject: [PATCH 2/6] Renaming methods Signed-off-by: Leanid Astrakou --- c/zos.c | 6 +++--- h/zos.h | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/c/zos.c b/c/zos.c index dbff8b321..9a7969012 100644 --- a/c/zos.c +++ b/c/zos.c @@ -1480,7 +1480,7 @@ typedef struct WTO2Common31_tag{ char mcsFlags2; } WTO2Common31; -void message(char *message){ +void message2(char *message){ ALLOC_STRUCT31( STRUCT31_NAME(below2G), @@ -1509,7 +1509,7 @@ void message(char *message){ } #define WTO_MAX_SIZE 126 -void wtoPrintf(char *formatString, ...){ +void wtoPrintfMetal(char *formatString, ...){ char text[WTO_MAX_SIZE+1]; /* Allow for trailing null character */ va_list argPointer; int cnt; @@ -1546,7 +1546,7 @@ void wtoPrintf(char *formatString, ...){ if (cnt>0 && text[cnt-1] == '\n') /* If text ends with \n */ text[cnt-1] = 0; /* Change it into a null character */ - message(text); + message2(text); } /* end WTO SECTION */ diff --git a/h/zos.h b/h/zos.h index b8b03a331..b43ef145e 100644 --- a/h/zos.h +++ b/h/zos.h @@ -1529,6 +1529,10 @@ DSAB *getDSAB(char *ddname); int dsabIsOMVS(DSAB *dsab); +void message2(char *message); + +void wtoPrintfMetal(char *formatString, ...); + int locate(char *dsn, int *volserCount, char *firstVolser); /* From 29a5560a76c06dd288cb4381c4802fc23dbd7ab0 Mon Sep 17 00:00:00 2001 From: Leanid Astrakou Date: Thu, 24 Aug 2023 04:54:35 -0400 Subject: [PATCH 3/6] Removed code duplication and added shim methods Signed-off-by: Leanid Astrakou --- c/metalio.c | 68 ++++++----------------------------------------------- c/zos.c | 2 +- h/zos.h | 2 +- 3 files changed, 9 insertions(+), 63 deletions(-) diff --git a/c/metalio.c b/c/metalio.c index 320651e0e..a0bc91ab8 100644 --- a/c/metalio.c +++ b/c/metalio.c @@ -378,30 +378,7 @@ SYSOUT *getSYSOUTStruct(char *ddname, SYSOUT *existingSysout, char *buffer){ */ void message(char *message){ - ALLOC_STRUCT31( - STRUCT31_NAME(below2G), - STRUCT31_FIELDS( - WTOCommon31 common; - char text[126]; /* Maximum length of WTO text is 126 - ABEND D23-xxxx0005 if longer than 126 */ - ) - ); - - int len = strlen(message); - if (len>sizeof(below2G->text)) - len=sizeof(below2G->text); - - below2G->common.length = len+sizeof(below2G->common); /* +4 for header */ - memcpy(below2G->text,message,len); - - __asm(ASM_PREFIX - " WTO MF=(E,(%[wtobuf])) \n" - : - :[wtobuf]"NR:r1"(&below2G->common) - :"r0","r1","r15"); - - FREE_STRUCT31( - STRUCT31_NAME(below2G) - ); + message2(message); } /* this can only be called from authorized callers */ @@ -485,44 +462,13 @@ void sendWTO(int descriptorCode, int routingCode, char *message, int length){ } #define WTO_MAX_SIZE 126 -void wtoPrintf(char *formatString, ...){ - char text[WTO_MAX_SIZE+1]; /* Allow for trailing null character */ +void wtoPrintf(char *formatString, ...) { va_list argPointer; - int cnt; - - for (int pass=0; pass<2; pass++){ - - /* The resulting text string from vsnprintf is unpredictable if - there is an error in the format string or arguments. In that - case we will set the output text area to null, repeat the - vsnprintf, and then find the length of the null terminated - string. This avoids initializing the output text area prior - to every successful request. - */ - - va_start(argPointer,formatString); - cnt = vsnprintf(text,sizeof(text),formatString,argPointer); - va_end(argPointer); - - if (cnt<0){ - if (pass==0) - memset(text,0,sizeof(text)); /* Clear the text buffer before retrying the vsnprint request */ - else { - text[WTO_MAX_SIZE] = 0; /* Ensure strlen stops at the end of the text buffer */ - cnt = strlen(text); /* Find the end of the text string */ - } - } else - break; /* vsnprintf did not return an error - cnt was set */ - } - if (cnt>WTO_MAX_SIZE) /* If more data to format than the text buffer length */ - cnt = WTO_MAX_SIZE; /* Truncate the formatted length to the text buffer length */ - - /* We never want to include a final \n character in the WTO text */ - - if (cnt>0 && text[cnt-1] == '\n') /* If text ends with \n */ - text[cnt-1] = 0; /* Change it into a null character */ - - message(text); + va_start(argPointer, formatString); + + wtoPrintf3(formatString, argPointer); + + va_end(argPointer); } void authWTOPrintf(char *formatString, ...){ diff --git a/c/zos.c b/c/zos.c index 9a7969012..12b631543 100644 --- a/c/zos.c +++ b/c/zos.c @@ -1509,7 +1509,7 @@ void message2(char *message){ } #define WTO_MAX_SIZE 126 -void wtoPrintfMetal(char *formatString, ...){ +void wtoPrintf3(char *formatString, ...) { char text[WTO_MAX_SIZE+1]; /* Allow for trailing null character */ va_list argPointer; int cnt; diff --git a/h/zos.h b/h/zos.h index b43ef145e..71819f9c5 100644 --- a/h/zos.h +++ b/h/zos.h @@ -1531,7 +1531,7 @@ int dsabIsOMVS(DSAB *dsab); void message2(char *message); -void wtoPrintfMetal(char *formatString, ...); +void wtoPrintf3(char *formatString, ...); int locate(char *dsn, int *volserCount, char *firstVolser); From 0d0fba4a99dbd958a076c4be545eb372fc12f010 Mon Sep 17 00:00:00 2001 From: Leanid Astrakou Date: Thu, 24 Aug 2023 05:32:30 -0400 Subject: [PATCH 4/6] Added CHANGELOG Signed-off-by: Leanid Astrakou --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c105de66e..e669afff5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Zowe Common C Changelog +## `2.11.0` + +- WTO printing methods have been moved to zos.c to be more available as utilities (for ex: for the Launcher) + ## `2.10.0` - Feature: The configmgr can now use the 'zos' module in YAML config templates. The 'zos' module is only added when run on ZOS. For a list of available functions, see https://github.com/zowe/zowe-install-packaging/blob/v2.x/staging/build/zwe/types/%40qjstypes/zos.d.ts (#384) From 8761e59d191c4e2ae67136b984be3535920c3323 Mon Sep 17 00:00:00 2001 From: Leanid Astrakou Date: Mon, 28 Aug 2023 14:32:36 -0400 Subject: [PATCH 5/6] Addressed more code review Signed-off-by: Leanid Astrakou --- c/metalio.c | 1 + c/zos.c | 13 ++----------- h/metalio.h | 7 ------- h/zos.h | 7 +++++++ 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/c/metalio.c b/c/metalio.c index a0bc91ab8..8cc0bca75 100644 --- a/c/metalio.c +++ b/c/metalio.c @@ -55,6 +55,7 @@ #include "qsam.h" #include "metalio.h" #include "alloc.h" +#include "zos.h" static int isopen(void * dcbptr) { diff --git a/c/zos.c b/c/zos.c index 12b631543..74923d87f 100644 --- a/c/zos.c +++ b/c/zos.c @@ -1469,23 +1469,14 @@ int safStat(int options, char *safClass, char *copy, int copyLength, int *racfSt get current TCB AC */ -/* begin WTO SECTION - -TODO(?): This is code duplication from metalio.c but the following works for LE & metal */ - -typedef struct WTO2Common31_tag{ - char replyBufferLength; /* 31-bit WTOR only, else 0 */ - char length; /* message length +4 */ - char mcsFlags1; - char mcsFlags2; -} WTO2Common31; +/* begin WTO SECTION */ void message2(char *message){ ALLOC_STRUCT31( STRUCT31_NAME(below2G), STRUCT31_FIELDS( - WTO2Common31 common; + WTOCommon31 common; char text[126]; /* Maximum length of WTO text is 126 - ABEND D23-xxxx0005 if longer than 126 */ ) ); diff --git a/h/metalio.h b/h/metalio.h index 7429f550a..cd78cbe53 100644 --- a/h/metalio.h +++ b/h/metalio.h @@ -70,13 +70,6 @@ typedef struct WTORPrefix31_tag{ char *replayECBAddress; } WTORPrefix31; -typedef struct WTOCommon31_tag{ - char replyBufferLength; /* 31-bit WTOR only, else 0 */ - char length; /* message length +4 */ - char mcsFlags1; - char mcsFlags2; -} WTOCommon31; - #define WTO_ROUTE_CODE_OPERATOR_ACTION 1 #define WTO_ROUTE_CODE_OPERATOR_INFORMATION 2 #define WTO_ROUTE_CODE_TAPE_POOL 3 diff --git a/h/zos.h b/h/zos.h index 71819f9c5..2e9a30f67 100644 --- a/h/zos.h +++ b/h/zos.h @@ -1522,6 +1522,13 @@ typedef struct IDTA_tag { char reserved[8]; } IDTA; +typedef struct WTOCommon31_tag{ + char replyBufferLength; /* 31-bit WTOR only, else 0 */ + char length; /* message length +4 */ + char mcsFlags1; + char mcsFlags2; +} WTOCommon31; + ZOWE_PRAGMA_PACK_RESET DSAB *getDSAB(char *ddname); From d0c1ce93c2658c47ca8a772aed309f49d99ac84a Mon Sep 17 00:00:00 2001 From: Leanid Astrakou Date: Tue, 29 Aug 2023 11:06:19 -0400 Subject: [PATCH 6/6] Better method name + better const usage Signed-off-by: Leanid Astrakou --- c/metalio.c | 2 +- c/zos.c | 6 +++--- h/zos.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/c/metalio.c b/c/metalio.c index 8cc0bca75..9b6c45edf 100644 --- a/c/metalio.c +++ b/c/metalio.c @@ -379,7 +379,7 @@ SYSOUT *getSYSOUTStruct(char *ddname, SYSOUT *existingSysout, char *buffer){ */ void message(char *message){ - message2(message); + wtoMessage(message); } /* this can only be called from authorized callers */ diff --git a/c/zos.c b/c/zos.c index 74923d87f..2a5879198 100644 --- a/c/zos.c +++ b/c/zos.c @@ -1471,7 +1471,7 @@ int safStat(int options, char *safClass, char *copy, int copyLength, int *racfSt /* begin WTO SECTION */ -void message2(char *message){ +void wtoMessage(const char *message){ ALLOC_STRUCT31( STRUCT31_NAME(below2G), @@ -1500,7 +1500,7 @@ void message2(char *message){ } #define WTO_MAX_SIZE 126 -void wtoPrintf3(char *formatString, ...) { +void wtoPrintf3(const char *formatString, ...) { char text[WTO_MAX_SIZE+1]; /* Allow for trailing null character */ va_list argPointer; int cnt; @@ -1537,7 +1537,7 @@ void wtoPrintf3(char *formatString, ...) { if (cnt>0 && text[cnt-1] == '\n') /* If text ends with \n */ text[cnt-1] = 0; /* Change it into a null character */ - message2(text); + wtoMessage(text); } /* end WTO SECTION */ diff --git a/h/zos.h b/h/zos.h index 2e9a30f67..1daba3f21 100644 --- a/h/zos.h +++ b/h/zos.h @@ -1536,9 +1536,9 @@ DSAB *getDSAB(char *ddname); int dsabIsOMVS(DSAB *dsab); -void message2(char *message); +void wtoMessage(const char *message); -void wtoPrintf3(char *formatString, ...); +void wtoPrintf3(const char *formatString, ...); int locate(char *dsn, int *volserCount, char *firstVolser);