about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-06-01 22:32:29 +0000
committerEric Wong <e@80x24.org>2016-06-05 08:47:48 +0000
commita03ccc608f68f44122f83dbde7bb09e9acbbc185 (patch)
tree407dd7d359cfe0299ed5e6cc451c68ea3d6d52db
parenta19f6bf70866e9fed34c7220f8a83d8486102821 (diff)
downloadcmogstored-a03ccc608f68f44122f83dbde7bb09e9acbbc185.tar.gz
If we fail to register a process, it is not fatal since
a process is already running.  However, we may not know
about when to restart it when it dies.
-rw-r--r--cmogstored.c4
-rw-r--r--process.c26
2 files changed, 21 insertions, 9 deletions
diff --git a/cmogstored.c b/cmogstored.c
index 5625775..2e57def 100644
--- a/cmogstored.c
+++ b/cmogstored.c
@@ -476,9 +476,11 @@ static void process_died(pid_t pid, int status)
         default:
                 /* could be an inherited iostat if we're using worker+master */
                 name = mog_process_name(id);
+                if (!name)
+                        syslog(LOG_ERR, "OOM: %m");
                 syslog(LOG_INFO,
                        "reaped %s pid=%d with status=%d, ignoring",
-                       name, (int)pid, status);
+                       name ? name : "unknown", (int)pid, status);
                 free(name);
         }
 }
diff --git a/process.c b/process.c
index 3122e08..8dfa10a 100644
--- a/process.c
+++ b/process.c
@@ -49,16 +49,17 @@ void mog_process_reset(void)
 
 char *mog_process_name(unsigned id)
 {
+        char *s;
         if (mog_process_is_worker(id))
-                return xasprintf("worker[%u]", id);
+                return asprintf(&s, "worker[%u]", id) >= 0 ? s : 0;
 
         switch (id) {
-        case MOG_PROC_UNKNOWN: return xstrdup("unknown");
-        case MOG_PROC_IOSTAT: return xstrdup("iostat");
-        case MOG_PROC_UPGRADE: return xstrdup("upgrade");
+        case MOG_PROC_UNKNOWN: return 0;
+        case MOG_PROC_IOSTAT: return strdup("iostat");
+        case MOG_PROC_UPGRADE: return strdup("upgrade");
         }
-        assert(0 && "Unknown ID");
-        return xasprintf("BUG[%u]", id);
+
+        return asprintf(&s, "BUG[%u]", id) >= 0 ? s : 0;
 }
 
 bool mog_process_is_worker(unsigned id)
@@ -114,15 +115,24 @@ size_t mog_kill_each_worker(int signo)
 /* Registers a process with a given id */
 void mog_process_register(pid_t pid, unsigned id)
 {
-        struct mog_process *p = xmalloc(sizeof(struct mog_process));
+        struct mog_process *p = malloc(sizeof(struct mog_process));
 
         assert(id != MOG_PROC_UNKNOWN &&
               "MOG_PROC_UNKNOWN may not be registered");
 
+        if (!p)
+                goto err;
+
         p->pid = pid;
         p->id = id;
 
-        mog_oom_if_null(hash_insert(processes, p));
+        if (hash_insert(processes, p))
+                return; /* success */
+
+        PRESERVE_ERRNO(free(p));
+err:
+        syslog(LOG_ERR, "unable to register PID:%d with id=%u: %m",
+                (int)pid, id);
 }
 
 /*