Message ID | 515a2ca2-1f68-d2d1-524d-f4fc89be337d@google.com |
---|---|
State | Accepted |
Delegated to: | Petr Vorel |
Headers | show |
Series | added SAFE_SOCKETPAIR() | expand |
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
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
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) {
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(+)