Fix the UDS path too long issue
This commit is contained in:
parent
22b02850a3
commit
ce174e1496
@ -18,9 +18,7 @@ use occlum_exec::occlum_exec::{
|
|||||||
KillProcessRequest, StopRequest,
|
KillProcessRequest, StopRequest,
|
||||||
};
|
};
|
||||||
use occlum_exec::occlum_exec_grpc::OcclumExecClient;
|
use occlum_exec::occlum_exec_grpc::OcclumExecClient;
|
||||||
use occlum_exec::{
|
use occlum_exec::{DEFAULT_SERVER_FILE, DEFAULT_SERVER_TIMER, DEFAULT_SOCK_FILE};
|
||||||
DEFAULT_CLIENT_FILE, DEFAULT_SERVER_FILE, DEFAULT_SERVER_TIMER, DEFAULT_SOCK_FILE,
|
|
||||||
};
|
|
||||||
use protobuf::RepeatedField;
|
use protobuf::RepeatedField;
|
||||||
use sendfd::SendWithFd;
|
use sendfd::SendWithFd;
|
||||||
use signal_hook::iterator::Signals;
|
use signal_hook::iterator::Signals;
|
||||||
@ -142,7 +140,12 @@ fn start_server(client: &OcclumExecClient, server_name: &str) -> Result<u32, Str
|
|||||||
Err(_resp) => {
|
Err(_resp) => {
|
||||||
if !server_launched {
|
if !server_launched {
|
||||||
debug!("server is not running, try to launch the server.");
|
debug!("server is not running, try to launch the server.");
|
||||||
match Command::new(server_name).stdout(Stdio::null()).spawn() {
|
match Command::new(server_name)
|
||||||
|
.arg("-d")
|
||||||
|
.arg(env::current_dir().unwrap())
|
||||||
|
.stdout(Stdio::null())
|
||||||
|
.spawn()
|
||||||
|
{
|
||||||
Err(_r) => {
|
Err(_r) => {
|
||||||
return Err("Failed to launch server".to_string());
|
return Err("Failed to launch server".to_string());
|
||||||
}
|
}
|
||||||
@ -233,6 +236,14 @@ fn main() -> Result<(), i32> {
|
|||||||
|
|
||||||
let matches = App::new("Occlum")
|
let matches = App::new("Occlum")
|
||||||
.version("0.1.0")
|
.version("0.1.0")
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("instance_dir")
|
||||||
|
.short("d")
|
||||||
|
.long("instance_dir")
|
||||||
|
.takes_value(true)
|
||||||
|
.default_value("./")
|
||||||
|
.help("The Occlum instance dir."),
|
||||||
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
App::new("start").about(
|
App::new("start").about(
|
||||||
"Start the Occlum server. If the server already running, immediately return.",
|
"Start the Occlum server. If the server already running, immediately return.",
|
||||||
@ -263,32 +274,20 @@ fn main() -> Result<(), i32> {
|
|||||||
)
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
let args: Vec<String> = env::args().collect();
|
|
||||||
let env: Vec<String> = env::vars()
|
let env: Vec<String> = env::vars()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(key, val)| format!("{}={}", key, val))
|
.map(|(key, val)| format!("{}={}", key, val))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut sock_file = String::from(args[0].as_str());
|
// Set the instance_dir as the current dir
|
||||||
let sock_file = str::replace(
|
let instance_dir = Path::new(matches.value_of("instance_dir").unwrap());
|
||||||
sock_file.as_mut_str(),
|
assert!(env::set_current_dir(&instance_dir).is_ok());
|
||||||
DEFAULT_CLIENT_FILE,
|
|
||||||
DEFAULT_SOCK_FILE,
|
|
||||||
);
|
|
||||||
|
|
||||||
let client = OcclumExecClient::new_plain_unix(&sock_file, ClientConf::new())
|
let client = OcclumExecClient::new_plain_unix(DEFAULT_SOCK_FILE, ClientConf::new())
|
||||||
.expect("failed to create UDS client");
|
.expect("failed to create UDS client");
|
||||||
|
|
||||||
if let Some(ref _matches) = matches.subcommand_matches("start") {
|
if let Some(ref _matches) = matches.subcommand_matches("start") {
|
||||||
//get the server name with the first args
|
if let Err(s) = start_server(&client, DEFAULT_SERVER_FILE) {
|
||||||
let mut server_name = String::from(args[0].as_str());
|
|
||||||
let server_name = str::replace(
|
|
||||||
server_name.as_mut_str(),
|
|
||||||
DEFAULT_CLIENT_FILE,
|
|
||||||
DEFAULT_SERVER_FILE,
|
|
||||||
);
|
|
||||||
|
|
||||||
if let Err(s) = start_server(&client, &server_name) {
|
|
||||||
println!("start_server failed {}", s);
|
println!("start_server failed {}", s);
|
||||||
return Err(-1);
|
return Err(-1);
|
||||||
}
|
}
|
||||||
|
@ -5,16 +5,18 @@ extern crate occlum_exec;
|
|||||||
extern crate protobuf;
|
extern crate protobuf;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
|
use clap::{App, Arg};
|
||||||
use futures::executor;
|
use futures::executor;
|
||||||
use grpc::prelude::*;
|
use grpc::prelude::*;
|
||||||
use grpc::ClientConf;
|
use grpc::ClientConf;
|
||||||
use occlum_exec::occlum_exec::HealthCheckRequest;
|
use occlum_exec::occlum_exec::HealthCheckRequest;
|
||||||
use occlum_exec::occlum_exec_grpc::{OcclumExecClient, OcclumExecServer};
|
use occlum_exec::occlum_exec_grpc::{OcclumExecClient, OcclumExecServer};
|
||||||
use occlum_exec::server::OcclumExecImpl;
|
use occlum_exec::server::OcclumExecImpl;
|
||||||
use occlum_exec::{DEFAULT_SERVER_FILE, DEFAULT_SOCK_FILE};
|
use occlum_exec::DEFAULT_SOCK_FILE;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::{CStr, OsString};
|
use std::ffi::{CStr, OsString};
|
||||||
use std::os::unix::ffi::OsStrExt;
|
use std::os::unix::ffi::OsStrExt;
|
||||||
|
use std::path::Path;
|
||||||
use std::sync::{Arc, Condvar, Mutex};
|
use std::sync::{Arc, Condvar, Mutex};
|
||||||
|
|
||||||
//Checks the server status, if the server is running return true, else recover the socket file and return false.
|
//Checks the server status, if the server is running return true, else recover the socket file and return false.
|
||||||
@ -52,17 +54,24 @@ fn check_server_status(sock_file: &str) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
//get the UDS file name
|
let matches = App::new("Occlum_server")
|
||||||
let args: Vec<String> = env::args().collect();
|
.version("0.1.0")
|
||||||
let mut sockfile = String::from(args[0].as_str());
|
.arg(
|
||||||
let sockfile = str::replace(
|
Arg::with_name("instance_dir")
|
||||||
sockfile.as_mut_str(),
|
.short("d")
|
||||||
DEFAULT_SERVER_FILE,
|
.long("instance_dir")
|
||||||
DEFAULT_SOCK_FILE,
|
.takes_value(true)
|
||||||
);
|
.default_value("./")
|
||||||
|
.help("The Occlum instance dir."),
|
||||||
|
)
|
||||||
|
.get_matches();
|
||||||
|
|
||||||
|
// Set the instance_dir as the current dir
|
||||||
|
let instance_dir = Path::new(matches.value_of("instance_dir").unwrap());
|
||||||
|
assert!(env::set_current_dir(&instance_dir).is_ok());
|
||||||
|
|
||||||
//If the server already startted, then return
|
//If the server already startted, then return
|
||||||
if check_server_status(sockfile.as_str()) {
|
if check_server_status(DEFAULT_SOCK_FILE) {
|
||||||
println!("server stared");
|
println!("server stared");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -74,7 +83,7 @@ fn main() {
|
|||||||
);
|
);
|
||||||
let mut server_builder = grpc::ServerBuilder::new_plain();
|
let mut server_builder = grpc::ServerBuilder::new_plain();
|
||||||
server_builder.add_service(service_def);
|
server_builder.add_service(service_def);
|
||||||
match server_builder.http.set_unix_addr(sockfile) {
|
match server_builder.http.set_unix_addr(DEFAULT_SOCK_FILE) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
debug!("{:?}", e);
|
debug!("{:?}", e);
|
||||||
|
@ -13,7 +13,6 @@ pub mod occlum_exec_grpc;
|
|||||||
|
|
||||||
pub mod server;
|
pub mod server;
|
||||||
|
|
||||||
pub const DEFAULT_SERVER_FILE: &'static str = "occlum_exec_server";
|
pub const DEFAULT_SERVER_FILE: &'static str = "build/bin/occlum_exec_server";
|
||||||
pub const DEFAULT_CLIENT_FILE: &'static str = "occlum_exec_client";
|
pub const DEFAULT_SOCK_FILE: &'static str = "run/occlum_exec.sock";
|
||||||
pub const DEFAULT_SOCK_FILE: &'static str = "occlum_exec.sock";
|
|
||||||
pub const DEFAULT_SERVER_TIMER: u32 = 3;
|
pub const DEFAULT_SERVER_TIMER: u32 = 3;
|
||||||
|
Loading…
Reference in New Issue
Block a user