Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mauro.chehab@linux.intel.com>
To: Kamil Konieczny <kamil.konieczny@linux.intel.com>
Cc: igt-dev@lists.freedesktop.org, Craig Small <csmall@dropbear.xyz>
Subject: Re: [igt-dev] [PATCH i-g-t 1/1] Use the new procps library libproc2
Date: Fri, 28 Apr 2023 13:40:19 +0200	[thread overview]
Message-ID: <20230428134019.41a3b0f5@maurocar-mobl2> (raw)
In-Reply-To: <20230428132808.38b4c452@maurocar-mobl2>

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

> On Tue, 25 Apr 2023 10:35:54 +0200
> Kamil Konieczny <kamil.konieczny@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

  reply	other threads:[~2023-04-28 11:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-24 16:26 [igt-dev] [PATCH i-g-t 0/1] Use new library libproc2 Kamil Konieczny
2023-04-24 16:26 ` [igt-dev] [PATCH i-g-t 1/1] Use the new procps " Kamil Konieczny
2023-04-25  8:35   ` Kamil Konieczny
2023-04-28 11:28     ` Mauro Carvalho Chehab
2023-04-28 11:40       ` Mauro Carvalho Chehab [this message]
2023-04-24 17:13 ` [igt-dev] ✗ Fi.CI.BAT: failure for Use new " Patchwork
2023-04-24 17:22   ` Kamil Konieczny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230428134019.41a3b0f5@maurocar-mobl2 \
    --to=mauro.chehab@linux.intel.com \
    --cc=csmall@dropbear.xyz \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=kamil.konieczny@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox