[RFC PATCH v3 2/5] Refactor scan_fdinfo and decode-fd functions
Dmitry V. Levin
ldv at strace.io
Mon May 13 21:37:04 UTC 2024
On Tue, May 14, 2024 at 12:27:16AM +0530, Sahil wrote:
> Hi,
>
> On Monday, May 13, 2024 5:21:17 PM GMT+5:30 Dmitry V. Levin wrote:
> > On Fri, May 10, 2024 at 10:44:08AM +0530, Sahil Siddiq wrote:
> > > [...]
> > > @@ -734,8 +746,17 @@ get_finfo_for_dev(pid_t pid, int fd, const char *path, struct finfo *finfo)
> > > static const char prefix[] = "tty-index:\t";
> > >
> > > finfo->dev.tty_index = -1;
> > > - scan_fdinfo(pid, fd, prefix, sizeof(prefix) - 1,
> > > - set_tty_index, finfo);
> > > +
> > > + struct fdinfo fdinfo_lines[] = {
> > > + {
> > > + .search_pfx = prefix,
> > > + .search_pfx_len = sizeof(prefix) - 1,
> > > + .fn = set_tty_index,
> > > + .data = finfo
> > > + }
> > > + };
> > > +
> > > + scan_fdinfo(pid, fd, fdinfo_lines, ARRAY_SIZE(fdinfo_lines));
> >
> > There is an option to give the new edition of scan_fdinfo() a new name,
> > e.g. scan_fdinfo_array(), and create an inline wrapper scan_fdinfo()
> > around it, this way there won't be any need to patch its call sites.
>
> Sorry, I am not entirely clear on this. Even if a wrapper scan_fdinfo()
> is implemented around scan_fdinfo_array(), wouldn't the wrapper have
> different parameter types compared to the original scan_fdinfo() which
> has char *, size_t and a function pointer "scan_fdinfo_fn" as its parameters?
>
> I haven't understood how this can be implemented without patching the
> call sites.
I mean something like this:
static inline bool
scan_fdinfo(pid_t pid, int fd, const char *search_pfx,
size_t search_pfx_len, scan_fdinfo_fn fn, void *data)
{
struct scan_fdinfo lines[] = {
{
.search_pfx = search_pfx,
.search_pfx_len = search_pfx_len,
.fn = fn,
.data = data
}
};
return scan_fdinfo_array(pid, fd, lines, ARRAY_SIZE(lines));
}
--
ldv
More information about the Strace-devel
mailing list