Skip to main content

start_command/
mod.rs

1//! start-command library
2//!
3//! Provides command execution with isolation, substitution, and failure handling.
4
5// `println!` and friends that drop write errors instead of panicking. Rust
6// ignores SIGPIPE, so printing into a closed pipe (`start --version | head -1`)
7// fails with EPIPE; like the JavaScript edition, start keeps running and exits
8// with its own code (issue #222). Defined before the modules, these shadow the
9// std macros in all of them; the binary imports them from the crate root.
10#[macro_export]
11macro_rules! print {
12    ($($arg:tt)*) => {{
13        use ::std::io::Write as _;
14        let _ = ::std::write!(::std::io::stdout(), $($arg)*);
15    }};
16}
17
18#[macro_export]
19macro_rules! println {
20    ($($arg:tt)*) => {{
21        use ::std::io::Write as _;
22        let _ = ::std::writeln!(::std::io::stdout(), $($arg)*);
23    }};
24}
25
26#[macro_export]
27macro_rules! eprint {
28    ($($arg:tt)*) => {{
29        use ::std::io::Write as _;
30        let _ = ::std::write!(::std::io::stderr(), $($arg)*);
31    }};
32}
33
34#[macro_export]
35macro_rules! eprintln {
36    ($($arg:tt)*) => {{
37        use ::std::io::Write as _;
38        let _ = ::std::writeln!(::std::io::stderr(), $($arg)*);
39    }};
40}
41
42pub mod args_parser;
43pub mod args_parser_queries;
44mod atomic_write;
45pub mod attached_diagnostics;
46pub mod cgroup_memory;
47pub mod cpu_penalty;
48pub mod cpu_penalty_monitor;
49pub mod detached_finalize;
50pub mod detached_output;
51pub(crate) mod docker_cleanup;
52pub mod docker_command_handoff;
53mod docker_network_lifecycle;
54pub mod docker_post_mortem;
55pub mod docker_recovery_options;
56pub mod docker_resource_limits;
57pub mod docker_resource_options;
58pub mod docker_snapshot_safety;
59pub mod execution_attach;
60pub mod execution_attempt;
61pub mod execution_control;
62pub mod execution_recovery;
63pub mod execution_resume;
64pub mod execution_resume_all;
65pub mod execution_store;
66pub mod exit_evidence;
67pub mod exit_reason;
68pub mod failure_handler;
69pub mod isolation;
70pub mod isolation_metadata;
71pub mod launch_owner;
72pub mod log_sanitizer;
73pub mod log_uploader;
74pub mod output_blocks;
75pub mod query_commands;
76pub mod recovery_delay;
77pub mod resume_resources;
78pub mod sequence_parser;
79pub mod session_probe;
80pub mod signal_handler;
81pub mod status_footer;
82pub mod status_formatter;
83pub mod status_probe;
84pub mod store_lock;
85pub mod substitution;
86pub mod usage;
87pub mod user_manager;
88
89mod lino_value_json;
90mod local_hostname;
91
92// Re-export commonly used items
93pub use args_parser::{
94    generate_session_name, generate_uuid, get_effective_mode, has_isolation, is_valid_uuid,
95    parse_args, validate_options, ParsedArgs, WrapperOptions, VALID_BACKENDS, VALID_OUTPUT_FORMATS,
96    VALID_SHELLS,
97};
98pub use detached_finalize::{
99    build_detached_finalize_snippet, finalize_detached_execution, reconcile_finalized_record,
100    run_internal_finalize, DetachedFinalizeFacts, FinalizeOutcome,
101    END_TIME_SOURCE_DOCKER_FINISHED_AT, END_TIME_SOURCE_LOG_FOOTER, END_TIME_SOURCE_OBSERVED_AT,
102    INTERNAL_FINALIZE_FLAG, WATCHER_LOST_CONTAINER,
103};
104pub use docker_cleanup::{
105    build_detached_docker_completion_script, build_detached_docker_completion_script_with,
106    docker_command, DockerContainerCleanupPolicy, DockerWatcherOptions,
107};
108pub use docker_post_mortem::{
109    build_docker_post_mortem_snippet, build_docker_removal_note_snippet,
110    build_docker_running_condition, build_docker_state_snippet,
111    build_docker_still_running_note_snippet, build_docker_wait_for_exit_snippet,
112    format_container_post_mortem, format_container_removal_note, format_lifetime,
113    normalize_docker_timestamp, ContainerPostMortem, DOCKER_RUNNING_INSPECT_FORMAT,
114    DOCKER_STATE_INSPECT_FORMAT, DOCKER_ZERO_TIME, LOG_CAPTURE_STOPPED_NOTE, POST_MORTEM_HEADER,
115    STILL_RUNNING_NOTE,
116};
117pub use execution_attach::{
118    attach_execution, attach_execution_with_runners, build_attach_plan,
119    format_attach_result_as_links_notation, AttachPlan, AttachResultFields, ExecutionAttachResult,
120    InteractiveRunner, SystemInteractiveRunner,
121};
122pub use execution_control::{
123    collect_descendant_pids, collect_descendant_pids_with_runner, collect_process_ids,
124    collect_process_ids_with_runner, control_execution, control_execution_with_runner,
125    format_control_result_as_links_notation, get_control_command, parse_screen_pid,
126    CommandRunOutput, CommandRunner, ControlAction, ControlCommand, ExecutionControlResult,
127    SystemCommandRunner,
128};
129pub use execution_resume::{
130    build_resume_plan, build_resumed_session_name, build_snapshot_image_name, resume_execution,
131    resume_execution_with, ExecutionResumeResult, ResumeHooks, ResumeMode, ResumePlan,
132    ResumeResultFields, SystemResumeHooks,
133};
134pub use execution_resume_all::{
135    format_resume_all, resume_all_executions, resume_all_executions_with, ExecutionResumeAllResult,
136    ResumeAllAction, ResumeAllEntry,
137};
138pub use execution_store::{
139    is_clink_installed, CleanupOptions, CleanupResult, ExecutionRecord, ExecutionRecordOptions,
140    ExecutionStats, ExecutionStatus, ExecutionStore, ExecutionStoreOptions,
141};
142pub use exit_reason::{
143    describe_exit_code, describe_exit_code_str, detect_exit_reason, resolve_exit_reason,
144    signal_name_for_exit_code, ExitCodeDescription,
145};
146pub use failure_handler::{handle_failure, Config as FailureConfig};
147pub use isolation::{
148    append_log_file, build_command_string, build_command_string_with, build_display_command,
149    build_shell_with_args_cmd_args, command_name, create_log_footer, create_log_header,
150    create_log_path, create_log_path_for_execution, docker_image_exists, docker_pull_image,
151    get_default_docker_image, get_timestamp, is_command_available, is_interactive_shell_command,
152    is_shell_invocation_with_args, quote_shell_arg, quote_shell_arg_with, run_as_isolated_user,
153    run_isolated, split_shell_words, split_shell_words_with, to_shell_words, write_log_file,
154    IsolationOptions, IsolationResult, LogHeaderParams, ShellQuotingStyle,
155};
156pub use isolation_metadata::{
157    build_isolation_options_map, docker_runtime_metadata, docker_runtime_status_lines,
158    docker_runtime_status_lines_for_options,
159};
160pub use log_uploader::upload_execution_log;
161#[allow(deprecated)]
162pub use output_blocks::{
163    // Timeline format API (formerly "status spine")
164    create_command_line,
165    create_empty_spine_line, // deprecated, use create_empty_timeline_line
166    create_empty_timeline_line,
167    create_finish_block,
168    create_spine_line, // deprecated, use create_timeline_line
169    create_start_block,
170    create_timeline_line,
171    create_timeline_separator,
172    create_virtual_command_block,
173    create_virtual_command_result,
174    escape_for_links_notation,
175    format_duration,
176    format_value_for_links_notation,
177    generate_isolation_lines,
178    get_result_marker,
179    parse_isolation_metadata,
180    FinishBlockOptions,
181    IsolationMetadata,
182    StartBlockOptions,
183    FAILURE_MARKER,
184    SPINE, // deprecated, use TIMELINE_MARKER
185    SUCCESS_MARKER,
186    TIMELINE_MARKER,
187};
188pub use query_commands::{dispatch_query_command, handle_cleanup, report_result, QueryOutcome};
189pub use session_probe::{probe_session, SessionProbe, SessionState};
190pub use signal_handler::{
191    clear_current_execution, get_signal_exit_code, set_current_execution, setup_signal_handlers,
192    was_signal_received,
193};
194pub use status_footer::{
195    parse_footer_from_tail, parse_footer_timestamp, read_footer_from_log, LogFooter,
196};
197pub use status_formatter::{
198    attach_current_time, enrich_detached_status, format_record, format_record_as_links_notation,
199    format_record_as_links_notation_with_current_time, format_record_as_text,
200    format_record_as_text_with_current_time, format_record_list,
201    format_record_list_as_links_notation, format_record_list_as_text,
202    format_record_with_current_time, list_executions, list_executions_filtered, query_status,
203    read_exit_code_from_log, StatusQueryResult,
204};
205pub use status_probe::is_detached_session_alive;
206pub use substitution::{process_command, ProcessOptions, SubstitutionResult};
207pub use usage::print_usage;
208pub use user_manager::{
209    create_isolated_user, delete_user, get_current_user, get_current_user_groups, has_sudo_access,
210    CreateIsolatedUserOptions, DeleteUserOptions, UserOperationResult,
211};