applauncherd
Classes | Macros | Typedefs | Functions | Variables
invoker.c File Reference
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <signal.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/uio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <sys/wait.h>
#include <limits.h>
#include <getopt.h>
#include <fcntl.h>
#include <time.h>
#include <poll.h>
#include <dbus/dbus.h>
#include "report.h"
#include "protocol.h"
#include "invokelib.h"
#include "search.h"
#include "sailjail.h"

Go to the source code of this file.

Classes

struct  InvokeArgs
 

Macros

#define _GNU_SOURCE
 
#define BOOSTER_SESSION   "silica-session"
 
#define BOOSTER_GENERIC   "generic"
 
#define UNDEFINED_APPLICATION   "default"
 
#define VERBOSE_SIGNALS   0
 
#define INVOKE_ARGS_INIT
 

Typedefs

typedef struct InvokeArgs InvokeArgs
 

Functions

static char * strip (char *str)
 
static char * slice (const char *pos, const char **ppos, const char *delim)
 
static char ** split (const char *str, const char *delim)
 
static void sigs_restore (void)
 
static void sigs_init (void)
 
static void sig_forwarder (int sig)
 
static void sigs_set (struct sigaction *sig)
 
static unsigned timestamp (void)
 
static bool shutdown_socket (int socket_fd)
 
static void kill_application (pid_t pid)
 
static bool invoke_recv_ack (int fd)
 
static int invoker_init (const char *app_type, const char *app_name)
 
static uint32_t invoker_recv_pid (int fd)
 
static bool invoker_recv_exit (int fd, int *status)
 
static void invoker_send_magic (int fd, uint32_t options)
 
static void invoker_send_name (int fd, const char *name)
 
static void invoker_send_exec (int fd, char *exec)
 
static void invoker_send_args (int fd, int argc, char **argv)
 
static void invoker_send_prio (int fd, int prio)
 
static void invoker_send_delay (int fd, int delay)
 
static void invoker_send_ids (int fd, int uid, int gid)
 
static void invoker_send_env (int fd)
 
static void invoker_send_io (int fd)
 
static void invoker_send_end (int fd)
 
static void usage (int status)
 
static unsigned int get_delay (char *delay_arg, char *param_name, unsigned int min_value, unsigned int max_value)
 
static void notify_app_launch (const char *desktop_file)
 
static bool ask_for_sandboxing (const char *app)
 
static int wait_for_launched_process_to_exit (int socket_fd)
 
static int invoke_remote (int socket_fd, const InvokeArgs *args)
 
static void invoke_fallback (const InvokeArgs *args)
 
static int invoke (InvokeArgs *args)
 
int main (int argc, char *argv[])
 

Variables

static const unsigned int EXIT_DELAY = 0
 
static const unsigned int MIN_EXIT_DELAY = 1
 
static const unsigned int MAX_EXIT_DELAY = 86400
 
static const unsigned int RESPAWN_DELAY = 1
 
static const unsigned int MIN_RESPAWN_DELAY = 0
 
static const unsigned int MAX_RESPAWN_DELAY = 10
 
static const unsigned char EXIT_STATUS_APPLICATION_NOT_FOUND = 0x7f
 
char ** environ
 
static pid_t g_invoked_pid = -1
 
static int g_signal_pipe [2] = { -1, -1 }
 Pipe used to safely catch Unix signals.
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 22 of file invoker.c.

◆ BOOSTER_GENERIC

#define BOOSTER_GENERIC   "generic"

Definition at line 54 of file invoker.c.

◆ BOOSTER_SESSION

#define BOOSTER_SESSION   "silica-session"

Definition at line 53 of file invoker.c.

◆ INVOKE_ARGS_INIT

#define INVOKE_ARGS_INIT
Value:
{\
.prog_argc = 0,\
.prog_argv = NULL,\
.prog_name = NULL,\
.app_type = NULL,\
.app_name = UNDEFINED_APPLICATION,\
.magic_options = INVOKER_MSG_MAGIC_OPTION_WAIT,\
.wait_term = true,\
.respawn_delay = RESPAWN_DELAY,\
.test_mode = false,\
.desktop_file = NULL,\
.sandboxing_id = NULL,\
.exit_delay = EXIT_DELAY,\
}
#define UNDEFINED_APPLICATION
Definition invoker.c:59
static const unsigned int RESPAWN_DELAY
Definition invoker.c:139
static const unsigned int EXIT_DELAY
Definition invoker.c:133

Definition at line 781 of file invoker.c.

◆ UNDEFINED_APPLICATION

#define UNDEFINED_APPLICATION   "default"

Definition at line 59 of file invoker.c.

◆ VERBOSE_SIGNALS

#define VERBOSE_SIGNALS   0

Definition at line 65 of file invoker.c.

Typedef Documentation

◆ InvokeArgs

typedef struct InvokeArgs InvokeArgs

Function Documentation

◆ ask_for_sandboxing()

static bool ask_for_sandboxing ( const char *  app)
static

Definition at line 674 of file invoker.c.

◆ get_delay()

static unsigned int get_delay ( char *  delay_arg,
char *  param_name,
unsigned int  min_value,
unsigned int  max_value 
)
static

Definition at line 627 of file invoker.c.

References EXIT_DELAY, and usage().

◆ invoke()

static int invoke ( InvokeArgs args)
static

◆ invoke_fallback()

static void invoke_fallback ( const InvokeArgs args)
static

◆ invoke_recv_ack()

static bool invoke_recv_ack ( int  fd)
static

Definition at line 335 of file invoker.c.

References invoke_recv_msg().

◆ invoke_remote()

static int invoke_remote ( int  socket_fd,
const InvokeArgs args 
)
static

