2010-08-17 05:33:07 +04:00
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2010-01-23 03:52:57 +03:00
2012-07-18 21:07:51 +04:00
# pragma once
2010-01-23 03:52:57 +03:00
2010-02-03 15:03:47 +03:00
/***
This file is part of systemd .
Copyright 2010 Lennart Poettering
systemd is free software ; you can redistribute it and / or modify it
2012-04-12 02:20:58 +04:00
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation ; either version 2.1 of the License , or
2010-02-03 15:03:47 +03:00
( at your option ) any later version .
systemd is distributed in the hope that it will be useful , but
WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
2012-04-12 02:20:58 +04:00
Lesser General Public License for more details .
2010-02-03 15:03:47 +03:00
2012-04-12 02:20:58 +04:00
You should have received a copy of the GNU Lesser General Public License
2010-02-03 15:03:47 +03:00
along with systemd ; If not , see < http : //www.gnu.org/licenses/>.
* * */
2010-01-23 03:52:57 +03:00
typedef struct ExecStatus ExecStatus ;
typedef struct ExecCommand ExecCommand ;
typedef struct ExecContext ExecContext ;
2013-11-27 23:23:18 +04:00
typedef struct ExecRuntime ExecRuntime ;
2014-08-23 17:28:37 +04:00
typedef struct ExecParameters ExecParameters ;
2010-01-23 03:52:57 +03:00
2010-09-03 14:26:30 +04:00
# include <linux/types.h>
2010-01-23 03:52:57 +03:00
# include <sys/time.h>
# include <sys/resource.h>
# include <sys/capability.h>
# include <stdbool.h>
# include <stdio.h>
2010-01-30 03:55:42 +03:00
# include <sched.h>
2010-01-23 03:52:57 +03:00
# include "list.h"
2010-01-26 06:18:44 +03:00
# include "util.h"
2014-03-03 20:12:56 +04:00
# include "set.h"
2013-11-27 23:23:18 +04:00
# include "fdset.h"
2014-03-05 05:29:58 +04:00
# include "missing.h"
2014-06-04 01:41:44 +04:00
# include "namespace.h"
2014-08-18 21:55:32 +04:00
# include "bus-endpoint.h"
2010-01-23 03:52:57 +03:00
2010-04-13 04:06:27 +04:00
typedef enum ExecInput {
EXEC_INPUT_NULL ,
EXEC_INPUT_TTY ,
EXEC_INPUT_TTY_FORCE ,
EXEC_INPUT_TTY_FAIL ,
2010-04-15 08:19:54 +04:00
EXEC_INPUT_SOCKET ,
2010-04-13 04:06:27 +04:00
_EXEC_INPUT_MAX ,
_EXEC_INPUT_INVALID = - 1
} ExecInput ;
2010-01-28 04:06:20 +03:00
typedef enum ExecOutput {
2010-04-13 04:06:27 +04:00
EXEC_OUTPUT_INHERIT ,
2010-01-30 03:55:42 +03:00
EXEC_OUTPUT_NULL ,
2010-04-13 04:06:27 +04:00
EXEC_OUTPUT_TTY ,
2010-01-30 03:55:42 +03:00
EXEC_OUTPUT_SYSLOG ,
2011-02-15 03:27:53 +03:00
EXEC_OUTPUT_SYSLOG_AND_CONSOLE ,
2010-05-19 23:49:03 +04:00
EXEC_OUTPUT_KMSG ,
2011-02-15 03:27:53 +03:00
EXEC_OUTPUT_KMSG_AND_CONSOLE ,
2012-01-06 02:54:45 +04:00
EXEC_OUTPUT_JOURNAL ,
EXEC_OUTPUT_JOURNAL_AND_CONSOLE ,
2010-04-15 08:19:54 +04:00
EXEC_OUTPUT_SOCKET ,
2010-01-30 03:55:42 +03:00
_EXEC_OUTPUT_MAX ,
_EXEC_OUTPUT_INVALID = - 1
2010-01-28 04:06:20 +03:00
} ExecOutput ;
2010-01-23 03:52:57 +03:00
struct ExecStatus {
2010-07-01 02:26:44 +04:00
dual_timestamp start_timestamp ;
dual_timestamp exit_timestamp ;
2010-04-21 06:01:24 +04:00
pid_t pid ;
2010-01-24 02:39:29 +03:00
int code ; /* as in siginfo_t::si_code */
int status ; /* as in sigingo_t::si_status */
2010-01-23 03:52:57 +03:00
} ;
struct ExecCommand {
char * path ;
char * * argv ;
2010-01-26 06:18:44 +03:00
ExecStatus exec_status ;
LIST_FIELDS ( ExecCommand , command ) ; /* useful for chaining commands */
2010-08-12 00:37:10 +04:00
bool ignore ;
2010-01-23 03:52:57 +03:00
} ;
2013-11-27 23:23:18 +04:00
struct ExecRuntime {
int n_ref ;
char * tmp_dir ;
char * var_tmp_dir ;
int netns_storage_socket [ 2 ] ;
} ;
2010-01-23 03:52:57 +03:00
struct ExecContext {
char * * environment ;
2011-03-04 05:44:43 +03:00
char * * environment_files ;
2014-03-05 05:29:58 +04:00
struct rlimit * rlimit [ _RLIMIT_MAX ] ;
2010-01-29 22:46:22 +03:00
char * working_directory , * root_directory ;
2010-04-21 06:01:24 +04:00
mode_t umask ;
2010-08-31 03:33:39 +04:00
int oom_score_adjust ;
2010-01-23 03:52:57 +03:00
int nice ;
2010-01-29 22:46:22 +03:00
int ioprio ;
2010-01-30 03:55:42 +03:00
int cpu_sched_policy ;
int cpu_sched_priority ;
2010-04-21 06:01:24 +04:00
2010-07-04 18:44:58 +04:00
cpu_set_t * cpuset ;
unsigned cpuset_ncpus ;
2010-01-28 04:53:56 +03:00
2010-04-13 04:06:27 +04:00
ExecInput std_input ;
ExecOutput std_output ;
ExecOutput std_error ;
2012-05-31 06:27:03 +04:00
nsec_t timer_slack_nsec ;
2010-01-28 04:06:20 +03:00
2010-04-21 06:01:24 +04:00
char * tty_path ;
2010-01-23 03:52:57 +03:00
2011-05-18 03:07:31 +04:00
bool tty_reset ;
bool tty_vhangup ;
bool tty_vt_disallocate ;
2012-02-09 06:18:04 +04:00
bool ignore_sigpipe ;
2010-01-30 03:55:42 +03:00
/* Since resolving these names might might involve socket
2010-01-23 03:52:57 +03:00
* connections and we don ' t want to deadlock ourselves these
2010-01-30 03:55:42 +03:00
* names are resolved on execution only and in the child
* process . */
2010-01-23 03:52:57 +03:00
char * user ;
char * group ;
char * * supplementary_groups ;
2010-04-21 06:01:24 +04:00
2010-06-16 23:54:17 +04:00
char * pam_name ;
2010-10-08 18:06:23 +04:00
char * utmp_id ;
2014-02-17 19:52:52 +04:00
bool selinux_context_ignore ;
2014-02-06 13:05:16 +04:00
char * selinux_context ;
2014-02-20 19:19:44 +04:00
bool apparmor_profile_ignore ;
char * apparmor_profile ;
2010-04-22 00:15:06 +04:00
char * * read_write_dirs , * * read_only_dirs , * * inaccessible_dirs ;
unsigned long mount_flags ;
2010-04-21 06:01:24 +04:00
uint64_t capability_bounding_set_drop ;
cap_t capabilities ;
int secure_bits ;
2010-08-12 00:37:10 +04:00
int syslog_priority ;
char * syslog_identifier ;
bool syslog_level_prefix ;
2010-04-21 06:01:24 +04:00
bool cpu_sched_reset_on_fork ;
bool non_blocking ;
2010-04-22 00:15:06 +04:00
bool private_tmp ;
2011-08-02 07:24:58 +04:00
bool private_network ;
2014-01-20 22:54:51 +04:00
bool private_devices ;
2014-06-04 20:07:55 +04:00
ProtectSystem protect_system ;
ProtectHome protect_home ;
2010-04-21 06:01:24 +04:00
2012-07-17 06:17:53 +04:00
bool no_new_privileges ;
2010-04-21 06:01:24 +04:00
/* This is not exposed to the user but available
* internally . We need it to make sure that whenever we spawn
* / bin / mount it is run in the same process group as us so
* that the autofs logic detects that it belongs to us and we
* don ' t enter a trigger loop . */
2010-07-05 03:08:13 +04:00
bool same_pgrp ;
2010-07-10 06:49:37 +04:00
2014-02-19 05:15:24 +04:00
unsigned long personality ;
2014-02-12 21:28:21 +04:00
Set * syscall_filter ;
2014-02-13 03:24:00 +04:00
Set * syscall_archs ;
2014-02-12 21:28:21 +04:00
int syscall_errno ;
bool syscall_whitelist : 1 ;
2012-07-17 06:17:53 +04:00
2014-02-25 23:37:03 +04:00
Set * address_families ;
bool address_families_whitelist : 1 ;
2014-03-03 20:14:07 +04:00
char * * runtime_directory ;
mode_t runtime_directory_mode ;
2010-08-31 03:33:39 +04:00
bool oom_score_adjust_set : 1 ;
2010-08-12 00:37:10 +04:00
bool nice_set : 1 ;
bool ioprio_set : 1 ;
bool cpu_sched_set : 1 ;
2014-03-05 07:41:01 +04:00
bool no_new_privileges_set : 1 ;
2014-08-18 21:55:32 +04:00
/* custom dbus enpoint */
BusEndpoint * bus_endpoint ;
2010-01-23 03:52:57 +03:00
} ;
2013-06-27 06:14:27 +04:00
# include "cgroup.h"
2014-08-23 17:28:37 +04:00
struct ExecParameters {
char * * argv ;
int * fds ; unsigned n_fds ;
char * * environment ;
bool apply_permissions ;
bool apply_chroot ;
bool apply_tty_stdin ;
bool confirm_spawn ;
2014-07-24 12:40:28 +04:00
bool selinux_context_net ;
2014-08-23 17:28:37 +04:00
CGroupControllerMask cgroup_supported ;
const char * cgroup_path ;
2014-11-05 19:57:23 +03:00
bool cgroup_delegate ;
2014-08-23 17:28:37 +04:00
const char * runtime_prefix ;
const char * unit_id ;
usec_t watchdog_usec ;
int * idle_pipe ;
2014-08-22 21:02:03 +04:00
char * bus_endpoint_path ;
int bus_endpoint_fd ;
2014-08-23 17:28:37 +04:00
} ;
2010-04-10 07:03:14 +04:00
int exec_spawn ( ExecCommand * command ,
2014-08-23 17:28:37 +04:00
const ExecContext * context ,
const ExecParameters * exec_params ,
2013-11-27 23:23:18 +04:00
ExecRuntime * runtime ,
2010-02-15 00:43:08 +03:00
pid_t * ret ) ;
2010-01-23 03:52:57 +03:00
2010-04-10 19:47:07 +04:00
void exec_command_done ( ExecCommand * c ) ;
void exec_command_done_array ( ExecCommand * c , unsigned n ) ;
2010-01-23 03:52:57 +03:00
void exec_command_free_list ( ExecCommand * c ) ;
2010-01-26 06:18:44 +03:00
void exec_command_free_array ( ExecCommand * * c , unsigned n ) ;
2010-01-23 03:52:57 +03:00
2010-04-15 05:11:11 +04:00
char * exec_command_line ( char * * argv ) ;
2010-01-26 09:02:51 +03:00
void exec_command_dump ( ExecCommand * c , FILE * f , const char * prefix ) ;
void exec_command_dump_list ( ExecCommand * c , FILE * f , const char * prefix ) ;
2010-02-14 03:05:55 +03:00
void exec_command_append_list ( ExecCommand * * l , ExecCommand * e ) ;
2010-04-10 19:46:41 +04:00
int exec_command_set ( ExecCommand * c , const char * path , . . . ) ;
2014-09-24 16:29:05 +04:00
int exec_command_append ( ExecCommand * c , const char * path , . . . ) ;
2010-01-26 09:02:51 +03:00
2010-01-26 06:18:44 +03:00
void exec_context_init ( ExecContext * c ) ;
2013-11-27 23:23:18 +04:00
void exec_context_done ( ExecContext * c ) ;
2010-01-23 03:52:57 +03:00
void exec_context_dump ( ExecContext * c , FILE * f , const char * prefix ) ;
2014-03-03 20:14:07 +04:00
int exec_context_destroy_runtime_directory ( ExecContext * c , const char * runtime_root ) ;
2014-10-17 13:46:01 +04:00
int exec_context_load_environment ( const ExecContext * c , const char * unit_id , char * * * l ) ;
2011-03-04 05:44:43 +03:00
2013-02-28 04:36:55 +04:00
bool exec_context_may_touch_console ( ExecContext * c ) ;
2014-11-05 19:57:23 +03:00
bool exec_context_maintains_privileges ( ExecContext * c ) ;
2013-02-28 04:36:55 +04:00
2010-07-04 20:49:58 +04:00
void exec_status_start ( ExecStatus * s , pid_t pid ) ;
2011-05-18 03:07:31 +04:00
void exec_status_exit ( ExecStatus * s , ExecContext * context , pid_t pid , int code , int status ) ;
2010-04-10 07:03:14 +04:00
void exec_status_dump ( ExecStatus * s , FILE * f , const char * prefix ) ;
2010-01-23 03:52:57 +03:00
2013-11-27 23:23:18 +04:00
int exec_runtime_make ( ExecRuntime * * rt , ExecContext * c , const char * id ) ;
ExecRuntime * exec_runtime_ref ( ExecRuntime * r ) ;
ExecRuntime * exec_runtime_unref ( ExecRuntime * r ) ;
int exec_runtime_serialize ( ExecRuntime * rt , Unit * u , FILE * f , FDSet * fds ) ;
int exec_runtime_deserialize_item ( ExecRuntime * * rt , Unit * u , const char * key , const char * value , FDSet * fds ) ;
void exec_runtime_destroy ( ExecRuntime * rt ) ;
2013-05-03 06:51:50 +04:00
const char * exec_output_to_string ( ExecOutput i ) _const_ ;
ExecOutput exec_output_from_string ( const char * s ) _pure_ ;
2010-01-30 03:55:42 +03:00
2013-05-03 06:51:50 +04:00
const char * exec_input_to_string ( ExecInput i ) _const_ ;
ExecInput exec_input_from_string ( const char * s ) _pure_ ;