If invalid non-switch args are given (for example, pgpool -f
authorTatsuo Ishii <ishii at sraoss.co.jp>
Wed, 10 Aug 2005 12:11:12 +0000 (12:11 +0000)
committerTatsuo Ishii <ishii at sraoss.co.jp>
Wed, 10 Aug 2005 12:11:12 +0000 (12:11 +0000)
pgpool.conf foobar), pgpool silently deletes pgpool.pid even if it's a
valid one. Per report from Brad Nicholson.

main.c

diff --git a/main.c b/main.c
index 510fbf5d2908ef8b41cb79116a4913e7c63b27df..e2cecc691a0848e390ddf04e2b7a869a5fe580ee 100644 (file)
--- a/main.c
+++ b/main.c
@@ -170,7 +170,7 @@ int main(int argc, char **argv)
        if (pool_get_config(conf_file))
        {
                pool_error("Unable to get configuration. Exiting...");
-               mypid = getpid();
+               mypid = 0;              /* do not delete UNIX domain socket or pid file */
                myexit(1);
        }
 
@@ -183,6 +183,9 @@ int main(int argc, char **argv)
                                                   (pool_config.weight_master + pool_config.weight_secondary));
        pool_debug("weight: %ld", weight_master);
 
+       /*
+        * if a non-switch argument remains, then it should be either "stop" or "switch"
+        */
        if (optind == (argc - 1))
        {
                if (!strcmp(argv[optind], "stop"))
@@ -195,7 +198,15 @@ int main(int argc, char **argv)
                        switch_me();
                        exit(0);
                }
+               else
+               {
+                       usage();
+                       exit(1);
+               }
        }
+       /*
+        * else if no non-switch argument remains, then it should be a start request
+        */
        else if (optind == argc)
        {
                pid = read_pid_file();
@@ -210,13 +221,15 @@ int main(int argc, char **argv)
                                fprintf(stderr, "pid file found but it seems bogus. Trying to start pgpool anyway...\n");
                }
        }
-       else if (optind < argc)
+       /*
+        * otherwise an error...
+        */
+       else
        {
                usage();
                exit(1);
        }
 
-
        /* set signal masks */
        poolinitmask();