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