pagekite: add patchs for 64bit time
authorKarl Palsson <karlp@etactica.com>
Mon, 19 Sep 2022 14:15:27 +0000 (14:15 +0000)
committerKarl Palsson <karlp@etactica.com>
Mon, 26 Sep 2022 09:38:00 +0000 (09:38 +0000)
Source: https://github.com/pagekite/libpagekite/pull/78

Signed-off-by: Karl Palsson <karlp@etactica.com>
net/pagekitec/Makefile
net/pagekitec/patches/0001-Fix-to-work-ok-with-64-bit-time_t-time64.patch [new file with mode: 0644]
net/pagekitec/patches/0002-pagekitec-status-files-correctly-support-64bit-time.patch [new file with mode: 0644]

index a31a701b49573c08d2b53969cf1f9e36b572483a..3da1782ef96b1c4983bd80682e29d1f82c6175f7 100644 (file)
@@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
 PKG_NAME:=pagekitec
 PKG_REV:=0.91.201110
 PKG_VERSION:=$(PKG_REV)C
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 PKG_LICENSE:=Apache-2.0
 PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
diff --git a/net/pagekitec/patches/0001-Fix-to-work-ok-with-64-bit-time_t-time64.patch b/net/pagekitec/patches/0001-Fix-to-work-ok-with-64-bit-time_t-time64.patch
new file mode 100644 (file)
index 0000000..a19b93c
--- /dev/null
@@ -0,0 +1,98 @@
+From 37be74afa0e49749796591cd6f3c87536a8e8c3f Mon Sep 17 00:00:00 2001
+From: Lukas Zeller <luz@plan44.ch>
+Date: Sat, 4 Jun 2022 19:27:07 +0200
+Subject: [PATCH 1/2] Fix to work ok with 64 bit time_t (time64)
+
+In several places, time_t arguments were formatted using the "%d"
+format specifier, which is not compatible with 64bit time_t
+(as for example in musl >=1.2.0)
+
+This commit now uses "%lld" with an explicit cast of the
+arguments to long long. The cast ensures that the code is still
+safe to compile with 32 bit time_t (but introduces a slight
+performance penalty in that case).
+---
+ libpagekite/pklogging.c | 10 +++++-----
+ libpagekite/pkmanager.c |  8 ++++----
+ libpagekite/pkproto.c   |  4 ++--
+ 3 files changed, 11 insertions(+), 11 deletions(-)
+
+diff --git a/libpagekite/pklogging.c b/libpagekite/pklogging.c
+index 6129c30..1b1835c 100644
+--- a/libpagekite/pklogging.c
++++ b/libpagekite/pklogging.c
+@@ -208,9 +208,9 @@ void pk_dump_conn(char* prefix, struct pk_conn* conn)
+   if (conn->sockfd < 0) return;
+   pk_log(PK_LOG_MANAGER_DEBUG, "%s/sockfd: %d", prefix, conn->sockfd);
+-  pk_log(PK_LOG_MANAGER_DEBUG, "%s/activity: %x (%ds ago)", prefix,
+-                               conn->activity,
+-                               pk_time(0) - conn->activity);
++  pk_log(PK_LOG_MANAGER_DEBUG, "%s/activity: %llx (%llds ago)", prefix,
++                               (long long)conn->activity,
++                               (long long)(pk_time(0) - conn->activity));
+   pk_log(PK_LOG_MANAGER_DEBUG, "%s/read_bytes: %d", prefix, conn->read_bytes);
+   pk_log(PK_LOG_MANAGER_DEBUG, "%s/read_kb: %d", prefix, conn->read_kb);
+   pk_log(PK_LOG_MANAGER_DEBUG, "%s/sent_kb: %d", prefix, conn->sent_kb);
+@@ -281,8 +281,8 @@ void pk_dump_state(struct pk_manager* pkm)
+   pk_log(LL, "pk_manager/kite_max: %d", pkm->kite_max);
+   pk_log(LL, "pk_manager/tunnel_max: %d", pkm->tunnel_max);
+   pk_log(LL, "pk_manager/be_conn_max: %d", pkm->be_conn_max);
+-  pk_log(LL, "pk_manager/last_world_update: %x", pkm->last_world_update);
+-  pk_log(LL, "pk_manager/next_tick: %d", pkm->next_tick);
++  pk_log(LL, "pk_manager/last_world_update: %llx", (long long)pkm->last_world_update);
++  pk_log(LL, "pk_manager/next_tick: %lld", (long long)pkm->next_tick);
+   pk_log(LL, "pk_manager/enable_timer: %d", 0 < pkm->enable_timer);
+   pk_log(LL, "pk_manager/fancy_pagekite_net_rejection_url: %s", pkm->fancy_pagekite_net_rejection_url);
+   pk_log(LL, "pk_manager/want_spare_frontends: %d", pkm->want_spare_frontends);
+diff --git a/libpagekite/pkmanager.c b/libpagekite/pkmanager.c
+index 2e526c5..007f078 100644
+--- a/libpagekite/pkmanager.c
++++ b/libpagekite/pkmanager.c
+@@ -1070,8 +1070,8 @@ static void pkm_tick_cb(EV_P_ ev_async* w, int revents)
+     pkm->timer.repeat = pkm->next_tick;
+     ev_timer_again(pkm->loop, &(pkm->timer));
+     pk_log(PK_LOG_MANAGER_INFO,
+-           "Tick!  [repeating=%s, next=%d, status=%d, tunnels=%d, v=%s]",
+-           pkm->enable_timer ? "yes" : "no", pkm->next_tick,
++           "Tick!  [repeating=%s, next=%lld, status=%d, tunnels=%d, v=%s]",
++           pkm->enable_timer ? "yes" : "no", (long long)pkm->next_tick,
+            pkm->status, pk_state.live_tunnels, PK_VERSION);
+     /* We slow down exponentially by default... */
+@@ -1122,8 +1122,8 @@ static void pkm_tick_cb(EV_P_ ev_async* w, int revents)
+           fe->last_ping = now;
+           pkc_write(&(fe->conn), ping, pingsize);
+           pk_log(PK_LOG_TUNNEL_DATA,
+-              "%d: Sent PING (idle=%ds>%ds)",
+-              fe->conn.sockfd, now - fe->conn.activity, now - inactive);
++              "%d: Sent PING (idle=%llds>%llds)",
++              fe->conn.sockfd, (long long)(now - fe->conn.activity), (long long)(now - inactive));
+           next_tick = 1 + pkm->housekeeping_interval_min;
+         }
+       }
+diff --git a/libpagekite/pkproto.c b/libpagekite/pkproto.c
+index fda41d2..02a47c7 100644
+--- a/libpagekite/pkproto.c
++++ b/libpagekite/pkproto.c
+@@ -577,7 +577,7 @@ int pk_make_salt(char* salt) {
+ char* pk_sign(const char* token, const char* secret, time_t ts,
+               const char* payload, int length, char *buffer)
+ {
+-  char tbuffer[128], tsbuf[16], scratch[10240];
++  char tbuffer[128], tsbuf[32], scratch[10240];
+   PK_TRACE_FUNCTION;
+@@ -606,7 +606,7 @@ char* pk_sign(const char* token, const char* secret, time_t ts,
+   /* Optionally embed a timestamp to the resolution of 10 minutes */
+   if (ts > 0) {
+-    sprintf(tsbuf, "%lx", ts / 600);
++    sprintf(tsbuf, "%llx", (long long)(ts / 600));
+     buffer[0] = 't';
+   }
+   else tsbuf[0] = '\0';
+-- 
+2.37.3
+
diff --git a/net/pagekitec/patches/0002-pagekitec-status-files-correctly-support-64bit-time.patch b/net/pagekitec/patches/0002-pagekitec-status-files-correctly-support-64bit-time.patch
new file mode 100644 (file)
index 0000000..8abcb66
--- /dev/null
@@ -0,0 +1,50 @@
+From 3dc6bd45838bb170ee4d95f014f0588c5d084d31 Mon Sep 17 00:00:00 2001
+From: Karl Palsson <karlp@etactica.com>
+Date: Mon, 19 Sep 2022 17:03:58 +0000
+Subject: [PATCH 2/2] pagekitec: status files: correctly support 64bit time
+
+This explicitly casts to long long, as in #78, which may or may not
+be desired globally. It's certainly required in OpenWrt with musl 1.2+
+
+See also: https://github.com/pagekite/libpagekite/pull/78
+
+Fixes: e8cfa5f (incomplete)
+Signed-off-by: Karl Palsson <karlp@etactica.com>
+---
+ contrib/backends/pagekitec.c | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/contrib/backends/pagekitec.c b/contrib/backends/pagekitec.c
+index ce39e30..76a78ac 100644
+--- a/contrib/backends/pagekitec.c
++++ b/contrib/backends/pagekitec.c
+@@ -54,7 +54,7 @@ Note: For alternate license terms, see the file COPYING.md.
+         "  \"pagekitec_status_code\": %d,\n" \
+         "  \"pagekitec_pid\": %d,\n"         \
+         "  \"pagekitec_update_min_interval\": %d,\n" \
+-        "  \"pagekitec_update_ts\": %ld\n"   \
++        "  \"pagekitec_update_ts\": %lld\n"   \
+         "}\n")
+ /* Enable this format using -Y text:/path/to/file/ */
+@@ -64,7 +64,7 @@ Note: For alternate license terms, see the file COPYING.md.
+         "pagekitec_status_code: %d\n" \
+         "pagekitec_pid: %d\n"         \
+         "pagekitec_update_min_interval: %d\n" \
+-        "pagekitec_update_ts: %ld\n")
++        "pagekitec_update_ts: %lld\n")
+ pagekite_mgr m;
+@@ -153,7 +153,7 @@ int summarize_status(const char* fpath, const char* format, const char *status_m
+     }
+     fprintf(fd, format,
+-      PK_VERSION, status_msg, status, getpid(), STATUS_MIN_INTERVAL, now);
++      PK_VERSION, status_msg, status, getpid(), STATUS_MIN_INTERVAL, (long long)now);
+     if (0 == ftruncate(fileno(fd), ftell(fd))) fflush(fd);
+     fclose(fd);
+-- 
+2.37.3
+