aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Seebach <peter.seebach@windriver.com>2014-04-21 16:13:54 -0500
committerPeter Seebach <peter.seebach@windriver.com>2014-04-21 16:16:23 -0500
commitf1d474452e24e185c4f657bba700ac6509cbd0cd (patch)
tree8c2097985d598775e3df4290ee0a1dab899d2b33
parente10d0b6a04e77793bb07541f10ba5b8d82f7221c (diff)
downloadpseudo-f1d474452e24e185c4f657bba700ac6509cbd0cd.tar.gz
pseudo-f1d474452e24e185c4f657bba700ac6509cbd0cd.tar.bz2
pseudo-f1d474452e24e185c4f657bba700ac6509cbd0cd.zip
pseudo command-line use: shut down server
When invoked as a non-daemon, either with a command or to get a shell, shut the server down automatically. This is currently implemented by sending a shutdown request; I also considered adding an environment flag for "shut down when there's no clients", but this was simpler. Main reason this is useful: In development, it's often the case that I want to run a single command under pseudo, then check the database directly with sqlite. Signed-off-by: Peter Seebach <peter.seebach@windriver.com>
-rw-r--r--pseudo.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/pseudo.c b/pseudo.c
index 4d5ada9..cc19b9c 100644
--- a/pseudo.c
+++ b/pseudo.c
@@ -31,6 +31,7 @@
#include <fcntl.h>
#include <sys/fcntl.h>
#include <sys/file.h>
+#include <sys/wait.h>
#include "pseudo.h"
#include "pseudo_ipc.h"
@@ -410,12 +411,22 @@ main(int argc, char *argv[]) {
}
pseudo_setupenv();
- rc = execv(fullpath, argv);
- if (rc == -1) {
- pseudo_diag("pseudo: can't run %s: %s\n",
- argv[0], strerror(errno));
+ rc = fork();
+ if (rc) {
+ waitpid(rc, &rc, 0);
+ /* try to hint that we don't think we still need
+ * the server.
+ */
+ pseudo_client_shutdown();
+ return WEXITSTATUS(rc);
+ } else {
+ rc = execv(fullpath, argv);
+ if (rc == -1) {
+ pseudo_diag("pseudo: can't run %s: %s\n",
+ argv[0], strerror(errno));
+ }
+ exit(EXIT_FAILURE);
}
- exit(EXIT_FAILURE);
}
/* if we got here, we are not running a command, and we are not in
* a pseudo environment.