Page MenuHome GnuPG

libassuan: Clear semantics for assuan_get_pid and improve use cases for process control
Testing, WishlistPublic


The API of assuan_get_pid and its semantics are not good and resulted questionable use cases.
And it is non-portable, since the concept PID is different between POSIX and Windows.
We need better API here.

assuan_get_pid is used for two different purposes. Considering about Winodws:
(1) Getting some sort of ID for a process of client (used by server program).
(1-1) If the usage is showing it to a user for identifying process (in a dialog window), it would be better for Windows to use Process ID, instead of HANDLE
(2) Getting process HANDLE of server program to control the process (used by client program).
(2-1) It may be better offer a function for waitpid/WaitForSingleObject for assuan connection by libassuan, instead of exposing internal thing like PID (for POSIX) and allow direct access to the process with it.

Event Timeline

gniibe triaged this task as Wishlist priority.May 15 2023, 6:45 AM
gniibe created this task.
gniibe renamed this task from libassuan: Deprecate assuan_get_pid and improve use cases for process control to libassuan: Clear semantics for assuan_get_pid and improve use cases for process control.May 16 2023, 8:06 AM

Finished the step to have cleaner semantics of the implementation by: rA6350f796fdd1: w32: Cleaner semantics for PID and Process handle.
Clarified the fact (1-1).
And as a bonus, when it's "cygwin" mode, peer (client) process ID is now available.

For (2-2), there are two use cases in GnuPG.
(A) In call-daemon.c (for SCD and TPM2D), wait_child_thread cares about daemon termination to clean up resources. In this case, it calls waitpid/WaitForSingleObject.
(B) In call-pinentry.c, watch_sock cares about dangling pinentry. When it detects client's EOF on the socket (between the client and gpg-agent), it kills pinentry process. In this case, it calls kill/TerminateProcess.

Possibly, adding something like assuan_ctl with feature (A) waiting peer's termination, (B) killing peer process would be needed here.

I conclude that adding two public functions for pipe connection of client will be useful (and solve the pid_t issue, by successfully hiding those use cases).

  • assuan_pipe_wait_server_termination to call waitpid/WaitForSingleObject internally
  • assuan_pipe_kill_server to call kill/TerminateProcess internally

Those functions are only valid for a connection created by assuan_pipe_connect (which spawn a process, internally).

gniibe changed the task status from Open to Testing.Jul 24 2023, 7:56 AM

Merged to master (to be 3.0.0).