CAPS Universe documentation  1.0.4
All you need to know to be successful
Functions
caps-printer-process.c File Reference

Process Management to start a printing provider/printer driver. More...

Functions

static void sanitize_string (char *string)
 
static char ** create_default_argv (size_t *cnt)
 
static char ** spread_options (char *options, size_t *cnt)
 
static void caps_prn_add_base_options (char **argv, const char *executable, const char *descr_ini, const char *param)
 
static int caps_prn_exec (const char *executable, const char *descr_ini, const char *param_dir, const char *options)
 
int caps_prn_launch_printer_provider (const char *descr_ini, const char *param_dir)
 

Detailed Description

Author
Jürgen Borleis
Warning
Use as experimental

Function Documentation

◆ sanitize_string()

static void sanitize_string ( char *  string)
static

Sanitize a string in place

Parameters
[in,out]stringThe string to sanitize

Sanitizing means

  • no leading whitespace
  • only one whitespace at a time
  • no trailing whitespaces

◆ create_default_argv()

static char ** create_default_argv ( size_t *  cnt)
static

Create the default required argv array

Parameters
[out]cntElement count in the returned array
Returns
Pointer to the array

Three elements are required for the executable name and two additional fixed options. The last element in the array must be NULL to terminate the array according to the execv() man page

Note
This function does not return in case of memory failure

◆ spread_options()

static char ** spread_options ( char *  options,
size_t *  cnt 
)
static

Re-facture the options into an array of string

Parameters
[in]optionsFree options text
[in]cntCount of elements in the returned array
Returns
Array to be used for the printer driver's option list

Additional options are added beginning with element four in the argv array, since the first three elements have a fixed meaning. While at it, already reserved option keywords are sorted out.

Already reserved option keywords are (refer caps_pp_instance_runtime_prepare()):

  • –driver-ini=<name> / -s <name>
  • –parameter-dir=<name> / -d <name>
Note
The array has at least a size of three for: prog name, the features INI and the parameter directory
Does not return in case or memory failure
Todo:
spread_options() still needs to sort out invalid options for the printer driver

◆ caps_prn_add_base_options()

static void caps_prn_add_base_options ( char **  argv,
const char *  executable,
const char *  descr_ini,
const char *  param 
)
static

Insert the base argv options

Parameters
[out]argvThe string pointer array with at least 4 elements
[in]executableThe executable string. Name only, no path component!
[in]descr_iniThe driver INI file name. Name only, no path component! (can be NULL)
[in]paramThe device parameter directory name. Name only, no path component

execv() expects the executable name as argv[0]

Precondition
At least three entries are expected in argv

◆ caps_prn_exec()

static int caps_prn_exec ( const char *  executable,
const char *  descr_ini,
const char *  param_dir,
const char *  options 
)
static

Execute a program and forward some fixed and some free options to it

Parameters
[in]executablePrinter driver executable name (no path!)
[in]descr_iniFilename of the driver corresponding driver INI file (no path!)
[in]param_dirDirectory name of the corresponding device parameter directory (no path!)
[in]optionsFree option text to be forwarded to the printer driver (can be NULL)
Return values
nothingIn case of success it does not return
negative-errno else
Note
The options text can contain whitespaces (e.g. can contain more than one option)
Terminates the process in case of memory failure
Precondition
The driver expects an open file descriptor "3" for printer access
Todo:

Replace the process's name by the printer driver from the journald point of view. Else, the printer driver is still 'caps-printer' in the journal.

Clean up the environment and use execve() to launch the driver executable

◆ caps_prn_launch_printer_provider()

int caps_prn_launch_printer_provider ( const char *  descr_ini,
const char *  param_dir 
)

Launch a printing provider

Parameters
[in]descr_iniPrinting provider's description INI file (file name only)
[in]param_dirParameter directory for this device (directory name only)
Return values
0On success
negative-errno else

File descriptors:

  • 0 stdin is closed
  • 1 stdout
  • 2 stderr
  • 3 Line printer device node

Keep stdout and stderr open, the filedescriptor to the printer device node as well.

Calls the printer driver as:

</path/to/caps/exec/dir>/<drivername> --driver-ini=<driverdefault.ini> --parameter-dir=<parameterdir>

These specific options are expected when the printing provider uses libcapsprovider.