]>
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 | ||
21 | #ifndef QIO_CHANNEL_COMMAND_H__ | |
22 | #define QIO_CHANNEL_COMMAND_H__ | |
23 | ||
24 | #include "io/channel.h" | |
25 | ||
26 | #define TYPE_QIO_CHANNEL_COMMAND "qio-channel-command" | |
27 | #define QIO_CHANNEL_COMMAND(obj) \ | |
28 | OBJECT_CHECK(QIOChannelCommand, (obj), TYPE_QIO_CHANNEL_COMMAND) | |
29 | ||
30 | typedef struct QIOChannelCommand QIOChannelCommand; | |
31 | ||
32 | ||
33 | /** | |
34 | * QIOChannelCommand: | |
35 | * | |
36 | * The QIOChannelCommand class provides a channel implementation | |
37 | * that can transport data with an externally running command | |
38 | * via its stdio streams. | |
39 | */ | |
40 | ||
41 | struct QIOChannelCommand { | |
42 | QIOChannel parent; | |
43 | int writefd; | |
44 | int readfd; | |
45 | pid_t pid; | |
46 | }; | |
47 | ||
48 | ||
49 | /** | |
50 | * qio_channel_command_new_pid: | |
51 | * @writefd: the FD connected to the command's stdin | |
52 | * @readfd: the FD connected to the command's stdout | |
53 | * @pid: the PID of the running child command | |
54 | * @errp: pointer to an uninitialized error object | |
55 | * | |
56 | * Create a channel for performing I/O with the | |
57 | * previously spawned command identified by @pid. | |
58 | * The two file descriptors provide the connection | |
59 | * to command's stdio streams, either one or which | |
60 | * may be -1 to indicate that stream is not open. | |
61 | * | |
62 | * The channel will take ownership of the process | |
63 | * @pid and will kill it when closing the channel. | |
64 | * Similarly it will take responsibility for | |
65 | * closing the file descriptors @writefd and @readfd. | |
66 | * | |
67 | * Returns: the command channel object, or NULL on error | |
68 | */ | |
69 | QIOChannelCommand * | |
70 | qio_channel_command_new_pid(int writefd, | |
71 | int readfd, | |
72 | pid_t pid); | |
73 | ||
74 | /** | |
75 | * qio_channel_command_new_spawn: | |
76 | * @argv: the NULL terminated list of command arguments | |
77 | * @flags: the I/O mode, one of O_RDONLY, O_WRONLY, O_RDWR | |
78 | * @errp: pointer to an uninitialized error object | |
79 | * | |
80 | * Create a channel for performing I/O with the | |
81 | * command to be spawned with arguments @argv. | |
82 | * | |
83 | * Returns: the command channel object, or NULL on error | |
84 | */ | |
85 | QIOChannelCommand * | |
86 | qio_channel_command_new_spawn(const char *const argv[], | |
87 | int flags, | |
88 | Error **errp); | |
89 | ||
90 | ||
91 | #endif /* QIO_CHANNEL_COMMAND_H__ */ |