Archived
3
0
This repository has been archived on 2024-06-18. You can view files and clone it, but cannot push or open issues or pull requests.
libipc-old/examples/fd-exchange-receiving.c

38 lines
970 B
C
Raw Normal View History

2019-07-27 15:48:10 +02:00
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "../src/ipc.h"
#include "../src/usocket.h"
// This program receives an open file descriptor from another running program.
// see examples/fd-exchange-providing.c
int main (int argc, char *argv[])
2019-07-27 15:48:10 +02:00
{
if (argc != 1) {
fprintf (stderr, "usage: %s", argv[0]);
exit (EXIT_FAILURE);
}
int usock = 0;
int usockclient = 0;
int fd = 0;
TEST_IPC_Q (usock_init (&usock, "SOCKET_FD_EXCHANGE_TEST"), EXIT_FAILURE);
TEST_IPC_Q (usock_accept (usock, &usockclient), EXIT_FAILURE);
TEST_IPC_Q (ipc_receive_fd (usockclient, &fd), EXIT_FAILURE);
2019-07-27 15:48:10 +02:00
T_PERROR_R ((write (fd, "coucou\n", 7) < 0), "cannot write a message in the file", EXIT_FAILURE);
T_PERROR_R ((close (fd) < 0) , "cannot close the file descriptor" , EXIT_FAILURE);
2019-07-27 15:48:10 +02:00
TEST_IPC_Q (usock_close (usock), EXIT_FAILURE);
2019-07-27 15:48:10 +02:00
return EXIT_SUCCESS;
2019-07-27 15:48:10 +02:00
}