r4548 - in developers/zecke: . app_restarter

zecke at docs.openmoko.org zecke at docs.openmoko.org
Tue Jul 22 16:29:36 CEST 2008


Author: zecke
Date: 2008-07-22 16:29:36 +0200 (Tue, 22 Jul 2008)
New Revision: 4548

Added:
   developers/zecke/app_restarter/
   developers/zecke/app_restarter/app_restarter.c
Log:
Restart a server process. Inspired by e_alert.c, it will show a XWindow asking the user...


Added: developers/zecke/app_restarter/app_restarter.c
===================================================================
--- developers/zecke/app_restarter/app_restarter.c	                        (rev 0)
+++ developers/zecke/app_restarter/app_restarter.c	2008-07-22 14:29:36 UTC (rev 4548)
@@ -0,0 +1,60 @@
+/*
+ * (C) Copyright 2008 Openmoko Inc.
+ * Author: Holger Hans Peter Freyther
+ *
+ * Licensed under GPLv2 or later, no warranty
+ *
+ * keep a giving process going
+ *
+ * stolen and inspired from e_alert.c
+ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+static void usage(char* name)
+{
+    fprintf(stderr, "%s crash_comment appname [params for app]\n", name);
+}
+
+void fork_and_exec(char* file, int argc, char** argv)
+{
+    pid_t pid = vfork();
+
+    if (pid == 0) {
+        execvp(file, argv);
+        fprintf(stderr, "Failed to launch: %s\n", file);
+        _exit(-1);
+    } else {
+        int status;
+
+        /* wait for the process to die */
+        while (waitpid(pid, &status, 0) != pid);
+
+        fprintf(stderr, "The process exited: %d normal: %d\n", status, WIFEXITED(status));
+    }
+}
+
+int main(int argc, char** argv)
+{
+    int i = 0;
+
+    if (argc < 3) {
+        usage(argv[0]);
+        return EXIT_FAILURE;
+    }
+
+    /* Create a list for execvp with a sentinel */
+    int commands = argc-3;
+    char** command_arguments = (char**) malloc(sizeof(char*)*(commands+1));
+    for (i = 0; i < commands; ++i)
+        command_arguments[i] = argv[2+i];
+    command_arguments[commands] = NULL;
+
+    for (;;)
+        fork_and_exec(argv[2], commands, command_arguments);
+}


Property changes on: developers/zecke/app_restarter/app_restarter.c
___________________________________________________________________
Name: svn:eol-style
   + native





More information about the commitlog mailing list