OpenPrinting / pappl-retrofit

PPD/Classic CUPS driver retro-fit Printer Application Library
Apache License 2.0
7 stars 10 forks source link

A amount of temporary PPD files in the /tmp directory have not been deleted when the legacy-printer-app is shutdown #17

Open szlt5 opened 8 months ago

szlt5 commented 8 months ago

Describe the bug A amount of temporary PPD files in the /tmp directory have not been deleted when the legacy-printer-app is shutdown.

Expected behavior The temporary PPD files in the /tmp directory should be deleted when the legacy-printer-app is shutdown.

Additional context Is the following solution feasible? (1) In the _prDriverSetup():don't copy a temporary PPD file and just store the real PPD file path. (2) In the _prCreateJobData(): copy a temporary PPD file from the real PPD file path. (3) In the _prFreeJobData(): Unlink the temporary PPD file.

szlt5 commented 8 months ago

@michaelrsweet Is it possible to add a callback function to let legacy-printer-app clear some temporary files during shutdown?

michaelrsweet commented 8 months ago

@szlt5 So currently there is no callback for system shutdown, just for printer deletion. But for a typical printer application you can simply do your cleanup when papplMainloop returns.

I might be able to update the papplCreateTempFile API to keep track of all temporary files and remove them on exit, but that might have some side-effects since PAPPL hasn't done that before... Also, I'm not clear on how legacy-printer-app is managing its temporary files or why it is storing PPD files in /tmp...

szlt5 commented 8 months ago

Also, I'm not clear on how legacy-printer-app is managing its temporary files or why it is storing PPD files in /tmp...

My explanation may be incomplete.
In the driver_cb() function, legacy-printer-app initializes the driver_data & driver_attrs based on PPD content and create a physical copy of the PPD file in a temporary file and store the temporary file name in the driver_data->extension structure.
When print a job, set the environment variable "PPD" as the temporary file name so that the CUPS filter defined in the PPD file or a CUPS backend can read it.
legacy-printer-app will delete the temporary file in the printer deletion callback function.

szlt5 commented 8 months ago

I propose several solutions, @tillkamppeter can you give me some suggestions?
<Solution 1>: Do not copy a temporary PPD file, let CUPS filter or a CUPS backend read the original PPD file.
<Solution 2>: Just copy a temporary PPD file when create Job Data (_prCreateJobData) and delete it when the job finished (_prFreeJobData).
<Solution 3>: Use @michaelrsweet's solution.

michaelrsweet commented 8 months ago

@szlt5 A persistent copy of the PPD file should not be stored in /tmp - it sounds like this file needs to remain until the print queue is removed.

Instead, papplPrinterOpenFile can be used to create a persistent PPD file in the state directory (and named consistently with other printer resource files) that can be cleaned up by the delete callback and won't leave old files in /tmp.