Commit f445a5cc authored by Pavan Balaji's avatar Pavan Balaji
Browse files

[svn-r4087] Converted the error checks to the MPICH2 style check-and-pop macros.

parent eb12895b
......@@ -41,10 +41,7 @@ HYD_Status HYD_BSCD_fork_launch_procs(void)
* for everyone else, it's NULL. */
status = HYDU_Create_process(client_arg, (process_id == 0 ? &handle.in : NULL),
&partition->out, &partition->err, &partition->pid);
if (status != HYD_SUCCESS) {
HYDU_Error_printf("bootstrap spawn process returned error\n");
goto fn_fail;
}
HYDU_ERR_POP(status, "create process returned error\n");
for (arg = 0; client_arg[arg]; arg++)
HYDU_FREE(client_arg[arg]);
......
......@@ -33,18 +33,14 @@ HYD_Status HYD_BSCI_init(char *bootstrap)
}
}
if (HYD_BSCI_comp_array[i] == NULL) {
HYDU_Error_printf("unrecognized bootstrap server: %s\n", bootstrap);
status = HYD_INTERNAL_ERROR;
goto fn_fail;
}
if (HYD_BSCI_fns.launch_procs == NULL) {
/* This function is mandatory */
HYDU_Error_printf("Mandatory bootstrap launch function undefined\n");
status = HYD_INTERNAL_ERROR;
goto fn_fail;
}
if (HYD_BSCI_comp_array[i] == NULL)
HYDU_ERR_SETANDJUMP1(status, HYD_INTERNAL_ERROR,
"unrecognized bootstrap server: %s\n", bootstrap);
/* This function is mandatory */
if (HYD_BSCI_fns.launch_procs == NULL)
HYDU_ERR_SETANDJUMP(status, HYD_INTERNAL_ERROR,
"mandatory bootstrap launch function undefined\n");
if (HYD_BSCI_fns.get_usize == NULL)
HYD_BSCI_fns.get_usize = HYD_BSCU_get_usize;
if (HYD_BSCI_fns.wait_for_completion == NULL)
......
......@@ -61,10 +61,7 @@ HYD_Status HYD_BSCD_ssh_launch_procs(void)
* for everyone else, it's NULL. */
status = HYDU_Create_process(client_arg, (process_id == 0 ? &handle.in : NULL),
&partition->out, &partition->err, &partition->pid);
if (status != HYD_SUCCESS) {
HYDU_Error_printf("bootstrap spawn process returned error\n");
goto fn_fail;
}
HYDU_ERR_POP(status, "create process returned error\n");
for (arg = 0; client_arg[arg]; arg++)
HYDU_FREE(client_arg[arg]);
......
......@@ -22,11 +22,7 @@ HYD_Status HYD_CSI_Close_fd(int fd)
/* Deregister the FD with the demux engine and close it. */
status = HYD_DMX_Deregister_fd(fd);
if (status != HYD_SUCCESS) {
HYDU_Error_printf("demux engine returned error when deregistering fd: %d\n", fd);
goto fn_fail;
}
HYDU_ERR_SETANDJUMP1(status, status, "error deregistering fd %d\n", fd);
close(fd);
/* Find the FD in the handle and remove it. */
......
......@@ -16,16 +16,10 @@ HYD_Status HYD_CSI_Finalize(void)
HYDU_FUNC_ENTER();
status = HYD_PMCI_Finalize();
if (status != HYD_SUCCESS) {
HYDU_Error_printf("process manager finalize returned an error\n");
goto fn_fail;
}
HYDU_ERR_POP(status, "error returned from PM finalize\n");
status = HYD_DMX_Finalize();
if (status != HYD_SUCCESS) {
HYDU_Error_printf("demux engine finalize returned an error\n");
goto fn_fail;
}
HYDU_ERR_POP(status, "error returned from demux finalize\n");
fn_exit:
HYDU_FUNC_EXIT();
......
......@@ -22,53 +22,33 @@ HYD_Status HYD_CSI_Launch_procs(void)
HYDU_FUNC_ENTER();
status = HYD_PMCI_Launch_procs();
if (status != HYD_SUCCESS) {
HYDU_Error_printf("process manager returned error when launching processes\n");
goto fn_fail;
}
HYDU_ERR_POP(status, "PM returned error while launching processes\n");
for (proc_params = handle.proc_params; proc_params; proc_params = proc_params->next) {
for (partition = proc_params->partition; partition; partition = partition->next) {
status =
HYD_DMX_Register_fd(1, &partition->out, HYD_STDOUT, proc_params->stdout_cb);
if (status != HYD_SUCCESS) {
HYDU_Error_printf("demux engine returned error when registering fd\n");
goto fn_fail;
}
HYDU_ERR_POP(status, "demux returned error registering fd\n");
status =
HYD_DMX_Register_fd(1, &partition->err, HYD_STDOUT, proc_params->stderr_cb);
if (status != HYD_SUCCESS) {
HYDU_Error_printf("demux engine returned error when registering fd\n");
goto fn_fail;
}
HYDU_ERR_POP(status, "demux returned error registering fd\n");
}
}
if (handle.in != -1) { /* Only process_id 0 */
status = HYDU_Sock_set_nonblock(handle.in);
if (status != HYD_SUCCESS) {
HYDU_Error_printf("Unable to set socket as non-blocking\n");
status = HYD_SOCK_ERROR;
goto fn_fail;
}
HYDU_ERR_POP(status, "unable to set socket as non-blocking\n");
stdin_fd = 0;
status = HYDU_Sock_set_nonblock(stdin_fd);
if (status != HYD_SUCCESS) {
HYDU_Error_printf("Unable to set socket as non-blocking\n");
status = HYD_SOCK_ERROR;
goto fn_fail;
}
HYDU_ERR_POP(status, "unable to set socket as non-blocking\n");
handle.stdin_buf_count = 0;
handle.stdin_buf_offset = 0;
status = HYD_DMX_Register_fd(1, &stdin_fd, HYD_STDIN, handle.stdin_cb);
if (status != HYD_SUCCESS) {
HYDU_Error_printf("demux engine returned error when registering fd\n");
goto fn_fail;
}
HYDU_ERR_POP(status, "demux returned error registering fd\n");
}
fn_exit:
......
......@@ -24,10 +24,7 @@ HYD_Status HYD_CSI_Wait_for_completion(void)
while (1) {
/* Wait for some event to occur */
status = HYD_DMX_Wait_for_event(HYDU_Time_left(handle.start, handle.timeout));
if (status != HYD_SUCCESS) {
HYDU_Error_printf("demux engine returned error when waiting for event\n");
goto fn_fail;
}
HYDU_ERR_POP(status, "error waiting for event\n");
/* Check to see if there's any open read socket left; if there
* are, we will just wait for more events. */
......@@ -49,10 +46,7 @@ HYD_Status HYD_CSI_Wait_for_completion(void)
/* Make sure all the processes have terminated. The process
* manager control device will take care of that. */
status = HYD_PMCI_Wait_for_completion();
if (status != HYD_SUCCESS) {
HYDU_Error_printf("process manager returned error when waiting for completion\n");
goto fn_fail;
}
HYDU_ERR_POP(status, "error waiting for completion\n");
/* We are done */
break;
......
......@@ -30,13 +30,10 @@ HYD_Status HYD_DMX_Register_fd(int num_fds, int *fd, HYD_Event_t events,
HYDU_FUNC_ENTER();
for (i = 0; i < num_fds; i++) {
if (fd[i] < 0) {
HYDU_Error_printf("registering bad fd %d\n", fd[i]);
status = HYD_INTERNAL_ERROR;
goto fn_fail;
}
}
for (i = 0; i < num_fds; i++)
if (fd[i] < 0)
HYDU_ERR_SETANDJUMP1(status, HYD_INTERNAL_ERROR, "registering bad fd %d\n",
fd[i]);
HYDU_MALLOC(cb_element, HYD_DMXI_Callback_t *, sizeof(HYD_DMXI_Callback_t), status);
cb_element->num_fds = num_fds;
......@@ -88,9 +85,8 @@ HYD_Status HYD_DMX_Deregister_fd(int fd)
}
/* FD is not found */
HYDU_Error_printf("couldn't find the fd to deregister: %d\n", fd);
status = HYD_INTERNAL_ERROR;
goto fn_fail;
HYDU_ERR_SETANDJUMP1(status, HYD_INTERNAL_ERROR,
"could not find fd to deregister: %d\n", fd);
fn_exit:
HYDU_FUNC_EXIT();
......@@ -143,9 +139,7 @@ HYD_Status HYD_DMX_Wait_for_event(int time)
status = HYD_SUCCESS;
goto fn_exit;
}
HYDU_Error_printf("poll error (errno: %d)\n", errno);
status = HYD_SOCK_ERROR;
goto fn_fail;
HYDU_ERR_SETANDJUMP1(status, HYD_SOCK_ERROR, "poll error (errno: %d)\n", errno);
}
break;
}
......@@ -165,10 +159,7 @@ HYD_Status HYD_DMX_Wait_for_event(int time)
events |= HYD_STDOUT;
status = run->callback(pollfds[i].fd, events);
if (status != HYD_SUCCESS) {
HYDU_Error_printf("callback returned error status\n", errno);
goto fn_fail;
}
HYDU_ERR_POP(status, "callback returned error status\n");
}
i++;
......
......@@ -67,6 +67,57 @@ typedef enum {
HYD_INTERNAL_ERROR
} HYD_Status;
#define HYDU_ERR_POP(status, message) \
{ \
if (status != HYD_SUCCESS && status != HYD_GRACEFUL_ABORT) { \
if (message) \
HYDU_Error_printf(message); \
goto fn_fail; \
} \
else if (status == HYD_GRACEFUL_ABORT) { \
goto fn_exit; \
} \
}
#define HYDU_ERR_SETANDJUMP(status, error, message) \
{ \
status = error; \
if (status != HYD_SUCCESS && status != HYD_GRACEFUL_ABORT) { \
if (message) \
HYDU_Error_printf(message); \
goto fn_fail; \
} \
else if (status == HYD_GRACEFUL_ABORT) { \
goto fn_exit; \
} \
}
#define HYDU_ERR_SETANDJUMP1(status, error, message, arg1) \
{ \
status = error; \
if (status != HYD_SUCCESS && status != HYD_GRACEFUL_ABORT) { \
if (message) \
HYDU_Error_printf(message, arg1); \
goto fn_fail; \
} \
else if (status == HYD_GRACEFUL_ABORT) { \
goto fn_exit; \
} \
}
#define HYDU_ERR_SETANDJUMP2(status, error, message, arg1, arg2) \
{ \
status = error; \
if (status != HYD_SUCCESS && status != HYD_GRACEFUL_ABORT) { \
if (message) \
HYDU_Error_printf(message, arg1, arg2); \
goto fn_fail; \
} \
else if (status == HYD_GRACEFUL_ABORT) { \
goto fn_exit; \
} \
}
#define HYD_STDOUT (1)
#define HYD_STDIN (2)
......
......@@ -78,11 +78,10 @@ HYD_Status HYDU_Chdir(const char *dir);
#define HYDU_MALLOC(p, type, size, status) \
{ \
(p) = (type) MPIU_Malloc((size)); \
if ((p) == NULL) { \
HYDU_Error_printf("failed trying to allocate %d bytes\n", (size)); \
(status) = HYD_NO_MEM; \
goto fn_fail; \
} \
if ((p) == NULL) \
HYDU_ERR_SETANDJUMP1((status), HYD_NO_MEM, \
"failed to allocate %d bytes\n", \
(size)); \
}
#define HYDU_FREE(p) \
......@@ -93,11 +92,9 @@ HYD_Status HYDU_Chdir(const char *dir);
#define HYDU_STRDUP(src, dest, type, status) \
{ \
(dest) = (type) MPIU_Strdup((src)); \
if ((dest) == NULL) { \
HYDU_Error_printf("failed duping string %s\n", (src)); \
(status) = HYD_INTERNAL_ERROR; \
goto fn_fail; \
} \
if ((dest) == NULL) \
HYDU_ERR_SETANDJUMP1((status), HYD_INTERNAL_ERROR, \
"failed duping string %s\n", (src)); \
}
HYD_Status HYDU_String_alloc_and_join(char **strlist, char **strjoin);
......
......@@ -20,17 +20,13 @@ HYD_Status HYD_LCHI_stdout_cb(int fd, HYD_Event_t events)
/* Write output to fd 1 */
status = HYDU_Sock_stdout_cb(fd, events, 1, &closed);
if (status != HYD_SUCCESS) {
HYDU_Error_printf("socket stdout callback error on fd: %d (errno: %d)\n", fd, errno);
goto fn_fail;
}
HYDU_ERR_SETANDJUMP2(status, status, "stdout callback error on fd %d (errno: %d)\n",
fd, errno);
if (closed) {
status = HYD_CSI_Close_fd(fd);
if (status != HYD_SUCCESS) {
HYDU_Error_printf("socket close error on fd: %d (errno: %d)\n", fd, errno);
goto fn_fail;
}
HYDU_ERR_SETANDJUMP2(status, status, "socket close error on fd %d (errno: %d)\n",
fd, errno);
goto fn_exit;
}
......@@ -52,17 +48,13 @@ HYD_Status HYD_LCHI_stderr_cb(int fd, HYD_Event_t events)
/* Write output to fd 2 */
status = HYDU_Sock_stdout_cb(fd, events, 2, &closed);
if (status != HYD_SUCCESS) {
HYDU_Error_printf("socket stdout callback error on fd: %d (errno: %d)\n", fd, errno);
goto fn_fail;
}
HYDU_ERR_SETANDJUMP2(status, status, "stdout callback error on %d (errno: %d)\n",
fd, errno)
if (closed) {
status = HYD_CSI_Close_fd(fd);
if (status != HYD_SUCCESS) {
HYDU_Error_printf("socket close error on fd: %d (errno: %d)\n", fd, errno);
goto fn_fail;
}
HYDU_ERR_SETANDJUMP2(status, status, "socket close error on fd %d (errno: %d)\n",
fd, errno);
goto fn_exit;
}
......@@ -84,18 +76,12 @@ HYD_Status HYD_LCHI_stdin_cb(int fd, HYD_Event_t events)
status = HYDU_Sock_stdin_cb(handle.in, events, handle.stdin_tmp_buf,
&handle.stdin_buf_count, &handle.stdin_buf_offset, &closed);
if (status != HYD_SUCCESS) {
HYDU_Error_printf("sock stdin callback returned an error\n");
status = HYD_SOCK_ERROR;
goto fn_fail;
}
HYDU_ERR_POP(status, "stdin callback error\n");
if (closed) {
status = HYD_CSI_Close_fd(fd);
if (status != HYD_SUCCESS) {
HYDU_Error_printf("socket close error on fd: %d (errno: %d)\n", fd, errno);
goto fn_fail;
}
HYDU_ERR_SETANDJUMP2(status, status, "socket close error on fd %d (errno: %d)\n",
fd, errno);
/* Close the input handler for the process, so it knows that
* we got a close event */
......
......@@ -66,25 +66,16 @@ int main(int argc, char **argv)
if (handle.debug) {
status = HYD_LCHI_Print_parameters();
if (status != HYD_SUCCESS) {
HYDU_Error_printf("unable to create host list\n");
goto fn_fail;
}
HYDU_ERR_POP(status, NULL);
}
/* Convert the host file to a host list */
status = HYD_LCHU_Create_host_list();
if (status != HYD_SUCCESS) {
HYDU_Error_printf("unable to create host list\n");
goto fn_fail;
}
HYDU_ERR_POP(status, "unable to create host list\n");
/* Consolidate the environment list that we need to propagate */
status = HYD_LCHU_Create_env_list();
if (status != HYD_SUCCESS) {
HYDU_Error_printf("unable to create host list\n");
goto fn_fail;
}
HYDU_ERR_POP(status, "unable to create env list\n");
proc_params = handle.proc_params;
while (proc_params) {
......@@ -104,18 +95,11 @@ int main(int argc, char **argv)
/* Launch the processes */
status = HYD_CSI_Launch_procs();
if (status != HYD_SUCCESS) {
HYDU_Error_printf("control system returned error when launching processes\n");
goto fn_fail;
}
HYDU_ERR_POP(status, "control system error launching processes\n");
/* Wait for their completion */
status = HYD_CSI_Wait_for_completion();
if (status != HYD_SUCCESS) {
HYDU_Error_printf
("control system returned error when waiting for process' completion\n");
goto fn_fail;
}
HYDU_ERR_POP(status, "control system error waiting for completion\n");
/* Check for the exit status for all the processes */
exit_status = 0;
......@@ -125,10 +109,7 @@ int main(int argc, char **argv)
/* Call finalize functions for lower layers to cleanup their resources */
status = HYD_CSI_Finalize();
if (status != HYD_SUCCESS) {
HYDU_Error_printf("control system returned error on finalize\n");
goto fn_fail;
}
HYDU_ERR_POP(status, "control system error on finalize\n");
/* Free the mpiexec params */
HYD_LCHU_Free_params();
......
......@@ -63,10 +63,7 @@ static HYD_Status get_current_proc_params(struct HYD_Proc_params **params)
if (handle.proc_params == NULL) {
status = allocate_proc_params(&handle.proc_params);
if (status != HYD_SUCCESS) {
HYDU_Error_printf("unable to allocate proc_params\n");
goto fn_fail;
}
HYDU_ERR_POP(status, "unable to allocate proc_params\n");
}
proc_params = handle.proc_params;
......@@ -106,123 +103,69 @@ HYD_Status HYD_LCHI_Get_parameters(int t_argc, char **t_argv)
HYD_LCHU_Init_params();
status = HYDU_Get_base_path(argv[0], &handle.base_path);
if (status != HYD_SUCCESS) {
HYDU_Error_printf("unable to get base path\n");
goto fn_fail;
}
HYDU_ERR_POP(status, "unable to get base path\n");
status = HYDU_Env_global_list(&handle.global_env);
if (status != HYD_SUCCESS) {
HYDU_Error_printf("unable to get the global env list\n");
goto fn_fail;
}
HYDU_ERR_POP(status, "unable to get the global env list\n");
while (--argc && ++argv) {
status = HYDU_String_break(*argv, &str1, &str2);
if (status != HYD_SUCCESS) {
HYDU_Error_printf("string break returned error\n");
goto fn_fail;
}
HYDU_ERR_POP(status, "string break returned error\n");
/* Help options */
if (!strcmp(str1, "-h") || !strcmp(str1, "--help") || !strcmp(str1, "-help")) {
/* Just return from this function; the main code will show the usage */
status = HYD_INTERNAL_ERROR;
goto fn_fail;
}
if (!strcmp(str1, "-h") || !strcmp(str1, "--help") || !strcmp(str1, "-help"))
HYDU_ERR_SETANDJUMP(status, HYD_INTERNAL_ERROR, NULL);
/* Check what debug level is requested */
if (!strcmp(str1, "--verbose")) {
/* Debug level already set */
if (handle.debug != -1) {
HYDU_Error_printf
("Duplicate debug level setting; previously set to %d\n", handle.debug);
status = HYD_INTERNAL_ERROR;
goto fn_fail;
}
if (handle.debug != -1)
HYDU_ERR_SETANDJUMP(status, HYD_INTERNAL_ERROR, "duplicate debug level\n");
handle.debug = 1;
continue;
}
/* Version information */
if (!strcmp(str1, "--version")) {
/* Just show the version information and continue. This
* option can be used in conjunction with other
* options. */
show_version();
status = HYD_GRACEFUL_ABORT;
goto fn_fail;
HYDU_ERR_SETANDJUMP(status, HYD_GRACEFUL_ABORT, NULL);
}
/* Bootstrap server */
if (!strcmp(str1, "--bootstrap")) {
if (!str2) {
CHECK_NEXT_ARG_VALID(status);
str2 = *argv;
}
if (handle.bootstrap != NULL) {
HYDU_Error_printf("Duplicate bootstrap setting; previously set to %s\n",
handle.bootstrap);
status = HYD_INTERNAL_ERROR;
goto fn_fail;
}
if (handle.bootstrap != NULL)
HYDU_ERR_SETANDJUMP(status, HYD_INTERNAL_ERROR, "duplicate bootstrap\n");
handle.bootstrap = MPIU_Strdup(str2);
continue;
}
/* Check if X forwarding is explicitly set */
if (!strcmp(str1, "--enable-x") || !strcmp(str1, "--disable-x")) {
/* X forwarding already enabled or disabled */
if (handle.enablex != -1) {
HYDU_Error_printf
("Duplicate enable-x setting; previously set to %d\n", handle.enablex);
status = HYD_INTERNAL_ERROR;
goto fn_fail;
}
if (handle.enablex != -1)
HYDU_ERR_SETANDJUMP(status, HYD_INTERNAL_ERROR, "duplicate enable-x\n");
handle.enablex = !strcmp(str1, "--enable-x");
continue;
}
/* Check if the proxy port is set */
if (!strcmp(str1, "--proxy-port")) {
if (!str2) {
CHECK_NEXT_ARG_VALID(status);
str2 = *argv;
}
if (handle.proxy_port != -1) {
HYDU_Error_printf("Duplicate proxy port setting; previously set to %d\n",
handle.proxy_port);
status = HYD_INTERNAL_ERROR;
goto fn_fail;
}
if (handle.proxy_port != -1)
HYDU_ERR_SETANDJUMP(status, HYD_INTERNAL_ERROR, "duplicate proxy port\n");
handle.proxy_port = atoi(str2);
continue;
}
/* Check what all environment variables need to be propagated */
if (!strcmp(str1, "-genvall") || !strcmp(str1, "-genvnone") ||
!strcmp(str1, "-genvlist")) {
/* propagation already set */
if (handle.prop != HYD_ENV_PROP_UNSET) {
HYDU_Error_printf
("Duplicate propagation setting; previously set to %d\n", handle.prop);
status = HYD_INTERNAL_ERROR;
goto fn_fail;
}
if (handle.prop != HYD_ENV_PROP_UNSET)
HYDU_ERR_SETANDJUMP(status, HYD_INTERNAL_ERROR, "duplicate prop setting\n");
if (!strcmp(str1, "-genvall")) {
if (!strcmp(str1, "-genvall"))
handle.prop = HYD_ENV_PROP_ALL;
}
else if (!strcmp(str1, "-genvnone")) {
else if (!strcmp(str1, "-genvnone"))
handle.prop = HYD_ENV_PROP_NONE;
}
else if (!strcmp(str1, "-genvlist")) {
handle.prop = HYD_ENV_PROP_LIST;
......@@ -234,45 +177,27 @@ HYD_Status HYD_LCHI_Get_parameters(int t_argc, char **t_argv)
env_name = strtok(str2, ",");
do {
status = HYDU_Env_create(&env, env_name, NULL);
if (status != HYD_SUCCESS) {
HYDU_Error_printf("unable to create env struct\n");
goto fn_fail;
}
HYDU_ERR_POP(status, "unable to create env struct\n");
status = HYDU_Env_add_to_list(&handle.user_env, *env);
if (status != HYD_SUCCESS) {
HYDU_Error_printf("unable to add env to list\n");