Skip to content

Commit

Permalink
Merge pull request #391 from zowe/feature/wto-syslog
Browse files Browse the repository at this point in the history
Move WTO code from metal.c to zos.c + add shim
  • Loading branch information
1000TurquoisePogs authored Aug 29, 2023
2 parents de0e4fd + f055d1c commit 82f0d3c
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 68 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
69 changes: 8 additions & 61 deletions c/metalio.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "qsam.h"
#include "metalio.h"
#include "alloc.h"
#include "zos.h"

static int isopen(void * dcbptr) {

Expand Down Expand Up @@ -378,30 +379,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)
);
wtoMessage(message);
}

/* this can only be called from authorized callers */
Expand Down Expand Up @@ -485,44 +463,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, ...){
Expand Down
72 changes: 72 additions & 0 deletions c/zos.c
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,78 @@ int safStat(int options, char *safClass, char *copy, int copyLength, int *racfSt
get current TCB AC
*/

/* begin WTO SECTION */

void wtoMessage(const 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)
);
}

#define WTO_MAX_SIZE 126
void wtoPrintf3(const 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 */

wtoMessage(text);
}

/* end WTO SECTION */

/* LOCATE/CAMLIST */

Expand Down
7 changes: 0 additions & 7 deletions h/metalio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions h/zos.h
Original file line number Diff line number Diff line change
Expand Up @@ -1522,13 +1522,24 @@ 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);


int dsabIsOMVS(DSAB *dsab);

void wtoMessage(const char *message);

void wtoPrintf3(const char *formatString, ...);

int locate(char *dsn, int *volserCount, char *firstVolser);

/*
Expand Down

0 comments on commit 82f0d3c

Please sign in to comment.