* [LTP] [RFC] [PATCH] safe_macros: Add fallback pwrite() and pread() declarations
@ 2017-01-02 15:47 Cyril Hrubis
2017-01-11 14:41 ` Cyril Hrubis
0 siblings, 1 reply; 6+ messages in thread
From: Cyril Hrubis @ 2017-01-02 15:47 UTC (permalink / raw)
To: ltp
This fixes numerous "implicit function declaration" on slightly older
distributions where pwrite() and pread() needs to defined either of
_XOPEN_SOURCE or _GNU_SOURCE.
This is a bit hacky solution to the problem, but consider that:
o These functions has to be inlined in the header because the prototype
contains off_t whose size depends on compile time settings
o Defining _GNU_SOURCE in the safe macros header is not a solution
either since it has to be defined before we include any libc headers
in order to take any effect
Also note that glibc uses __REDIRECT() assembler tricks or preprocessor
rename to pread64() and pwrite64() in case that large file support is
turned on but that should not matter to us since these functions are not
used in 99% of the testcases and these that use it has to define
_GNU_SOURCE either way and gets these tricks included, at least that is
the theory.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
This is the last patch that should fix the numerous "implicit function
declaration" warnings. Either we do this or we need to create a separate
safe_* header for the safe_pread and safe_pwrite. Or has anybody a
better idea?
include/tst_safe_macros.h | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index df858be..b51c025 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -98,8 +98,11 @@ static inline int safe_dup(const char *file, const int lineno,
safe_read(__FILE__, __LINE__, NULL, (len_strict), (fildes), (buf), (nbyte))
/*
- * inline function that uses off_t since sizeof(off_t) depends on compile flags
+ * Fallback function definition, older glibc does not export it unless we
+ * define _XOPEN_SOURCE or _GNU_SOURCE.
*/
+ssize_t pread(int fd, void *buf, size_t count, off_t offset);
+
static inline ssize_t safe_pread(const char *file, const int lineno,
char len_strict, int fildes, void *buf, size_t nbyte,
off_t offset)
@@ -167,6 +170,12 @@ pid_t safe_getpgid(const char *file, const int lineno, pid_t pid);
#define SAFE_WRITE(len_strict, fildes, buf, nbyte) \
safe_write(__FILE__, __LINE__, NULL, (len_strict), (fildes), (buf), (nbyte))
+/*
+ * Fallback function definition, older glibc does not export it unless we
+ * define _XOPEN_SOURCE or _GNU_SOURCE.
+ */
+ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
+
static inline ssize_t safe_pwrite(const char *file, const int lineno,
char len_strict, int fildes, const void *buf, size_t nbyte,
off_t offset)
--
2.7.3
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [RFC] [PATCH] safe_macros: Add fallback pwrite() and pread() declarations
2017-01-02 15:47 [LTP] [RFC] [PATCH] safe_macros: Add fallback pwrite() and pread() declarations Cyril Hrubis
@ 2017-01-11 14:41 ` Cyril Hrubis
2017-01-12 8:33 ` Jan Stancek
0 siblings, 1 reply; 6+ messages in thread
From: Cyril Hrubis @ 2017-01-11 14:41 UTC (permalink / raw)
To: ltp
Hi!
I was thinking about this, and I think that we should rather go with a
safer approach, i.e. moving the safe_pread/safe_pwrite into a separate
header. Something as the following patch.
--
Cyril Hrubis
chrubis@suse.cz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-safe_macros-Move-SAFE_PREAD-and-SAFE_PWRITE-to-separ.patch
Type: text/x-diff
Size: 6083 bytes
Desc: not available
URL: <http://lists.linux.it/pipermail/ltp/attachments/20170111/27db3d8b/attachment.patch>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] [RFC] [PATCH] safe_macros: Add fallback pwrite() and pread() declarations
2017-01-11 14:41 ` Cyril Hrubis
@ 2017-01-12 8:33 ` Jan Stancek
2017-01-12 9:02 ` Cyril Hrubis
0 siblings, 1 reply; 6+ messages in thread
From: Jan Stancek @ 2017-01-12 8:33 UTC (permalink / raw)
To: ltp
----- Original Message -----
> From: "Cyril Hrubis" <chrubis@suse.cz>
> To: ltp@lists.linux.it
> Sent: Wednesday, 11 January, 2017 3:41:26 PM
> Subject: Re: [LTP] [RFC] [PATCH] safe_macros: Add fallback pwrite() and pread() declarations
>
> Hi!
> I was thinking about this, and I think that we should rather go with a
> safer approach, i.e. moving the safe_pread/safe_pwrite into a separate
> header. Something as the following patch.
+1 for safer approach, I didn't know about glibc macros.
Does this affect oldlib too?
Regards,
Jan
>
> --
> Cyril Hrubis
> chrubis@suse.cz
>
>
> [Text
> Documents:0001-safe_macros-Move-SAFE_PREAD-and-SAFE_PWRITE-to-separ.patch]
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/x-diff
Size: 6083 bytes
Desc: not available
URL: <http://lists.linux.it/pipermail/ltp/attachments/20170112/b53422cd/attachment-0001.diff>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] [RFC] [PATCH] safe_macros: Add fallback pwrite() and pread() declarations
2017-01-12 8:33 ` Jan Stancek
@ 2017-01-12 9:02 ` Cyril Hrubis
2017-01-12 9:07 ` Jan Stancek
0 siblings, 1 reply; 6+ messages in thread
From: Cyril Hrubis @ 2017-01-12 9:02 UTC (permalink / raw)
To: ltp
Hi!
> > I was thinking about this, and I think that we should rather go with a
> > safer approach, i.e. moving the safe_pread/safe_pwrite into a separate
> > header. Something as the following patch.
>
> +1 for safer approach, I didn't know about glibc macros.
> Does this affect oldlib too?
Not anymore, there was one user with zero offset which was converted to
plain old SAFE_WRITE() and these two safe macros were then removed from
oldlib safe macros in f4b028122.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] [RFC] [PATCH] safe_macros: Add fallback pwrite() and pread() declarations
2017-01-12 9:02 ` Cyril Hrubis
@ 2017-01-12 9:07 ` Jan Stancek
2017-01-12 9:10 ` Cyril Hrubis
0 siblings, 1 reply; 6+ messages in thread
From: Jan Stancek @ 2017-01-12 9:07 UTC (permalink / raw)
To: ltp
----- Original Message -----
> From: "Cyril Hrubis" <chrubis@suse.cz>
> To: "Jan Stancek" <jstancek@redhat.com>
> Cc: ltp@lists.linux.it
> Sent: Thursday, 12 January, 2017 10:02:32 AM
> Subject: Re: [LTP] [RFC] [PATCH] safe_macros: Add fallback pwrite() and pread() declarations
>
> Hi!
> > > I was thinking about this, and I think that we should rather go with a
> > > safer approach, i.e. moving the safe_pread/safe_pwrite into a separate
> > > header. Something as the following patch.
> >
> > +1 for safer approach, I didn't know about glibc macros.
> > Does this affect oldlib too?
>
> Not anymore, there was one user with zero offset which was converted to
> plain old SAFE_WRITE() and these two safe macros were then removed from
> oldlib safe macros in f4b028122.
Ah, I see. No objections to patch from my side.
Regards,
Jan
>
> --
> Cyril Hrubis
> chrubis@suse.cz
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] [RFC] [PATCH] safe_macros: Add fallback pwrite() and pread() declarations
2017-01-12 9:07 ` Jan Stancek
@ 2017-01-12 9:10 ` Cyril Hrubis
0 siblings, 0 replies; 6+ messages in thread
From: Cyril Hrubis @ 2017-01-12 9:10 UTC (permalink / raw)
To: ltp
Hi!
> > Not anymore, there was one user with zero offset which was converted to
> > plain old SAFE_WRITE() and these two safe macros were then removed from
> > oldlib safe macros in f4b028122.
>
> Ah, I see. No objections to patch from my side.
Pushed with your ack.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-01-12 9:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-02 15:47 [LTP] [RFC] [PATCH] safe_macros: Add fallback pwrite() and pread() declarations Cyril Hrubis
2017-01-11 14:41 ` Cyril Hrubis
2017-01-12 8:33 ` Jan Stancek
2017-01-12 9:02 ` Cyril Hrubis
2017-01-12 9:07 ` Jan Stancek
2017-01-12 9:10 ` Cyril Hrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox