Skip to content

Commit

Permalink
update on ipc shortcut lib
Browse files Browse the repository at this point in the history
  • Loading branch information
like101101 authored and tommy-u committed Dec 31, 2022
1 parent 5449597 commit 612665f
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions bin/ipc_shortcut/ipc_shortcut.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,31 @@

static JobRequestBuffer_t* s_JobBuffer = NULL;

#define VERIFY_JOB_BUFFER if (s_JobBuffer == NULL) { \
s_JobBuffer = ipc_get_job_buffer(); \
if (s_JobBuffer == NULL) { \
fprintf(stderr, "[-] Failed to retrieve a working job buffer\n"); \
} \
}

void __attribute__ ((constructor)) init(void) {
printf("ipc_shortcut_lib init\n");
printf("[sym] ipc_shortcut_lib init\n");
s_JobBuffer = ipc_get_job_buffer();
if (s_JobBuffer == NULL) {
fprintf(stderr, "[-] Failed to retrieve a working job buffer\n");
exit(1);
}
s_JobBuffer->pid = getpid();
}

void __attribute__ ((destructor)) cleanUp(void) {
if (s_JobBuffer) {
s_JobBuffer->status = JOB_NO_REQUEST;
printf("[sym] disconecting from the server\n");
if (!s_JobBuffer) {
fprintf(stderr, "[-] Failed to retrieve a working job buffer\n");
exit(1);
}
disconnect_job_buffer(s_JobBuffer);
}

ssize_t write(int fd, const void* buf, size_t len) {
VERIFY_JOB_BUFFER
if (s_JobBuffer == NULL) {
fprintf(stderr, "[IPC Server] Failed to retrieve a working job buffer\n");
exit(1);
}

s_JobBuffer->pid = getpid();
s_JobBuffer->cmd = CMD_WRITE;
s_JobBuffer->arg1 = fd;
memcpy(s_JobBuffer->buffer, buf, len);
Expand Down

0 comments on commit 612665f

Please sign in to comment.