]>
Commit | Line | Data |
---|---|---|
195e14d0 DB |
1 | /* |
2 | * QEMU I/O channels external command driver | |
3 | * | |
4 | * Copyright (c) 2015 Red Hat, Inc. | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. | |
18 | * | |
19 | */ | |
20 | ||
2a6a4076 MA |
21 | #ifndef QIO_CHANNEL_COMMAND_H |
22 | #define QIO_CHANNEL_COMMAND_H | |
195e14d0 DB |
23 | |
24 | #include "io/channel.h" | |
db1015e9 | 25 | #include "qom/object.h" |
195e14d0 DB |
26 | |
27 | #define TYPE_QIO_CHANNEL_COMMAND "qio-channel-command" | |
db1015e9 | 28 | typedef struct QIOChannelCommand QIOChannelCommand; |
8110fa1d EH |
29 | DECLARE_INSTANCE_CHECKER(QIOChannelCommand, QIO_CHANNEL_COMMAND, |
30 | TYPE_QIO_CHANNEL_COMMAND) | |
195e14d0 | 31 | |
195e14d0 DB |
32 | |
33 | ||
34 | /** | |
35 | * QIOChannelCommand: | |
36 | * | |
37 | * The QIOChannelCommand class provides a channel implementation | |
38 | * that can transport data with an externally running command | |
39 | * via its stdio streams. | |
40 | */ | |
41 | ||
42 | struct QIOChannelCommand { | |
43 | QIOChannel parent; | |
44 | int writefd; | |
45 | int readfd; | |
46 | pid_t pid; | |
47 | }; | |
48 | ||
49 | ||
50 | /** | |
51 | * qio_channel_command_new_pid: | |
52 | * @writefd: the FD connected to the command's stdin | |
53 | * @readfd: the FD connected to the command's stdout | |
54 | * @pid: the PID of the running child command | |
821791b5 | 55 | * @errp: pointer to a NULL-initialized error object |
195e14d0 DB |
56 | * |
57 | * Create a channel for performing I/O with the | |
58 | * previously spawned command identified by @pid. | |
59 | * The two file descriptors provide the connection | |
60 | * to command's stdio streams, either one or which | |
61 | * may be -1 to indicate that stream is not open. | |
62 | * | |
63 | * The channel will take ownership of the process | |
64 | * @pid and will kill it when closing the channel. | |
65 | * Similarly it will take responsibility for | |
66 | * closing the file descriptors @writefd and @readfd. | |
67 | * | |
68 | * Returns: the command channel object, or NULL on error | |
69 | */ | |
70 | QIOChannelCommand * | |
71 | qio_channel_command_new_pid(int writefd, | |
72 | int readfd, | |
73 | pid_t pid); | |
74 | ||
75 | /** | |
76 | * qio_channel_command_new_spawn: | |
77 | * @argv: the NULL terminated list of command arguments | |
78 | * @flags: the I/O mode, one of O_RDONLY, O_WRONLY, O_RDWR | |
821791b5 | 79 | * @errp: pointer to a NULL-initialized error object |
195e14d0 DB |
80 | * |
81 | * Create a channel for performing I/O with the | |
82 | * command to be spawned with arguments @argv. | |
83 | * | |
84 | * Returns: the command channel object, or NULL on error | |
85 | */ | |
86 | QIOChannelCommand * | |
87 | qio_channel_command_new_spawn(const char *const argv[], | |
88 | int flags, | |
89 | Error **errp); | |
90 | ||
91 | ||
2a6a4076 | 92 | #endif /* QIO_CHANNEL_COMMAND_H */ |