From 0518ecc0b37422863f8929c89ac4ae481bf30b9d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pascal=20J=C3=A4ger?= <pascal.jaeger@leimstift.de>
Date: Sun, 11 Dec 2022 23:39:18 +0100
Subject: [PATCH 1/5] autotools: check for tinfo lib
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
---
 configure.ac | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configure.ac b/configure.ac
index f225c3b..bb6df16 100644
--- a/configure.ac
+++ b/configure.ac
@@ -24,6 +24,7 @@ AC_CHECK_LIB([curses], [initscr],
                   AC_DEFINE([HAVE_LIBCURSES], [1], [Define to 1 if you have the `curses' library (-lcurses).])
                   LIBS="-lcurses $LIBS"],
              [have_curses=no])
+AC_CHECK_LIB([tinfo], [keypad], LIBS="-ltinfo $LIBS")
 fi
 
 if test ! x$disable_libxml2 = xno; then # check only if not disabled

From e0bb55dac42a38d1af83c0239179d5872490abbd Mon Sep 17 00:00:00 2001
From: Tomasz Buchert <tomasz@debian.org>
Date: Thu, 9 Jul 2015 16:07:23 +0200
Subject: [PATCH 2/5] fix reproducibility of build process

The upstream Makefile sets macros that depend on
a particular platform where the package is built.
We don't set them which fixes the problem.
---
 src/Makefile.in | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/Makefile.in b/src/Makefile.in
index e1d93f4..4e4fbb3 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -48,9 +48,7 @@ Makefile: Makefile.in ../config.status
 
 
 version.o: version.c
-	$(CC) $(CFLAGS) -DCOMPILE_HOST="\""`hostname`"\"" \
-                        -DCOMPILE_DATE="\"`date`\"" \
-                        -c $(srcdir)/version.c
+	$(CC) $(CFLAGS) -c $(srcdir)/version.c
 
 
 lex.yy.c: calc.lex

From eff5506f939e8a9f6119557a72c0f7187dcf35f4 Mon Sep 17 00:00:00 2001
From: Tomasz Buchert <tomasz@debian.org>
Date: Fri, 7 Jul 2017 21:15:58 +0200
Subject: [PATCH 3/5] Fix parallel build problems (by Adrian Bunk)

---
 src/Makefile.in | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/Makefile.in b/src/Makefile.in
index 4e4fbb3..7ec4135 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -57,8 +57,9 @@ lex.yy.c: calc.lex
 lex.yy.o: lex.yy.c
 	$(CC) $(CFLAGS) -I$(srcdir) -c lex.yy.c
 
+y.tab.c: y.tab.h
 
-y.tab.c y.tab.h: calc.y
+y.tab.h: calc.y
 	$(YACC) -d $(srcdir)/calc.y
 
 y.tab.o: y.tab.c

From d4542885a2ec3c4a1b7f8858596a2574628450c2 Mon Sep 17 00:00:00 2001
From: Gunnar Wolf <gwolf@debian.org>
Date: Sat, 3 Feb 2018 08:51:55 +0100
Subject: [PATCH 4/5] Report that root access is required
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When perf_event_paranoid level is set to 3 (default), tiptop requires
root access to be run (#862461). Notify the user accordingly.
Origin: vendor https://bugs.debian.org/862461
Bug-Debian: https://bugs.debian.org/862461
Forwarded: no
Reviewed-By: Gunnar Wolf <gwolf@debian.orG>
Last-Update: 2017-10-31

Get paranoid level from /proc to report when root acces is required

Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
---
 src/requisite.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/requisite.c b/src/requisite.c
index 441c779..f4d1a89 100644
--- a/src/requisite.c
+++ b/src/requisite.c
@@ -17,13 +17,34 @@
 #include "pmc.h"
 #include "requisite.h"
 
+#define PARANOID1 "/proc/sys/kernel/perf_counter_paranoid"
+#define PARANOID2 "/proc/sys/kernel/perf_event_paranoid"
 
 void check()
 {
   int fd, cpu, grp, flags, pid;
+  FILE* paranoid;
+  int   paranoia_level = 999;
   struct utsname os;
   struct STRUCT_NAME events = {0, };
+  int    n;
 
+  paranoid = fopen(PARANOID1, "r");
+  if (!paranoid)
+    paranoid = fopen(PARANOID2, "r");
+
+  if (!paranoid) {
+    fprintf(stderr, "System does not support performance events.\n");
+    fprintf(stderr, "File '/proc/sys/kernel/perf_*_paranoid' is missing.\n");
+    exit(EXIT_FAILURE);
+  }
+  n = fscanf(paranoid, "%d", &paranoia_level);
+  if (n != 1) {
+    fprintf(stderr, "Could not read '/proc/sys/kernel/perf_*_paranoid'.\n");
+    fprintf(stderr, "Trying to proceed anyway...\n");
+  }
+
+  fclose(paranoid);
   events.disabled = 0;
   events.exclude_hv = 1;
   events.exclude_kernel = 1;
@@ -47,8 +68,11 @@ void check()
     else if (strcmp(os.release, "2.6.31") < 0) {  /* lexicographic order */
       fprintf(stderr, "Linux 2.6.31+ is required, OS reports '%s'.\n",
               os.release);
-    }
-    else {
+    } else if (paranoia_level == 3) {
+      fprintf(stderr, "Your kernel is set with an event paranoia value of 3\n");
+      fprintf(stderr, "Either run this program as root, or set a lower\n");
+      fprintf(stderr, "paranoia value at '%s'.\n", PARANOID2);
+    } else {
       fprintf(stderr, "Don't know why...\n");
     }
     exit(EXIT_FAILURE);

From 5714f268ee7c9883ac9937d85cfcbd731f5f3b7d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pascal=20J=C3=A4ger?= <pascal.jaeger@leimstift.de>
Date: Sun, 11 Dec 2022 23:49:55 +0100
Subject: [PATCH 5/5] Fix implicit function declarations
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When LEX=reflex is used, this compiling calc.lex fails with a
implicit function declaration error when
Werror=implicit-function-declaration. (Like with clang16)

Bug: https://bugs.gentoo.org/884361

Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
---
 src/calc.lex  | 1 +
 src/process.h | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/src/calc.lex b/src/calc.lex
index 60f20c0..772db56 100644
--- a/src/calc.lex
+++ b/src/calc.lex
@@ -11,6 +11,7 @@
 %{
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "formula-parser.h"
 #include "y.tab.h"
diff --git a/src/process.h b/src/process.h
index 11b06d8..0ab781f 100644
--- a/src/process.h
+++ b/src/process.h
@@ -95,4 +95,6 @@ void reset_values(const struct process_list* const);
 
 void update_name_cmdline(int pid, int name_only);
 
+void handle_error (int retval);
+
 #endif  /* _PROCESS_H */