◆ invoker_init()

static int invoker_init ( const char *  app_type,
const char *  app_name 
)
static

Definition at line 350 of file invoker.c.

◆ invoker_recv_exit()

static bool invoker_recv_exit ( int  fd,
int *  status 
)
static

Definition at line 432 of file invoker.c.

References invoke_recv_msg().

◆ invoker_recv_pid()

static uint32_t invoker_recv_pid ( int  fd)
static

Definition at line 414 of file invoker.c.

References invoke_recv_msg().

◆ invoker_send_args()

static void invoker_send_args ( int  fd,
int  argc,
char **  argv 
)
static

Definition at line 475 of file invoker.c.

References invoke_send_msg(), and invoke_send_str().

◆ invoker_send_delay()

static void invoker_send_delay ( int  fd,
int  delay 
)
static

Definition at line 495 of file invoker.c.

References invoke_send_msg().

◆ invoker_send_end()

static void invoker_send_end ( int  fd)
static

Definition at line 567 of file invoker.c.

References invoke_recv_ack(), and invoke_send_msg().

◆ invoker_send_env()

static void invoker_send_env ( int  fd)
static

Definition at line 510 of file invoker.c.

References environ, invoke_send_msg(), and invoke_send_str().

◆ invoker_send_exec()

static void invoker_send_exec ( int  fd,
char *  exec 
)
static

Definition at line 469 of file invoker.c.

References invoke_send_msg(), and invoke_send_str().

◆ invoker_send_ids()

static void invoker_send_ids ( int  fd,
int  uid,
int  gid 
)
static

Definition at line 502 of file invoker.c.

References invoke_send_msg().

◆ invoker_send_io()

static void invoker_send_io ( int  fd)
static

Definition at line 529 of file invoker.c.

References invoke_send_msg().

◆ invoker_send_magic()

static void invoker_send_magic ( int  fd,
uint32_t  options 
)
static

Definition at line 456 of file invoker.c.

References invoke_send_msg().

◆ invoker_send_name()

static void invoker_send_name ( int  fd,
const char *  name 
)
static

Definition at line 463 of file invoker.c.

References invoke_send_msg(), and invoke_send_str().

◆ invoker_send_prio()

static void invoker_send_prio ( int  fd,
int  prio 
)
static

Definition at line 488 of file invoker.c.

References invoke_send_msg().

◆ kill_application()

static void kill_application ( pid_t  pid)
static

Definition at line 292 of file invoker.c.

◆ main()

int main ( int  argc,
char *  argv[] 
)

◆ notify_app_launch()

static void notify_app_launch ( const char *  desktop_file)
static

Definition at line 650 of file invoker.c.

◆ shutdown_socket()

static bool shutdown_socket ( int  socket_fd)
static

Definition at line 226 of file invoker.c.

References timestamp().

◆ sig_forwarder()

static void sig_forwarder ( int  sig)
static

Definition at line 158 of file invoker.c.

References g_signal_pipe.

◆ sigs_init()

static void sigs_init ( void  )
static

Definition at line 186 of file invoker.c.

References sig_forwarder(), and sigs_set().

◆ sigs_restore()

static void sigs_restore ( void  )
static

Definition at line 198 of file invoker.c.

References sigs_set().

◆ sigs_set()

static void sigs_set ( struct sigaction *  sig)
static

Definition at line 179 of file invoker.c.

◆ slice()

static char * slice ( const char *  pos,
const char **  ppos,
const char *  delim 
)
static

Definition at line 89 of file invoker.c.

◆ split()

static char ** split ( const char *  str,
const char *  delim 
)
static

Definition at line 105 of file invoker.c.

References slice(), and strip().

◆ strip()

static char * strip ( char *  str)
static

Definition at line 68 of file invoker.c.

◆ timestamp()

static unsigned timestamp ( void  )
static

Definition at line 209 of file invoker.c.

◆ usage()

static void usage ( int  status)
static

Definition at line 575 of file invoker.c.

References EXIT_DELAY, MAX_RESPAWN_DELAY, and RESPAWN_DELAY.

◆ wait_for_launched_process_to_exit()

static int wait_for_launched_process_to_exit ( int  socket_fd)
static

Variable Documentation

◆ environ

char** environ
extern

◆ EXIT_DELAY

const unsigned int EXIT_DELAY = 0
static

Definition at line 133 of file invoker.c.

◆ EXIT_STATUS_APPLICATION_NOT_FOUND

const unsigned char EXIT_STATUS_APPLICATION_NOT_FOUND = 0x7f
static

Definition at line 143 of file invoker.c.

◆ g_invoked_pid

pid_t g_invoked_pid = -1
static

Definition at line 149 of file invoker.c.

◆ g_signal_pipe

int g_signal_pipe[2] = { -1, -1 }
static

Pipe used to safely catch Unix signals.

Definition at line 155 of file invoker.c.

◆ MAX_EXIT_DELAY

const unsigned int MAX_EXIT_DELAY = 86400
static

Definition at line 135 of file invoker.c.

◆ MAX_RESPAWN_DELAY

const unsigned int MAX_RESPAWN_DELAY = 10
static

Definition at line 141 of file invoker.c.

◆ MIN_EXIT_DELAY

const unsigned int MIN_EXIT_DELAY = 1
static

Definition at line 134 of file invoker.c.

◆ MIN_RESPAWN_DELAY

const unsigned int MIN_RESPAWN_DELAY = 0
static

Definition at line 140 of file invoker.c.

◆ RESPAWN_DELAY

const unsigned int RESPAWN_DELAY = 1
static

Definition at line 139 of file invoker.c.