[igt-dev] [PATCH i-g-t 1/1] Use the new procps library libproc2

Mauro Carvalho Chehab mauro.chehab at linux.intel.com
Fri Apr 28 11:40:19 UTC 2023


On Fri, 28 Apr 2023 13:28:08 +0200
Mauro Carvalho Chehab <mauro.chehab at linux.intel.com> wrote:

> On Tue, 25 Apr 2023 10:35:54 +0200
> Kamil Konieczny <kamil.konieczny at linux.intel.com> wrote:
> 
> I would try to confine the procps-ng version check to the helper functions,
> keeping here a logic that would be generic enough to be used with either
> versions, probably using some abstraction, like placing version-specific
> structs like:
> 
> 	#ifdef HAVE_LIBPROCPS
> 		struct igt_process {
> 			struct pids_info *info = NULL;
> 			struct pids_stack *stack;
> 		};
> 	#else
> 		struct igt_process {
> 			proc_t *proc_info;
> 			PROCTAB *proc;
> 		};
> 	#endif
> 
> And adding a helper functions to handle open/close and ID retrieve logic,
> e.g. changing the code to something similar to:
> 
> 	struct igt_process proc;
> 
> 	...
> 	igt_info("Preventing pipewire-pulse to use the audio drivers\n");
> 	open_process(&proc);
> 	while (get_process_ids(proc, &tid, &euid, &egid)) {
> 		if (pipewire_pulse_pid == tid)
> 			break;
> 	}
> 	close_proccess(proc);
> 
> This would make easier to maintain, as newer versions of procps-ng
> may use different implementations too, and the business logic will
> be split from the procps API internal details.

As a generic note, #ifdefs usually makes the code harder to read.

So, I would try to code implementation inside the C source code either
as separate files or, if inside the same C file, as:


	#ifdef HAVE_LIBPROCPS
	// procps-ng (up to) version 3.x
	#  include <proc/readproc.h>
	#else
	// procps-ng version 4.x
	#  include <libproc2/pids.h>
	#endif

	...

 	#ifdef HAVE_LIBPROCPS

	struct igt_process {
		struct pids_info *info;
		struct pids_stack *stack;
	};

	int open_process(...)
	{
		// procps-ng version 3 implementation
	}

	void close_process(...)
	{
		// procps-ng version 3 implementation
	}

	int get_process_ids(...)
	{
		// procps-ng version 3 implementation
	}

	...

 	#else

	struct igt_process {
		proc_t *proc_info;
		PROCTAB *proc;
	};

	int open_process(...)
	{
		// procps-ng version 4 implementation
	}

	void close_process(...)
	{
		// procps-ng version 4 implementation
	}

	int get_process_ids(...)
	{
		// procps-ng version 4 implementation
	}

		...
 	#endif // HAVE_LIBPROCPS

Regards,
Mauro


More information about the igt-dev mailing list