Instrument Neutral Distributed Interface INDI 2.2.5
fakedriver.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2022 Ludovic Pollet. All rights reserved.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*******************************************************************************/
18
19#include <stdlib.h>
20#include <stdio.h>
21#include <unistd.h>
22#include "utils.h"
23
24// This fake driver will just forward its 0 & 1 FD to a process over unix socket
25int main()
26{
27 fprintf(stderr, "fake driver starting\n");
29
30 const char * path = getenv("FAKEDRIVER_ADDRESS");
31 if (!path)
32 {
33 fprintf(stderr, "FAKEDRIVER_ADDRESS not set\n");
34 }
35 int cnx = unixSocketConnect(path);
36
37 fprintf(stderr, "fake driver connected to %s on %d\n", path, cnx);
38
39 int fds[2] = {0, 1};
40 unixSocketSendFds(cnx, 2, fds);
41 close(fds[0]);
42 close(fds[1]);
43 fprintf(stderr, "fake driver pipes sent\n");
44
45 char buff[1];
46 ssize_t ret = read(cnx, &buff, 1);
47 if (ret == -1)
48 {
49 perror("read failed");
50 }
51 return 0;
52}
int main()
int unixSocketConnect(const std::string &unixAddr, bool failAllowed)
Definition utils.cpp:155
void unixSocketSendFds(int fd, int count, int *fds)
Definition utils.cpp:183
void setupSigPipe()
Definition utils.cpp:37