- Copyright
- GNU Lesser General Public License 2.1
- Author
- Jürgen Borleis
- Warning
- Use as experimental
caps-printer will be started as non-root and replaces itself by the regular printing device driver. On order to do so, it expects the printing device is already registered in the run-time printing device database. The Printer Preparation will ensure this (if a printing device driver is present). The printing device node will be locked to ensure only one printing driver instance will run for one printing device.
static void fd_workaround_start |
( |
void |
| ) |
|
|
static |
Begin the workaround to keep the filedescriptor 3 free for us
Whenever we use systemd's journald for logging, this could occupie our filedescriptor 3. We must lock it, before we do the first log output into the journal.
At some point running this tool, it had the following filedescriptors already open:
$ sudo ls -l /proc/<some pid>/fd total 0 lr-x---— 1 lp lp 64 Jun 7 19:19 0 -> /dev/null lrwx---— 1 lp lp 64 Jun 7 19:19 1 -> 'socket:[627790]' lrwx---— 1 lp lp 64 Jun 7 19:19 2 -> 'socket:[627790]' lrwx---— 1 lp lp 64 Jun 7 19:19 3 -> 'socket:[627799]'
After adding this workaround, the final open filehandles changed to:
sudo ls -l /proc/750245/fd total 0 lr-x---— 1 lp lp 64 Jun 7 19:31 0 -> /dev/null lrwx---— 1 lp lp 64 Jun 7 19:31 1 -> 'socket:[1245770]' lrwx---— 1 lp lp 64 Jun 7 19:31 2 -> 'socket:[1245770]' lrwx---— 1 lp lp 64 Jun 7 19:31 3 -> /dev/usb/lp0 lrwx---— 1 lp lp 64 Jun 7 19:31 4 -> 'socket:[1245780]' lrwx---— 1 lp lp 64 Jun 7 19:31 6 -> 'socket:[1245781]'
- Precondition
- Run this function before sending the first message to systemd's journald
int main |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
We are called here for exactly one printer device when it gets attached or detected.
- Parameters
-
[in] | argc | Guess what |
[in] | argv | Guess what |
- Returns
- EXIT_FAILURE, else we never return here
As a parameter we receive the corresponding device node via '–node=<nodename>'. We run as a systemd service with 'Type=notify'. After recognizing the corresponding printer driver we exec into this executable.
If we run as root, bail out. We need to run as a regular user here!
Just discover the corresponding printer driver and launch it.