* [LTP] [PATCH 1/1] syscalls, lib: Use SAFE_{BIND, LISTEN, SOCKET} macros
@ 2017-09-29 23:10 Petr Vorel
2017-09-29 23:15 ` Petr Vorel
2017-10-02 11:00 ` Richard Palethorpe
0 siblings, 2 replies; 15+ messages in thread
From: Petr Vorel @ 2017-09-29 23:10 UTC (permalink / raw)
To: ltp
instead of tst_brk{,m}(TBROK, ...)
Patch was made thanks to Coccinelle.
Signed-off-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
---
lib/tst_net.c | 12 ++-----
testcases/kernel/syscalls/accept/accept01.c | 12 ++-----
testcases/kernel/syscalls/connect/connect01.c | 17 +++------
.../kernel/syscalls/getpeername/getpeername01.c | 7 ++--
.../kernel/syscalls/getsockname/getsockname01.c | 13 +++----
.../kernel/syscalls/getsockopt/getsockopt01.c | 13 +++----
testcases/kernel/syscalls/listen/listen01.c | 8 ++---
testcases/kernel/syscalls/recv/recv01.c | 17 +++------
testcases/kernel/syscalls/recvfrom/recvfrom01.c | 17 +++------
testcases/kernel/syscalls/recvmsg/recvmsg01.c | 23 +++---------
testcases/kernel/syscalls/send/send01.c | 17 +++------
testcases/kernel/syscalls/sendfile/sendfile02.c | 14 ++------
testcases/kernel/syscalls/sendfile/sendfile04.c | 14 ++------
testcases/kernel/syscalls/sendfile/sendfile05.c | 14 ++------
testcases/kernel/syscalls/sendfile/sendfile06.c | 13 ++-----
testcases/kernel/syscalls/sendmsg/sendmsg01.c | 42 ++++++----------------
testcases/kernel/syscalls/sendto/sendto01.c | 17 +++------
.../kernel/syscalls/setsockopt/setsockopt01.c | 13 +++----
testcases/kernel/syscalls/sockioctl/sockioctl01.c | 20 ++++-------
19 files changed, 75 insertions(+), 228 deletions(-)
diff --git a/lib/tst_net.c b/lib/tst_net.c
index f842e94a6..326b92e6f 100644
--- a/lib/tst_net.c
+++ b/lib/tst_net.c
@@ -25,6 +25,7 @@
#include <netinet/in.h>
#include "test.h"
+#include "safe_macros.h"
unsigned short tst_get_unused_port(void (cleanup_fn)(void),
unsigned short family, int type)
@@ -57,16 +58,9 @@ unsigned short tst_get_unused_port(void (cleanup_fn)(void),
return -1;
}
- sock = socket(addr->sa_family, type, 0);
- if (sock < 0) {
- tst_brkm(TBROK | TERRNO, cleanup_fn, "socket failed");
- return -1;
- }
+ sock = SAFE_SOCKET(cleanup_fn, addr->sa_family, type, 0);
- if (bind(sock, addr, slen) < 0) {
- tst_brkm(TBROK | TERRNO, cleanup_fn, "bind failed");
- return -1;
- }
+ SAFE_BIND(cleanup_fn, sock, addr, slen);
if (getsockname(sock, addr, &slen) == -1) {
tst_brkm(TBROK | TERRNO, cleanup_fn, "getsockname failed");
diff --git a/testcases/kernel/syscalls/accept/accept01.c b/testcases/kernel/syscalls/accept/accept01.c
index 986415897..b50056520 100644
--- a/testcases/kernel/syscalls/accept/accept01.c
+++ b/testcases/kernel/syscalls/accept/accept01.c
@@ -156,15 +156,9 @@ static void cleanup0(void)
static void setup1(void)
{
- s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
- if (s < 0) {
- tst_brkm(TBROK, cleanup, "socket setup failed for accept "
- "test %d: %s", testno, strerror(errno));
- }
- if (bind(s, (struct sockaddr *)&sin0, sizeof(sin0)) < 0) {
- tst_brkm(TBROK, cleanup, "socket bind failed for accept "
- "test %d: %s", testno, strerror(errno));
- }
+ s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+ tdat[testno].proto);
+ SAFE_BIND(cleanup, s, (struct sockaddr *)&sin0, sizeof(sin0));
sinlen = sizeof(fsin1);
}
diff --git a/testcases/kernel/syscalls/connect/connect01.c b/testcases/kernel/syscalls/connect/connect01.c
index af6035435..5880b0794 100644
--- a/testcases/kernel/syscalls/connect/connect01.c
+++ b/testcases/kernel/syscalls/connect/connect01.c
@@ -53,6 +53,7 @@
#include <netinet/in.h>
#include "test.h"
+#include "safe_macros.h"
char *TCID = "connect01";
int testno;
@@ -230,19 +231,9 @@ pid_t start_server(struct sockaddr_in *sin0)
sin0->sin_port = 0; /* pick random free port */
sin0->sin_addr.s_addr = INADDR_ANY;
- sfd = socket(PF_INET, SOCK_STREAM, 0);
- if (sfd < 0) {
- tst_brkm(TBROK | TERRNO, cleanup, "server socket failed");
- return -1;
- }
- if (bind(sfd, (struct sockaddr *)sin0, sizeof(*sin0)) < 0) {
- tst_brkm(TBROK | TERRNO, cleanup, "server bind failed");
- return -1;
- }
- if (listen(sfd, 10) < 0) {
- tst_brkm(TBROK | TERRNO, cleanup, "server listen failed");
- return -1;
- }
+ sfd = SAFE_SOCKET(cleanup, PF_INET, SOCK_STREAM, 0);
+ SAFE_BIND(cleanup, sfd, (struct sockaddr *)sin0, sizeof(*sin0));
+ SAFE_LISTEN(cleanup, sfd, 10);
if (getsockname(sfd, (struct sockaddr *)sin0, &slen) == -1)
tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
diff --git a/testcases/kernel/syscalls/getpeername/getpeername01.c b/testcases/kernel/syscalls/getpeername/getpeername01.c
index fd5d58d57..817cd38ad 100644
--- a/testcases/kernel/syscalls/getpeername/getpeername01.c
+++ b/testcases/kernel/syscalls/getpeername/getpeername01.c
@@ -153,11 +153,8 @@ static void setup3(int i)
tst_brkm(TBROK | TERRNO, cleanup,
"socket setup failed for getpeername test %d", i);
}
- if (bind(test_cases[i].sockfd, (struct sockaddr *)&server_addr,
- sizeof(server_addr)) < 0) {
- tst_brkm(TBROK | TERRNO, cleanup,
- "socket bind failed for getpeername test %d", i);
- }
+ SAFE_BIND(cleanup, test_cases[i].sockfd,
+ (struct sockaddr *)&server_addr, sizeof(server_addr));
}
static void setup4(int i)
diff --git a/testcases/kernel/syscalls/getsockname/getsockname01.c b/testcases/kernel/syscalls/getsockname/getsockname01.c
index c4b6e9b1a..cce1543fd 100644
--- a/testcases/kernel/syscalls/getsockname/getsockname01.c
+++ b/testcases/kernel/syscalls/getsockname/getsockname01.c
@@ -52,6 +52,7 @@
#include <netinet/in.h>
#include "test.h"
+#include "safe_macros.h"
char *TCID = "getsockname01";
int testno;
@@ -167,15 +168,9 @@ void cleanup0(void)
void setup1(void)
{
- s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
- if (s < 0) {
- tst_brkm(TBROK, cleanup, "socket setup failed for getsockname "
- "test %d: %s", testno, strerror(errno));
- }
- if (bind(s, (struct sockaddr *)&sin0, sizeof(sin0)) < 0) {
- tst_brkm(TBROK, cleanup, "socket bind failed for getsockname "
- "test %d: %s", testno, strerror(errno));
- }
+ s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+ tdat[testno].proto);
+ SAFE_BIND(cleanup, s, (struct sockaddr *)&sin0, sizeof(sin0));
sinlen = sizeof(fsin1);
}
diff --git a/testcases/kernel/syscalls/getsockopt/getsockopt01.c b/testcases/kernel/syscalls/getsockopt/getsockopt01.c
index 1195306a0..d1692fcd3 100644
--- a/testcases/kernel/syscalls/getsockopt/getsockopt01.c
+++ b/testcases/kernel/syscalls/getsockopt/getsockopt01.c
@@ -52,6 +52,7 @@
#include <netinet/in.h>
#include "test.h"
+#include "safe_macros.h"
char *TCID = "getsockopt01";
int testno;
@@ -193,15 +194,9 @@ void cleanup0(void)
void setup1(void)
{
- s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
- if (s < 0) {
- tst_brkm(TBROK, cleanup, "socket setup failed for getsockopt: "
- "%s", strerror(errno));
- }
- if (bind(s, (struct sockaddr *)&sin0, sizeof(sin0)) < 0) {
- tst_brkm(TBROK, cleanup, "socket bind failed for getsockopt: "
- "%s", strerror(errno));
- }
+ s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+ tdat[testno].proto);
+ SAFE_BIND(cleanup, s, (struct sockaddr *)&sin0, sizeof(sin0));
sinlen = sizeof(fsin1);
optlen = sizeof(optval);
}
diff --git a/testcases/kernel/syscalls/listen/listen01.c b/testcases/kernel/syscalls/listen/listen01.c
index e421bb46d..b3dd7125d 100644
--- a/testcases/kernel/syscalls/listen/listen01.c
+++ b/testcases/kernel/syscalls/listen/listen01.c
@@ -53,6 +53,7 @@
#include <netinet/in.h>
#include "test.h"
+#include "safe_macros.h"
char *TCID = "listen01";
int testno;
@@ -140,11 +141,8 @@ void cleanup0(void)
void setup1(void)
{
- s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
- if (s < 0) {
- tst_brkm(TBROK, cleanup, "socket setup failed for listen: "
- "%s", strerror(errno));
- }
+ s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+ tdat[testno].proto);
}
void cleanup1(void)
diff --git a/testcases/kernel/syscalls/recv/recv01.c b/testcases/kernel/syscalls/recv/recv01.c
index 9c21dc206..470cf9a19 100644
--- a/testcases/kernel/syscalls/recv/recv01.c
+++ b/testcases/kernel/syscalls/recv/recv01.c
@@ -53,6 +53,7 @@
#include <netinet/in.h>
#include "test.h"
+#include "safe_macros.h"
char *TCID = "recv01";
int testno;
@@ -225,19 +226,9 @@ pid_t start_server(struct sockaddr_in *sin0)
sin0->sin_port = 0; /* pick random free port */
sin0->sin_addr.s_addr = INADDR_ANY;
- sfd = socket(PF_INET, SOCK_STREAM, 0);
- if (sfd < 0) {
- tst_brkm(TBROK | TERRNO, cleanup, "server socket failed");
- return -1;
- }
- if (bind(sfd, (struct sockaddr *)sin0, sizeof(*sin0)) < 0) {
- tst_brkm(TBROK | TERRNO, cleanup, "server bind failed");
- return -1;
- }
- if (listen(sfd, 10) < 0) {
- tst_brkm(TBROK | TERRNO, cleanup, "server listen failed");
- return -1;
- }
+ sfd = SAFE_SOCKET(cleanup, PF_INET, SOCK_STREAM, 0);
+ SAFE_BIND(cleanup, sfd, (struct sockaddr *)sin0, sizeof(*sin0));
+ SAFE_LISTEN(cleanup, sfd, 10);
if (getsockname(sfd, (struct sockaddr *)sin0, &slen) == -1)
tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
diff --git a/testcases/kernel/syscalls/recvfrom/recvfrom01.c b/testcases/kernel/syscalls/recvfrom/recvfrom01.c
index 3bcf2a1fc..d95c28f9a 100644
--- a/testcases/kernel/syscalls/recvfrom/recvfrom01.c
+++ b/testcases/kernel/syscalls/recvfrom/recvfrom01.c
@@ -53,6 +53,7 @@
#include <netinet/in.h>
#include "test.h"
+#include "safe_macros.h"
char *TCID = "recvfrom01";
int testno;
@@ -254,19 +255,9 @@ pid_t start_server(struct sockaddr_in *sin0)
sin0->sin_port = 0; /* pick random free port */
sin0->sin_addr.s_addr = INADDR_ANY;
- sfd = socket(PF_INET, SOCK_STREAM, 0);
- if (sfd < 0) {
- tst_brkm(TBROK | TERRNO, cleanup, "server socket failed");
- return -1;
- }
- if (bind(sfd, (struct sockaddr *)sin0, sizeof(*sin0)) < 0) {
- tst_brkm(TBROK | TERRNO, cleanup, "server bind failed");
- return -1;
- }
- if (listen(sfd, 10) < 0) {
- tst_brkm(TBROK | TERRNO, cleanup, "server listen failed");
- return -1;
- }
+ sfd = SAFE_SOCKET(cleanup, PF_INET, SOCK_STREAM, 0);
+ SAFE_BIND(cleanup, sfd, (struct sockaddr *)sin0, sizeof(*sin0));
+ SAFE_LISTEN(cleanup, sfd, 10);
if (getsockname(sfd, (struct sockaddr *)sin0, &slen) == -1)
tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
diff --git a/testcases/kernel/syscalls/recvmsg/recvmsg01.c b/testcases/kernel/syscalls/recvmsg/recvmsg01.c
index 13bd58f4b..51b2a0061 100644
--- a/testcases/kernel/syscalls/recvmsg/recvmsg01.c
+++ b/testcases/kernel/syscalls/recvmsg/recvmsg01.c
@@ -56,6 +56,7 @@
#include <netinet/in.h>
#include "test.h"
+#include "safe_macros.h"
char *TCID = "recvmsg01";
int testno;
@@ -374,28 +375,14 @@ pid_t start_server(struct sockaddr_in *ssin, struct sockaddr_un *ssun)
ssin->sin_addr.s_addr = INADDR_ANY;
/* set up inet socket */
- sfd = socket(PF_INET, SOCK_STREAM, 0);
- if (sfd < 0) {
- tst_brkm(TBROK | TERRNO, cleanup, "server socket failed");
- return -1;
- }
- if (bind(sfd, (struct sockaddr *)ssin, sizeof(*ssin)) < 0) {
- tst_brkm(TBROK | TERRNO, cleanup, "server bind failed");
- return -1;
- }
- if (listen(sfd, 10) < 0) {
- tst_brkm(TBROK | TERRNO, cleanup, "server listen failed");
- return -1;
- }
+ sfd = SAFE_SOCKET(cleanup, PF_INET, SOCK_STREAM, 0);
+ SAFE_BIND(cleanup, sfd, (struct sockaddr *)ssin, sizeof(*ssin));
+ SAFE_LISTEN(cleanup, sfd, 10);
if (getsockname(sfd, (struct sockaddr *)ssin, &slen) == -1)
tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
/* set up UNIX-domain socket */
- ufd = socket(PF_UNIX, SOCK_STREAM, 0);
- if (ufd < 0) {
- tst_brkm(TBROK | TERRNO, cleanup, "server UD socket failed");
- return -1;
- }
+ ufd = SAFE_SOCKET(cleanup, PF_UNIX, SOCK_STREAM, 0);
if (bind(ufd, (struct sockaddr *)ssun, sizeof(*ssun))) {
tst_brkm(TBROK | TERRNO, cleanup, "server UD bind failed");
return -1;
diff --git a/testcases/kernel/syscalls/send/send01.c b/testcases/kernel/syscalls/send/send01.c
index 6f71300ce..cef0c90a0 100644
--- a/testcases/kernel/syscalls/send/send01.c
+++ b/testcases/kernel/syscalls/send/send01.c
@@ -42,6 +42,7 @@
#include <netinet/in.h>
#include "test.h"
+#include "safe_macros.h"
char *TCID = "send01";
int testno;
@@ -169,19 +170,9 @@ static pid_t start_server(struct sockaddr_in *sin0)
sin0->sin_port = 0; /* pick random free port */
sin0->sin_addr.s_addr = INADDR_ANY;
- sfd = socket(PF_INET, SOCK_STREAM, 0);
- if (sfd < 0) {
- tst_brkm(TBROK | TERRNO, cleanup, "server socket failed");
- return -1;
- }
- if (bind(sfd, (struct sockaddr *)sin0, sizeof(*sin0)) < 0) {
- tst_brkm(TBROK | TERRNO, cleanup, "server bind failed");
- return -1;
- }
- if (listen(sfd, 10) < 0) {
- tst_brkm(TBROK | TERRNO, cleanup, "server listen failed");
- return -1;
- }
+ sfd = SAFE_SOCKET(cleanup, PF_INET, SOCK_STREAM, 0);
+ SAFE_BIND(cleanup, sfd, (struct sockaddr *)sin0, sizeof(*sin0));
+ SAFE_LISTEN(cleanup, sfd, 10);
if (getsockname(sfd, (struct sockaddr *)sin0, &slen) == -1)
tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
diff --git a/testcases/kernel/syscalls/sendfile/sendfile02.c b/testcases/kernel/syscalls/sendfile/sendfile02.c
index ba12308b3..37680839f 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile02.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile02.c
@@ -57,6 +57,7 @@
#include <unistd.h>
#include <inttypes.h>
#include "test.h"
+#include "safe_macros.h"
#ifndef OFF_T
#define OFF_T off_t
@@ -214,21 +215,12 @@ int create_server(void)
static int count = 0;
socklen_t slen = sizeof(sin1);
- sockfd = socket(PF_INET, SOCK_DGRAM, 0);
- if (sockfd < 0) {
- tst_brkm(TBROK, cleanup, "call to socket() failed: %s",
- strerror(errno));
- return -1;
- }
+ sockfd = SAFE_SOCKET(cleanup, PF_INET, SOCK_DGRAM, 0);
sin1.sin_family = AF_INET;
sin1.sin_port = 0; /* pick random free port */
sin1.sin_addr.s_addr = INADDR_ANY;
count++;
- if (bind(sockfd, (struct sockaddr *)&sin1, sizeof(sin1)) < 0) {
- tst_brkm(TBROK, cleanup, "call to bind() failed: %s",
- strerror(errno));
- return -1;
- }
+ SAFE_BIND(cleanup, sockfd, (struct sockaddr *)&sin1, sizeof(sin1));
if (getsockname(sockfd, (struct sockaddr *)&sin1, &slen) == -1)
tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
diff --git a/testcases/kernel/syscalls/sendfile/sendfile04.c b/testcases/kernel/syscalls/sendfile/sendfile04.c
index 822c4688c..45c15df50 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile04.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile04.c
@@ -57,6 +57,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include "test.h"
+#include "safe_macros.h"
#ifndef OFF_T
#define OFF_T off_t
@@ -212,21 +213,12 @@ int create_server(void)
static int count = 0;
socklen_t slen = sizeof(sin1);
- sockfd = socket(PF_INET, SOCK_DGRAM, 0);
- if (sockfd < 0) {
- tst_brkm(TBROK, cleanup, "call to socket() failed: %s",
- strerror(errno));
- return -1;
- }
+ sockfd = SAFE_SOCKET(cleanup, PF_INET, SOCK_DGRAM, 0);
sin1.sin_family = AF_INET;
sin1.sin_port = 0; /* pick random free port */
sin1.sin_addr.s_addr = INADDR_ANY;
count++;
- if (bind(sockfd, (struct sockaddr *)&sin1, sizeof(sin1)) < 0) {
- tst_brkm(TBROK, cleanup, "call to bind() failed: %s",
- strerror(errno));
- return -1;
- }
+ SAFE_BIND(cleanup, sockfd, (struct sockaddr *)&sin1, sizeof(sin1));
if (getsockname(sockfd, (struct sockaddr *)&sin1, &slen) == -1)
tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
diff --git a/testcases/kernel/syscalls/sendfile/sendfile05.c b/testcases/kernel/syscalls/sendfile/sendfile05.c
index 110194b84..d3222c19a 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile05.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile05.c
@@ -52,6 +52,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include "test.h"
+#include "safe_macros.h"
#ifndef OFF_T
#define OFF_T off_t
@@ -176,21 +177,12 @@ int create_server(void)
static int count = 0;
socklen_t slen = sizeof(sin1);
- sockfd = socket(PF_INET, SOCK_DGRAM, 0);
- if (sockfd < 0) {
- tst_brkm(TBROK, cleanup, "call to socket() failed: %s",
- strerror(errno));
- return -1;
- }
+ sockfd = SAFE_SOCKET(cleanup, PF_INET, SOCK_DGRAM, 0);
sin1.sin_family = AF_INET;
sin1.sin_port = 0; /* pick random free port */
sin1.sin_addr.s_addr = INADDR_ANY;
count++;
- if (bind(sockfd, (struct sockaddr *)&sin1, sizeof(sin1)) < 0) {
- tst_brkm(TBROK, cleanup, "call to bind() failed: %s",
- strerror(errno));
- return -1;
- }
+ SAFE_BIND(cleanup, sockfd, (struct sockaddr *)&sin1, sizeof(sin1));
if (getsockname(sockfd, (struct sockaddr *)&sin1, &slen) == -1)
tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
diff --git a/testcases/kernel/syscalls/sendfile/sendfile06.c b/testcases/kernel/syscalls/sendfile/sendfile06.c
index 794519549..b77c193a4 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile06.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile06.c
@@ -154,21 +154,12 @@ static int create_server(void)
int s;
socklen_t slen = sizeof(sin1);
- sockfd = socket(PF_INET, SOCK_DGRAM, 0);
- if (sockfd < 0) {
- tst_brkm(TBROK, cleanup, "call to socket() failed: %s",
- strerror(errno));
- return -1;
- }
+ sockfd = SAFE_SOCKET(cleanup, PF_INET, SOCK_DGRAM, 0);
sin1.sin_family = AF_INET;
sin1.sin_port = 0; /* pick random free port */
sin1.sin_addr.s_addr = INADDR_ANY;
- if (bind(sockfd, (struct sockaddr *)&sin1, sizeof(sin1)) < 0) {
- tst_brkm(TBROK, cleanup, "call to bind() failed: %s",
- strerror(errno));
- return -1;
- }
+ SAFE_BIND(cleanup, sockfd, (struct sockaddr *)&sin1, sizeof(sin1));
if (getsockname(sockfd, (struct sockaddr *)&sin1, &slen) == -1)
tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
diff --git a/testcases/kernel/syscalls/sendmsg/sendmsg01.c b/testcases/kernel/syscalls/sendmsg/sendmsg01.c
index dcf3ab7e8..364c7e584 100644
--- a/testcases/kernel/syscalls/sendmsg/sendmsg01.c
+++ b/testcases/kernel/syscalls/sendmsg/sendmsg01.c
@@ -48,6 +48,7 @@
#include <netinet/in.h>
#include "test.h"
+#include "safe_macros.h"
char *TCID = "sendmsg01";
int testno;
@@ -425,17 +426,8 @@ static pid_t start_server(struct sockaddr_in *sin0, struct sockaddr_un *sun0)
sin0->sin_addr.s_addr = INADDR_ANY;
/* set up inet socket */
- sfd = socket(PF_INET, SOCK_STREAM, 0);
- if (sfd < 0) {
- tst_brkm(TBROK, cleanup, "server socket failed: %s",
- strerror(errno));
- return -1;
- }
- if (bind(sfd, (struct sockaddr *)sin0, sizeof(*sin0)) < 0) {
- tst_brkm(TBROK, cleanup, "server bind failed: %s",
- strerror(errno));
- return -1;
- }
+ sfd = SAFE_SOCKET(cleanup, PF_INET, SOCK_STREAM, 0);
+ SAFE_BIND(cleanup, sfd, (struct sockaddr *)sin0, sizeof(*sin0));
if (listen(sfd, 10) < 0) {
tst_brkm(TBROK, cleanup, "server listen failed: %s",
strerror(errno));
@@ -445,12 +437,7 @@ static pid_t start_server(struct sockaddr_in *sin0, struct sockaddr_un *sun0)
tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
/* set up UNIX-domain socket */
- ufd = socket(PF_UNIX, SOCK_DGRAM, 0);
- if (ufd < 0) {
- tst_brkm(TBROK, cleanup, "server UD socket failed: %s",
- strerror(errno));
- return -1;
- }
+ ufd = SAFE_SOCKET(cleanup, PF_UNIX, SOCK_DGRAM, 0);
if (bind(ufd, (struct sockaddr *)sun0, sizeof(*sun0))) {
tst_brkm(TBROK, cleanup, "server UD bind failed: %s",
strerror(errno));
@@ -589,11 +576,8 @@ static void cleanup0(void)
static void setup1(void)
{
- s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
- if (s < 0) {
- tst_brkm(TBROK, cleanup, "socket setup failed: %s",
- strerror(errno));
- }
+ s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+ tdat[testno].proto);
if (tdat[testno].type == SOCK_STREAM &&
connect(s, (struct sockaddr *)tdat[testno].to,
tdat[testno].tolen) < 0) {
@@ -618,11 +602,8 @@ static void setup2(void)
static void setup3(void)
{
- s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
- if (s < 0) {
- tst_brkm(TBROK, cleanup, "socket setup failed: %s",
- strerror(errno));
- }
+ s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+ tdat[testno].proto);
}
static char tmpfilename[1024];
@@ -659,11 +640,8 @@ static void cleanup4(void)
static void setup5(void)
{
- s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
- if (s < 0) {
- tst_brkm(TBROK, cleanup, "socket setup failed: %s",
- strerror(errno));
- }
+ s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+ tdat[testno].proto);
if (connect(s, (struct sockaddr *)&sin1, sizeof(sin1)) < 0)
tst_brkm(TBROK, cleanup, "connect failed: %s", strerror(errno));
diff --git a/testcases/kernel/syscalls/sendto/sendto01.c b/testcases/kernel/syscalls/sendto/sendto01.c
index ec0766197..7753a4ffb 100644
--- a/testcases/kernel/syscalls/sendto/sendto01.c
+++ b/testcases/kernel/syscalls/sendto/sendto01.c
@@ -41,6 +41,7 @@
#include <netinet/in.h>
#include "test.h"
+#include "safe_macros.h"
char *TCID = "sendto01";
int testno;
@@ -239,19 +240,9 @@ static pid_t start_server(struct sockaddr_in *sin0)
sin0->sin_port = 0; /* pick random free port */
sin0->sin_addr.s_addr = INADDR_ANY;
- sfd = socket(PF_INET, SOCK_STREAM, 0);
- if (sfd < 0) {
- tst_brkm(TBROK | TERRNO, cleanup, "server socket failed");
- return -1;
- }
- if (bind(sfd, (struct sockaddr *)sin0, sizeof(*sin0)) < 0) {
- tst_brkm(TBROK | TERRNO, cleanup, "server bind failed");
- return -1;
- }
- if (listen(sfd, 10) < 0) {
- tst_brkm(TBROK | TERRNO, cleanup, "server listen failed");
- return -1;
- }
+ sfd = SAFE_SOCKET(cleanup, PF_INET, SOCK_STREAM, 0);
+ SAFE_BIND(cleanup, sfd, (struct sockaddr *)sin0, sizeof(*sin0));
+ SAFE_LISTEN(cleanup, sfd, 10);
if (getsockname(sfd, (struct sockaddr *)sin0, &slen) == -1)
tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
diff --git a/testcases/kernel/syscalls/setsockopt/setsockopt01.c b/testcases/kernel/syscalls/setsockopt/setsockopt01.c
index f25694a96..743c6be14 100644
--- a/testcases/kernel/syscalls/setsockopt/setsockopt01.c
+++ b/testcases/kernel/syscalls/setsockopt/setsockopt01.c
@@ -54,6 +54,7 @@
#include <netinet/in.h>
#include "test.h"
+#include "safe_macros.h"
char *TCID = "setsockopt01";
int testno;
@@ -200,15 +201,9 @@ void cleanup0(void)
void setup1(void)
{
- s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
- if (s < 0) {
- tst_brkm(TBROK, cleanup, "socket setup failed for setsockopt:"
- " %s", strerror(errno));
- }
- if (bind(s, (struct sockaddr *)&sin0, sizeof(sin0)) < 0) {
- tst_brkm(TBROK, cleanup, "socket bind failed for setsockopt:"
- " %s", strerror(errno));
- }
+ s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+ tdat[testno].proto);
+ SAFE_BIND(cleanup, s, (struct sockaddr *)&sin0, sizeof(sin0));
}
void cleanup1(void)
diff --git a/testcases/kernel/syscalls/sockioctl/sockioctl01.c b/testcases/kernel/syscalls/sockioctl/sockioctl01.c
index 50bdc935a..096f138a9 100644
--- a/testcases/kernel/syscalls/sockioctl/sockioctl01.c
+++ b/testcases/kernel/syscalls/sockioctl/sockioctl01.c
@@ -40,6 +40,7 @@
#include <net/if.h>
#include "test.h"
+#include "safe_macros.h"
char *TCID = "sockioctl01";
int testno;
@@ -204,15 +205,9 @@ static void cleanup0(void)
static void setup1(void)
{
- s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
- if (s < 0) {
- tst_brkm(TBROK, cleanup, "socket setup failed: %s",
- strerror(errno));
- }
- if (bind(s, (struct sockaddr *)&sin0, sizeof(sin0)) < 0) {
- tst_brkm(TBROK, cleanup, "socket bind failed for: %s",
- strerror(errno));
- }
+ s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+ tdat[testno].proto);
+ SAFE_BIND(cleanup, s, (struct sockaddr *)&sin0, sizeof(sin0));
sinlen = sizeof(fsin1);
if (strncmp(tdat[testno].desc, "ATMARK on UDP", 14) == 0) {
@@ -223,11 +218,8 @@ static void setup1(void)
static void setup2(void)
{
- s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
- if (s < 0) {
- tst_brkm(TBROK, cleanup, "socket setup failed: %s",
- strerror(errno));
- }
+ s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+ tdat[testno].proto);
ifc.ifc_len = sizeof(buf);
ifc.ifc_buf = buf;
}
--
2.14.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH 1/1] syscalls, lib: Use SAFE_{BIND, LISTEN, SOCKET} macros
2017-09-29 23:10 [LTP] [PATCH 1/1] syscalls, lib: Use SAFE_{BIND, LISTEN, SOCKET} macros Petr Vorel
@ 2017-09-29 23:15 ` Petr Vorel
2017-10-02 11:00 ` Richard Palethorpe
1 sibling, 0 replies; 15+ messages in thread
From: Petr Vorel @ 2017-09-29 23:15 UTC (permalink / raw)
To: ltp
> instead of tst_brk{,m}(TBROK, ...)
> Patch was made thanks to Coccinelle.
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
Please ignore second sign.
<snip>
> diff --git a/lib/tst_net.c b/lib/tst_net.c
> index f842e94a6..326b92e6f 100644
> --- a/lib/tst_net.c
> +++ b/lib/tst_net.c
> @@ -25,6 +25,7 @@
> #include <netinet/in.h>
> #include "test.h"
> +#include "safe_macros.h"
> unsigned short tst_get_unused_port(void (cleanup_fn)(void),
> unsigned short family, int type)
> @@ -57,16 +58,9 @@ unsigned short tst_get_unused_port(void (cleanup_fn)(void),
> return -1;
> }
> - sock = socket(addr->sa_family, type, 0);
> - if (sock < 0) {
> - tst_brkm(TBROK | TERRNO, cleanup_fn, "socket failed");
> - return -1;
> - }
> + sock = SAFE_SOCKET(cleanup_fn, addr->sa_family, type, 0);
> - if (bind(sock, addr, slen) < 0) {
> - tst_brkm(TBROK | TERRNO, cleanup_fn, "bind failed");
> - return -1;
> - }
> + SAFE_BIND(cleanup_fn, sock, addr, slen);
I suppose tst_brkm(TBROK, ...) always exit testing, so we can have SAFE_* macros even here
in lib.
Kind regards,
Petr
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 1/1] syscalls, lib: Use SAFE_{BIND, LISTEN, SOCKET} macros
2017-09-29 23:10 [LTP] [PATCH 1/1] syscalls, lib: Use SAFE_{BIND, LISTEN, SOCKET} macros Petr Vorel
2017-09-29 23:15 ` Petr Vorel
@ 2017-10-02 11:00 ` Richard Palethorpe
2017-10-02 12:29 ` Petr Vorel
1 sibling, 1 reply; 15+ messages in thread
From: Richard Palethorpe @ 2017-10-02 11:00 UTC (permalink / raw)
To: ltp
Hello Petr,
Petr Vorel writes:
> instead of tst_brk{,m}(TBROK, ...)
>
> Patch was made thanks to Coccinelle.
>
Very good. Also how about including the Coccinelle patch in the tools or
scripts folder?
--
Thank you,
Richard.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 1/1] syscalls, lib: Use SAFE_{BIND, LISTEN, SOCKET} macros
2017-10-02 11:00 ` Richard Palethorpe
@ 2017-10-02 12:29 ` Petr Vorel
2017-10-02 14:51 ` Richard Palethorpe
0 siblings, 1 reply; 15+ messages in thread
From: Petr Vorel @ 2017-10-02 12:29 UTC (permalink / raw)
To: ltp
Hi Richard, Cyril,
> Hello Petr,
> > Patch was made thanks to Coccinelle.
> Very good. Also how about including the Coccinelle patch in the tools or
> scripts folder?
Cyril, do you like this idea?
Well, I'm not much proud on that script, it's my first Coccinelle script :-)
@test_h@
@@
#include "test.h"
@tst_test_h@
@@
#include "tst_test.h"
// test.h does not include safe_macros.h
@safe_macros_h@
@@
#include "safe_macros.h"
@is_safe_socket@
@@
int safe_socket(...) {...}
// SAFE_BIND
@old_safe_bind depends on test_h@
expression sockfd, sockaddr, addrlen;
identifier cleanup_fn;
expression e, x;
constant TFAIL;
@@
-if (bind(sockfd, sockaddr, addrlen) < 0) {
- tst_brkm(e, cleanup_fn, ...);
(
- return -1;
|
)
... when != x & TFAIL
-}
+SAFE_BIND(cleanup_fn, sockfd, sockaddr, addrlen);
@safe_bind depends on tst_test_h@
expression sockfd, sockaddr, addrlen;
expression e, x;
constant TFAIL;
@@
-if (bind(sockfd, sockaddr, addrlen) < 0) {
- tst_brk(e, ...);
(
- return -1;
|
)
... when != x & TFAIL
-}
+SAFE_BIND(sockfd, sockaddr, addrlen);
// SAFE_SOCKET
@old_safe_socket depends on test_h && !is_safe_socket@
expression family, type, protocol;
identifier fd;
identifier cleanup_fn;
expression e, x;
constant TFAIL;
@@
-fd = socket(family, type, protocol);
-if (fd < 0) {
- tst_brkm(e, cleanup_fn, ...);
(
- return -1;
|
)
... when != x & TFAIL
-}
+fd = SAFE_SOCKET(cleanup_fn, family, type, protocol);
@safe_socket depends on tst_test_h && !is_safe_socket@
expression family, type, protocol;
identifier fd;
expression e, x;
constant TFAIL;
@@
-fd = socket(family, type, protocol);
-if (fd < 0) {
- tst_brk(e, ...);
(
- return -1;
|
)
... when != x & TFAIL
-}
+fd = SAFE_SOCKET(family, type, protocol);
// SAFE_FSETXATTR
// not used so far, not in old
@safe_fsetxattr depends on tst_test_h@
expression fd, name, value, flags, size;
identifier r;
expression e, x;
constant TFAIL;
@@
-r = fsetxattr(fd, name, value, size, flags);
-if (r < 0) {
- tst_brk(e, ...);
(
- return -1;
|
)
... when != x & TFAIL
-}
+SAFE_FSETXATTR(fd, name, value, size, flags);
// SAFE_LISTEN
@safe_listen depends on tst_test_h@
expression backlog;
identifier socket;
identifier r;
expression e, x;
constant TFAIL;
@@
-r = listen(socket, backlog); if (r < 0) {
- tst_brk(e, ...);
(
- return -1;
|
)
... when != x & TFAIL
-}
+SAFE_LISTEN(socket, backlog);
@safe_listen2 depends on tst_test_h@
expression backlog;
identifier socket;
identifier r;
expression e, x;
constant TFAIL;
@@
-if (listen(socket, backlog) < 0) {
- tst_brk(e, ...);
(
- return -1;
|
)
... when != x & TFAIL
-}
+SAFE_LISTEN(socket, backlog);
@old_safe_listen depends on test_h@
expression backlog;
identifier socket, cleanup_fn;
identifier r;
expression e, x;
constant TFAIL;
@@
-r = listen(socket, backlog); if (r < 0) {
- tst_brk(e, ...);
(
- return -1;
|
)
... when != x & TFAIL
-}
+SAFE_LISTEN(cleanup_fn, socket, backlog);
@old_safe_listen2 depends on test_h@
expression backlog;
identifier socket, cleanup_fn;
identifier r;
expression e, x;
constant TFAIL;
@@
-if (listen(socket, backlog) < 0) {
- tst_brkm(TBROK | TERRNO, cleanup_fn, "server listen failed");
- return -1;
- }
+SAFE_LISTEN(cleanup_fn, socket, backlog);
// SAFE_SENDTO
// not used so far, not in old
@safe_sendto depends on tst_test_h@
expression fd, buf, len, flags, dest_addr, addrlen;
identifier r;
expression e, x;
constant TFAIL;
@@
-r = sendto(fd, buf, len, flags, dest_addr, addrlen);
-if (r < 0) {
- tst_brk(e, ...);
(
- return -1;
|
)
... when != x & TFAIL
-}
+SAFE_SENDTO(1, fd, buf, len, flags, dest_addr, addrlen);
// INCLUDE
@depends on !safe_macros_h && (old_safe_bind || old_safe_listen || old_safe_listen2 || old_safe_socket)@
@@
#include "test.h"
+#include "safe_macros.h"
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 1/1] syscalls, lib: Use SAFE_{BIND, LISTEN, SOCKET} macros
2017-10-02 12:29 ` Petr Vorel
@ 2017-10-02 14:51 ` Richard Palethorpe
2017-10-02 15:04 ` Petr Vorel
0 siblings, 1 reply; 15+ messages in thread
From: Richard Palethorpe @ 2017-10-02 14:51 UTC (permalink / raw)
To: ltp
Hello,
Petr Vorel writes:
> Hi Richard, Cyril,
>
>> Hello Petr,
>
>> > Patch was made thanks to Coccinelle.
>> Very good. Also how about including the Coccinelle patch in the tools or
>> scripts folder?
>
> Cyril, do you like this idea?
>
> Well, I'm not much proud on that script, it's my first Coccinelle
> script :-)
It is more advanced than the one I created to do something similar.
>
> @test_h@
> @@
> #include "test.h"
>
> @tst_test_h@
> @@
> #include "tst_test.h"
>
> // test.h does not include safe_macros.h
> @safe_macros_h@
> @@
> #include "safe_macros.h"
>
> @is_safe_socket@
> @@
> int safe_socket(...) {...}
>
> // SAFE_BIND
> @old_safe_bind depends on test_h@
> expression sockfd, sockaddr, addrlen;
> identifier cleanup_fn;
> expression e, x;
> constant TFAIL;
> @@
> -if (bind(sockfd, sockaddr, addrlen) < 0) {
> - tst_brkm(e, cleanup_fn, ...);
> (
> - return -1;
> |
> )
> ... when != x & TFAIL
What does the last line do? I am guessing it prevents the substitution
if it finds TFAIL anywhere in the above expression.
--
Thank you,
Richard.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 1/1] syscalls, lib: Use SAFE_{BIND, LISTEN, SOCKET} macros
2017-10-02 14:51 ` Richard Palethorpe
@ 2017-10-02 15:04 ` Petr Vorel
2017-10-02 15:21 ` Cyril Hrubis
0 siblings, 1 reply; 15+ messages in thread
From: Petr Vorel @ 2017-10-02 15:04 UTC (permalink / raw)
To: ltp
Hi Richard,
> It is more advanced than the one I created to do something similar.
> > // SAFE_BIND
> > @old_safe_bind depends on test_h@
> > expression sockfd, sockaddr, addrlen;
> > identifier cleanup_fn;
> > expression e, x;
> > constant TFAIL;
> > @@
> > -if (bind(sockfd, sockaddr, addrlen) < 0) {
> > - tst_brkm(e, cleanup_fn, ...);
> > (
> > - return -1;
> > )
> > ... when != x & TFAIL
> What does the last line do? I am guessing it prevents the substitution
> if it finds TFAIL anywhere in the above expression.
Precisely :-).
Kind regards,
Petr
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 1/1] syscalls, lib: Use SAFE_{BIND, LISTEN, SOCKET} macros
2017-10-02 15:04 ` Petr Vorel
@ 2017-10-02 15:21 ` Cyril Hrubis
2017-10-02 15:36 ` Petr Vorel
0 siblings, 1 reply; 15+ messages in thread
From: Cyril Hrubis @ 2017-10-02 15:21 UTC (permalink / raw)
To: ltp
Hi!
> > > // SAFE_BIND
> > > @old_safe_bind depends on test_h@
> > > expression sockfd, sockaddr, addrlen;
> > > identifier cleanup_fn;
> > > expression e, x;
> > > constant TFAIL;
> > > @@
> > > -if (bind(sockfd, sockaddr, addrlen) < 0) {
> > > - tst_brkm(e, cleanup_fn, ...);
> > > (
> > > - return -1;
>
> > > )
> > > ... when != x & TFAIL
>
> > What does the last line do? I am guessing it prevents the substitution
> > if it finds TFAIL anywhere in the above expression.
> Precisely :-).
Shouldn't that be when != e & TFAIL? As far as I can tell the x is not
used in the matching part, or did I miss something?
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 1/1] syscalls, lib: Use SAFE_{BIND, LISTEN, SOCKET} macros
2017-10-02 15:21 ` Cyril Hrubis
@ 2017-10-02 15:36 ` Petr Vorel
2017-10-03 11:43 ` Cyril Hrubis
0 siblings, 1 reply; 15+ messages in thread
From: Petr Vorel @ 2017-10-02 15:36 UTC (permalink / raw)
To: ltp
> Hi!
> > > > ... when != x & TFAIL
> > > What does the last line do? I am guessing it prevents the substitution
> > > if it finds TFAIL anywhere in the above expression.
> > Precisely :-).
> Shouldn't that be when != e & TFAIL? As far as I can tell the x is not
> used in the matching part, or did I miss something?
Sure, you're right, Cyril. Now I got your question Richard.
I'm surprised that it work with x (result is the same).
Kind regards,
Petr
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 1/1] syscalls, lib: Use SAFE_{BIND, LISTEN, SOCKET} macros
2017-10-02 15:36 ` Petr Vorel
@ 2017-10-03 11:43 ` Cyril Hrubis
2017-10-03 12:31 ` Petr Vorel
0 siblings, 1 reply; 15+ messages in thread
From: Cyril Hrubis @ 2017-10-03 11:43 UTC (permalink / raw)
To: ltp
Hi!
> > Shouldn't that be when != e & TFAIL? As far as I can tell the x is not
> > used in the matching part, or did I miss something?
> Sure, you're right, Cyril. Now I got your question Richard.
> I'm surprised that it work with x (result is the same).
I guess that this condition simply was always true, and it does not work
either way.
Anyway I got an idea yesterday and implemented a shell script that
generates a spatch based on function name and made it iterate over all
safe macros we have implemented making a git commit for each. The script
is attached for a reference.
I will look at the patches and do some minor adjustements now, there are
a few cases where the formatting ended up a bit confusing.
And I would consider these to be obvious enough to be commited without
review, but I can send them to ML if anyone wants to double check the
results.
--
Cyril Hrubis
chrubis@suse.cz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch_safe_macros.sh
Type: application/x-sh
Size: 2280 bytes
Desc: not available
URL: <http://lists.linux.it/pipermail/ltp/attachments/20171003/23122597/attachment.sh>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 1/1] syscalls, lib: Use SAFE_{BIND, LISTEN, SOCKET} macros
2017-10-03 11:43 ` Cyril Hrubis
@ 2017-10-03 12:31 ` Petr Vorel
2017-10-03 12:56 ` Cyril Hrubis
2017-10-03 14:28 ` Cyril Hrubis
0 siblings, 2 replies; 15+ messages in thread
From: Petr Vorel @ 2017-10-03 12:31 UTC (permalink / raw)
To: ltp
Hi Cyril,
> Anyway I got an idea yesterday and implemented a shell script that
> generates a spatch based on function name and made it iterate over all
> safe macros we have implemented making a git commit for each. The script
> is attached for a reference.
Really nice solution :-).
This script is really worth of adding into LTP (even it requires to check formatting).
Kind regards,
Petr
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 1/1] syscalls, lib: Use SAFE_{BIND, LISTEN, SOCKET} macros
2017-10-03 12:31 ` Petr Vorel
@ 2017-10-03 12:56 ` Cyril Hrubis
2017-10-03 13:21 ` Petr Vorel
2017-10-03 18:08 ` Jan Stancek
2017-10-03 14:28 ` Cyril Hrubis
1 sibling, 2 replies; 15+ messages in thread
From: Cyril Hrubis @ 2017-10-03 12:56 UTC (permalink / raw)
To: ltp
Hi!
> > Anyway I got an idea yesterday and implemented a shell script that
> > generates a spatch based on function name and made it iterate over all
> > safe macros we have implemented making a git commit for each. The script
> > is attached for a reference.
> Really nice solution :-).
> This script is really worth of adding into LTP (even it requires to check formatting).
I will strip the old library parts, then we can add it, maybe we can
even use it as a commit hook or something to automatically check if
we could have used a SAFE_MACRO() instead of custom error handling...
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 1/1] syscalls, lib: Use SAFE_{BIND, LISTEN, SOCKET} macros
2017-10-03 12:56 ` Cyril Hrubis
@ 2017-10-03 13:21 ` Petr Vorel
2017-10-03 18:08 ` Jan Stancek
1 sibling, 0 replies; 15+ messages in thread
From: Petr Vorel @ 2017-10-03 13:21 UTC (permalink / raw)
To: ltp
> Hi!
> > > Anyway I got an idea yesterday and implemented a shell script that
> > > generates a spatch based on function name and made it iterate over all
> > > safe macros we have implemented making a git commit for each. The script
> > > is attached for a reference.
> > Really nice solution :-).
> > This script is really worth of adding into LTP (even it requires to check formatting).
> I will strip the old library parts, then we can add it, maybe we can
> even use it as a commit hook or something to automatically check if
> we could have used a SAFE_MACRO() instead of custom error handling...
Good idea. What a shame that post-receive hook on GitHub (aka "WebHooks") do not allow to
execute anything on server side...
Kind regards,
Petr
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 1/1] syscalls, lib: Use SAFE_{BIND, LISTEN, SOCKET} macros
2017-10-03 12:31 ` Petr Vorel
2017-10-03 12:56 ` Cyril Hrubis
@ 2017-10-03 14:28 ` Cyril Hrubis
1 sibling, 0 replies; 15+ messages in thread
From: Cyril Hrubis @ 2017-10-03 14:28 UTC (permalink / raw)
To: ltp
Hi!
> > Anyway I got an idea yesterday and implemented a shell script that
> > generates a spatch based on function name and made it iterate over all
> > safe macros we have implemented making a git commit for each. The script
> > is attached for a reference.
> Really nice solution :-).
> This script is really worth of adding into LTP (even it requires to check formatting).
FYI: I've missed a pattern where the result is stored in a variable
first hence things like SAFE_OPEN() haven't had chance to be used
at all, I will fix that one and rerun the script.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 1/1] syscalls, lib: Use SAFE_{BIND, LISTEN, SOCKET} macros
2017-10-03 12:56 ` Cyril Hrubis
2017-10-03 13:21 ` Petr Vorel
@ 2017-10-03 18:08 ` Jan Stancek
2017-10-03 19:05 ` Cyril Hrubis
1 sibling, 1 reply; 15+ messages in thread
From: Jan Stancek @ 2017-10-03 18:08 UTC (permalink / raw)
To: ltp
----- Original Message -----
> Hi!
> > > Anyway I got an idea yesterday and implemented a shell script that
> > > generates a spatch based on function name and made it iterate over all
> > > safe macros we have implemented making a git commit for each. The script
> > > is attached for a reference.
> > Really nice solution :-).
> > This script is really worth of adding into LTP (even it requires to check
> > formatting).
>
> I will strip the old library parts, then we can add it, maybe we can
> even use it as a commit hook or something to automatically check if
> we could have used a SAFE_MACRO() instead of custom error handling...
>
As I was looking at changes, I came across:
tst_brkm(TFAIL | TERRNO, ...);
I guess most of these tst_brk TFAILs should be TBROKs, but that would be
likely difficult to script.
Regards,
Jan
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 1/1] syscalls, lib: Use SAFE_{BIND, LISTEN, SOCKET} macros
2017-10-03 18:08 ` Jan Stancek
@ 2017-10-03 19:05 ` Cyril Hrubis
0 siblings, 0 replies; 15+ messages in thread
From: Cyril Hrubis @ 2017-10-03 19:05 UTC (permalink / raw)
To: ltp
Hi!
> > > Really nice solution :-).
> > > This script is really worth of adding into LTP (even it requires to check
> > > formatting).
> >
> > I will strip the old library parts, then we can add it, maybe we can
> > even use it as a commit hook or something to automatically check if
> > we could have used a SAFE_MACRO() instead of custom error handling...
> >
>
> As I was looking at changes, I came across:
> tst_brkm(TFAIL | TERRNO, ...);
>
> I guess most of these tst_brk TFAILs should be TBROKs, but that would be
> likely difficult to script.
Yes, we would have to review which of these are real TFAILs manually,
which could be done, but would be quite time consuming. So I stuck with
changes I can formally prove are equal.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2017-10-03 19:05 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-29 23:10 [LTP] [PATCH 1/1] syscalls, lib: Use SAFE_{BIND, LISTEN, SOCKET} macros Petr Vorel
2017-09-29 23:15 ` Petr Vorel
2017-10-02 11:00 ` Richard Palethorpe
2017-10-02 12:29 ` Petr Vorel
2017-10-02 14:51 ` Richard Palethorpe
2017-10-02 15:04 ` Petr Vorel
2017-10-02 15:21 ` Cyril Hrubis
2017-10-02 15:36 ` Petr Vorel
2017-10-03 11:43 ` Cyril Hrubis
2017-10-03 12:31 ` Petr Vorel
2017-10-03 12:56 ` Cyril Hrubis
2017-10-03 13:21 ` Petr Vorel
2017-10-03 18:08 ` Jan Stancek
2017-10-03 19:05 ` Cyril Hrubis
2017-10-03 14:28 ` Cyril Hrubis
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.