summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStam He <stamhe@163.com>2013-02-27 11:53:11 +0800
committerantirez <antirez@gmail.com>2013-02-27 11:50:35 +0100
commit9c8be6cab9e4ec6c4fad2e1dd01fb13f7032205b (patch)
tree0db44e2a27efa7077546fae3ca010524c4ac4e95 /src
parentdeb1f4d841d402508d27a5bda0bf3a7c19cc0a6d (diff)
downloadredis-9c8be6cab9e4ec6c4fad2e1dd01fb13f7032205b.tar.gz
Set proctitle: avoid the use of __attribute__((constructor)).
This cased a segfault in some Linux system and was GCC-specific. Commit modified by @antirez: 1) Stripped away the part to set the proc title via config for now. 2) Handle initialization of setproctitle only when the replacement is used. 3) Don't require GCC now that the attribute constructor is no longer used.
Diffstat (limited to 'src')
-rw-r--r--src/config.h2
-rw-r--r--src/redis.c7
-rw-r--r--src/setproctitle.c10
3 files changed, 15 insertions, 4 deletions
diff --git a/src/config.h b/src/config.h
index 961503c63..9f2baaa1f 100644
--- a/src/config.h
+++ b/src/config.h
@@ -114,6 +114,8 @@
#if (defined __linux || defined __APPLE__)
#define USE_SETPROCTITLE
+#define INIT_SETPROCTITLE_REPLACEMENT
+void spt_init(int argc, char *argv[]);
void setproctitle(const char *fmt, ...);
#endif
diff --git a/src/redis.c b/src/redis.c
index 2cee1e815..107cd757b 100644
--- a/src/redis.c
+++ b/src/redis.c
@@ -2663,16 +2663,23 @@ void redisOutOfMemoryHandler(size_t allocation_size) {
}
void redisSetProcTitle(char *title) {
+#ifdef USE_SETPROCTITLE
setproctitle("%s %s:%d",
title,
server.bindaddr ? server.bindaddr : "*",
server.port);
+#else
+ REDIS_NOTUSED(title);
+#endif
}
int main(int argc, char **argv) {
struct timeval tv;
/* We need to initialize our libraries, and the server configuration. */
+#ifdef INIT_SETPROCTITLE_REPLACEMENT
+ spt_init(argc, argv);
+#endif
zmalloc_enable_thread_safeness();
zmalloc_set_oom_handler(redisOutOfMemoryHandler);
srand(time(NULL)^getpid());
diff --git a/src/setproctitle.c b/src/setproctitle.c
index 99bccf2c0..f44253e16 100644
--- a/src/setproctitle.c
+++ b/src/setproctitle.c
@@ -2,6 +2,8 @@
* setproctitle.c - Linux/Darwin setproctitle.
* --------------------------------------------------------------------------
* Copyright (C) 2010 William Ahern
+ * Copyright (C) 2013 Salvatore Sanfilippo
+ * Copyright (C) 2013 Stam He
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
@@ -42,8 +44,9 @@
#if !HAVE_SETPROCTITLE
-#if (defined __linux || defined __APPLE__) && defined __GNUC__
+#if (defined __linux || defined __APPLE__)
+extern char **environ;
static struct {
/* original value */
@@ -142,9 +145,8 @@ static int spt_copyargs(int argc, char *argv[]) {
} /* spt_copyargs() */
-void spt_init(int argc, char *argv[], char *envp[]) __attribute__((constructor));
-
-void spt_init(int argc, char *argv[], char *envp[]) {
+void spt_init(int argc, char *argv[]) {
+ char **envp = environ;
char *base, *end, *nul, *tmp;
int i, error;