diff options
Diffstat (limited to 'runtime/staprun/common.c')
-rw-r--r-- | runtime/staprun/common.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/runtime/staprun/common.c b/runtime/staprun/common.c index 93da51d8..fd16b4b8 100644 --- a/runtime/staprun/common.c +++ b/runtime/staprun/common.c @@ -14,6 +14,8 @@ #include <sys/types.h> #include <unistd.h> #include <sys/utsname.h> +#include <assert.h> + /* variables needed by parse_args() */ int verbose; @@ -314,3 +316,31 @@ err: close(fd); return -1; } + + +/** + * send_request - send request to kernel over control channel + * @type: the relay-app command id + * @data: pointer to the data to be sent + * @len: length of the data to be sent + * + * Returns 0 on success, negative otherwise. + */ +int send_request(int type, void *data, int len) +{ + char buf[1024]; + int rc = 0; + + /* Before doing memcpy, make sure 'buf' is big enough. */ + if ((len + 4) > (int)sizeof(buf)) { + _err("exceeded maximum send_request size.\n"); + return -1; + } + memcpy(buf, &type, 4); + memcpy(&buf[4], data, len); + + assert (control_channel >= 0); + rc = write (control_channel, buf, len + 4); + if (rc < 0) return rc; + return (rc != len+4); +} |