commit
f905cddcf7
44
0002-test-test.c-Whitespace-cleanup.patch
Normal file
44
0002-test-test.c-Whitespace-cleanup.patch
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
From ce70d7a39f384c526e0a0e5fdfd1d3ed523f4942 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Phil Sutter <psutter@redhat.com>
|
||||||
|
Date: Fri, 25 Nov 2016 11:36:14 +0100
|
||||||
|
Subject: [PATCH] test/test.c: Whitespace cleanup
|
||||||
|
|
||||||
|
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
||||||
|
---
|
||||||
|
test/test.c | 6 +++---
|
||||||
|
1 file changed, 3 insertions(+), 3 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/test/test.c b/test/test.c
|
||||||
|
index c793225eaa820..224c1b4944fc5 100644
|
||||||
|
--- a/test/test.c
|
||||||
|
+++ b/test/test.c
|
||||||
|
@@ -69,7 +69,7 @@ int main()
|
||||||
|
}
|
||||||
|
printf("TCP_KEEPCNT = %d\n", optval);
|
||||||
|
#endif
|
||||||
|
-
|
||||||
|
+
|
||||||
|
#ifdef TCP_KEEPIDLE
|
||||||
|
if(getsockopt(s, SOL_TCP, TCP_KEEPIDLE, &optval, &optlen) < 0) {
|
||||||
|
perror("getsockopt()");
|
||||||
|
@@ -78,7 +78,7 @@ int main()
|
||||||
|
}
|
||||||
|
printf("TCP_KEEPIDLE = %d\n", optval);
|
||||||
|
#endif
|
||||||
|
-
|
||||||
|
+
|
||||||
|
#ifdef TCP_KEEPINTVL
|
||||||
|
if(getsockopt(s, SOL_TCP, TCP_KEEPINTVL, &optval, &optlen) < 0) {
|
||||||
|
perror("getsockopt()");
|
||||||
|
@@ -88,7 +88,7 @@ int main()
|
||||||
|
printf("TCP_KEEPINTVL = %d\n", optval);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
-
|
||||||
|
+
|
||||||
|
close(s);
|
||||||
|
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
--
|
||||||
|
2.10.0
|
||||||
|
|
||||||
114
0003-test-Implement-self-test-functionality.patch
Normal file
114
0003-test-Implement-self-test-functionality.patch
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
From c5e5b8415e9c91d132678dcfccde8df848ee70c8 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Phil Sutter <psutter@redhat.com>
|
||||||
|
Date: Fri, 25 Nov 2016 11:38:02 +0100
|
||||||
|
Subject: [PATCH] test: Implement self-test functionality
|
||||||
|
|
||||||
|
This allows to run 'test' unattended by setting environment variable
|
||||||
|
SELFTEST=on. Instead of printing the settings libkeepalive should have
|
||||||
|
changed, it uses the input values still present in environment to assert
|
||||||
|
them being set correctly.
|
||||||
|
|
||||||
|
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
||||||
|
---
|
||||||
|
test/test.c | 42 ++++++++++++++++++++++++++++++++++++++----
|
||||||
|
1 file changed, 38 insertions(+), 4 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/test/test.c b/test/test.c
|
||||||
|
index 224c1b4944fc5..7eaaaed2e9840 100644
|
||||||
|
--- a/test/test.c
|
||||||
|
+++ b/test/test.c
|
||||||
|
@@ -32,14 +32,23 @@
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
+#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
+#include <strings.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <netinet/tcp.h>
|
||||||
|
|
||||||
|
+#define assert(x) do { \
|
||||||
|
+ if (!(x)) { \
|
||||||
|
+ printf("%s:%d: assertion '" #x "' failed!\n", __FILE__, __LINE__); \
|
||||||
|
+ exit(EXIT_FAILURE); \
|
||||||
|
+ } \
|
||||||
|
+} while (0)
|
||||||
|
+
|
||||||
|
int main(void);
|
||||||
|
|
||||||
|
int main()
|
||||||
|
@@ -47,6 +56,11 @@ int main()
|
||||||
|
int s;
|
||||||
|
int optval;
|
||||||
|
socklen_t optlen = sizeof(optval);
|
||||||
|
+ const char *env;
|
||||||
|
+ bool selftest = false;
|
||||||
|
+
|
||||||
|
+ env = getenv("SELFTEST");
|
||||||
|
+ selftest = env && !strcasecmp(env, "on");
|
||||||
|
|
||||||
|
if((s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
|
||||||
|
perror("socket()");
|
||||||
|
@@ -58,7 +72,12 @@ int main()
|
||||||
|
close(s);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
- printf("SO_KEEPALIVE is %s\n", (optval ? "ON" : "OFF"));
|
||||||
|
+ if (selftest) {
|
||||||
|
+ env = getenv("KEEPALIVE");
|
||||||
|
+ assert((env && !strcasecmp(env, "off")) ^ optval);
|
||||||
|
+ } else {
|
||||||
|
+ printf("SO_KEEPALIVE is %s\n", (optval ? "ON" : "OFF"));
|
||||||
|
+ }
|
||||||
|
|
||||||
|
if(optval) {
|
||||||
|
#ifdef TCP_KEEPCNT
|
||||||
|
@@ -67,7 +86,12 @@ int main()
|
||||||
|
close(s);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
- printf("TCP_KEEPCNT = %d\n", optval);
|
||||||
|
+ if (selftest) {
|
||||||
|
+ env = getenv("KEEPCNT");
|
||||||
|
+ assert(!env || atoi(env) == optval);
|
||||||
|
+ } else {
|
||||||
|
+ printf("TCP_KEEPCNT = %d\n", optval);
|
||||||
|
+ }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TCP_KEEPIDLE
|
||||||
|
@@ -76,7 +100,12 @@ int main()
|
||||||
|
close(s);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
- printf("TCP_KEEPIDLE = %d\n", optval);
|
||||||
|
+ if (selftest) {
|
||||||
|
+ env = getenv("KEEPIDLE");
|
||||||
|
+ assert(!env || atoi(env) == optval);
|
||||||
|
+ } else {
|
||||||
|
+ printf("TCP_KEEPIDLE = %d\n", optval);
|
||||||
|
+ }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TCP_KEEPINTVL
|
||||||
|
@@ -85,7 +114,12 @@ int main()
|
||||||
|
close(s);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
- printf("TCP_KEEPINTVL = %d\n", optval);
|
||||||
|
+ if (selftest) {
|
||||||
|
+ env = getenv("KEEPINTVL");
|
||||||
|
+ assert(!env || atoi(env) == optval);
|
||||||
|
+ } else {
|
||||||
|
+ printf("TCP_KEEPINTVL = %d\n", optval);
|
||||||
|
+ }
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
--
|
||||||
|
2.10.0
|
||||||
|
|
||||||
48
0004-Makefile-Make-self-test-accessible-by-make-test.patch
Normal file
48
0004-Makefile-Make-self-test-accessible-by-make-test.patch
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
From 22820938a43871b7cd634767809faec31d139f27 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Phil Sutter <psutter@redhat.com>
|
||||||
|
Date: Fri, 25 Nov 2016 11:45:05 +0100
|
||||||
|
Subject: [PATCH] Makefile: Make self-test accessible by 'make test'
|
||||||
|
|
||||||
|
This will call 'test' three times: The first call makes sure that
|
||||||
|
KEEPALIVE=off is respected, the last two calls check that environment
|
||||||
|
variables KEEPCNT, KEEPIDLE and KEEPINTVL are applied as expected.
|
||||||
|
|
||||||
|
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
||||||
|
---
|
||||||
|
Makefile | 3 +++
|
||||||
|
test/Makefile | 6 ++++++
|
||||||
|
2 files changed, 9 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/Makefile b/Makefile
|
||||||
|
index 524d6a98c8329..01622771d73c5 100644
|
||||||
|
--- a/Makefile
|
||||||
|
+++ b/Makefile
|
||||||
|
@@ -13,6 +13,9 @@ default:
|
||||||
|
cp src/libkeepalive.so libkeepalive.so
|
||||||
|
strip -s libkeepalive.so
|
||||||
|
|
||||||
|
+test: default
|
||||||
|
+ make -C test/ runtest
|
||||||
|
+
|
||||||
|
clean:
|
||||||
|
make -C src/ clean
|
||||||
|
make -C test/ clean
|
||||||
|
diff --git a/test/Makefile b/test/Makefile
|
||||||
|
index 2a0f6e2780d5e..6baf822c2338d 100644
|
||||||
|
--- a/test/Makefile
|
||||||
|
+++ b/test/Makefile
|
||||||
|
@@ -11,5 +11,11 @@ CC=gcc
|
||||||
|
|
||||||
|
default: test
|
||||||
|
|
||||||
|
+TENV = LD_PRELOAD=../libkeepalive.so SELFTEST=on
|
||||||
|
+runtest:
|
||||||
|
+ ${TENV} KEEPALIVE=off ./test
|
||||||
|
+ ${TENV} KEEPCNT=13 KEEPIDLE=23 KEEPINTVL=42 ./test
|
||||||
|
+ ${TENV} KEEPCNT=42 KEEPIDLE=13 KEEPINTVL=23 ./test
|
||||||
|
+
|
||||||
|
clean:
|
||||||
|
rm -f test
|
||||||
|
--
|
||||||
|
2.10.0
|
||||||
|
|
||||||
49
0005-Makefile-Allow-setting-custom-compiler-flags.patch
Normal file
49
0005-Makefile-Allow-setting-custom-compiler-flags.patch
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
From 910e5ec42b7d04e4d7e650f8bd20afd06f418ae5 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Phil Sutter <psutter@redhat.com>
|
||||||
|
Date: Fri, 25 Nov 2016 12:22:13 +0100
|
||||||
|
Subject: [PATCH] Makefile: Allow setting custom compiler flags
|
||||||
|
|
||||||
|
This allows to override CC variable and to extend CFLAGS, LDFLAGS and
|
||||||
|
LDLIBS variables.
|
||||||
|
|
||||||
|
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
||||||
|
---
|
||||||
|
src/Makefile | 8 ++++----
|
||||||
|
test/Makefile | 2 +-
|
||||||
|
2 files changed, 5 insertions(+), 5 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/src/Makefile b/src/Makefile
|
||||||
|
index b8b0188502189..19e3785665a86 100644
|
||||||
|
--- a/src/Makefile
|
||||||
|
+++ b/src/Makefile
|
||||||
|
@@ -7,10 +7,10 @@
|
||||||
|
#
|
||||||
|
# (C) Fabio Busatto <fabio.busatto@gmail.com>
|
||||||
|
|
||||||
|
-CC=gcc
|
||||||
|
-CFLAGS=-fPIC -ansi -pedantic -Wall
|
||||||
|
-LDFLAGS=-shared -Wl,-soname,libkeepalive.so
|
||||||
|
-LDLIBS=-ldl
|
||||||
|
+CC := gcc
|
||||||
|
+CFLAGS += -fPIC -ansi -pedantic -Wall
|
||||||
|
+LDFLAGS += -shared -Wl,-soname,libkeepalive.so
|
||||||
|
+LDLIBS += -ldl
|
||||||
|
|
||||||
|
default: libkeepalive.so
|
||||||
|
|
||||||
|
diff --git a/test/Makefile b/test/Makefile
|
||||||
|
index 6baf822c2338d..6a279a0ac6b94 100644
|
||||||
|
--- a/test/Makefile
|
||||||
|
+++ b/test/Makefile
|
||||||
|
@@ -7,7 +7,7 @@
|
||||||
|
#
|
||||||
|
# (C) Fabio Busatto <fabio.busatto@gmail.com>
|
||||||
|
|
||||||
|
-CC=gcc
|
||||||
|
+CC := gcc
|
||||||
|
|
||||||
|
default: test
|
||||||
|
|
||||||
|
--
|
||||||
|
2.10.0
|
||||||
|
|
||||||
BIN
libkeepalive-0.3.tar.gz
Normal file
BIN
libkeepalive-0.3.tar.gz
Normal file
Binary file not shown.
40
libkeepalive.spec
Normal file
40
libkeepalive.spec
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
Name: libkeepalive
|
||||||
|
Version: 0.3
|
||||||
|
Release: 1
|
||||||
|
Summary: Enable TCP keepalive in dynamic binaries
|
||||||
|
URL: http://libkeepalive.sourceforge.net/
|
||||||
|
BuildRequires: gcc
|
||||||
|
License: MIT
|
||||||
|
Source0: https://cfhcable.dl.sourceforge.net/project/%{name}/%{name}/0.3/%{name}-0.3.tar.gz
|
||||||
|
|
||||||
|
# All patches sent to the upstream maintainer directly via email.
|
||||||
|
Patch1: 0002-test-test.c-Whitespace-cleanup.patch
|
||||||
|
Patch2: 0003-test-Implement-self-test-functionality.patch
|
||||||
|
Patch3: 0004-Makefile-Make-self-test-accessible-by-make-test.patch
|
||||||
|
Patch4: 0005-Makefile-Allow-setting-custom-compiler-flags.patch
|
||||||
|
%description
|
||||||
|
libkeepalive is a library that enables tcp keepalive features in glibc based
|
||||||
|
binary dynamic executables, without any change in the original program.
|
||||||
|
|
||||||
|
%prep
|
||||||
|
%autosetup -p1
|
||||||
|
|
||||||
|
%build
|
||||||
|
export CFLAGS="%{optflags}"
|
||||||
|
export LDFLAGS="%{__global_ldflags}"
|
||||||
|
%make_build
|
||||||
|
|
||||||
|
%check
|
||||||
|
make test
|
||||||
|
|
||||||
|
%install
|
||||||
|
install -p -m 0755 -D src/libkeepalive.so %{buildroot}%{_libdir}/libkeepalive.so
|
||||||
|
|
||||||
|
%files
|
||||||
|
%license LICENSE
|
||||||
|
%doc README
|
||||||
|
%{_libdir}/libkeepalive.so
|
||||||
|
|
||||||
|
%changelog
|
||||||
|
* Thu Aug 13 2020 tuShenmei <tushenmei@huawei.com> - 0.3-1
|
||||||
|
- package init
|
||||||
4
libkeepalive.yaml
Normal file
4
libkeepalive.yaml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
version_control: NA
|
||||||
|
src_repo: NA
|
||||||
|
tag_prefix: "libkeepalive-"
|
||||||
|
separator: "."
|
||||||
Loading…
x
Reference in New Issue
Block a user