public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] added SAFE_SOCKETPAIR()
@ 2018-12-06 22:58 Ramon Pantin
  2018-12-11 20:08 ` Petr Vorel
  0 siblings, 1 reply; 3+ messages in thread
From: Ramon Pantin @ 2018-12-06 22:58 UTC (permalink / raw)
  To: ltp

Signed-off-by: Ramon Pantin <pantin@google.com>
---
  include/safe_net_fn.h  |  3 +++
  include/tst_safe_net.h |  3 +++
  lib/safe_net.c         | 28 ++++++++++++++++++++++++++++
  3 files changed, 34 insertions(+)

diff --git a/include/safe_net_fn.h b/include/safe_net_fn.h
index 89e5bf0cc..3183b2a1c 100644
--- a/include/safe_net_fn.h
+++ b/include/safe_net_fn.h
@@ -33,6 +33,9 @@ int tst_getsockport(const char *file, const int lineno, int sockfd);
  int safe_socket(const char *file, const int lineno, void (cleanup_fn)(void),
  		int domain, int type, int protocol);
  
+int safe_socketpair(const char *file, const int lineno, int domain, int type,
+		    int protocol, int sv[]);
+
  int safe_getsockopt(const char *file, const int lineno, int sockfd, int level,
  		    int optname, void *optval, socklen_t *optlen);
  
diff --git a/include/tst_safe_net.h b/include/tst_safe_net.h
index d0c0a1dc5..83a2f27bf 100644
--- a/include/tst_safe_net.h
+++ b/include/tst_safe_net.h
@@ -32,6 +32,9 @@
  #define SAFE_SOCKET(domain, type, protocol) \
  	safe_socket(__FILE__, __LINE__, NULL, domain, type, protocol)
  
+#define SAFE_SOCKETPAIR(domain, type, protocol, sv) \
+	safe_socketpair(__FILE__, __LINE__, domain, type, protocol, sv)
+
  #define SAFE_GETSOCKOPT(fd, level, optname, optval, optlen) \
  	safe_getsockopt(__FILE__, __LINE__, fd, level, optname, optval, optlen)
  
diff --git a/lib/safe_net.c b/lib/safe_net.c
index 64e2cbcf6..4ab6ae48e 100644
--- a/lib/safe_net.c
+++ b/lib/safe_net.c
@@ -132,6 +132,34 @@ int safe_socket(const char *file, const int lineno, void (cleanup_fn)(void),
  	return rval;
  }
  
+int safe_socketpair(const char *file, const int lineno, int domain, int type,
+		    int protocol, int sv[])
+{
+	int rval, ttype;
+
+	rval = socketpair(domain, type, protocol, sv);
+
+	if (rval < 0) {
+		switch (errno) {
+		case EPROTONOSUPPORT:
+		case ESOCKTNOSUPPORT:
+		case EOPNOTSUPP:
+		case EPFNOSUPPORT:
+		case EAFNOSUPPORT:
+			ttype = TCONF;
+			break;
+		default:
+			ttype = TBROK;
+		}
+
+		tst_brkm(ttype | TERRNO, NULL,
+			 "%s:%d: socketpair(%d, %d, %d, %p) failed",
+			 file, lineno, domain, type, protocol, sv);
+	}
+
+	return rval;
+}
+
  int safe_getsockopt(const char *file, const int lineno, int sockfd, int level,
  		    int optname, void *optval, socklen_t *optlen)
  {
-- 
2.20.0.rc2.403.gdbc3b29805-goog


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20181206/712d4e6f/attachment.html>

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [LTP] added SAFE_SOCKETPAIR()
  2018-12-06 22:58 [LTP] added SAFE_SOCKETPAIR() Ramon Pantin
@ 2018-12-11 20:08 ` Petr Vorel
  2019-01-15 19:13   ` Petr Vorel
  0 siblings, 1 reply; 3+ messages in thread
From: Petr Vorel @ 2018-12-11 20:08 UTC (permalink / raw)
  To: ltp

Hi Ramon,

Reviewed-by: Petr Vorel <pvorel@suse.cz>

...
> +++ b/lib/safe_net.c
> @@ -132,6 +132,34 @@ int safe_socket(const char *file, const int lineno, void (cleanup_fn)(void),
>  	return rval;
>  }
> +int safe_socketpair(const char *file, const int lineno, int domain, int type,
> +		    int protocol, int sv[])
> +{
> +	int rval, ttype;
> +
> +	rval = socketpair(domain, type, protocol, sv);
> +
> +	if (rval < 0) {
> +		switch (errno) {
> +		case EPROTONOSUPPORT:
> +		case ESOCKTNOSUPPORT:
> +		case EOPNOTSUPP:
> +		case EPFNOSUPPORT:
> +		case EAFNOSUPPORT:
> +			ttype = TCONF;
> +			break;
> +		default:
> +			ttype = TBROK;
> +		}
It looks like you copy paste errno's from safe_socket(). While it does not harm
to have more errno's, I guess these to never come: ESOCKTNOSUPPORT, EPFNOSUPPORT.
They're listed in safe_socket() as man socket(2) says "Other errors may be
generated by the underlying protocol modules.", it was needed to ad them.

Otherwise LGTM.

> +
> +		tst_brkm(ttype | TERRNO, NULL,
> +			 "%s:%d: socketpair(%d, %d, %d, %p) failed",
> +			 file, lineno, domain, type, protocol, sv);
...


Kind regards,
Petr

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [LTP] added SAFE_SOCKETPAIR()
  2018-12-11 20:08 ` Petr Vorel
@ 2019-01-15 19:13   ` Petr Vorel
  0 siblings, 0 replies; 3+ messages in thread
From: Petr Vorel @ 2019-01-15 19:13 UTC (permalink / raw)
  To: ltp

Hi Ramon,

> ...
> > +++ b/lib/safe_net.c
> > @@ -132,6 +132,34 @@ int safe_socket(const char *file, const int lineno, void (cleanup_fn)(void),
> >  	return rval;
> >  }
> > +int safe_socketpair(const char *file, const int lineno, int domain, int type,
> > +		    int protocol, int sv[])
> > +{
> > +	int rval, ttype;
> > +
> > +	rval = socketpair(domain, type, protocol, sv);
> > +
> > +	if (rval < 0) {
> > +		switch (errno) {
> > +		case EPROTONOSUPPORT:
> > +		case ESOCKTNOSUPPORT:
> > +		case EOPNOTSUPP:
> > +		case EPFNOSUPPORT:
> > +		case EAFNOSUPPORT:
> > +			ttype = TCONF;
> > +			break;
> > +		default:
> > +			ttype = TBROK;
> > +		}
> It looks like you copy paste errno's from safe_socket(). While it does not harm
> to have more errno's, I guess these to never come: ESOCKTNOSUPPORT, EPFNOSUPPORT.
> They're listed in safe_socket() as man socket(2) says "Other errors may be
> generated by the underlying protocol modules.", it was needed to ad them.

> Otherwise LGTM.

Merged with this change.
Thanks for your work.


Kind regards,
Petr

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-01-15 19:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-06 22:58 [LTP] added SAFE_SOCKETPAIR() Ramon Pantin
2018-12-11 20:08 ` Petr Vorel
2019-01-15 19:13   ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox