diff options
author | Dana Robinson <43805+derobins@users.noreply.github.com> | 2023-07-27 18:20:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-27 18:20:47 (GMT) |
commit | aa9c06135979ee1415b41ea1bccc15524fbfca82 (patch) | |
tree | 40feffe7f98dca846bf40da5884b36aa9d89ac06 /utils | |
parent | 85fa6c27e7f6a5bbd342515e59d2f513044575b2 (diff) | |
download | hdf5-aa9c06135979ee1415b41ea1bccc15524fbfca82.zip hdf5-aa9c06135979ee1415b41ea1bccc15524fbfca82.tar.gz hdf5-aa9c06135979ee1415b41ea1bccc15524fbfca82.tar.bz2 |
Normalize mirror server code (#3289)
Diffstat (limited to 'utils')
-rw-r--r-- | utils/mirror_vfd/mirror_remote.c | 67 | ||||
-rw-r--r-- | utils/mirror_vfd/mirror_remote.h | 5 | ||||
-rw-r--r-- | utils/mirror_vfd/mirror_server.c | 131 | ||||
-rw-r--r-- | utils/mirror_vfd/mirror_server_stop.c | 62 | ||||
-rw-r--r-- | utils/mirror_vfd/mirror_writer.c | 99 |
5 files changed, 153 insertions, 211 deletions
diff --git a/utils/mirror_vfd/mirror_remote.c b/utils/mirror_vfd/mirror_remote.c index 170d61d..4f87c17 100644 --- a/utils/mirror_vfd/mirror_remote.c +++ b/utils/mirror_vfd/mirror_remote.c @@ -10,9 +10,8 @@ * help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* Common operations for "remote" processes for the Mirror VFD. - * - * Jacob Smith, 2020-03-06 +/* + * Common operations for "remote" processes for the mirror VFD */ #include "mirror_remote.h" @@ -31,28 +30,28 @@ mirror_log(struct mirror_log_info *info, unsigned int level, const char *format, { FILE *stream = MIRROR_LOG_DEFAULT_STREAM; unsigned int verbosity = MIRROR_LOG_DEFAULT_VERBOSITY; - hbool_t custom = FALSE; + bool custom = false; if (info != NULL && info->magic == MIRROR_LOG_INFO_MAGIC) { stream = info->stream; verbosity = info->verbosity; - custom = TRUE; + custom = true; } if (level == V_NONE) { return; } else if (level <= verbosity) { - if (custom == TRUE && info->prefix[0] != '\0') { - HDfprintf(stream, "%s", info->prefix); + if (custom == true && info->prefix[0] != '\0') { + fprintf(stream, "%s", info->prefix); } switch (level) { case (V_ERR): - HDfprintf(stream, "ERROR "); + fprintf(stream, "ERROR "); break; case (V_WARN): - HDfprintf(stream, "WARNING "); + fprintf(stream, "WARNING "); break; default: break; @@ -60,13 +59,13 @@ mirror_log(struct mirror_log_info *info, unsigned int level, const char *format, if (format != NULL) { va_list args; - HDva_start(args, format); + va_start(args, format); HDvfprintf(stream, format, args); - HDva_end(args); + va_end(args); } - HDfprintf(stream, "\n"); - HDfflush(stream); + fprintf(stream, "\n"); + fflush(stream); } /* end if sufficiently verbose to print */ } /* end mirror_log() */ @@ -99,41 +98,41 @@ mirror_log_bytes(struct mirror_log_info *info, unsigned int level, size_t n_byte /* print whole lines */ while ((n_bytes - bytes_written) >= 32) { b = buf + bytes_written; /* point to region in buffer */ - HDfprintf(stream, - "%04zX %02X%02X%02X%02X %02X%02X%02X%02X" - " %02X%02X%02X%02X %02X%02X%02X%02X" - " %02X%02X%02X%02X %02X%02X%02X%02X" - " %02X%02X%02X%02X %02X%02X%02X%02X\n", - bytes_written, b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], - b[12], b[13], b[14], b[15], b[16], b[17], b[18], b[19], b[20], b[21], b[22], b[23], - b[24], b[25], b[26], b[27], b[28], b[29], b[30], b[31]); + fprintf(stream, + "%04zX %02X%02X%02X%02X %02X%02X%02X%02X" + " %02X%02X%02X%02X %02X%02X%02X%02X" + " %02X%02X%02X%02X %02X%02X%02X%02X" + " %02X%02X%02X%02X %02X%02X%02X%02X\n", + bytes_written, b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], + b[12], b[13], b[14], b[15], b[16], b[17], b[18], b[19], b[20], b[21], b[22], b[23], b[24], + b[25], b[26], b[27], b[28], b[29], b[30], b[31]); bytes_written += 32; } /* start partial line */ if (n_bytes > bytes_written) { - HDfprintf(stream, "%04zX ", bytes_written); + fprintf(stream, "%04zX ", bytes_written); } /* partial line blocks */ while ((n_bytes - bytes_written) >= 4) { - HDfprintf(stream, " %02X%02X%02X%02X", buf[bytes_written], buf[bytes_written + 1], - buf[bytes_written + 2], buf[bytes_written + 3]); + fprintf(stream, " %02X%02X%02X%02X", buf[bytes_written], buf[bytes_written + 1], + buf[bytes_written + 2], buf[bytes_written + 3]); bytes_written += 4; } /* block separator before partial block */ if (n_bytes > bytes_written) { - HDfprintf(stream, " "); + fprintf(stream, " "); } /* partial block individual bytes */ while (n_bytes > bytes_written) { - HDfprintf(stream, "%02X", buf[bytes_written++]); + fprintf(stream, "%02X", buf[bytes_written++]); } /* end partial line */ - HDfprintf(stream, "\n"); + fprintf(stream, "\n"); } /* end if suitably verbose to log */ } /* end mirror_log_bytes() */ @@ -151,7 +150,7 @@ mirror_log_init(char *path, const char *prefix, unsigned int verbosity) { loginfo_t *info = NULL; - info = (loginfo_t *)HDmalloc(sizeof(loginfo_t)); + info = (loginfo_t *)malloc(sizeof(loginfo_t)); if (info != NULL) { info->magic = MIRROR_LOG_INFO_MAGIC; info->verbosity = verbosity; @@ -164,12 +163,12 @@ mirror_log_init(char *path, const char *prefix, unsigned int verbosity) if (path && *path) { FILE *f = NULL; - f = HDfopen(path, "w"); + f = fopen(path, "w"); if (NULL == f) { - HDfprintf(MIRROR_LOG_DEFAULT_STREAM, "WARN custom logging path could not be opened: %s\n", - path); + fprintf(MIRROR_LOG_DEFAULT_STREAM, "WARN custom logging path could not be opened: %s\n", + path); info->magic += 1; - HDfree(info); + free(info); } else { info->stream = f; @@ -197,12 +196,12 @@ mirror_log_term(loginfo_t *info) return FAIL; } if (info->stream != stderr || info->stream != stdout) { - if (HDfclose(info->stream) < 0) { + if (fclose(info->stream) < 0) { return FAIL; } } info->magic += 1; - HDfree(info); + free(info); return SUCCEED; } /* end mirror_log_term() */ diff --git a/utils/mirror_vfd/mirror_remote.h b/utils/mirror_vfd/mirror_remote.h index 02cf41b..00a09b0 100644 --- a/utils/mirror_vfd/mirror_remote.h +++ b/utils/mirror_vfd/mirror_remote.h @@ -10,9 +10,8 @@ * help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* Common definitions for "remote" processes for the Mirror VFD. - * - * Jacob Smith, 2020-03-06 +/* + * Common definitions for "remote" processes for the mirror VFD */ #include "hdf5.h" diff --git a/utils/mirror_vfd/mirror_server.c b/utils/mirror_vfd/mirror_server.c index 79c9d80..3bf075a 100644 --- a/utils/mirror_vfd/mirror_server.c +++ b/utils/mirror_vfd/mirror_server.c @@ -131,27 +131,6 @@ struct server_run { }; /* --------------------------------------------------------------------------- - * Function: mybzero - * - * Purpose: Introduce bzero without neededing it on the system. - * - * Programmer: Jacob Smith - * 2020-03-30 - * --------------------------------------------------------------------------- - */ -static void -mybzero(void *dest, size_t size) -{ - size_t i = 0; - char *s = NULL; - HDassert(dest); - s = (char *)dest; - for (i = 0; i < size; i++) { - *(s + i) = 0; - } -} /* end mybzero() */ - -/* --------------------------------------------------------------------------- * Function: usage * * Purpose: Print the usage message to stdout. @@ -160,22 +139,22 @@ mybzero(void *dest, size_t size) static void usage(void) { - HDfprintf(stdout, - "mirror_server [options]\n" - "\n" - "Application for providing Mirror Writer process to " - " Mirror VFD on file-open.\n" - "Listens on a dedicated socket; forks as a Writer upon receipt" - " of a valid OPEN xmit.\n" - "\n" - "Options:\n" - "--help [-h] : Print this help message and quit.\n" - "--logpath=PATH : File path for logging output " - "(default none, to stdout).\n" - "--port=PORT : Primary port (default %d).\n" - "--verbosity=NUM : Debug printing level " - "0..4, (default %d).\n", - DEFAULT_PORT, MIRROR_LOG_DEFAULT_VERBOSITY); + fprintf(stdout, + "mirror_server [options]\n" + "\n" + "Application for providing Mirror Writer process to " + " Mirror VFD on file-open.\n" + "Listens on a dedicated socket; forks as a Writer upon receipt" + " of a valid OPEN xmit.\n" + "\n" + "Options:\n" + "--help [-h] : Print this help message and quit.\n" + "--logpath=PATH : File path for logging output " + "(default none, to stdout).\n" + "--port=PORT : Primary port (default %d).\n" + "--verbosity=NUM : Debug printing level " + "0..4, (default %d).\n", + DEFAULT_PORT, MIRROR_LOG_DEFAULT_VERBOSITY); } /* end usage() */ /* --------------------------------------------------------------------------- @@ -190,18 +169,16 @@ usage(void) static int parse_args(int argc, char **argv, struct op_args *args_out) { - int i; - - /* preset default values - */ + /* Preset default values */ args_out->main_port = DEFAULT_PORT; args_out->help = 0; args_out->log_prepend_serv = 1; args_out->log_prepend_type = 1; args_out->verbosity = MIRROR_LOG_DEFAULT_VERBOSITY; - /* preset empty strings */ - mybzero(args_out->log_path, PATH_MAX + 1); - mybzero(args_out->writer_log_path, PATH_MAX + 1); + + /* Preset empty strings */ + memset(args_out->log_path, 0, PATH_MAX + 1); + memset(args_out->writer_log_path, 0, PATH_MAX + 1); if (argv == NULL || *argv == NULL) { mirror_log(NULL, V_ERR, "invalid argv pointer"); @@ -209,7 +186,7 @@ parse_args(int argc, char **argv, struct op_args *args_out) } /* Loop over arguments after program name */ - for (i = 1; i < argc; i++) { + for (int i = 1; i < argc; i++) { if (!HDstrncmp(argv[i], "-h", 3) || !HDstrncmp(argv[i], "--help", 7)) { mirror_log(NULL, V_INFO, "found help argument"); args_out->help = 1; @@ -217,11 +194,11 @@ parse_args(int argc, char **argv, struct op_args *args_out) } /* end if help */ else if (!HDstrncmp(argv[i], "--port=", 7)) { mirror_log(NULL, V_INFO, "parsing 'main_port' (%s)", argv[i] + 7); - args_out->main_port = HDatoi(argv[i] + 7); + args_out->main_port = atoi(argv[i] + 7); } /* end if port */ else if (!HDstrncmp(argv[i], "--verbosity=", 12)) { mirror_log(NULL, V_INFO, "parsing 'verbosity' (%s)", argv[i] + 12); - args_out->verbosity = (unsigned int)HDatoi(argv[i] + 12); + args_out->verbosity = (unsigned int)atoi(argv[i] + 12); } /* end if verbosity */ else if (!HDstrncmp(argv[i], "--logpath=", 10)) { mirror_log(NULL, V_INFO, "parsing 'logpath' (%s)", argv[i] + 10); @@ -264,28 +241,28 @@ prepare_listening_socket(struct server_run *run) mirror_log(run->loginfo, V_INFO, "preparing socket"); server_addr.sin_family = AF_INET; - server_addr.sin_addr.s_addr = HDhtonl(INADDR_ANY); - server_addr.sin_port = HDhtons((uint16_t)run->opts.main_port); + server_addr.sin_addr.s_addr = htonl(INADDR_ANY); + server_addr.sin_port = htons((uint16_t)run->opts.main_port); mirror_log(run->loginfo, V_INFO, "socket()"); - ret_value = HDsocket(AF_INET, SOCK_STREAM, 0); + ret_value = socket(AF_INET, SOCK_STREAM, 0); if (ret_value < 0) { mirror_log(run->loginfo, V_ERR, "listening socket:%d", ret_value); goto error; } mirror_log(run->loginfo, V_ALL, "setsockopt()"); - HDsetsockopt(ret_value, SOL_SOCKET, SO_REUSEADDR, &_true, sizeof(int)); + setsockopt(ret_value, SOL_SOCKET, SO_REUSEADDR, &_true, sizeof(int)); mirror_log(run->loginfo, V_INFO, "bind()"); - ret = HDbind(ret_value, (struct sockaddr *)&server_addr, sizeof(server_addr)); + ret = bind(ret_value, (struct sockaddr *)&server_addr, sizeof(server_addr)); if (ret < 0) { mirror_log(run->loginfo, V_ERR, "bind() %s", HDstrerror(errno)); goto error; } mirror_log(run->loginfo, V_INFO, "listen()"); - ret = HDlisten(ret_value, LISTENQ); + ret = listen(ret_value, LISTENQ); if (ret < 0) { mirror_log(run->loginfo, V_ERR, "H5FD server listen:%d", ret); goto error; @@ -314,7 +291,7 @@ init_server_run(int argc, char **argv) { struct server_run *run; - run = (struct server_run *)HDmalloc(sizeof(struct server_run)); + run = (struct server_run *)malloc(sizeof(struct server_run)); if (run == NULL) { mirror_log(NULL, V_ERR, "can't allocate server_run struct"); return NULL; @@ -347,7 +324,7 @@ init_server_run(int argc, char **argv) error: if (run != NULL) { - HDfree(run); + free(run); } return NULL; @@ -385,7 +362,7 @@ term_server_run(struct server_run *run) (run->magic)++; (run->opts.magic)++; - HDfree(run); + free(run); return 0; } /* end term_server_run() */ @@ -415,7 +392,7 @@ accept_connection(struct server_run *run) /*------------------------------*/ /* accept a connection on a socket */ clilen = sizeof(client_addr); - connfd = HDaccept(run->listenfd, (struct sockaddr *)&client_addr, &clilen); + connfd = accept(run->listenfd, (struct sockaddr *)&client_addr, &clilen); if (connfd < 0) { mirror_log(run->loginfo, V_ERR, "accept:%d", connfd); goto error; @@ -424,15 +401,15 @@ accept_connection(struct server_run *run) /*------------------------------*/ /* get client address information */ - host_port = HDgethostbyaddr((const char *)&client_addr.sin_addr.s_addr, - sizeof(client_addr.sin_addr.s_addr), AF_INET); + host_port = gethostbyaddr((const char *)&client_addr.sin_addr.s_addr, sizeof(client_addr.sin_addr.s_addr), + AF_INET); if (host_port == NULL) { mirror_log(run->loginfo, V_ERR, "gethostbyaddr()"); goto error; } /* function has the string space statically scoped -- OK until next call */ - hostaddrp = HDinet_ntoa(client_addr.sin_addr); + hostaddrp = inet_ntoa(client_addr.sin_addr); /* TODO? proper error-checking */ mirror_log(run->loginfo, V_INFO, "server connected with %s (%s)", host_port->h_name, hostaddrp); @@ -455,7 +432,7 @@ error: static void wait_for_child(int H5_ATTR_UNUSED sig) { - while (HDwaitpid(-1, NULL, WNOHANG) > 0) + while (waitpid(-1, NULL, WNOHANG) > 0) ; } /* end wait_for_child() */ @@ -502,11 +479,11 @@ handle_requests(struct server_run *run) return 1; } - if (NULL == (mybuf = HDmalloc(H5FD_MIRROR_XMIT_OPEN_SIZE * sizeof(char)))) { + if (NULL == (mybuf = malloc(H5FD_MIRROR_XMIT_OPEN_SIZE * sizeof(char)))) { mirror_log(NULL, V_ERR, "out of memory"); goto error; } - if (NULL == (xopen = HDmalloc(sizeof(H5FD_mirror_xmit_open_t)))) { + if (NULL == (xopen = malloc(sizeof(H5FD_mirror_xmit_open_t)))) { mirror_log(NULL, V_ERR, "out of memory"); goto error; } @@ -569,7 +546,7 @@ handle_requests(struct server_run *run) mirror_log(run->loginfo, V_INFO, "probable OPEN xmit received"); H5FD_mirror_xmit_decode_open(xopen, (const unsigned char *)mybuf); - if (FALSE == H5FD_mirror_xmit_is_open(xopen)) { + if (false == H5FD_mirror_xmit_is_open(xopen)) { mirror_log(run->loginfo, V_WARN, "expected OPEN xmit was malformed"); HDclose(connfd); continue; @@ -577,7 +554,7 @@ handle_requests(struct server_run *run) mirror_log(run->loginfo, V_INFO, "probable OPEN xmit confirmed"); - pid = HDfork(); + pid = fork(); if (pid < 0) { /* fork error */ mirror_log(run->loginfo, V_ERR, "cannot fork"); goto error; @@ -585,14 +562,14 @@ handle_requests(struct server_run *run) else if (pid == 0) { /* child process (writer side of fork) */ mirror_log(run->loginfo, V_INFO, "executing writer"); if (run_writer(connfd, xopen) < 0) { - HDprintf("can't run writer\n"); + printf("can't run writer\n"); } else { - HDprintf("writer OK\n"); + printf("writer OK\n"); } HDclose(connfd); - HDexit(EXIT_SUCCESS); + exit(EXIT_SUCCESS); } /* end if writer side of fork */ else { /* parent process (server side of fork) */ mirror_log(run->loginfo, V_INFO, "tidying up from handshake"); @@ -614,8 +591,8 @@ done: HDclose(connfd); } - HDfree(mybuf); - HDfree(xopen); + free(mybuf); + free(xopen); return ret_value; @@ -623,8 +600,8 @@ error: if (connfd >= 0) { HDclose(connfd); } - HDfree(mybuf); - HDfree(xopen); + free(mybuf); + free(xopen); return -1; } /* end handle_requests() */ @@ -637,7 +614,7 @@ main(int argc, char **argv) run = init_server_run(argc, argv); if (NULL == run) { mirror_log(NULL, V_ERR, "can't initialize run"); - HDexit(EXIT_FAILURE); + exit(EXIT_FAILURE); } if (handle_requests(run) < 0) { @@ -646,10 +623,10 @@ main(int argc, char **argv) if (term_server_run(run) < 0) { mirror_log(NULL, V_ERR, "problem closing server run"); - HDexit(EXIT_FAILURE); + exit(EXIT_FAILURE); } - HDexit(EXIT_SUCCESS); + exit(EXIT_SUCCESS); } /* end main() */ #else /* H5_HAVE_MIRROR_VFD */ @@ -657,8 +634,8 @@ main(int argc, char **argv) int main(void) { - HDprintf("Mirror VFD was not built -- cannot launch server.\n"); - HDexit(EXIT_FAILURE); + printf("Mirror VFD was not built -- cannot launch server.\n"); + exit(EXIT_FAILURE); } #endif /* H5_HAVE_MIRROR_VFD */ diff --git a/utils/mirror_vfd/mirror_server_stop.c b/utils/mirror_vfd/mirror_server_stop.c index 44386bf..52dea08 100644 --- a/utils/mirror_vfd/mirror_server_stop.c +++ b/utils/mirror_vfd/mirror_server_stop.c @@ -60,15 +60,15 @@ struct mshs_opts { static void usage(void) { - HDprintf("mirror_server_stop [options]\n" - "System-independent Mirror Server shutdown program.\n" - "Sends shutdown message to Mirror Server at given IP:port\n" - "\n" - "Options:\n" - " -h | --help Print this usage message and exit.\n" - " --ip=ADDR IP Address of remote server (default %s)\n" - " --port=PORT Handshake port of remote server (default %d)\n", - MSHS_DEFAULT_IP, MSHS_DEFAULT_PORTNO); + printf("mirror_server_stop [options]\n" + "System-independent Mirror Server shutdown program.\n" + "Sends shutdown message to Mirror Server at given IP:port\n" + "\n" + "Options:\n" + " -h | --help Print this usage message and exit.\n" + " --ip=ADDR IP Address of remote server (default %s)\n" + " --port=PORT Handshake port of remote server (default %d)\n", + MSHS_DEFAULT_IP, MSHS_DEFAULT_PORTNO); } /* end usage() */ /* ---------------------------------------------------------------------------- @@ -99,10 +99,10 @@ parse_args(int argc, char **argv, struct mshs_opts *opts) HDstrncpy(opts->ip, argv[i] + 5, MSHS_IP_STR_SIZE); } else if (!HDstrncmp(argv[i], "--port=", 7)) { - opts->portno = HDatoi(argv[i] + 7); + opts->portno = atoi(argv[i] + 7); } else { - HDprintf("Unrecognized option: '%s'\n", argv[i]); + printf("Unrecognized option: '%s'\n", argv[i]); usage(); opts->magic++; /* invalidate for sanity */ return -1; @@ -133,43 +133,43 @@ send_shutdown(struct mshs_opts *opts) struct sockaddr_in target_addr; if (opts->magic != MSHS_OPTS_MAGIC) { - HDprintf("invalid options structure\n"); + printf("invalid options structure\n"); return -1; } - live_socket = HDsocket(AF_INET, SOCK_STREAM, 0); + live_socket = socket(AF_INET, SOCK_STREAM, 0); if (live_socket < 0) { - HDprintf("ERROR socket()\n"); + printf("ERROR socket()\n"); return -1; } target_addr.sin_family = AF_INET; - target_addr.sin_port = HDhtons((uint16_t)opts->portno); - target_addr.sin_addr.s_addr = HDinet_addr(opts->ip); - HDmemset(target_addr.sin_zero, '\0', sizeof(target_addr.sin_zero)); + target_addr.sin_port = htons((uint16_t)opts->portno); + target_addr.sin_addr.s_addr = inet_addr(opts->ip); + memset(target_addr.sin_zero, 0, sizeof(target_addr.sin_zero)); - if (HDconnect(live_socket, (struct sockaddr *)&target_addr, (socklen_t)sizeof(target_addr)) < 0) { - HDprintf("ERROR connect() (%d)\n%s\n", errno, HDstrerror(errno)); + if (connect(live_socket, (struct sockaddr *)&target_addr, (socklen_t)sizeof(target_addr)) < 0) { + printf("ERROR connect() (%d)\n%s\n", errno, HDstrerror(errno)); return -1; } if (HDwrite(live_socket, "SHUTDOWN", 9) == -1) { - HDprintf("ERROR write() (%d)\n%s\n", errno, HDstrerror(errno)); + printf("ERROR write() (%d)\n%s\n", errno, HDstrerror(errno)); return -1; } /* Read & verify response from port connection. */ if (HDread(live_socket, &mybuf, sizeof(mybuf)) == -1) { - HDprintf("ERROR read() can't receive data\n"); + printf("ERROR read() can't receive data\n"); return -1; } if (HDstrncmp("CLOSING", mybuf, 8)) { - HDprintf("ERROR read() didn't receive data from server\n"); + printf("ERROR read() didn't receive data from server\n"); return -1; } if (HDclose(live_socket) < 0) { - HDprintf("ERROR close() can't close socket\n"); + printf("ERROR close() can't close socket\n"); return -1; } @@ -183,21 +183,21 @@ main(int argc, char **argv) struct mshs_opts opts; if (parse_args(argc, argv, &opts) < 0) { - HDprintf("Unable to parse arguments\n"); - HDexit(EXIT_FAILURE); + printf("Unable to parse arguments\n"); + exit(EXIT_FAILURE); } if (opts.help) { usage(); - HDexit(EXIT_FAILURE); + exit(EXIT_FAILURE); } if (send_shutdown(&opts) < 0) { - HDprintf("Unable to send shutdown command\n"); - HDexit(EXIT_FAILURE); + printf("Unable to send shutdown command\n"); + exit(EXIT_FAILURE); } - HDexit(EXIT_SUCCESS); + exit(EXIT_SUCCESS); } /* end main() */ #else /* H5_HAVE_MIRROR_VFD */ @@ -206,8 +206,8 @@ main(int argc, char **argv) int main(void) { - HDprintf("Mirror VFD not built -- unable to perform shutdown.\n"); - HDexit(EXIT_FAILURE); + printf("Mirror VFD not built -- unable to perform shutdown.\n"); + exit(EXIT_FAILURE); } #endif /* H5_HAVE_MIRROR_VFD */ diff --git a/utils/mirror_vfd/mirror_writer.c b/utils/mirror_vfd/mirror_writer.c index ad7cd91..2acc166 100644 --- a/utils/mirror_vfd/mirror_writer.c +++ b/utils/mirror_vfd/mirror_writer.c @@ -154,32 +154,9 @@ struct mirror_writer_opts { char *logpath; }; -static void mybzero(void *dest, size_t size); - static int do_open(struct mirror_session *session, const H5FD_mirror_xmit_open_t *xmit_open); /* --------------------------------------------------------------------------- - * Function: mybzero - * - * Purpose: Introduce bzero without neededing it on the system. - * - * Programmer: Jacob Smith - * 2020-03-30 - * --------------------------------------------------------------------------- - */ -static void -mybzero(void *dest, size_t size) -{ - size_t i = 0; - char *s = NULL; - HDassert(dest); - s = (char *)dest; - for (i = 0; i < size; i++) { - *(s + i) = 0; - } -} /* end mybzero() */ - -/* --------------------------------------------------------------------------- * Function: session_init * * Purpose: Populate mirror_session structure with default and @@ -201,7 +178,7 @@ session_init(struct mirror_writer_opts *opts) goto error; } - session = (struct mirror_session *)HDmalloc(sizeof(struct mirror_session)); + session = (struct mirror_session *)malloc(sizeof(struct mirror_session)); if (session == NULL) { mirror_log(NULL, V_ERR, "can't allocate session structure"); goto error; @@ -217,10 +194,9 @@ session_init(struct mirror_writer_opts *opts) session->reply.pub.version = H5FD_MIRROR_XMIT_CURR_VERSION; session->reply.pub.op = H5FD_MIRROR_OP_REPLY; session->reply.pub.session_token = 0; - mybzero(session->reply.message, H5FD_MIRROR_STATUS_MESSAGE_MAX); + memset(session->reply.message, 0, H5FD_MIRROR_STATUS_MESSAGE_MAX); - /* Options-derived population - */ + /* Options-derived population */ session->loginfo = mirror_log_init(opts->logpath, "W- ", MIRROR_LOG_DEFAULT_VERBOSITY); @@ -228,7 +204,7 @@ session_init(struct mirror_writer_opts *opts) error: if (session) { - HDfree(session); + free(session); } return NULL; } /* end session_init() */ @@ -247,7 +223,7 @@ session_stop(struct mirror_session *session) { int ret_value = 0; - HDassert(session && (session->magic == MW_SESSION_MAGIC)); + assert(session && (session->magic == MW_SESSION_MAGIC)); mirror_log(session->loginfo, V_INFO, "session_stop()"); @@ -271,7 +247,7 @@ session_stop(struct mirror_session *session) /* Invalidate and release structure */ session->magic++; - HDfree(session); + free(session); return ret_value; } /* end session_stop() */ @@ -291,25 +267,16 @@ session_start(int socketfd, const H5FD_mirror_xmit_open_t *xmit_open) { struct mirror_session *session = NULL; struct mirror_writer_opts opts; -#if 0 /* TODO: behavior option */ - char logpath[H5FD_MIRROR_XMIT_FILEPATH_MAX] = ""; -#endif mirror_log(NULL, V_INFO, "session_start()"); - if (FALSE == H5FD_mirror_xmit_is_open(xmit_open)) { + if (false == H5FD_mirror_xmit_is_open(xmit_open)) { mirror_log(NULL, V_ERR, "invalid OPEN xmit"); return NULL; } - opts.magic = MW_OPTS_MAGIC; -#if 0 /* TODO: behavior option */ - HDsnprintf(logpath, H5FD_MIRROR_XMIT_FILEPATH_MAX, "%s.log", - xmit_open->filename); - opts.logpath = logpath; -#else + opts.magic = MW_OPTS_MAGIC; opts.logpath = NULL; -#endif session = session_init(&opts); if (NULL == session) { @@ -350,7 +317,7 @@ _xmit_reply(struct mirror_session *session) unsigned char xmit_buf[H5FD_MIRROR_XMIT_REPLY_SIZE]; H5FD_mirror_xmit_reply_t *reply = &(session->reply); - HDassert(session && (session->magic == MW_SESSION_MAGIC)); + assert(session && (session->magic == MW_SESSION_MAGIC)); mirror_log(session->loginfo, V_ALL, "_xmit_reply()"); @@ -386,12 +353,12 @@ reply_ok(struct mirror_session *session) { H5FD_mirror_xmit_reply_t *reply = &(session->reply); - HDassert(session && (session->magic == MW_SESSION_MAGIC)); + assert(session && (session->magic == MW_SESSION_MAGIC)); mirror_log(session->loginfo, V_ALL, "reply_ok()"); reply->status = H5FD_MIRROR_STATUS_OK; - mybzero(reply->message, H5FD_MIRROR_STATUS_MESSAGE_MAX); + memset(reply->message, 0, H5FD_MIRROR_STATUS_MESSAGE_MAX); return _xmit_reply(session); } /* end reply_ok() */ @@ -410,7 +377,7 @@ reply_error(struct mirror_session *session, const char *msg) { H5FD_mirror_xmit_reply_t *reply = &(session->reply); - HDassert(session && (session->magic == MW_SESSION_MAGIC)); + assert(session && (session->magic == MW_SESSION_MAGIC)); mirror_log(session->loginfo, V_ALL, "reply_error(%s)", msg); @@ -431,7 +398,7 @@ static int do_close(struct mirror_session *session) { - HDassert(session && (session->magic == MW_SESSION_MAGIC)); + assert(session && (session->magic == MW_SESSION_MAGIC)); mirror_log(session->loginfo, V_INFO, "do_close()"); @@ -471,7 +438,7 @@ do_lock(struct mirror_session *session, const unsigned char *xmit_buf) size_t decode_ret = 0; H5FD_mirror_xmit_lock_t xmit_lock; - HDassert(session && (session->magic == MW_SESSION_MAGIC) && xmit_buf); + assert(session && (session->magic == MW_SESSION_MAGIC) && xmit_buf); mirror_log(session->loginfo, V_INFO, "do_lock()"); @@ -489,7 +456,7 @@ do_lock(struct mirror_session *session, const unsigned char *xmit_buf) } mirror_log(session->loginfo, V_INFO, "lock rw: (%d)", xmit_lock.rw); - if (H5FDlock(session->file, (hbool_t)xmit_lock.rw) < 0) { + if (H5FDlock(session->file, (bool)xmit_lock.rw) < 0) { mirror_log(session->loginfo, V_ERR, "H5FDlock()"); reply_error(session, "remote H5FDlock() failure"); return -1; @@ -519,8 +486,8 @@ do_open(struct mirror_session *session, const H5FD_mirror_xmit_open_t *xmit_open unsigned _flags = 0; haddr_t _maxaddr = HADDR_UNDEF; - HDassert(session && (session->magic == MW_SESSION_MAGIC) && xmit_open && - TRUE == H5FD_mirror_xmit_is_open(xmit_open)); + assert(session && (session->magic == MW_SESSION_MAGIC) && xmit_open && + true == H5FD_mirror_xmit_is_open(xmit_open)); mirror_log(session->loginfo, V_INFO, "do_open()"); @@ -595,7 +562,7 @@ error: { (void)H5Pclose(fapl_id); } - H5E_END_TRY; + H5E_END_TRY } return -1; } /* end do_open() */ @@ -614,7 +581,7 @@ do_set_eoa(struct mirror_session *session, const unsigned char *xmit_buf) size_t decode_ret = 0; H5FD_mirror_xmit_eoa_t xmit_seoa; - HDassert(session && (session->magic == MW_SESSION_MAGIC) && xmit_buf); + assert(session && (session->magic == MW_SESSION_MAGIC) && xmit_buf); mirror_log(session->loginfo, V_INFO, "do_set_eoa()"); @@ -660,11 +627,11 @@ static int do_truncate(struct mirror_session *session) { - HDassert(session && (session->magic == MW_SESSION_MAGIC)); + assert(session && (session->magic == MW_SESSION_MAGIC)); mirror_log(session->loginfo, V_INFO, "do_truncate()"); - /* default DXPL ID (0), 0 for "FALSE" closing -- both probably unused */ + /* default DXPL ID (0), 0 for "false" closing -- both probably unused */ if (H5FDtruncate(session->file, 0, 0) < 0) { mirror_log(session->loginfo, V_ERR, "H5FDtruncate()"); reply_error(session, "remote H5FDtruncate() failure"); @@ -691,7 +658,7 @@ do_truncate(struct mirror_session *session) static int do_unlock(struct mirror_session *session) { - HDassert(session && (session->magic == MW_SESSION_MAGIC)); + assert(session && (session->magic == MW_SESSION_MAGIC)); mirror_log(session->loginfo, V_INFO, "do_unlock()"); @@ -735,7 +702,7 @@ do_write(struct mirror_session *session, const unsigned char *xmit_buf) ssize_t nbytes_in_packet = 0; H5FD_mirror_xmit_write_t xmit_write; - HDassert(session && (session->magic == MW_SESSION_MAGIC) && xmit_buf); + assert(session && (session->magic == MW_SESSION_MAGIC) && xmit_buf); mirror_log(session->loginfo, V_INFO, "do_write()"); @@ -763,7 +730,7 @@ do_write(struct mirror_session *session, const unsigned char *xmit_buf) /* Allocate the buffer once -- re-use between loops. */ - buf = (char *)HDmalloc(sizeof(char) * H5FD_MIRROR_DATA_BUFFER_MAX); + buf = (char *)malloc(sizeof(char) * H5FD_MIRROR_DATA_BUFFER_MAX); if (NULL == buf) { mirror_log(session->loginfo, V_ERR, "can't allocate databuffer"); reply_error(session, "can't allocate buffer for receiving data"); @@ -815,7 +782,7 @@ do_write(struct mirror_session *session, const unsigned char *xmit_buf) } while (sum_bytes_written < xmit_write.size); /* end while ingesting */ - HDfree(buf); + free(buf); /* signal that we're done here and a-ok */ if (reply_ok(session) < 0) { @@ -847,13 +814,13 @@ receive_communique(struct mirror_session *session, struct sock_comm *comm) size_t decode_ret; H5FD_mirror_xmit_t *X = comm->xmit_recd; - HDassert((session != NULL) && (session->magic == MW_SESSION_MAGIC) && (comm != NULL) && - (comm->magic == MW_SOCK_COMM_MAGIC) && (comm->xmit_recd != NULL) && (comm->raw != NULL) && - (comm->raw_size >= H5FD_MIRROR_XMIT_BUFFER_MAX)); + assert((session != NULL) && (session->magic == MW_SESSION_MAGIC) && (comm != NULL) && + (comm->magic == MW_SOCK_COMM_MAGIC) && (comm->xmit_recd != NULL) && (comm->raw != NULL) && + (comm->raw_size >= H5FD_MIRROR_XMIT_BUFFER_MAX)); mirror_log(session->loginfo, V_INFO, "receive_communique()"); - mybzero(comm->raw, comm->raw_size); + memset(comm->raw, 0, comm->raw_size); comm->recd_die = 0; mirror_log(session->loginfo, V_INFO, "ready to receive"); /* TODO */ @@ -933,13 +900,13 @@ process_instructions(struct mirror_session *session) size_t buf_size; H5FD_mirror_xmit_t xmit_recd; /* for decoded xmit header */ - HDassert(session && (session->magic == MW_SESSION_MAGIC)); + assert(session && (session->magic == MW_SESSION_MAGIC)); mirror_log(session->loginfo, V_INFO, "process_instructions()"); buf_size = H5FD_MIRROR_XMIT_BUFFER_MAX * sizeof(char); - if (NULL == (xmit_buf = HDmalloc(buf_size))) { + if (NULL == (xmit_buf = malloc(buf_size))) { mirror_log(session->loginfo, V_ERR, "out of memory"); goto error; } @@ -1008,11 +975,11 @@ process_instructions(struct mirror_session *session) done: comm.magic = 0; /* invalidate structure, on principle */ xmit_recd.magic = 0; /* invalidate structure, on principle */ - HDfree(xmit_buf); + free(xmit_buf); return 0; error: - HDfree(xmit_buf); + free(xmit_buf); return -1; } /* end process_instructions() */ |