Process Management to start a printing provider/printer driver.
More...
- Copyright
- GNU Lesser General Public License 2.1
- Author
- Jürgen Borleis
- Warning
- Use as experimental
◆ sanitize_string()
static void sanitize_string |
( |
char * |
string | ) |
|
|
static |
Sanitize a string in place
- Parameters
-
[in,out] | string | The 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] | cnt | Element 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] | options | Free options text |
[in] | cnt | Count 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] | argv | The string pointer array with at least 4 elements |
[in] | executable | The executable string. Name only, no path component! |
[in] | descr_ini | The driver INI file name. Name only, no path component! (can be NULL) |
[in] | param | The 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] | executable | Printer driver executable name (no path!) |
[in] | descr_ini | Filename of the driver corresponding driver INI file (no path!) |
[in] | param_dir | Directory name of the corresponding device parameter directory (no path!) |
[in] | options | Free option text to be forwarded to the printer driver (can be NULL) |
- Return values
-
nothing | In 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_ini | Printing provider's description INI file (file name only) |
[in] | param_dir | Parameter directory for this device (directory name only) |
- Return values
-
0 | On 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.