/** * pka_channel_set_pid: * @channel: A #PkaChannel. * @context: A #PkaContext. * @pid: A #GPid. * @error: A location for #GError, or %NULL. * * Sets the pid of the process of which to attach. If set, the channel will * not spawn a process, but instead instruct the sources to attach to the * existing process. If the context does not have permissions, this * operation will fail. Also, this may only be called before the channel has * been started. * * Returns: %TRUE if successful; otherwise %FALSE. * Side effects: None. */ gboolean pka_channel_set_pid (PkaChannel *channel, /* IN */ PkaContext *context, /* IN */ GPid pid, /* IN */ GError **error) /* OUT */ { PkaChannelPrivate *priv; gboolean ret = FALSE; ENTRY; priv = channel->priv; AUTHORIZE_IOCTL(context, MODIFY_CHANNEL, channel, failed); g_mutex_lock(priv->mutex); ENSURE_STATE(channel, READY, unlock); INFO(Channel, "Setting pid of channel %d to %d on behalf of context %d.", priv->id, pid, pka_context_get_id(context)); priv->pid = pid; priv->pid_set = TRUE; g_free(priv->target); priv->target = NULL; ret = TRUE; unlock: g_mutex_unlock(priv->mutex); failed: RETURN(ret); }
/*! * \brief Truncate or extend file backed by a File handle. * * \note The file position is *not* changed after a successful call of this * function. The size of the file may increase if the file position is * larger than the truncated file size and File::write() is called. * * \param size New size of file * * \return * * #FileStatus::OK if the file size was successfully changed * * #FileStatus::UNSUPPORTED if the handle source does not support truncation * * \<= #FileStatus::WARN if an error occurs */ FileStatus File::truncate(uint64_t size) { GET_PIMPL_OR_RETURN(FileStatus::FATAL); ENSURE_STATE(FileState::OPENED); auto ret = on_truncate(size); if (ret <= FileStatus::FATAL) { priv->state = FileState::FATAL; } return ret; }
/*! * \brief Open a File handle. * * Once the handle has been opened, the file operation functions, such as * File::read(), are available to use. * * \note This function should generally only be called by subclasses. Most * subclasses will provide a variant of this function that can take * parameters, such as a filename. * * \return * * #FileStatus::OK if there is no file open handler or if the file open * handle succeeds * * \<= #FileStatus::WARN if an error occurs */ FileStatus File::open() { GET_PIMPL_OR_RETURN(FileStatus::FATAL); ENSURE_STATE(FileState::NEW); auto ret = on_open(); if (ret == FileStatus::OK) { priv->state = FileState::OPENED; } else { // If the file was not successfully opened, then close it on_close(); } return ret; }
/*! * \brief Set file position of a File handle. * * \param[in] offset File position offset * \param[in] whence SEEK_SET, SEEK_CUR, or SEEK_END from `stdio.h` * \param[out] new_offset Output new file offset. This parameter can be NULL. * * \return * * #FileStatus::OK if the file position was successfully set * * #FileStatus::UNSUPPORTED if the handle source does not support seeking * * \<= #FileStatus::WARN if an error occurs */ FileStatus File::seek(int64_t offset, int whence, uint64_t *new_offset) { GET_PIMPL_OR_RETURN(FileStatus::FATAL); ENSURE_STATE(FileState::OPENED); uint64_t new_offset_temp; auto ret = on_seek(offset, whence, &new_offset_temp); if (ret == FileStatus::OK) { if (new_offset) { *new_offset = new_offset_temp; } } else if (ret <= FileStatus::FATAL) { priv->state = FileState::FATAL; } return ret; }
/*! * \brief Write to a File handle. * * Example usage: * * \code{.cpp} * size_t n; * * if (file.write(file, buf, sizeof(buf), &bytesWritten) * != FileStatus::OK) { * printf("Failed to write file: %s\n", file.error_string().c_str()); * } * \endcode * * \param[in] buf Buffer to write from * \param[in] size Buffer size * \param[out] bytes_written Output number of bytes that were written. This * parameter cannot be NULL. * * \return * * #FileStatus::OK if some bytes were written * * #FileStatus::RETRY if the same operation should be reattempted * * #FileStatus::UNSUPPORTED if the handle source does not support writing * * \<= #FileStatus::WARN if an error occurs */ FileStatus File::write(const void *buf, size_t size, size_t *bytes_written) { GET_PIMPL_OR_RETURN(FileStatus::FATAL); ENSURE_STATE(FileState::OPENED); auto ret = FileStatus::UNSUPPORTED; if (!bytes_written) { set_error(FileError::PROGRAMMER_ERROR, "%s: bytes_written is NULL", __func__); ret = FileStatus::FATAL; } else { ret = on_write(buf, size, bytes_written); } if (ret <= FileStatus::FATAL) { priv->state = FileState::FATAL; } return ret; }