File: ipc-api-tests-exported.c

package info (click to toggle)
mmlib 1.4.2-2.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,716 kB
  • sloc: ansic: 18,071; makefile: 431; sh: 135; python: 63
file content (69 lines) | stat: -rw-r--r-- 1,378 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
   @mindmaze_header@
 */
#if HAVE_CONFIG_H
# include <config.h>
#endif

#include <check.h>

#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <strings.h>

#include "mmerrno.h"
#include "mmlib.h"
#include "mmpredefs.h"
#include "mmsysio.h"
#include "mmthread.h"
#include "mmtime.h"

#include "tests-child-proc.h"
#include "ipc-api-tests-exported.h"

API_EXPORTED
intptr_t test_client_process(void * arg)
{
	int fd;
	char buf[256];
	int exit_value = -1;
	int recvfd = -1;
	struct ipc_test_ctx * ctx = arg;
	const char data[] = "ipc client test msg";
	char line[80] = "client message in shared object\n";

	fd = mm_ipc_connect(IPC_ADDR);
	if (fd == -1)
		goto cleanup;

	if (mm_ipc_build_send_msg(fd, data, sizeof(data), -1) < 0
	   || recv_msg_and_fd(fd, buf, sizeof(buf), &recvfd) < 0)
		goto cleanup;

	if (ctx->shared_object == SHARED_FILE
	   || ctx->shared_object == SHARED_MEM)
		mm_seek(recvfd, 0, SEEK_SET);

	mm_write(recvfd, line, strlen(line));
	mm_close(recvfd);
	recvfd = -1;

	/* send another message after we finished writing */
	if (mm_ipc_build_send_msg(fd, data, sizeof(data), -1) < 0)
		goto cleanup;

	exit_value = 0;

cleanup:
	if (exit_value != 0) {
		exit_value = mm_get_lasterror_number();
		fprintf(stderr, "%s() failed: %s",
		        __func__, mm_get_lasterror_desc());
	}

	mm_close(fd);
	mm_close(recvfd);

	return exit_value;
}