|
12 | 12 | #include <ctype.h> |
13 | 13 |
|
14 | 14 | #include <stdlib.h> |
15 | | -#include <errno.h> |
16 | 15 | #include <string.h> |
17 | 16 | #include <sys/types.h> |
18 | 17 | #include <sys/socket.h> |
|
28 | 27 | #include "../ipc.h" |
29 | 28 | #include "zcbor_helpers.h" |
30 | 29 |
|
31 | | -#define SOCK_PATH "ocre.sock" |
| 30 | +#define SOCK_PATH "/tmp/ocre.sock" |
32 | 31 |
|
33 | 32 | /* Buffer sizes for IPC communication */ |
34 | 33 | #define SMALL_PAYLOAD_SIZE 64 |
@@ -256,12 +255,15 @@ struct ocre_container *ocre_context_create_container(struct ocre_context *contex |
256 | 255 |
|
257 | 256 | struct ocre_container *ocre_context_get_container_by_id(struct ocre_context *context, const char *id) |
258 | 257 | { |
259 | | - (void)context; /* Context is not sent over IPC - server uses global context */ |
260 | 258 | int rc; |
261 | 259 |
|
262 | 260 | uint8_t payload[MEDIUM_PAYLOAD_SIZE]; |
263 | 261 | bool success; |
264 | 262 |
|
| 263 | + if (!context) { |
| 264 | + return NULL; |
| 265 | + } |
| 266 | + |
265 | 267 | /* Encode the request - server expects only the ID string */ |
266 | 268 | ZCBOR_STATE_E(encoding_state, 0, payload, sizeof(payload), 0); |
267 | 269 |
|
@@ -328,13 +330,12 @@ struct ocre_container *ocre_context_get_container_by_id(struct ocre_context *con |
328 | 330 |
|
329 | 331 | int ocre_context_remove_container(struct ocre_context *context, struct ocre_container *container) |
330 | 332 | { |
331 | | - (void)context; /* Context is not sent over IPC - server uses global context */ |
332 | 333 | int rc; |
333 | 334 |
|
334 | 335 | uint8_t payload[MEDIUM_PAYLOAD_SIZE]; |
335 | 336 | bool success; |
336 | 337 |
|
337 | | - if (!container || !container->id) { |
| 338 | + if (!context || !container || !container->id) { |
338 | 339 | return -1; |
339 | 340 | } |
340 | 341 |
|
@@ -385,12 +386,14 @@ int ocre_context_remove_container(struct ocre_context *context, struct ocre_cont |
385 | 386 |
|
386 | 387 | int ocre_context_get_container_count(struct ocre_context *context) |
387 | 388 | { |
388 | | - (void)context; /* Context is not sent over IPC - server uses global context */ |
389 | 389 | int rc; |
390 | 390 |
|
391 | 391 | uint8_t payload[SMALL_PAYLOAD_SIZE]; |
392 | 392 | bool success; |
393 | 393 |
|
| 394 | + if (!context) { |
| 395 | + return -1; |
| 396 | + } |
394 | 397 | /* Encode the request - server takes no parameters */ |
395 | 398 | ZCBOR_STATE_E(encoding_state, 0, payload, sizeof(payload), 0); |
396 | 399 |
|
@@ -438,12 +441,15 @@ int ocre_context_get_container_count(struct ocre_context *context) |
438 | 441 |
|
439 | 442 | int ocre_context_get_containers(struct ocre_context *context, struct ocre_container **containers, int max_size) |
440 | 443 | { |
441 | | - (void)context; /* Context is not sent over IPC - server uses global context */ |
442 | 444 | int rc; |
443 | 445 |
|
444 | 446 | uint8_t payload[SMALL_PAYLOAD_SIZE]; |
445 | 447 | bool success; |
446 | 448 |
|
| 449 | + if (!context || !containers) { |
| 450 | + return -1; |
| 451 | + } |
| 452 | + |
447 | 453 | /* Encode the request - server expects only max_size */ |
448 | 454 | ZCBOR_STATE_E(encoding_state, 0, payload, sizeof(payload), 0); |
449 | 455 |
|
@@ -533,13 +539,16 @@ int ocre_context_get_containers(struct ocre_context *context, struct ocre_contai |
533 | 539 |
|
534 | 540 | const char *ocre_context_get_working_directory(const struct ocre_context *context) |
535 | 541 | { |
536 | | - (void)context; /* Context is not sent over IPC - server uses global context */ |
537 | 542 | int rc; |
538 | 543 | static char workdir_buffer[STRING_BUFFER_SIZE]; |
539 | 544 |
|
540 | 545 | uint8_t payload[SMALL_PAYLOAD_SIZE]; |
541 | 546 | bool success; |
542 | 547 |
|
| 548 | + if (!context) { |
| 549 | + return NULL; |
| 550 | + } |
| 551 | + |
543 | 552 | /* Encode the request - server takes no parameters */ |
544 | 553 | ZCBOR_STATE_E(encoding_state, 0, payload, sizeof(payload), 0); |
545 | 554 |
|
@@ -975,7 +984,7 @@ int ocre_container_kill(struct ocre_container *container) |
975 | 984 | } |
976 | 985 |
|
977 | 986 | /* Decode the response */ |
978 | | - ZCBOR_STATE_D(decoding_state, 0, rx_buf, rc, 1, 0); |
| 987 | + ZCBOR_STATE_D(decoding_state, 0, rx_buf, rc, 2, 0); |
979 | 988 |
|
980 | 989 | uint32_t decoded_rsp; |
981 | 990 | success = zcbor_uint32_decode(decoding_state, &decoded_rsp); |
@@ -1031,7 +1040,7 @@ int ocre_container_wait(struct ocre_container *container, int *status) |
1031 | 1040 | } |
1032 | 1041 |
|
1033 | 1042 | /* Decode the response */ |
1034 | | - ZCBOR_STATE_D(decoding_state, 0, rx_buf, rc, 1, 0); |
| 1043 | + ZCBOR_STATE_D(decoding_state, 0, rx_buf, rc, 3, 0); |
1035 | 1044 |
|
1036 | 1045 | uint32_t decoded_rsp; |
1037 | 1046 | success = zcbor_uint32_decode(decoding_state, &decoded_rsp); |
|
0 commit comments