## <summary>Kernel Samepage Merging Tuning Daemon.</summary>

########################################
## <summary>
##	Execute a domain transition to run ksmtuned.
## </summary>
## <param name="domain">
## <summary>
##	Domain allowed to transition.
## </summary>
## </param>
#
interface(`ksmtuned_domtrans',`
	gen_require(`
		type ksmtuned_t, ksmtuned_exec_t;
	')

	corecmd_search_bin($1)
	domtrans_pattern($1, ksmtuned_exec_t, ksmtuned_t)
')

########################################
## <summary>
##	Execute ksmtuned server in
##	the ksmtuned domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed to transition.
##	</summary>
## </param>
#
interface(`ksmtuned_initrc_domtrans',`
	gen_require(`
		type ksmtuned_initrc_exec_t;
	')

	init_labeled_script_domtrans($1, ksmtuned_initrc_exec_t)
')

#######################################
## <summary>
##  Execute ksmtuned server in the ksmtunedd domain.
## </summary>
## <param name="domain">
##  <summary>
##  Domain allowed to transition.
##  </summary>
## </param>
#
interface(`ksmtuned_systemctl',`
    gen_require(`
        type ksmtuned_unit_file_t;
        type ksmtuned_t;
    ')

    systemd_exec_systemctl($1)
	init_reload_services($1)
    allow $1 ksmtuned_unit_file_t:file read_file_perms;
    allow $1 ksmtuned_unit_file_t:service manage_service_perms;

    ps_process_pattern($1, ksmtuned_t)
')

########################################
## <summary>
##	All of the rules required to
##	administrate an ksmtuned environment.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <rolecap/>
#
interface(`ksmtuned_admin',`
	gen_require(`
		type ksmtuned_t, ksmtuned_var_run_t, ksmtuned_initrc_exec_t, ksmtuned_unit_file_t;
		type ksmtuned_log_t;
	')

	allow $1 ksmtuned_t:process signal_perms;
	ps_process_pattern($1, ksmtuned_t)

	tunable_policy(`deny_ptrace',`',`
		allow $1 ksmtuned_t:process ptrace;
	')

	files_list_pids($1)
	admin_pattern($1, ksmtuned_var_run_t)

	logging_search_logs($1)
	admin_pattern($1, ksmtuned_log_t)

	ksmtuned_systemctl($1)
	admin_pattern($1, ksmtuned_unit_file_t)
	allow $1 ksmtuned_unit_file_t:service all_service_perms;
')
