diff options
author | Neelesh Gupta <neelegup@linux.vnet.ibm.com> | 2015-08-31 21:11:39 +0530 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2015-09-01 17:12:02 +1000 |
commit | 2c50e850d01e8387c883decbadfa2a02e78772d6 (patch) | |
tree | ea7da33e16d85737b6600691e25adef3f10796c8 | |
parent | 2e76e2ca6cade45066e26cccf98b9b3e4aa25d6d (diff) | |
download | skiboot-2c50e850d01e8387c883decbadfa2a02e78772d6.zip skiboot-2c50e850d01e8387c883decbadfa2a02e78772d6.tar.gz skiboot-2c50e850d01e8387c883decbadfa2a02e78772d6.tar.bz2 |
external/opal-prd: Move client socket common code to a function
This patch moves out the common code to a function send_prd_control()
which can be invoked for sending the control message to the opal-prd
daemon. It avoids the duplication of the code into the individual
functions corresponding to variety of control messages.
Signed-off-by: Neelesh Gupta <neelegup@linux.vnet.ibm.com>
Acked-by: Jeremy Kerr <jk@ozlabs.org>
Reviewed-by: Patrick Williams <iawillia@us.ibm.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
-rw-r--r-- | external/opal-prd/opal-prd.c | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/external/opal-prd/opal-prd.c b/external/opal-prd/opal-prd.c index 4d51ac8..f96e145 100644 --- a/external/opal-prd/opal-prd.c +++ b/external/opal-prd/opal-prd.c @@ -1400,27 +1400,11 @@ out_close: return rc; } -static int send_occ_control(struct opal_prd_ctx *ctx, const char *str) +static int send_prd_control(struct control_msg *msg) { struct sockaddr_un addr; - struct control_msg msg; int sd, rc; - memset(&msg, 0, sizeof(msg)); - - if (!strcmp(str, "enable")) { - msg.type = CONTROL_MSG_ENABLE_OCCS; - } else if (!strcmp(str, "disable")) { - msg.type = CONTROL_MSG_DISABLE_OCCS; - } else if (!strcmp(str, "reset")) { - msg.type = CONTROL_MSG_TEMP_OCC_RESET; - } else if (!strcmp(str, "process-error")) { - msg.type = CONTROL_MSG_TEMP_OCC_ERROR; - } else { - pr_log(LOG_ERR, "OCC: Invalid OCC action '%s'", str); - return -1; - } - sd = socket(AF_UNIX, SOCK_STREAM, 0); if (!sd) { pr_log(LOG_ERR, "CTRL: Failed to create control socket: %m"); @@ -1436,37 +1420,60 @@ static int send_occ_control(struct opal_prd_ctx *ctx, const char *str) goto out_close; } - rc = send(sd, &msg, sizeof(msg), 0); - if (rc != sizeof(msg)) { + rc = send(sd, msg, sizeof(*msg), 0); + if (rc != sizeof(*msg)) { pr_log(LOG_ERR, "CTRL: Failed to send control message: %m"); rc = -1; goto out_close; } /* wait for our reply */ - rc = recv(sd, &msg, sizeof(msg), 0); + rc = recv(sd, msg, sizeof(*msg), 0); if (rc < 0) { pr_log(LOG_ERR, "CTRL: Failed to receive control message: %m"); goto out_close; - } else if (rc != sizeof(msg)) { + } else if (rc != sizeof(*msg)) { pr_log(LOG_WARNING, "CTRL: Short read from control socket"); rc = -1; goto out_close; } - if (msg.response || ctx->debug) { - pr_debug("OCC: OCC action %s returned status %ld", - str, msg.response); - } - - rc = msg.response; + rc = msg->response; out_close: close(sd); return rc; } +static int send_occ_control(struct opal_prd_ctx *ctx, const char *str) +{ + struct control_msg msg; + int rc; + + memset(&msg, 0, sizeof(msg)); + + if (!strcmp(str, "enable")) { + msg.type = CONTROL_MSG_ENABLE_OCCS; + } else if (!strcmp(str, "disable")) { + msg.type = CONTROL_MSG_DISABLE_OCCS; + } else if (!strcmp(str, "reset")) { + msg.type = CONTROL_MSG_TEMP_OCC_RESET; + } else if (!strcmp(str, "process-error")) { + msg.type = CONTROL_MSG_TEMP_OCC_ERROR; + } else { + pr_log(LOG_ERR, "CTRL: Invalid OCC action '%s'", str); + return -1; + } + + rc = send_prd_control(&msg); + if (msg.response || ctx->debug) + pr_debug("CTRL: OCC action %s returned status %ld", str, + msg.response); + + return rc; +} + static void usage(const char *progname) { printf("Usage:\n"); |