xref: /openbmc/qemu/include/io/channel-command.h (revision 8063396bf3459a810d24e3efd6110b8480f0de5b)
1195e14d0SDaniel P. Berrange /*
2195e14d0SDaniel P. Berrange  * QEMU I/O channels external command driver
3195e14d0SDaniel P. Berrange  *
4195e14d0SDaniel P. Berrange  * Copyright (c) 2015 Red Hat, Inc.
5195e14d0SDaniel P. Berrange  *
6195e14d0SDaniel P. Berrange  * This library is free software; you can redistribute it and/or
7195e14d0SDaniel P. Berrange  * modify it under the terms of the GNU Lesser General Public
8195e14d0SDaniel P. Berrange  * License as published by the Free Software Foundation; either
9195e14d0SDaniel P. Berrange  * version 2 of the License, or (at your option) any later version.
10195e14d0SDaniel P. Berrange  *
11195e14d0SDaniel P. Berrange  * This library is distributed in the hope that it will be useful,
12195e14d0SDaniel P. Berrange  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13195e14d0SDaniel P. Berrange  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14195e14d0SDaniel P. Berrange  * Lesser General Public License for more details.
15195e14d0SDaniel P. Berrange  *
16195e14d0SDaniel P. Berrange  * You should have received a copy of the GNU Lesser General Public
17195e14d0SDaniel P. Berrange  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18195e14d0SDaniel P. Berrange  *
19195e14d0SDaniel P. Berrange  */
20195e14d0SDaniel P. Berrange 
212a6a4076SMarkus Armbruster #ifndef QIO_CHANNEL_COMMAND_H
222a6a4076SMarkus Armbruster #define QIO_CHANNEL_COMMAND_H
23195e14d0SDaniel P. Berrange 
24195e14d0SDaniel P. Berrange #include "io/channel.h"
25db1015e9SEduardo Habkost #include "qom/object.h"
26195e14d0SDaniel P. Berrange 
27195e14d0SDaniel P. Berrange #define TYPE_QIO_CHANNEL_COMMAND "qio-channel-command"
28*8063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(QIOChannelCommand, QIO_CHANNEL_COMMAND)
29195e14d0SDaniel P. Berrange 
30195e14d0SDaniel P. Berrange 
31195e14d0SDaniel P. Berrange 
32195e14d0SDaniel P. Berrange /**
33195e14d0SDaniel P. Berrange  * QIOChannelCommand:
34195e14d0SDaniel P. Berrange  *
35195e14d0SDaniel P. Berrange  * The QIOChannelCommand class provides a channel implementation
36195e14d0SDaniel P. Berrange  * that can transport data with an externally running command
37195e14d0SDaniel P. Berrange  * via its stdio streams.
38195e14d0SDaniel P. Berrange  */
39195e14d0SDaniel P. Berrange 
40195e14d0SDaniel P. Berrange struct QIOChannelCommand {
41195e14d0SDaniel P. Berrange     QIOChannel parent;
42195e14d0SDaniel P. Berrange     int writefd;
43195e14d0SDaniel P. Berrange     int readfd;
44195e14d0SDaniel P. Berrange     pid_t pid;
45195e14d0SDaniel P. Berrange };
46195e14d0SDaniel P. Berrange 
47195e14d0SDaniel P. Berrange 
48195e14d0SDaniel P. Berrange /**
49195e14d0SDaniel P. Berrange  * qio_channel_command_new_pid:
50195e14d0SDaniel P. Berrange  * @writefd: the FD connected to the command's stdin
51195e14d0SDaniel P. Berrange  * @readfd: the FD connected to the command's stdout
52195e14d0SDaniel P. Berrange  * @pid: the PID of the running child command
53821791b5SDaniel P. Berrange  * @errp: pointer to a NULL-initialized error object
54195e14d0SDaniel P. Berrange  *
55195e14d0SDaniel P. Berrange  * Create a channel for performing I/O with the
56195e14d0SDaniel P. Berrange  * previously spawned command identified by @pid.
57195e14d0SDaniel P. Berrange  * The two file descriptors provide the connection
58195e14d0SDaniel P. Berrange  * to command's stdio streams, either one or which
59195e14d0SDaniel P. Berrange  * may be -1 to indicate that stream is not open.
60195e14d0SDaniel P. Berrange  *
61195e14d0SDaniel P. Berrange  * The channel will take ownership of the process
62195e14d0SDaniel P. Berrange  * @pid and will kill it when closing the channel.
63195e14d0SDaniel P. Berrange  * Similarly it will take responsibility for
64195e14d0SDaniel P. Berrange  * closing the file descriptors @writefd and @readfd.
65195e14d0SDaniel P. Berrange  *
66195e14d0SDaniel P. Berrange  * Returns: the command channel object, or NULL on error
67195e14d0SDaniel P. Berrange  */
68195e14d0SDaniel P. Berrange QIOChannelCommand *
69195e14d0SDaniel P. Berrange qio_channel_command_new_pid(int writefd,
70195e14d0SDaniel P. Berrange                             int readfd,
71195e14d0SDaniel P. Berrange                             pid_t pid);
72195e14d0SDaniel P. Berrange 
73195e14d0SDaniel P. Berrange /**
74195e14d0SDaniel P. Berrange  * qio_channel_command_new_spawn:
75195e14d0SDaniel P. Berrange  * @argv: the NULL terminated list of command arguments
76195e14d0SDaniel P. Berrange  * @flags: the I/O mode, one of O_RDONLY, O_WRONLY, O_RDWR
77821791b5SDaniel P. Berrange  * @errp: pointer to a NULL-initialized error object
78195e14d0SDaniel P. Berrange  *
79195e14d0SDaniel P. Berrange  * Create a channel for performing I/O with the
80195e14d0SDaniel P. Berrange  * command to be spawned with arguments @argv.
81195e14d0SDaniel P. Berrange  *
82195e14d0SDaniel P. Berrange  * Returns: the command channel object, or NULL on error
83195e14d0SDaniel P. Berrange  */
84195e14d0SDaniel P. Berrange QIOChannelCommand *
85195e14d0SDaniel P. Berrange qio_channel_command_new_spawn(const char *const argv[],
86195e14d0SDaniel P. Berrange                               int flags,
87195e14d0SDaniel P. Berrange                               Error **errp);
88195e14d0SDaniel P. Berrange 
89195e14d0SDaniel P. Berrange 
902a6a4076SMarkus Armbruster #endif /* QIO_CHANNEL_COMMAND_H */
91