diff options
author | 2014-04-21 16:13:54 -0500 | |
---|---|---|
committer | 2014-04-21 16:16:23 -0500 | |
commit | f1d474452e24e185c4f657bba700ac6509cbd0cd (patch) | |
tree | 8c2097985d598775e3df4290ee0a1dab899d2b33 | |
parent | e10d0b6a04e77793bb07541f10ba5b8d82f7221c (diff) | |
download | pseudo-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.c | 21 |
1 files changed, 16 insertions, 5 deletions
@@ -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. |