From 5fa17f37fb6ec67843a02cfe42813b6b8a0191cf Mon Sep 17 00:00:00 2001 From: Moe Jette <jette1@llnl.gov> Date: Mon, 7 Oct 2002 19:05:30 +0000 Subject: [PATCH] Better descript size of I/O buffer header using #define. --- src/common/slurm_protocol_defs.h | 3 +++ src/common/slurm_protocol_pack.c | 2 ++ src/srun/io.c | 7 +++---- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/common/slurm_protocol_defs.h b/src/common/slurm_protocol_defs.h index a9d3cd273a7..f8cbffb8611 100644 --- a/src/common/slurm_protocol_defs.h +++ b/src/common/slurm_protocol_defs.h @@ -194,6 +194,9 @@ typedef struct slurm_protocol_header { uint32_t body_length; } header_t; +/* SLURM_IO_HEADER_SIZE is the packed data structure size, *\ +\* not necessarily sizeof(slurm_io_stream_header_t) */ +#define SLURM_IO_HEADER_SIZE (SLURM_SSL_SIGNATURE_LENGTH + 8) typedef struct slurm_io_stream_header { uint16_t version; /*version/magic number */ char key[SLURM_SSL_SIGNATURE_LENGTH]; diff --git a/src/common/slurm_protocol_pack.c b/src/common/slurm_protocol_pack.c index c4664630be4..dd84d556b42 100644 --- a/src/common/slurm_protocol_pack.c +++ b/src/common/slurm_protocol_pack.c @@ -76,6 +76,8 @@ void unpack_header ( header_t * header , Buf buffer ) unpack32 ( & header -> body_length , buffer ) ; } +/* SLURM_IO_HEADER_SIZE is the packed data structure size, *\ +\* not necessarily sizeof(slurm_io_stream_header_t) */ void pack_io_stream_header ( slurm_io_stream_header_t * msg , Buf buffer ) { uint32_t tmp=SLURM_SSL_SIGNATURE_LENGTH; diff --git a/src/srun/io.c b/src/srun/io.c index db764c44c79..1e254b7333f 100644 --- a/src/srun/io.c +++ b/src/srun/io.c @@ -281,7 +281,6 @@ _accept_io_stream(job_t *job, int i) int size = sizeof(addr); char buf[INET_ADDRSTRLEN]; slurm_io_stream_header_t hdr; - uint32_t len = sizeof(hdr) - 4; char *msgbuf; Buf buffer; @@ -298,9 +297,9 @@ _accept_io_stream(job_t *job, int i) sin = (struct sockaddr_in *) &addr; inet_ntop(AF_INET, &sin->sin_addr, buf, INET_ADDRSTRLEN); - msgbuf = xmalloc(len); - _readn(sd, msgbuf, len); - buffer = create_buf(msgbuf, len); + msgbuf = xmalloc(SLURM_IO_HEADER_SIZE); + _readn(sd, msgbuf, SLURM_IO_HEADER_SIZE); + buffer = create_buf(msgbuf, SLURM_IO_HEADER_SIZE); unpack_io_stream_header(&hdr, buffer); free_buf(buffer); /* NOTE: this frees msgbuf */ -- GitLab