[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[UNIKRAFT/LIBMEMCACHED PATCH 6/7] Add patches folder



From: gaulthier gain <gaulthier.gain@xxxxxxxxx>

The first patch fixes an internal declaration with `trace.h` to avoid
conflicts with unikraft. The second removes the daemonize mode. The
third one renames the `stats_init` function to avoid conflicts.
Finally, the last patch removes the root user mode.

Signed-off-by: gaulthier gain <gaulthier.gain@xxxxxxxxx>
---
 patches/0001-fix-trace-conflict.patch         | 43 +++++++++
 ...d-to-avoid-conflicts-with-stats_init.patch | 44 +++++++++
 patches/0003-remove-daemonize-mode.patch      | 92 +++++++++++++++++++
 patches/0004-remove-root-user-check.patch     | 47 ++++++++++
 4 files changed, 226 insertions(+)
 create mode 100644 patches/0001-fix-trace-conflict.patch
 create mode 100644 
patches/0002-update-memcached-to-avoid-conflicts-with-stats_init.patch
 create mode 100644 patches/0003-remove-daemonize-mode.patch
 create mode 100644 patches/0004-remove-root-user-check.patch

diff --git a/patches/0001-fix-trace-conflict.patch 
b/patches/0001-fix-trace-conflict.patch
new file mode 100644
index 0000000..1a25194
--- /dev/null
+++ b/patches/0001-fix-trace-conflict.patch
@@ -0,0 +1,43 @@
+From e22039da0cfc9ebd10b3483c1a5aa6224c390f88 Mon Sep 17 00:00:00 2001
+From: Gaulthier Gain <gaulthier.gain@xxxxxxxxx>
+Date: Tue, 20 Aug 2019 11:07:41 +0200
+Subject: [PATCH] Rename trace.h to avoid conflicts with unikraft
+
+Signed-off-by: Gaulthier Gain <gaulthier.gain@xxxxxxxxx>
+---
+ memcached.h                 | 2 +-
+ trace.h => memcachedtrace.h | 4 ++--
+ 2 files changed, 3 insertions(+), 3 deletions(-)
+ rename trace.h => memcachedtrace.h (98%)
+
+diff --git a/memcached.h b/memcached.h
+index a8dd59d..9258ed4 100644
+--- a/memcached.h
++++ b/memcached.h
+@@ -728,7 +728,7 @@ extern int daemonize(int nochdir, int noclose);
+ #include "assoc.h"
+ #include "items.h"
+ #include "crawler.h"
+-#include "trace.h"
++#include "memcachedtrace.h"
+ #include "hash.h"
+ #include "util.h"
+ 
+diff --git a/trace.h b/memcachedtrace.h
+similarity index 98%
+rename from trace.h
+rename to memcachedtrace.h
+index 94e585d..a2c422d 100644
+--- a/trace.h
++++ b/memcachedtrace.h
+@@ -1,5 +1,5 @@
+-#ifndef TRACE_H
+-#define TRACE_H
++#ifndef MEMCACHEDTRACE_H
++#define MEMCACHEDTRACE_H
+ 
+ #ifdef ENABLE_DTRACE
+ #include "memcached_dtrace.h"
+-- 
+2.11.0
+
diff --git 
a/patches/0002-update-memcached-to-avoid-conflicts-with-stats_init.patch 
b/patches/0002-update-memcached-to-avoid-conflicts-with-stats_init.patch
new file mode 100644
index 0000000..5af2976
--- /dev/null
+++ b/patches/0002-update-memcached-to-avoid-conflicts-with-stats_init.patch
@@ -0,0 +1,44 @@
+From 1e59864136b472d4f31757b420f374c1bb8acf83 Mon Sep 17 00:00:00 2001
+From: gaulthier gain <gaulthier.gain@xxxxxxxxx>
+Date: Mon, 10 Aug 2020 12:59:19 +0000
+Subject: [PATCH] Update memcached.c to avoid conflicts with stats_init
+
+Signed-off-by: gaulthier gain <gaulthier.gain@xxxxxxxxx>
+---
+ memcached.c | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/memcached.c b/memcached.c
+index 884469c..224016a 100644
+--- a/memcached.c
++++ b/memcached.c
+@@ -105,7 +105,7 @@ static void conn_set_state(conn *c, enum conn_states 
state);
+ static int start_conn_timeout_thread();
+ 
+ /* stats */
+-static void stats_init(void);
++static void stats_init_memcached(void);
+ static void server_stats(ADD_STAT add_stats, conn *c);
+ static void process_stat_settings(ADD_STAT add_stats, void *c);
+ static void conn_to_str(const conn *c, char *addr, char *svr_addr);
+@@ -232,7 +232,7 @@ static rel_time_t realtime(const time_t exptime) {
+     }
+ }
+ 
+-static void stats_init(void) {
++static void stats_init_memcached(void) {
+     memset(&stats, 0, sizeof(struct stats));
+     memset(&stats_state, 0, sizeof(struct stats_state));
+     stats_state.accepting_conns = true; /* assuming we start in this state. */
+@@ -8554,7 +8554,7 @@ int main (int argc, char **argv) {
+ 
+     /* initialize other stuff */
+     logger_init();
+-    stats_init();
++    stats_init_memcached();
+     conn_init();
+     bool reuse_mem = false;
+     void *mem_base = NULL;
+-- 
+2.17.1
+
diff --git a/patches/0003-remove-daemonize-mode.patch 
b/patches/0003-remove-daemonize-mode.patch
new file mode 100644
index 0000000..1cdceb2
--- /dev/null
+++ b/patches/0003-remove-daemonize-mode.patch
@@ -0,0 +1,92 @@
+From 102035fe58ebfc77f1c3ff8415304f11059734fc Mon Sep 17 00:00:00 2001
+From: gaulthier gain <gaulthier.gain@xxxxxxxxx>
+Date: Mon, 10 Aug 2020 13:05:05 +0000
+Subject: [PATCH] Remove daemonize mode
+
+This patch temporary removes the daemonize mode of memcached which is
+based on `fork()`. Since this primitive is not yet supported in
+Unikraft, we disable it.
+
+Signed-off-by: gaulthier gain <gaulthier.gain@xxxxxxxxx>
+---
+ memcached.c | 22 ----------------------
+ 1 file changed, 22 deletions(-)
+
+diff --git a/memcached.c b/memcached.c
+index 224016a..5368542 100644
+--- a/memcached.c
++++ b/memcached.c
+@@ -6595,7 +6595,6 @@ static void usage(void) {
+            "                          if TLS/SSL is enabled, 'notls' prefix 
can be used to\n"
+            "                          disable for specific listeners (-l 
notls:<ip>:<port>) \n"
+ #endif
+-           "-d, --daemon              run as a daemon\n"
+            "-r, --enable-coredumps    maximize core file limit\n"
+            "-u, --user=<user>         assume identity of <username> (only 
when run as root)\n"
+            "-m, --memory-limit=<num>  item memory in megabytes (default: 64 
MB)\n"
+@@ -7281,7 +7280,6 @@ static int _mc_meta_load_cb(const char *tag, void *ctx, 
void *data) {
+ int main (int argc, char **argv) {
+     int c;
+     bool lock_memory = false;
+-    bool do_daemonize = false;
+     bool preallocate = false;
+     int maxcore = 0;
+     char *username = NULL;
+@@ -7501,7 +7499,6 @@ int main (int argc, char **argv) {
+           "hiV" /* help, licence info, version */
+           "r"   /* maximize core file limit */
+           "v"   /* verbose */
+-          "d"   /* daemon mode */
+           "l:"  /* interface to listen on */
+           "u:"  /* user identity to run as */
+           "P:"  /* save PID in file */
+@@ -7541,7 +7538,6 @@ int main (int argc, char **argv) {
+         {"version", no_argument, 0, 'V'},
+         {"enable-coredumps", no_argument, 0, 'r'},
+         {"verbose", optional_argument, 0, 'v'},
+-        {"daemon", no_argument, 0, 'd'},
+         {"listen", required_argument, 0, 'l'},
+         {"user", required_argument, 0, 'u'},
+         {"pidfile", required_argument, 0, 'P'},
+@@ -7643,9 +7639,6 @@ int main (int argc, char **argv) {
+                 settings.inter= strdup(optarg);
+             }
+             break;
+-        case 'd':
+-            do_daemonize = true;
+-            break;
+         case 'r':
+             maxcore = 1;
+             break;
+@@ -8488,18 +8481,6 @@ int main (int argc, char **argv) {
+         init_sasl();
+     }
+ 
+-    /* daemonize if requested */
+-    /* if we want to ensure our ability to dump core, don't chdir to / */
+-    if (do_daemonize) {
+-        if (sigignore(SIGHUP) == -1) {
+-            perror("Failed to ignore SIGHUP");
+-        }
+-        if (daemonize(maxcore, settings.verbose) == -1) {
+-            fprintf(stderr, "failed to daemon() in order to daemonize\n");
+-            exit(EXIT_FAILURE);
+-        }
+-    }
+-
+     /* lock paged memory if needed */
+     if (lock_memory) {
+ #ifdef HAVE_MLOCKALL
+@@ -8811,9 +8792,6 @@ int main (int argc, char **argv) {
+         restart_mmap_close();
+     }
+ 
+-    /* remove the PID file if we're a daemon */
+-    if (do_daemonize)
+-        remove_pidfile(pid_file);
+     /* Clean up strdup() call for bind() address */
+     if (settings.inter)
+       free(settings.inter);
+-- 
+2.17.1
+
diff --git a/patches/0004-remove-root-user-check.patch 
b/patches/0004-remove-root-user-check.patch
new file mode 100644
index 0000000..c5ff784
--- /dev/null
+++ b/patches/0004-remove-root-user-check.patch
@@ -0,0 +1,47 @@
+From ecacaab5b500780eb99d8f58e57b0688f6d3119e Mon Sep 17 00:00:00 2001
+From: gaulthier gain <gaulthier.gain@xxxxxxxxx>
+Date: Mon, 10 Aug 2020 13:39:28 +0000
+Subject: [PATCH] Remove root user check
+
+Since unikraft does not support multi-user support, this patch
+removes this feature.
+
+Signed-off-by: gaulthier gain <gaulthier.gain@xxxxxxxxx>
+---
+ memcached.c | 20 --------------------
+ 1 file changed, 20 deletions(-)
+
+diff --git a/memcached.c b/memcached.c
+index 884469c..63590c6 100644
+--- a/memcached.c
++++ b/memcached.c
+@@ -8463,26 +8463,6 @@ int main (int argc, char **argv) {
+         }
+     }
+ 
+-    /* lose root privileges if we have them */
+-    if (getuid() == 0 || geteuid() == 0) {
+-        if (username == 0 || *username == '\0') {
+-            fprintf(stderr, "can't run as root without the -u switch\n");
+-            exit(EX_USAGE);
+-        }
+-        if ((pw = getpwnam(username)) == 0) {
+-            fprintf(stderr, "can't find the user %s to switch to\n", 
username);
+-            exit(EX_NOUSER);
+-        }
+-        if (setgroups(0, NULL) < 0) {
+-            fprintf(stderr, "failed to drop supplementary groups\n");
+-            exit(EX_OSERR);
+-        }
+-        if (setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0) {
+-            fprintf(stderr, "failed to assume identity of user %s\n", 
username);
+-            exit(EX_OSERR);
+-        }
+-    }
+-
+     /* Initialize Sasl if -S was specified */
+     if (settings.sasl) {
+         init_sasl();
+-- 
+2.17.1
+
-- 
2.17.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.