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
# ifndef fooexecutehfoo
# define fooexecutehfoo
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 ;
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
2010-03-31 18:29:55 +04:00
struct CGroupBonding ;
2011-08-20 02:20:41 +04:00
struct CGroupAttribute ;
2010-03-31 18:29:55 +04:00
2010-01-23 03:52:57 +03:00
# include "list.h"
2010-01-26 06:18:44 +03:00
# include "util.h"
2010-01-23 03:52:57 +03:00
2010-07-10 06:49:37 +04:00
typedef enum KillMode {
KILL_CONTROL_GROUP = 0 ,
KILL_PROCESS ,
KILL_NONE ,
_KILL_MODE_MAX ,
_KILL_MODE_INVALID = - 1
} KillMode ;
2010-10-22 18:11:50 +04:00
typedef enum KillWho {
KILL_MAIN ,
KILL_CONTROL ,
KILL_ALL ,
_KILL_WHO_MAX ,
_KILL_WHO_INVALID = - 1
} KillWho ;
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
} ;
struct ExecContext {
char * * environment ;
2011-03-04 05:44:43 +03:00
char * * environment_files ;
2010-01-30 03:55:42 +03:00
struct rlimit * rlimit [ RLIMIT_NLIMITS ] ;
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-06-16 18:25:42 +04:00
char * tcpwrap_name ;
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 ;
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 ;
2010-08-12 00:37:10 +04:00
/* Not relevant for spawning processes, just for killing */
KillMode kill_mode ;
int kill_signal ;
2011-01-19 00:55:54 +03:00
bool send_sigkill ;
2010-08-12 00:37:10 +04:00
2010-04-21 06:01:24 +04:00
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 ;
2010-04-21 06:01:24 +04:00
2011-06-30 02:11:25 +04:00
bool control_group_modify ;
2012-01-19 00:47:30 +04:00
int control_group_persistent ;
2011-06-30 02:11:25 +04:00
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
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 ;
2010-01-23 03:52:57 +03:00
} ;
2010-04-10 07:03:14 +04:00
int exec_spawn ( ExecCommand * command ,
2010-04-15 05:11:11 +04:00
char * * argv ,
2010-02-15 00:43:08 +03:00
const ExecContext * context ,
2010-04-13 22:43:02 +04:00
int fds [ ] , unsigned n_fds ,
2010-05-10 01:53:52 +04:00
char * * environment ,
2010-02-15 00:43:08 +03:00
bool apply_permissions ,
bool apply_chroot ,
2010-07-08 06:09:17 +04:00
bool apply_tty_stdin ,
2010-04-13 04:06:27 +04:00
bool confirm_spawn ,
2010-03-31 18:29:55 +04:00
struct CGroupBonding * cgroup_bondings ,
2011-08-20 02:20:41 +04:00
struct CGroupAttribute * cgroup_attributes ,
2012-04-14 01:24:47 +04:00
const char * cgroup_suffix ,
2012-04-24 16:28:00 +04:00
int pipe_fd [ 2 ] ,
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 , . . . ) ;
2010-01-26 09:02:51 +03:00
2010-01-26 06:18:44 +03:00
void exec_context_init ( ExecContext * c ) ;
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 ) ;
2011-05-18 03:07:31 +04:00
void exec_context_tty_reset ( const ExecContext * context ) ;
2010-01-23 03:52:57 +03:00
2011-03-04 05:44:43 +03:00
int exec_context_load_environment ( const ExecContext * c , char * * * l ) ;
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
2010-01-30 03:55:42 +03:00
const char * exec_output_to_string ( ExecOutput i ) ;
2011-05-23 23:37:45 +04:00
ExecOutput exec_output_from_string ( const char * s ) ;
2010-01-30 03:55:42 +03:00
const char * exec_input_to_string ( ExecInput i ) ;
2011-05-23 23:37:45 +04:00
ExecInput exec_input_from_string ( const char * s ) ;
2010-01-30 03:55:42 +03:00
2010-10-22 18:11:50 +04:00
const char * kill_mode_to_string ( KillMode k ) ;
KillMode kill_mode_from_string ( const char * s ) ;
const char * kill_who_to_string ( KillWho k ) ;
KillWho kill_who_from_string ( const char * s ) ;
2010-01-23 03:52:57 +03:00
# endif