Merge pull request #97 from mxpv/fmt

Add Rust fmt rules to format imports
This commit is contained in:
Maksym Pavlenko 2022-10-02 11:35:57 -07:00 committed by GitHub
commit edb96dc469
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
61 changed files with 600 additions and 530 deletions

View File

@ -22,9 +22,13 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }} repo-token: ${{ secrets.GITHUB_TOKEN }}
- run: cargo check --examples --tests --all-targets - run: cargo check --examples --tests --all-targets
- run: cargo check --examples --tests --all-targets --all-features - run: cargo check --examples --tests --all-targets --all-features
- run: cargo fmt --all -- --check --files-with-diff
- run: rustup toolchain install nightly --component rustfmt
- run: cargo +nightly fmt --all -- --check --files-with-diff
- run: cargo clippy --all-targets -- -D warnings - run: cargo clippy --all-targets -- -D warnings
- run: cargo clippy --all-targets --all-features -- -D warnings - run: cargo clippy --all-targets --all-features -- -D warnings
- run: cargo doc --no-deps - run: cargo doc --no-deps
env: env:
RUSTDOCFLAGS: -Dwarnings RUSTDOCFLAGS: -Dwarnings

View File

@ -14,9 +14,7 @@
limitations under the License. limitations under the License.
*/ */
use std::env; use std::{env, fs, io};
use std::fs;
use std::io;
const PROTO_FILES: &[&str] = &[ const PROTO_FILES: &[&str] = &[
// Types // Types

View File

@ -14,25 +14,20 @@
limitations under the License. limitations under the License.
*/ */
use std::{fs, fs::File};
use client::{
services::v1::{
container::Runtime, containers_client::ContainersClient, tasks_client::TasksClient,
Container, CreateContainerRequest, CreateTaskRequest, DeleteContainerRequest,
DeleteTaskRequest, StartRequest, WaitRequest,
},
with_namespace,
};
use containerd_client as client; use containerd_client as client;
use client::services::v1::container::Runtime;
use client::services::v1::containers_client::ContainersClient;
use client::services::v1::Container;
use client::services::v1::{CreateContainerRequest, DeleteContainerRequest};
use client::services::v1::tasks_client::TasksClient;
use client::services::v1::{CreateTaskRequest, DeleteTaskRequest, StartRequest, WaitRequest};
use prost_types::Any; use prost_types::Any;
use tonic::Request; use tonic::Request;
use std::fs;
use std::fs::File;
use client::with_namespace;
const CID: &str = "abc123"; const CID: &str = "abc123";
const NAMESPACE: &str = "default"; const NAMESPACE: &str = "default";

View File

@ -14,9 +14,8 @@
limitations under the License. limitations under the License.
*/ */
use containerd_client as client;
use client::services::v1::version_client::VersionClient; use client::services::v1::version_client::VersionClient;
use containerd_client as client;
/// Make sure you run containerd before running this example. /// Make sure you run containerd before running this example.
#[tokio::main(flavor = "current_thread")] #[tokio::main(flavor = "current_thread")]

View File

@ -69,6 +69,7 @@ pub async fn connect(
path: impl AsRef<std::path::Path>, path: impl AsRef<std::path::Path>,
) -> Result<tonic::transport::Channel, tonic::transport::Error> { ) -> Result<tonic::transport::Channel, tonic::transport::Error> {
use std::convert::TryFrom; use std::convert::TryFrom;
use tokio::net::UnixStream; use tokio::net::UnixStream;
use tonic::transport::Endpoint; use tonic::transport::Endpoint;

View File

@ -14,13 +14,9 @@
limitations under the License. limitations under the License.
*/ */
use std::fs; use std::{fs, io, io::BufRead, thread};
use std::io;
use std::io::BufRead;
use std::thread;
use containerd_shim_logging as logging; use containerd_shim_logging as logging;
use logging::{Config, Driver}; use logging::{Config, Driver};
fn pump(reader: fs::File) { fn pump(reader: fs::File) {

View File

@ -23,11 +23,7 @@
//! This crates replicates APIs provided by Go [version](https://github.com/containerd/containerd/blob/main/runtime/v2/README.md#logging). //! This crates replicates APIs provided by Go [version](https://github.com/containerd/containerd/blob/main/runtime/v2/README.md#logging).
//! //!
use std::env; use std::{env, fmt, fs, os::unix::io::FromRawFd, process};
use std::fmt;
use std::fs;
use std::os::unix::io::FromRawFd;
use std::process;
/// Logging binary configuration received from containerd. /// Logging binary configuration received from containerd.
#[derive(Debug)] #[derive(Debug)]

View File

@ -14,33 +14,36 @@
limitations under the License. limitations under the License.
*/ */
use std::env::current_dir; use std::{env::current_dir, sync::Arc};
use std::sync::Arc;
use ::runc::options::DeleteOpts;
use async_trait::async_trait; use async_trait::async_trait;
use containerd_shim::{
asynchronous::{
container::Container,
monitor::{monitor_subscribe, monitor_unsubscribe, Subscription},
processes::Process,
publisher::RemotePublisher,
spawn,
task::TaskService,
ExitSignal, Shim,
},
event::Event,
io_error,
monitor::{Subject, Topic},
protos::{events::task::TaskExit, protobuf::MessageDyn},
util::{
convert_to_timestamp, read_options, read_runtime, read_spec, timestamp, write_str_to_file,
},
Config, Context, DeleteResponse, Error, StartOpts,
};
use log::{debug, error, warn}; use log::{debug, error, warn};
use tokio::sync::mpsc::{channel, Receiver, Sender}; use tokio::sync::mpsc::{channel, Receiver, Sender};
use ::runc::options::DeleteOpts; use crate::{
use containerd_shim::asynchronous::container::Container; asynchronous::runc::{RuncContainer, RuncFactory},
use containerd_shim::asynchronous::monitor::{ common::{create_runc, has_shared_pid_namespace, ShimExecutor, GROUP_LABELS},
monitor_subscribe, monitor_unsubscribe, Subscription,
}; };
use containerd_shim::asynchronous::processes::Process;
use containerd_shim::asynchronous::publisher::RemotePublisher;
use containerd_shim::asynchronous::task::TaskService;
use containerd_shim::asynchronous::{spawn, ExitSignal, Shim};
use containerd_shim::event::Event;
use containerd_shim::monitor::{Subject, Topic};
use containerd_shim::protos::events::task::TaskExit;
use containerd_shim::protos::protobuf::MessageDyn;
use containerd_shim::util::{convert_to_timestamp, timestamp};
use containerd_shim::util::{read_options, read_runtime, read_spec, write_str_to_file};
use containerd_shim::{io_error, Config, Context, DeleteResponse, Error, StartOpts};
use crate::asynchronous::runc::{RuncContainer, RuncFactory};
use crate::common::{create_runc, has_shared_pid_namespace};
use crate::common::{ShimExecutor, GROUP_LABELS};
mod runc; mod runc;

View File

@ -14,46 +14,50 @@
limitations under the License. limitations under the License.
*/ */
use std::convert::TryFrom; use std::{
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; convert::TryFrom,
use std::os::unix::prelude::ExitStatusExt; os::unix::{
use std::path::{Path, PathBuf}; io::{AsRawFd, FromRawFd, RawFd},
use std::process::ExitStatus; prelude::ExitStatusExt,
use std::sync::Arc; },
path::{Path, PathBuf},
process::ExitStatus,
sync::Arc,
};
use async_trait::async_trait; use async_trait::async_trait;
use containerd_shim::{
api::{CreateTaskRequest, ExecProcessRequest, Options, Status},
asynchronous::{
console::ConsoleSocket,
container::{ContainerFactory, ContainerTemplate, ProcessFactory},
monitor::{monitor_subscribe, monitor_unsubscribe, Subscription},
processes::{ProcessLifecycle, ProcessTemplate},
},
io::Stdio,
io_error,
monitor::{ExitEvent, Subject, Topic},
other, other_error,
protos::{
api::ProcessInfo,
cgroups::metrics::Metrics,
protobuf::{CodedInputStream, Message},
},
util::{asyncify, mkdir, mount_rootfs, read_file_to_str, write_options, write_runtime},
Console, Error, ExitSignal, Result,
};
use log::{debug, error}; use log::{debug, error};
use nix::sys::signal::kill; use nix::{sys::signal::kill, unistd::Pid};
use nix::unistd::Pid;
use oci_spec::runtime::{LinuxResources, Process}; use oci_spec::runtime::{LinuxResources, Process};
use tokio::fs::{File, OpenOptions};
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite};
use containerd_shim::api::{CreateTaskRequest, ExecProcessRequest, Options, Status};
use containerd_shim::asynchronous::console::ConsoleSocket;
use containerd_shim::asynchronous::container::{
ContainerFactory, ContainerTemplate, ProcessFactory,
};
use containerd_shim::asynchronous::monitor::{
monitor_subscribe, monitor_unsubscribe, Subscription,
};
use containerd_shim::asynchronous::processes::{ProcessLifecycle, ProcessTemplate};
use containerd_shim::io::Stdio;
use containerd_shim::monitor::{ExitEvent, Subject, Topic};
use containerd_shim::protos::api::ProcessInfo;
use containerd_shim::protos::cgroups::metrics::Metrics;
use containerd_shim::protos::protobuf::{CodedInputStream, Message};
use containerd_shim::util::{
asyncify, mkdir, mount_rootfs, read_file_to_str, write_options, write_runtime,
};
use containerd_shim::{io_error, other, other_error, Console, Error, ExitSignal, Result};
use runc::{Command, Runc, Spawner}; use runc::{Command, Runc, Spawner};
use tokio::{
fs::{File, OpenOptions},
io::{AsyncRead, AsyncReadExt, AsyncWrite},
};
use crate::common::receive_socket;
use crate::common::CreateConfig;
use crate::common::{ use crate::common::{
check_kill_error, create_io, create_runc, get_spec_from_request, ProcessIO, ShimExecutor, check_kill_error, create_io, create_runc, get_spec_from_request, receive_socket, CreateConfig,
INIT_PID_FILE, ProcessIO, ShimExecutor, INIT_PID_FILE,
}; };
pub type ExecProcess = ProcessTemplate<RuncExecLifecycle>; pub type ExecProcess = ProcessTemplate<RuncExecLifecycle>;

View File

@ -14,25 +14,29 @@
limitations under the License. limitations under the License.
*/ */
use std::io::IoSliceMut; use std::{io::IoSliceMut, ops::Deref, os::unix::io::RawFd, path::Path, sync::Arc};
use std::ops::Deref;
use std::os::unix::io::RawFd;
use std::path::Path;
use std::sync::Arc;
use containerd_shim::{
api::{ExecProcessRequest, Options},
io::Stdio,
io_error, other, other_error,
util::IntoOption,
Error,
};
use log::{debug, warn}; use log::{debug, warn};
use nix::cmsg_space; use nix::{
use nix::sys::socket::{recvmsg, ControlMessageOwned, MsgFlags, UnixAddr}; cmsg_space,
use nix::sys::termios::tcgetattr; sys::{
socket::{recvmsg, ControlMessageOwned, MsgFlags, UnixAddr},
termios::tcgetattr,
},
};
use oci_spec::runtime::{LinuxNamespaceType, Spec}; use oci_spec::runtime::{LinuxNamespaceType, Spec};
use runc::{
use containerd_shim::api::{ExecProcessRequest, Options}; io::{Io, NullIo, FIFO},
use containerd_shim::io::Stdio; options::GlobalOpts,
use containerd_shim::util::IntoOption; Runc, Spawner,
use containerd_shim::{io_error, other, other_error, Error}; };
use runc::io::{Io, NullIo, FIFO};
use runc::options::GlobalOpts;
use runc::{Runc, Spawner};
pub const GROUP_LABELS: [&str; 2] = [ pub const GROUP_LABELS: [&str; 2] = [
"io.containerd.runc.v2.group", "io.containerd.runc.v2.group",

View File

@ -14,31 +14,34 @@
limitations under the License. limitations under the License.
*/ */
use std::collections::HashMap; use std::{
use std::convert::TryFrom; collections::HashMap,
use std::fs::{File, OpenOptions}; convert::TryFrom,
use std::os::unix::io::{AsRawFd, FromRawFd}; fs::{File, OpenOptions},
use std::path::Path; os::unix::io::{AsRawFd, FromRawFd},
use std::sync::mpsc::{sync_channel, Receiver, SyncSender}; path::Path,
sync::mpsc::{sync_channel, Receiver, SyncSender},
use log::debug; };
use oci_spec::runtime::LinuxResources;
use time::OffsetDateTime;
use containerd_shim as shim; use containerd_shim as shim;
use shim::api::*; use log::debug;
use shim::console::ConsoleSocket; use oci_spec::runtime::LinuxResources;
use shim::error::{Error, Result}; use shim::{
use shim::io::Stdio; api::*,
use shim::ioctl_set_winsz; console::ConsoleSocket,
use shim::protos::cgroups::metrics::Metrics; error::{Error, Result},
use shim::util::{convert_to_timestamp, read_pid_from_file}; io::Stdio,
use shim::Console; io_error, ioctl_set_winsz, other, other_error,
use shim::{io_error, other, other_error}; protos::cgroups::metrics::Metrics,
util::{convert_to_timestamp, read_pid_from_file},
Console,
};
use time::OffsetDateTime;
use crate::common::receive_socket; use crate::{
use crate::common::ProcessIO; common::{receive_socket, ProcessIO},
use crate::synchronous::io::spawn_copy_for_tty; synchronous::io::spawn_copy_for_tty,
};
pub trait ContainerFactory<C> { pub trait ContainerFactory<C> {
fn create(&self, ns: &str, req: &CreateTaskRequest) -> Result<C>; fn create(&self, ns: &str, req: &CreateTaskRequest) -> Result<C>;

View File

@ -14,18 +14,19 @@
limitations under the License. limitations under the License.
*/ */
use std::fs::OpenOptions; use std::{
use std::io::{ErrorKind, Read, Write}; fs::OpenOptions,
use std::thread::JoinHandle; io::{ErrorKind, Read, Write},
thread::JoinHandle,
};
use crossbeam::sync::WaitGroup;
use log::debug;
use containerd_shim::io::Stdio;
use containerd_shim::{ use containerd_shim::{
error::{Error, Result}, error::{Error, Result},
io::Stdio,
io_error, io_error,
}; };
use crossbeam::sync::WaitGroup;
use log::debug;
use crate::common::ProcessIO; use crate::common::ProcessIO;

View File

@ -15,43 +15,51 @@
*/ */
#![allow(unused)] #![allow(unused)]
use std::convert::TryFrom; use std::{
use std::io::Read; convert::TryFrom,
use std::os::unix::prelude::ExitStatusExt; io::Read,
use std::path::{Path, PathBuf}; os::unix::prelude::ExitStatusExt,
use std::process::ExitStatus; path::{Path, PathBuf},
use std::sync::mpsc::{Receiver, SyncSender}; process::ExitStatus,
use std::sync::Arc; sync::{
mpsc::{Receiver, SyncSender},
use log::{debug, error}; Arc,
use nix::sys::signal::kill; },
use nix::sys::stat::Mode; };
use nix::unistd::{mkdir, Pid};
use oci_spec::runtime::{LinuxNamespaceType, LinuxResources};
use time::OffsetDateTime;
use containerd_shim as shim; use containerd_shim as shim;
use runc::{Command, Spawner}; use log::{debug, error};
use shim::api::*; use nix::{
use shim::console::ConsoleSocket; sys::{signal::kill, stat::Mode},
use shim::error::{Error, Result}; unistd::{mkdir, Pid},
use shim::io::Stdio;
use shim::monitor::{monitor_subscribe, wait_pid, ExitEvent, Subject, Subscription, Topic};
use shim::mount::mount_rootfs;
use shim::protos::api::ProcessInfo;
use shim::protos::cgroups::metrics::Metrics;
use shim::protos::protobuf::{CodedInputStream, Message};
use shim::protos::shim::oci::ProcessDetails;
use shim::util::{convert_to_any, read_spec_from_file, write_options, write_runtime, IntoOption};
use shim::Console;
use shim::{other, other_error};
use crate::common;
use crate::common::{
create_io, has_shared_pid_namespace, CreateConfig, ShimExecutor, INIT_PID_FILE,
}; };
use crate::synchronous::container::{ use oci_spec::runtime::{LinuxNamespaceType, LinuxResources};
CommonContainer, CommonProcess, Container, ContainerFactory, Process, use runc::{Command, Spawner};
use shim::{
api::*,
console::ConsoleSocket,
error::{Error, Result},
io::Stdio,
monitor::{monitor_subscribe, wait_pid, ExitEvent, Subject, Subscription, Topic},
mount::mount_rootfs,
other, other_error,
protos::{
api::ProcessInfo,
cgroups::metrics::Metrics,
protobuf::{CodedInputStream, Message},
shim::oci::ProcessDetails,
},
util::{convert_to_any, read_spec_from_file, write_options, write_runtime, IntoOption},
Console,
};
use time::OffsetDateTime;
use crate::{
common,
common::{create_io, has_shared_pid_namespace, CreateConfig, ShimExecutor, INIT_PID_FILE},
synchronous::container::{
CommonContainer, CommonProcess, Container, ContainerFactory, Process,
},
}; };
#[derive(Clone, Default)] #[derive(Clone, Default)]

View File

@ -16,33 +16,47 @@
#![allow(unused)] #![allow(unused)]
use std::env::current_dir; use std::{
use std::path::Path; env::current_dir,
use std::sync::mpsc::{channel, Receiver, Sender}; path::Path,
use std::sync::Arc; sync::{
mpsc::{channel, Receiver, Sender},
use log::{debug, error}; Arc,
},
};
use containerd_shim as shim; use containerd_shim as shim;
use log::{debug, error};
use runc::options::{DeleteOpts, GlobalOpts, DEFAULT_COMMAND}; use runc::options::{DeleteOpts, GlobalOpts, DEFAULT_COMMAND};
use shim::api::*; use shim::{
use shim::error::{Error, Result}; api::*,
use shim::event::Event; error::{Error, Result},
use shim::monitor::{monitor_subscribe, Subject, Subscription, Topic}; event::Event,
use shim::protos::events::task::TaskExit; io_error,
use shim::protos::protobuf::{Message, MessageDyn}; monitor::{monitor_subscribe, Subject, Subscription, Topic},
use shim::publisher::RemotePublisher; other_error,
use shim::util::{ protos::{
convert_to_timestamp, read_options, read_runtime, read_spec_from_file, timestamp, write_address, events::task::TaskExit,
protobuf::{Message, MessageDyn},
},
publisher::RemotePublisher,
spawn,
util::{
convert_to_timestamp, read_options, read_runtime, read_spec_from_file, timestamp,
write_address,
},
warn, Config, Context, ExitSignal, Shim, StartOpts,
}; };
use shim::{io_error, other_error, warn};
use shim::{spawn, Config, Context, ExitSignal, Shim, StartOpts};
use crate::common::{create_runc, ShimExecutor, GROUP_LABELS}; use crate::{
use crate::synchronous::container::{Container, Process}; common::{create_runc, ShimExecutor, GROUP_LABELS},
use crate::synchronous::runc::{RuncContainer, RuncFactory}; synchronous::{
use crate::synchronous::task::ShimTask; container::{Container, Process},
use crate::synchronous::Service; runc::{RuncContainer, RuncFactory},
task::ShimTask,
Service,
},
};
impl Shim for Service { impl Shim for Service {
type T = ShimTask<RuncFactory, RuncContainer>; type T = ShimTask<RuncFactory, RuncContainer>;

View File

@ -14,24 +14,26 @@
limitations under the License. limitations under the License.
*/ */
use std::collections::HashMap; use std::{
use std::process; collections::HashMap,
use std::sync::mpsc::Sender; process,
use std::sync::{Arc, Mutex, Once}; sync::{mpsc::Sender, Arc, Mutex, Once},
};
use log::{debug, info, warn};
use oci_spec::runtime::LinuxResources;
use containerd_shim as shim; use containerd_shim as shim;
use log::{debug, info, warn};
use shim::api::*; use oci_spec::runtime::LinuxResources;
use shim::event::Event; use shim::{
use shim::protos::events::task::{ api::*,
TaskCreate, TaskDelete, TaskExecAdded, TaskExecStarted, TaskIO, TaskStart, event::Event,
other_error,
protos::{
events::task::{TaskCreate, TaskDelete, TaskExecAdded, TaskExecStarted, TaskIO, TaskStart},
protobuf::MessageDyn,
},
util::{convert_to_any, convert_to_timestamp, IntoOption},
Error, ExitSignal, Task, TtrpcContext, TtrpcResult,
}; };
use shim::protos::protobuf::MessageDyn;
use shim::util::{convert_to_any, convert_to_timestamp, IntoOption};
use shim::{other_error, Error, ExitSignal, Task, TtrpcContext, TtrpcResult};
use crate::synchronous::container::{Container, ContainerFactory}; use crate::synchronous::container::{Container, ContainerFactory};

View File

@ -36,8 +36,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use time::serde::timestamp; use time::{serde::timestamp, OffsetDateTime};
use time::OffsetDateTime;
/// Information for runc container /// Information for runc container
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]

View File

@ -33,9 +33,7 @@
* limitations under the License. * limitations under the License.
*/ */
use std::env; use std::{env, io, process::ExitStatus};
use std::io;
use std::process::ExitStatus;
use thiserror::Error; use thiserror::Error;

View File

@ -13,15 +13,16 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
use std::fmt::Debug;
use std::fs::{File, OpenOptions};
use std::io::Result;
#[cfg(not(feature = "async"))] #[cfg(not(feature = "async"))]
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::os::unix::fs::OpenOptionsExt; use std::{
use std::os::unix::io::AsRawFd; fmt::Debug,
use std::process::Stdio; fs::{File, OpenOptions},
use std::sync::Mutex; io::Result,
os::unix::{fs::OpenOptionsExt, io::AsRawFd},
process::Stdio,
sync::Mutex,
};
use log::debug; use log::debug;
use nix::unistd::{Gid, Uid}; use nix::unistd::{Gid, Uid};

View File

@ -35,10 +35,12 @@
//! A crate for consuming the runc binary in your Rust applications, similar to //! A crate for consuming the runc binary in your Rust applications, similar to
//! [go-runc](https://github.com/containerd/go-runc) for Go. //! [go-runc](https://github.com/containerd/go-runc) for Go.
use std::fmt::{self, Debug, Display}; use std::{
use std::path::{Path, PathBuf}; fmt::{self, Debug, Display},
use std::process::{ExitStatus, Stdio}; path::{Path, PathBuf},
use std::sync::Arc; process::{ExitStatus, Stdio},
sync::Arc,
};
#[cfg(feature = "async")] #[cfg(feature = "async")]
use async_trait::async_trait; use async_trait::async_trait;
@ -46,10 +48,7 @@ use async_trait::async_trait;
use log::debug; use log::debug;
use oci_spec::runtime::{LinuxResources, Process}; use oci_spec::runtime::{LinuxResources, Process};
use crate::container::Container; use crate::{container::Container, error::Error, options::*, utils::write_value_to_temp_file};
use crate::error::Error;
use crate::options::*;
use crate::utils::write_value_to_temp_file;
pub mod container; pub mod container;
pub mod error; pub mod error;
@ -603,8 +602,10 @@ impl Runc {
mod tests { mod tests {
use std::sync::Arc; use std::sync::Arc;
use super::io::{InheritedStdIo, PipedStdIo}; use super::{
use super::*; io::{InheritedStdIo, PipedStdIo},
*,
};
fn ok_client() -> Runc { fn ok_client() -> Runc {
GlobalOpts::new() GlobalOpts::new()
@ -786,8 +787,10 @@ mod tests {
mod tests { mod tests {
use std::sync::Arc; use std::sync::Arc;
use super::io::{InheritedStdIo, PipedStdIo}; use super::{
use super::*; io::{InheritedStdIo, PipedStdIo},
*,
};
fn ok_client() -> Runc { fn ok_client() -> Runc {
GlobalOpts::new() GlobalOpts::new()

View File

@ -19,8 +19,10 @@ use std::process::{ExitStatus, Output};
use async_trait::async_trait; use async_trait::async_trait;
use log::error; use log::error;
use time::OffsetDateTime; use time::OffsetDateTime;
use tokio::process::Command; use tokio::{
use tokio::sync::oneshot::{channel, Receiver, Sender}; process::Command,
sync::oneshot::{channel, Receiver, Sender},
};
use crate::error::Error; use crate::error::Error;
@ -132,8 +134,7 @@ pub async fn execute<T: ProcessMonitor + Send + Sync>(
mod tests { mod tests {
use std::process::Stdio; use std::process::Stdio;
use tokio::process::Command; use tokio::{process::Command, sync::oneshot::channel};
use tokio::sync::oneshot::channel;
use super::*; use super::*;

View File

@ -33,14 +33,13 @@
* limitations under the License. * limitations under the License.
*/ */
use std::path::{Path, PathBuf}; use std::{
use std::sync::Arc; path::{Path, PathBuf},
use std::time::Duration; sync::Arc,
time::Duration,
};
use crate::error::Error; use crate::{error::Error, io::Io, utils, DefaultExecutor, LogFormat, Runc, Spawner};
use crate::io::Io;
use crate::{utils, DefaultExecutor, Spawner};
use crate::{LogFormat, Runc};
// constants for log format // constants for log format
pub const JSON: &str = "json"; pub const JSON: &str = "json";

View File

@ -14,10 +14,12 @@
limitations under the License. limitations under the License.
*/ */
use std::env;
#[cfg(not(feature = "async"))] #[cfg(not(feature = "async"))]
use std::io::Write; use std::io::Write;
use std::path::{Path, PathBuf}; use std::{
env,
path::{Path, PathBuf},
};
use path_absolutize::*; use path_absolutize::*;
use serde::Serialize; use serde::Serialize;

View File

@ -14,10 +14,12 @@
limitations under the License. limitations under the License.
*/ */
use std::fs::File; use std::{
use std::io::{BufRead, BufReader}; env, fs,
use std::path::PathBuf; fs::File,
use std::{env, fs}; io::{BufRead, BufReader},
path::PathBuf,
};
use ttrpc_codegen::{Codegen, Customize, ProtobufCustomize}; use ttrpc_codegen::{Codegen, Customize, ProtobufCustomize};

View File

@ -16,12 +16,9 @@
use std::env; use std::env;
use client::{api, shim::shim_ttrpc_async::TaskClient};
use containerd_shim_protos as client; use containerd_shim_protos as client;
use ttrpc::{asynchronous::Client, context::Context};
use client::api;
use client::shim::shim_ttrpc_async::TaskClient;
use ttrpc::asynchronous::Client;
use ttrpc::context::Context;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {

View File

@ -16,9 +16,8 @@
use std::env; use std::env;
use containerd_shim_protos as client;
use client::api; use client::api;
use containerd_shim_protos as client;
use ttrpc::context::Context; use ttrpc::context::Context;
fn main() { fn main() {

View File

@ -13,10 +13,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use containerd_shim_protos::api::CreateTaskRequest; use containerd_shim_protos::{api::CreateTaskRequest, shim::shim_ttrpc_async::TaskClient};
use containerd_shim_protos::shim::shim_ttrpc_async::TaskClient; use ttrpc::{
use ttrpc::asynchronous::Client; asynchronous::Client,
use ttrpc::context::{self, Context}; context::{self, Context},
};
fn default_ctx() -> Context { fn default_ctx() -> Context {
let mut ctx = context::with_timeout(0); let mut ctx = context::with_timeout(0);

View File

@ -14,9 +14,10 @@
// limitations under the License. // limitations under the License.
use containerd_shim_protos::{api::CreateTaskRequest, TaskClient}; use containerd_shim_protos::{api::CreateTaskRequest, TaskClient};
use ttrpc::{
use ttrpc::context::{self, Context}; context::{self, Context},
use ttrpc::Client; Client,
};
fn main() { fn main() {
let c = Client::connect("unix:///tmp/shim-proto-ttrpc-001").unwrap(); let c = Client::connect("unix:///tmp/shim-proto-ttrpc-001").unwrap();

View File

@ -13,12 +13,13 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::sync::Arc; use std::{sync::Arc, thread};
use std::thread;
use async_trait::async_trait; use async_trait::async_trait;
use containerd_shim_protos::api::{CreateTaskRequest, CreateTaskResponse}; use containerd_shim_protos::{
use containerd_shim_protos::shim::shim_ttrpc_async::{create_task, Task}; api::{CreateTaskRequest, CreateTaskResponse},
shim::shim_ttrpc_async::{create_task, Task},
};
use ttrpc::asynchronous::Server; use ttrpc::asynchronous::Server;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]

View File

@ -13,8 +13,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::sync::Arc; use std::{sync::Arc, thread};
use std::thread;
use containerd_shim_protos::{ use containerd_shim_protos::{
api::{CreateTaskRequest, CreateTaskResponse}, api::{CreateTaskRequest, CreateTaskResponse},

View File

@ -77,11 +77,10 @@ pub mod shim_sync {
/// TTRPC client reexport for easier access. /// TTRPC client reexport for easier access.
pub use ttrpc::Client; pub use ttrpc::Client;
/// Shim task service.
pub use crate::shim::shim_ttrpc::{create_task, Task, TaskClient};
/// Shim events service. /// Shim events service.
pub use crate::shim::events_ttrpc::{create_events, Events, EventsClient}; pub use crate::shim::events_ttrpc::{create_events, Events, EventsClient};
/// Shim task service.
pub use crate::shim::shim_ttrpc::{create_task, Task, TaskClient};
} }
pub use shim_sync::*; pub use shim_sync::*;
@ -91,18 +90,13 @@ pub mod shim_async {
/// TTRPC client reexport for easier access. /// TTRPC client reexport for easier access.
pub use ttrpc::asynchronous::Client; pub use ttrpc::asynchronous::Client;
/// Shim task service.
pub use crate::shim::shim_ttrpc_async::{create_task, Task, TaskClient};
/// Shim events service. /// Shim events service.
pub use crate::shim::events_ttrpc_async::{create_events, Events, EventsClient}; pub use crate::shim::events_ttrpc_async::{create_events, Events, EventsClient};
/// Shim task service.
pub use crate::shim::shim_ttrpc_async::{create_task, Task, TaskClient};
} }
/// Reexport auto-generated public data structures. /// Reexport auto-generated public data structures.
pub mod api { pub mod api {
pub use crate::shim::empty::*; pub use crate::shim::{empty::*, events::*, mount::*, shim::*, task::*};
pub use crate::shim::events::*;
pub use crate::shim::mount::*;
pub use crate::shim::shim::*;
pub use crate::shim::task::*;
} }

View File

@ -64,8 +64,7 @@ mod gogo {
pub use crate::types::gogo::*; pub use crate::types::gogo::*;
} }
/// Shim task service.
pub use shim_ttrpc::{create_task, Task, TaskClient};
/// Shim events service. /// Shim events service.
pub use events_ttrpc::{create_events, Events, EventsClient}; pub use events_ttrpc::{create_events, Events, EventsClient};
/// Shim task service.
pub use shim_ttrpc::{create_task, Task, TaskClient};

View File

@ -3,13 +3,16 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// //
use std::collections::HashMap; use std::{
use std::sync::mpsc::channel; collections::HashMap,
use std::sync::Arc; sync::{mpsc::channel, Arc},
};
use containerd_shim_protos::api::{CreateTaskRequest, CreateTaskResponse, DeleteRequest}; use containerd_shim_protos::{
use containerd_shim_protos::shim::shim_ttrpc::create_task; api::{CreateTaskRequest, CreateTaskResponse, DeleteRequest},
use containerd_shim_protos::Task; shim::shim_ttrpc::create_task,
Task,
};
use protobuf::{CodedInputStream, CodedOutputStream, Message}; use protobuf::{CodedInputStream, CodedOutputStream, Message};
use ttrpc::{Code, MessageHeader, Request, Response, TtrpcContext}; use ttrpc::{Code, MessageHeader, Request, Response, TtrpcContext};

View File

@ -15,8 +15,7 @@
*/ */
use std::env; use std::env;
use containerd_shim::publisher::RemotePublisher; use containerd_shim::{publisher::RemotePublisher, Context};
use containerd_shim::Context;
use containerd_shim_protos::events::task::TaskOOM; use containerd_shim_protos::events::task::TaskOOM;
#[cfg(not(feature = "async"))] #[cfg(not(feature = "async"))]

View File

@ -20,11 +20,12 @@ use containerd_shim as shim;
mod skeleton { mod skeleton {
use std::sync::Arc; use std::sync::Arc;
use log::info;
use containerd_shim as shim; use containerd_shim as shim;
use shim::synchronous::publisher::RemotePublisher; use log::info;
use shim::{api, Config, DeleteResponse, ExitSignal, TtrpcContext, TtrpcResult}; use shim::{
api, synchronous::publisher::RemotePublisher, Config, DeleteResponse, ExitSignal,
TtrpcContext, TtrpcResult,
};
#[derive(Clone)] #[derive(Clone)]
pub(crate) struct Service { pub(crate) struct Service {

View File

@ -17,16 +17,16 @@
use std::sync::Arc; use std::sync::Arc;
use async_trait::async_trait; use async_trait::async_trait;
use containerd_shim::{
asynchronous::{run, spawn, ExitSignal, Shim},
publisher::RemotePublisher,
Config, Error, StartOpts, TtrpcResult,
};
use containerd_shim_protos::{
api, api::DeleteResponse, shim_async::Task, ttrpc::r#async::TtrpcContext,
};
use log::info; use log::info;
use containerd_shim::asynchronous::{run, spawn, ExitSignal, Shim};
use containerd_shim::publisher::RemotePublisher;
use containerd_shim::{Config, Error, StartOpts, TtrpcResult};
use containerd_shim_protos::api;
use containerd_shim_protos::api::DeleteResponse;
use containerd_shim_protos::shim_async::Task;
use containerd_shim_protos::ttrpc::r#async::TtrpcContext;
#[derive(Clone)] #[derive(Clone)]
struct Service { struct Service {
exit: Arc<ExitSignal>, exit: Arc<ExitSignal>,

View File

@ -20,9 +20,10 @@ use log::warn;
use tokio::net::{UnixListener, UnixStream}; use tokio::net::{UnixListener, UnixStream};
use uuid::Uuid; use uuid::Uuid;
use crate::util::{mkdir, xdg_runtime_dir}; use crate::{
use crate::Error; util::{mkdir, xdg_runtime_dir},
use crate::Result; Error, Result,
};
pub struct ConsoleSocket { pub struct ConsoleSocket {
pub listener: UnixListener, pub listener: UnixListener,

View File

@ -17,19 +17,16 @@
use std::collections::HashMap; use std::collections::HashMap;
use async_trait::async_trait; use async_trait::async_trait;
use containerd_shim_protos::{
api::{CreateTaskRequest, ExecProcessRequest, ProcessInfo, StateResponse},
cgroups::metrics::Metrics,
};
use log::debug; use log::debug;
use oci_spec::runtime::LinuxResources; use oci_spec::runtime::LinuxResources;
use time::OffsetDateTime; use time::OffsetDateTime;
use tokio::sync::oneshot::Receiver; use tokio::sync::oneshot::Receiver;
use containerd_shim_protos::api::{ use crate::{asynchronous::processes::Process, error::Result, Error};
CreateTaskRequest, ExecProcessRequest, ProcessInfo, StateResponse,
};
use containerd_shim_protos::cgroups::metrics::Metrics;
use crate::asynchronous::processes::Process;
use crate::error::Result;
use crate::Error;
#[async_trait] #[async_trait]
pub trait Container { pub trait Container {

View File

@ -14,42 +14,48 @@
limitations under the License. limitations under the License.
*/ */
use std::convert::TryFrom; use std::{
use std::os::unix::fs::FileTypeExt; convert::TryFrom,
use std::os::unix::io::AsRawFd; env,
use std::os::unix::net::UnixListener; os::unix::{fs::FileTypeExt, io::AsRawFd, net::UnixListener},
use std::path::Path; path::Path,
use std::process::Command; process,
use std::process::Stdio; process::{Command, Stdio},
use std::sync::atomic::{AtomicBool, Ordering}; sync::{
use std::sync::Arc; atomic::{AtomicBool, Ordering},
use std::{env, process}; Arc,
},
};
use async_trait::async_trait; use async_trait::async_trait;
use command_fds::{CommandFdExt, FdMapping}; use command_fds::{CommandFdExt, FdMapping};
use containerd_shim_protos::{
api::DeleteResponse,
protobuf::Message,
shim_async::{create_task, Client, Task},
ttrpc::r#async::Server,
};
use futures::StreamExt; use futures::StreamExt;
use libc::{SIGCHLD, SIGINT, SIGPIPE, SIGTERM}; use libc::{SIGCHLD, SIGINT, SIGPIPE, SIGTERM};
use log::{debug, error, info, warn}; use log::{debug, error, info, warn};
use nix::errno::Errno; use nix::{
use nix::sys::signal::Signal; errno::Errno,
use nix::sys::wait::{self, WaitPidFlag, WaitStatus}; sys::{
use nix::unistd::Pid; signal::Signal,
wait::{self, WaitPidFlag, WaitStatus},
},
unistd::Pid,
};
use signal_hook_tokio::Signals; use signal_hook_tokio::Signals;
use tokio::io::AsyncWriteExt; use tokio::{io::AsyncWriteExt, sync::Notify};
use tokio::sync::Notify;
use containerd_shim_protos::api::DeleteResponse;
use containerd_shim_protos::protobuf::Message;
use containerd_shim_protos::shim_async::{create_task, Client, Task};
use containerd_shim_protos::ttrpc::r#async::Server;
use crate::asynchronous::monitor::monitor_notify_by_pid;
use crate::asynchronous::publisher::RemotePublisher;
use crate::error::Error;
use crate::error::Result;
use crate::util::{asyncify, read_file_to_str, write_str_to_file};
use crate::{ use crate::{
args, logger, parse_sockaddr, reap, socket_address, Config, StartOpts, SOCKET_FD, TTRPC_ADDRESS, args,
asynchronous::{monitor::monitor_notify_by_pid, publisher::RemotePublisher},
error::{Error, Result},
logger, parse_sockaddr, reap, socket_address,
util::{asyncify, read_file_to_str, write_str_to_file},
Config, StartOpts, SOCKET_FD, TTRPC_ADDRESS,
}; };
pub mod console; pub mod console;

View File

@ -18,12 +18,15 @@ use std::collections::HashMap;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use log::error; use log::error;
use tokio::sync::mpsc::{channel, Receiver, Sender}; use tokio::sync::{
use tokio::sync::Mutex; mpsc::{channel, Receiver, Sender},
Mutex,
};
use crate::error::Error; use crate::{
use crate::error::Result; error::{Error, Result},
use crate::monitor::{ExitEvent, Subject, Topic}; monitor::{ExitEvent, Subject, Topic},
};
lazy_static! { lazy_static! {
pub static ref MONITOR: Mutex<Monitor> = { pub static ref MONITOR: Mutex<Monitor> = {
@ -143,10 +146,12 @@ impl Monitor {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::asynchronous::monitor::{ use crate::{
monitor_notify_by_exec, monitor_notify_by_pid, monitor_subscribe, monitor_unsubscribe, asynchronous::monitor::{
monitor_notify_by_exec, monitor_notify_by_pid, monitor_subscribe, monitor_unsubscribe,
},
monitor::{ExitEvent, Subject, Topic},
}; };
use crate::monitor::{ExitEvent, Subject, Topic};
#[tokio::test] #[tokio::test]
async fn test_monitor() { async fn test_monitor() {

View File

@ -14,21 +14,19 @@
limitations under the License. limitations under the License.
*/ */
use std::os::unix::io::AsRawFd; use std::{os::unix::io::AsRawFd, sync::Arc};
use std::sync::Arc;
use async_trait::async_trait; use async_trait::async_trait;
use containerd_shim_protos::{
api::{ProcessInfo, StateResponse, Status},
cgroups::metrics::Metrics,
protobuf::well_known_types::timestamp::Timestamp,
};
use oci_spec::runtime::LinuxResources; use oci_spec::runtime::LinuxResources;
use time::OffsetDateTime; use time::OffsetDateTime;
use tokio::sync::oneshot::{channel, Receiver, Sender}; use tokio::sync::oneshot::{channel, Receiver, Sender};
use containerd_shim_protos::api::{ProcessInfo, StateResponse, Status}; use crate::{io::Stdio, ioctl_set_winsz, util::asyncify, Console};
use containerd_shim_protos::cgroups::metrics::Metrics;
use containerd_shim_protos::protobuf::well_known_types::timestamp::Timestamp;
use crate::io::Stdio;
use crate::util::asyncify;
use crate::{ioctl_set_winsz, Console};
#[async_trait] #[async_trait]
pub trait Process { pub trait Process {

View File

@ -17,18 +17,19 @@
use std::os::unix::io::RawFd; use std::os::unix::io::RawFd;
use async_trait::async_trait; use async_trait::async_trait;
use containerd_shim_protos::{
api::Empty,
protobuf::MessageDyn,
shim::events,
shim_async::{Client, Events, EventsClient},
ttrpc,
ttrpc::{context::Context, r#async::TtrpcContext},
};
use containerd_shim_protos::api::Empty; use crate::{
use containerd_shim_protos::protobuf::MessageDyn; error::Result,
use containerd_shim_protos::shim::events; util::{asyncify, connect, convert_to_any, timestamp},
use containerd_shim_protos::shim_async::{Client, Events, EventsClient}; };
use containerd_shim_protos::ttrpc;
use containerd_shim_protos::ttrpc::context::Context;
use containerd_shim_protos::ttrpc::r#async::TtrpcContext;
use crate::error::Result;
use crate::util::asyncify;
use crate::util::{connect, convert_to_any, timestamp};
/// Async Remote publisher connects to containerd's TTRPC endpoint to publish events from shim. /// Async Remote publisher connects to containerd's TTRPC endpoint to publish events from shim.
pub struct RemotePublisher { pub struct RemotePublisher {
@ -97,17 +98,21 @@ impl Events for RemotePublisher {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::os::unix::io::AsRawFd; use std::{
use std::os::unix::net::UnixListener; os::unix::{io::AsRawFd, net::UnixListener},
use std::sync::Arc; sync::Arc,
};
use tokio::sync::mpsc::{channel, Sender}; use containerd_shim_protos::{
use tokio::sync::Barrier; api::{Empty, ForwardRequest},
events::task::TaskOOM,
use containerd_shim_protos::api::{Empty, ForwardRequest}; shim_async::create_events,
use containerd_shim_protos::events::task::TaskOOM; ttrpc::asynchronous::Server,
use containerd_shim_protos::shim_async::create_events; };
use containerd_shim_protos::ttrpc::asynchronous::Server; use tokio::sync::{
mpsc::{channel, Sender},
Barrier,
};
use super::*; use super::*;

View File

@ -14,37 +14,38 @@
limitations under the License. limitations under the License.
*/ */
use std::collections::HashMap; use std::{collections::HashMap, sync::Arc};
use std::sync::Arc;
use async_trait::async_trait; use async_trait::async_trait;
use containerd_shim_protos::{
api::{
CloseIORequest, ConnectRequest, ConnectResponse, DeleteResponse, PidsRequest, PidsResponse,
StatsRequest, StatsResponse, UpdateTaskRequest,
},
events::task::{TaskCreate, TaskDelete, TaskExecAdded, TaskExecStarted, TaskIO, TaskStart},
protobuf::MessageDyn,
shim_async::Task,
ttrpc,
ttrpc::r#async::TtrpcContext,
};
use log::{debug, info, warn}; use log::{debug, info, warn};
use oci_spec::runtime::LinuxResources; use oci_spec::runtime::LinuxResources;
use tokio::sync::mpsc::Sender; use tokio::sync::{mpsc::Sender, MappedMutexGuard, Mutex, MutexGuard};
use tokio::sync::{MappedMutexGuard, Mutex, MutexGuard};
use containerd_shim_protos::api::{ use crate::{
CloseIORequest, ConnectRequest, ConnectResponse, DeleteResponse, PidsRequest, PidsResponse, api::{
StatsRequest, StatsResponse, UpdateTaskRequest, CreateTaskRequest, CreateTaskResponse, DeleteRequest, Empty, ExecProcessRequest,
KillRequest, ResizePtyRequest, ShutdownRequest, StartRequest, StartResponse, StateRequest,
StateResponse, Status, WaitRequest, WaitResponse,
},
asynchronous::{
container::{Container, ContainerFactory},
ExitSignal,
},
event::Event,
util::{convert_to_any, convert_to_timestamp, AsOption},
TtrpcResult,
}; };
use containerd_shim_protos::events::task::{
TaskCreate, TaskDelete, TaskExecAdded, TaskExecStarted, TaskIO, TaskStart,
};
use containerd_shim_protos::protobuf::MessageDyn;
use containerd_shim_protos::shim_async::Task;
use containerd_shim_protos::ttrpc;
use containerd_shim_protos::ttrpc::r#async::TtrpcContext;
use crate::api::{
CreateTaskRequest, CreateTaskResponse, DeleteRequest, Empty, ExecProcessRequest, KillRequest,
ResizePtyRequest, ShutdownRequest, StartRequest, StartResponse, StateRequest, StateResponse,
Status, WaitRequest, WaitResponse,
};
use crate::asynchronous::container::{Container, ContainerFactory};
use crate::asynchronous::ExitSignal;
use crate::event::Event;
use crate::util::{convert_to_any, convert_to_timestamp, AsOption};
use crate::TtrpcResult;
type EventSender = Sender<(String, Box<dyn MessageDyn>)>; type EventSender = Sender<(String, Box<dyn MessageDyn>)>;

View File

@ -16,19 +16,20 @@
use std::path::Path; use std::path::Path;
use containerd_shim_protos::{api::Mount, shim::oci::Options};
use libc::mode_t; use libc::mode_t;
use nix::sys::stat::Mode; use nix::sys::stat::Mode;
use oci_spec::runtime::Spec; use oci_spec::runtime::Spec;
use tokio::fs::OpenOptions; use tokio::{
use tokio::io::{AsyncReadExt, AsyncWriteExt}; fs::OpenOptions,
use tokio::task::spawn_blocking; io::{AsyncReadExt, AsyncWriteExt},
task::spawn_blocking,
};
use containerd_shim_protos::api::Mount; use crate::{
use containerd_shim_protos::shim::oci::Options; error::{Error, Result},
util::{AsOption, JsonOptions, CONFIG_FILE_NAME, OPTIONS_FILE_NAME, RUNTIME_FILE_NAME},
use crate::error::Error; };
use crate::error::Result;
use crate::util::{AsOption, JsonOptions, CONFIG_FILE_NAME, OPTIONS_FILE_NAME, RUNTIME_FILE_NAME};
pub async fn asyncify<F, T>(f: F) -> Result<T> pub async fn asyncify<F, T>(f: F) -> Result<T>
where where

View File

@ -16,20 +16,17 @@
#![cfg(target_os = "linux")] #![cfg(target_os = "linux")]
use std::fs; use std::{fs, io::Read, path::Path};
use std::io::Read;
use std::path::Path;
use cgroups_rs::cgroup::get_cgroups_relative_paths_by_pid; use cgroups_rs::{
use cgroups_rs::{hierarchies, Cgroup, CgroupPid, MaxValue, Subsystem}; cgroup::get_cgroups_relative_paths_by_pid, hierarchies, Cgroup, CgroupPid, MaxValue, Subsystem,
use oci_spec::runtime::LinuxResources;
use containerd_shim_protos::cgroups::metrics::{
CPUStat, CPUUsage, MemoryEntry, MemoryStat, Metrics,
}; };
use containerd_shim_protos::protobuf::well_known_types::any::Any; use containerd_shim_protos::{
use containerd_shim_protos::protobuf::Message; cgroups::metrics::{CPUStat, CPUUsage, MemoryEntry, MemoryStat, Metrics},
use containerd_shim_protos::shim::oci::Options; protobuf::{well_known_types::any::Any, Message},
shim::oci::Options,
};
use oci_spec::runtime::LinuxResources;
use crate::error::{Error, Result}; use crate::error::{Error, Result};

View File

@ -16,8 +16,10 @@
use thiserror::Error; use thiserror::Error;
use crate::monitor::ExitEvent; use crate::{
use crate::protos::{protobuf, ttrpc}; monitor::ExitEvent,
protos::{protobuf, ttrpc},
};
pub type Result<T> = std::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;

View File

@ -1,5 +1,4 @@
use containerd_shim_protos::events::task::*; use containerd_shim_protos::{events::task::*, protobuf::MessageDyn};
use containerd_shim_protos::protobuf::MessageDyn;
pub trait Event: MessageDyn { pub trait Event: MessageDyn {
fn topic(&self) -> String; fn topic(&self) -> String;

View File

@ -32,18 +32,20 @@
//! ``` //! ```
//! //!
use std::collections::hash_map::DefaultHasher; use std::{
use std::fs::File; collections::hash_map::DefaultHasher,
use std::hash::Hasher; fs::File,
use std::os::unix::io::RawFd; hash::Hasher,
use std::os::unix::net::UnixListener; os::unix::{io::RawFd, net::UnixListener},
use std::path::{Path, PathBuf}; path::{Path, PathBuf},
};
use nix::ioctl_write_ptr_bad;
pub use containerd_shim_protos as protos; pub use containerd_shim_protos as protos;
pub use protos::shim::shim::DeleteResponse; use nix::ioctl_write_ptr_bad;
pub use protos::ttrpc::{context::Context, Result as TtrpcResult}; pub use protos::{
shim::shim::DeleteResponse,
ttrpc::{context::Context, Result as TtrpcResult},
};
#[cfg(feature = "async")] #[cfg(feature = "async")]
pub use crate::asynchronous::*; pub use crate::asynchronous::*;
@ -70,10 +72,11 @@ pub mod util;
/// Generated request/response structures. /// Generated request/response structures.
pub mod api { pub mod api {
pub use super::protos::api::Status; pub use super::protos::{
pub use super::protos::shim::oci::Options; api::Status,
pub use super::protos::shim::shim::*; shim::{oci::Options, shim::*},
pub use super::protos::types::empty::Empty; types::empty::Empty,
};
} }
macro_rules! cfg_not_async { macro_rules! cfg_not_async {

View File

@ -14,12 +14,14 @@
limitations under the License. limitations under the License.
*/ */
use std::borrow::BorrowMut; use std::{
use std::fs::{File, OpenOptions}; borrow::BorrowMut,
use std::io; fs::{File, OpenOptions},
use std::io::Write; io,
use std::path::Path; io::Write,
use std::sync::Mutex; path::Path,
sync::Mutex,
};
use log::{Metadata, Record}; use log::{Metadata, Record};

View File

@ -15,10 +15,12 @@
*/ */
#![allow(unused)] #![allow(unused)]
use std::collections::HashMap; use std::{
use std::env; collections::HashMap,
use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, Not}; env,
use std::path::Path; ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, Not},
path::Path,
};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use log::error; use log::error;

View File

@ -14,15 +14,18 @@
limitations under the License. limitations under the License.
*/ */
use std::os::unix::net::{UnixListener, UnixStream}; use std::{
use std::path::{Path, PathBuf}; os::unix::net::{UnixListener, UnixStream},
path::{Path, PathBuf},
};
use log::warn; use log::warn;
use uuid::Uuid; use uuid::Uuid;
use crate::util::{mkdir, xdg_runtime_dir}; use crate::{
use crate::Error; util::{mkdir, xdg_runtime_dir},
use crate::Result; Error, Result,
};
pub struct ConsoleSocket { pub struct ConsoleSocket {
pub listener: UnixListener, pub listener: UnixListener,

View File

@ -32,35 +32,42 @@
//! ``` //! ```
//! //!
use std::convert::TryFrom; use std::{
use std::env; convert::TryFrom,
use std::fs; env, fs,
use std::io::Write; io::Write,
use std::os::unix::fs::FileTypeExt; os::unix::{fs::FileTypeExt, io::AsRawFd},
use std::os::unix::io::AsRawFd; path::Path,
use std::path::Path; process::{self, Command, Stdio},
use std::process::{self, Command, Stdio}; sync::{Arc, Condvar, Mutex},
use std::sync::{Arc, Condvar, Mutex}; };
use command_fds::{CommandFdExt, FdMapping}; use command_fds::{CommandFdExt, FdMapping};
use libc::{SIGCHLD, SIGINT, SIGPIPE, SIGTERM}; use libc::{SIGCHLD, SIGINT, SIGPIPE, SIGTERM};
pub use log::{debug, error, info, warn}; pub use log::{debug, error, info, warn};
use nix::errno::Errno; use nix::{
use nix::sys::signal::Signal; errno::Errno,
use nix::sys::wait::{self, WaitPidFlag, WaitStatus}; sys::{
use nix::unistd::Pid; signal::Signal,
wait::{self, WaitPidFlag, WaitStatus},
},
unistd::Pid,
};
use signal_hook::iterator::Signals; use signal_hook::iterator::Signals;
use crate::protos::protobuf::Message;
use crate::protos::shim::shim_ttrpc::{create_task, Task};
use crate::protos::ttrpc::{Client, Server};
use util::{read_address, write_address}; use util::{read_address, write_address};
use crate::api::DeleteResponse; use crate::{
use crate::synchronous::publisher::RemotePublisher; api::DeleteResponse,
use crate::Error; args, logger, parse_sockaddr,
use crate::{args, logger, reap, Result, TTRPC_ADDRESS}; protos::{
use crate::{parse_sockaddr, socket_address, start_listener, Config, StartOpts, SOCKET_FD}; protobuf::Message,
shim::shim_ttrpc::{create_task, Task},
ttrpc::{Client, Server},
},
reap, socket_address, start_listener,
synchronous::publisher::RemotePublisher,
Config, Error, Result, StartOpts, SOCKET_FD, TTRPC_ADDRESS,
};
pub mod monitor; pub mod monitor;
pub mod publisher; pub mod publisher;

View File

@ -14,15 +14,21 @@
limitations under the License. limitations under the License.
*/ */
use std::collections::HashMap; use std::{
use std::sync::mpsc::{channel, Receiver, Sender}; collections::HashMap,
use std::sync::Mutex; sync::{
mpsc::{channel, Receiver, Sender},
Mutex,
},
};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use log::{error, warn}; use log::{error, warn};
use crate::monitor::{ExitEvent, Subject, Topic}; use crate::{
use crate::Result; monitor::{ExitEvent, Subject, Topic},
Result,
};
lazy_static! { lazy_static! {
pub static ref MONITOR: Mutex<Monitor> = { pub static ref MONITOR: Mutex<Monitor> = {

View File

@ -16,16 +16,19 @@
//! Implements a client to publish events from the shim back to containerd. //! Implements a client to publish events from the shim back to containerd.
use client::{
protobuf::MessageDyn,
shim::events,
ttrpc::{self, context::Context},
types::empty,
Client, Events, EventsClient,
};
use containerd_shim_protos as client; use containerd_shim_protos as client;
use client::protobuf::MessageDyn; use crate::{
use client::shim::events; error::Result,
use client::ttrpc::{self, context::Context}; util::{connect, convert_to_any, timestamp},
use client::types::empty; };
use client::{Client, Events, EventsClient};
use crate::error::Result;
use crate::util::{connect, convert_to_any, timestamp};
/// Remote publisher connects to containerd's TTRPC endpoint to publish events from shim. /// Remote publisher connects to containerd's TTRPC endpoint to publish events from shim.
pub struct RemotePublisher { pub struct RemotePublisher {
@ -87,15 +90,17 @@ impl Events for RemotePublisher {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::os::unix::io::AsRawFd; use std::{
use std::os::unix::net::UnixListener; os::unix::{io::AsRawFd, net::UnixListener},
use std::sync::{Arc, Barrier}; sync::{Arc, Barrier},
};
use client::{
api::{Empty, ForwardRequest},
events::task::TaskOOM,
};
use ttrpc::Server; use ttrpc::Server;
use client::api::{Empty, ForwardRequest};
use client::events::task::TaskOOM;
use super::*; use super::*;
struct FakeServer {} struct FakeServer {}

View File

@ -14,19 +14,22 @@
limitations under the License. limitations under the License.
*/ */
use std::fs::{rename, File, OpenOptions}; use std::{
use std::io::{Read, Write}; fs::{rename, File, OpenOptions},
use std::path::Path; io::{Read, Write},
path::Path,
};
use containerd_shim_protos::shim::oci::Options;
use libc::mode_t; use libc::mode_t;
use log::warn; use log::warn;
use nix::sys::stat::Mode; use nix::sys::stat::Mode;
use oci_spec::runtime::Spec; use oci_spec::runtime::Spec;
use containerd_shim_protos::shim::oci::Options; use crate::{
util::{JsonOptions, OPTIONS_FILE_NAME, RUNTIME_FILE_NAME},
use crate::util::{JsonOptions, OPTIONS_FILE_NAME, RUNTIME_FILE_NAME}; Error,
use crate::Error; };
pub fn read_file_to_str<P: AsRef<Path>>(filename: P) -> crate::Result<String> { pub fn read_file_to_str<P: AsRef<Path>>(filename: P) -> crate::Result<String> {
let mut file = File::open(&filename).map_err(io_error!( let mut file = File::open(&filename).map_err(io_error!(

View File

@ -14,21 +14,27 @@
limitations under the License. limitations under the License.
*/ */
use std::env; use std::{
use std::os::unix::io::RawFd; env,
use std::time::{SystemTime, UNIX_EPOCH}; os::unix::io::RawFd,
time::{SystemTime, UNIX_EPOCH},
};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use time::OffsetDateTime; use time::OffsetDateTime;
use crate::api::Options;
#[cfg(feature = "async")] #[cfg(feature = "async")]
pub use crate::asynchronous::util::*; pub use crate::asynchronous::util::*;
use crate::error::Result;
use crate::protos::protobuf::well_known_types::{any::Any, timestamp::Timestamp};
use crate::protos::protobuf::MessageDyn;
#[cfg(not(feature = "async"))] #[cfg(not(feature = "async"))]
pub use crate::synchronous::util::*; pub use crate::synchronous::util::*;
use crate::{
api::Options,
error::Result,
protos::protobuf::{
well_known_types::{any::Any, timestamp::Timestamp},
MessageDyn,
},
};
pub const CONFIG_FILE_NAME: &str = "config.json"; pub const CONFIG_FILE_NAME: &str = "config.json";
pub const OPTIONS_FILE_NAME: &str = "options.json"; pub const OPTIONS_FILE_NAME: &str = "options.json";
@ -96,8 +102,7 @@ impl From<JsonOptions> for Options {
} }
pub fn connect(address: impl AsRef<str>) -> Result<RawFd> { pub fn connect(address: impl AsRef<str>) -> Result<RawFd> {
use nix::sys::socket::*; use nix::{sys::socket::*, unistd::close};
use nix::unistd::close;
let unix_addr = UnixAddr::new(address.as_ref())?; let unix_addr = UnixAddr::new(address.as_ref())?;

View File

@ -14,9 +14,7 @@
limitations under the License. limitations under the License.
*/ */
use std::env; use std::{env, fs, io};
use std::fs;
use std::io;
const PROTO_FILES: &[&str] = &[ const PROTO_FILES: &[&str] = &[
"vendor/github.com/containerd/containerd/api/types/mount.proto", "vendor/github.com/containerd/containerd/api/types/mount.proto",

View File

@ -14,17 +14,14 @@
limitations under the License. limitations under the License.
*/ */
use std::collections::HashMap; use std::{collections::HashMap, env};
use std::env;
use futures::TryFutureExt;
use log::info;
use tokio::net::UnixListener;
use containerd_snapshots as snapshots; use containerd_snapshots as snapshots;
use containerd_snapshots::{api, Info, Usage}; use containerd_snapshots::{api, Info, Usage};
use futures::TryFutureExt;
use log::info;
use snapshots::tonic::transport::Server; use snapshots::tonic::transport::Server;
use tokio::net::UnixListener;
#[derive(Default)] #[derive(Default)]
struct Example; struct Example;

View File

@ -21,8 +21,7 @@ use std::convert::{TryFrom, TryInto};
use thiserror::Error; use thiserror::Error;
use tonic::Status; use tonic::Status;
use crate::api::snapshots::v1 as grpc; use crate::{api::snapshots::v1 as grpc, Info, Kind};
use crate::{Info, Kind};
impl From<Kind> for i32 { impl From<Kind> for i32 {
fn from(kind: Kind) -> i32 { fn from(kind: Kind) -> i32 {

View File

@ -49,10 +49,7 @@
//! ``` //! ```
//! //!
use std::collections::HashMap; use std::{collections::HashMap, fmt::Debug, ops::AddAssign, time::SystemTime};
use std::fmt::Debug;
use std::ops::AddAssign;
use std::time::SystemTime;
pub use tonic; pub use tonic;

View File

@ -16,16 +16,17 @@
//! Trait wrapper to server GRPC requests. //! Trait wrapper to server GRPC requests.
use std::convert::TryInto; use std::{convert::TryInto, fmt::Debug};
use std::fmt::Debug;
use tokio_stream::wrappers::ReceiverStream; use tokio_stream::wrappers::ReceiverStream;
use crate::api::snapshots::v1::{ use crate::{
snapshots_server::{Snapshots, SnapshotsServer}, api::snapshots::v1::{
*, snapshots_server::{Snapshots, SnapshotsServer},
*,
},
Snapshotter,
}; };
use crate::Snapshotter;
pub struct Wrapper<S: Snapshotter> { pub struct Wrapper<S: Snapshotter> {
snapshotter: S, snapshotter: S,

View File

@ -1 +1,4 @@
newline_style = "Unix" newline_style = "Unix"
unstable_features = true # Cargo fmt now needs to be called with `cargo +nightly fmt`
group_imports = "StdExternalCrate" # Create 3 groups: std, external crates, and self.
imports_granularity = "Crate" # Merge imports from the same crate into a single use statement