Author: pjd
Date: Tue Sep 27 07:57:15 2011
New Revision: 225782
URL: http://svn.freebsd.org/changeset/base/225782

Log:
  Prefer PJDLOG_ASSERT() and PJDLOG_ABORT() over assert() and abort().
  pjdlog versions will log problem to syslog when application is running in
  background.
  
  MFC after:    3 days

Modified:
  head/sbin/hastd/control.c
  head/sbin/hastd/parse.y
  head/sbin/hastd/secondary.c

Modified: head/sbin/hastd/control.c
==============================================================================
--- head/sbin/hastd/control.c   Tue Sep 27 07:52:39 2011        (r225781)
+++ head/sbin/hastd/control.c   Tue Sep 27 07:57:15 2011        (r225782)
@@ -33,7 +33,6 @@ __FBSDID("$FreeBSD$");
 #include <sys/types.h>
 #include <sys/wait.h>
 
-#include <assert.h>
 #include <errno.h>
 #include <pthread.h>
 #include <signal.h>
@@ -82,8 +81,8 @@ control_set_role_common(struct hastd_con
                nv_add_string(nvout, name, "resource%u", no);
 
        if (res == NULL) {
-               assert(cfg != NULL);
-               assert(name != NULL);
+               PJDLOG_ASSERT(cfg != NULL);
+               PJDLOG_ASSERT(name != NULL);
 
                TAILQ_FOREACH(res, &cfg->hc_resources, hr_next) {
                        if (strcmp(res->hr_name, name) == 0)
@@ -94,7 +93,7 @@ control_set_role_common(struct hastd_con
                        return;
                }
        }
-       assert(res != NULL);
+       PJDLOG_ASSERT(res != NULL);
 
        /* Send previous role back. */
        nv_add_string(nvout, role2str(res->hr_role), "role%u", no);
@@ -222,9 +221,9 @@ control_status(struct hastd_config *cfg,
     struct hast_resource *res, const char *name, unsigned int no)
 {
 
-       assert(cfg != NULL);
-       assert(nvout != NULL);
-       assert(name != NULL);
+       PJDLOG_ASSERT(cfg != NULL);
+       PJDLOG_ASSERT(nvout != NULL);
+       PJDLOG_ASSERT(name != NULL);
 
        /* Name is always needed. */
        nv_add_string(nvout, name, "resource%u", no);
@@ -239,7 +238,7 @@ control_status(struct hastd_config *cfg,
                        return;
                }
        }
-       assert(res != NULL);
+       PJDLOG_ASSERT(res != NULL);
        nv_add_string(nvout, res->hr_provname, "provname%u", no);
        nv_add_string(nvout, res->hr_localpath, "localpath%u", no);
        nv_add_string(nvout, res->hr_remoteaddr, "remoteaddr%u", no);
@@ -267,7 +266,7 @@ control_status(struct hastd_config *cfg,
 
        switch (res->hr_role) {
        case HAST_ROLE_PRIMARY:
-               assert(res->hr_workerpid != 0);
+               PJDLOG_ASSERT(res->hr_workerpid != 0);
                /* FALLTHROUGH */
        case HAST_ROLE_SECONDARY:
                if (res->hr_workerpid != 0)
@@ -470,7 +469,7 @@ ctrl_thread(void *arg)
                         * something related to us has changes, it sends reload
                         * message to us.
                         */
-                       assert(res->hr_role == HAST_ROLE_PRIMARY);
+                       PJDLOG_ASSERT(res->hr_role == HAST_ROLE_PRIMARY);
                        primary_config_reload(res, nvin);
                        nv_add_int16(nvout, 0, "error");
                        break;

Modified: head/sbin/hastd/parse.y
==============================================================================
--- head/sbin/hastd/parse.y     Tue Sep 27 07:52:39 2011        (r225781)
+++ head/sbin/hastd/parse.y     Tue Sep 27 07:57:15 2011        (r225782)
@@ -38,7 +38,6 @@
 
 #include <arpa/inet.h>
 
-#include <assert.h>
 #include <err.h>
 #include <errno.h>
 #include <stdio.h>
@@ -282,9 +281,9 @@ yy_config_parse(const char *config, bool
                }
        }
        TAILQ_FOREACH(curres, &lconfig->hc_resources, hr_next) {
-               assert(curres->hr_provname[0] != '\0');
-               assert(curres->hr_localpath[0] != '\0');
-               assert(curres->hr_remoteaddr[0] != '\0');
+               PJDLOG_ASSERT(curres->hr_provname[0] != '\0');
+               PJDLOG_ASSERT(curres->hr_localpath[0] != '\0');
+               PJDLOG_ASSERT(curres->hr_remoteaddr[0] != '\0');
 
                if (curres->hr_replication == -1) {
                        /*
@@ -426,7 +425,7 @@ control_statement:  CONTROL STR
                        }
                        break;
                default:
-                       assert(!"control at wrong depth level");
+                       PJDLOG_ABORT("control at wrong depth level");
                }
                free($2);
        }
@@ -460,7 +459,7 @@ listen_statement:   LISTEN STR
                                free(lst);
                        break;
                default:
-                       assert(!"listen at wrong depth level");
+                       PJDLOG_ABORT("listen at wrong depth level");
                }
                free($2);
        }
@@ -477,7 +476,7 @@ replication_statement:      REPLICATION repli
                                curres->hr_replication = $2;
                        break;
                default:
-                       assert(!"replication at wrong depth level");
+                       PJDLOG_ABORT("replication at wrong depth level");
                }
        }
        ;
@@ -501,7 +500,7 @@ checksum_statement: CHECKSUM checksum_ty
                                curres->hr_checksum = $2;
                        break;
                default:
-                       assert(!"checksum at wrong depth level");
+                       PJDLOG_ABORT("checksum at wrong depth level");
                }
        }
        ;
@@ -525,7 +524,7 @@ compression_statement:      COMPRESSION compr
                                curres->hr_compression = $2;
                        break;
                default:
-                       assert(!"compression at wrong depth level");
+                       PJDLOG_ABORT("compression at wrong depth level");
                }
        }
        ;
@@ -553,7 +552,7 @@ timeout_statement:  TIMEOUT NUM
                                curres->hr_timeout = $2;
                        break;
                default:
-                       assert(!"timeout at wrong depth level");
+                       PJDLOG_ABORT("timeout at wrong depth level");
                }
        }
        ;
@@ -581,7 +580,7 @@ exec_statement:             EXEC STR
                        }
                        break;
                default:
-                       assert(!"exec at wrong depth level");
+                       PJDLOG_ABORT("exec at wrong depth level");
                }
                free($2);
        }
@@ -605,7 +604,7 @@ node_start: STR
                        mynode = true;
                        break;
                default:
-                       assert(!"invalid isitme() return value");
+                       PJDLOG_ABORT("invalid isitme() return value");
                }
                free($1);
        }
@@ -785,7 +784,7 @@ name_statement:             NAME STR
                case 2:
                        if (!mynode)
                                break;
-                       assert(curres != NULL);
+                       PJDLOG_ASSERT(curres != NULL);
                        if (strlcpy(curres->hr_provname, $2,
                            sizeof(curres->hr_provname)) >=
                            sizeof(curres->hr_provname)) {
@@ -795,7 +794,7 @@ name_statement:             NAME STR
                        }
                        break;
                default:
-                       assert(!"name at wrong depth level");
+                       PJDLOG_ABORT("name at wrong depth level");
                }
                free($2);
        }
@@ -816,7 +815,7 @@ local_statement:    LOCAL STR
                case 2:
                        if (!mynode)
                                break;
-                       assert(curres != NULL);
+                       PJDLOG_ASSERT(curres != NULL);
                        if (strlcpy(curres->hr_localpath, $2,
                            sizeof(curres->hr_localpath)) >=
                            sizeof(curres->hr_localpath)) {
@@ -826,7 +825,7 @@ local_statement:    LOCAL STR
                        }
                        break;
                default:
-                       assert(!"local at wrong depth level");
+                       PJDLOG_ABORT("local at wrong depth level");
                }
                free($2);
        }
@@ -851,7 +850,7 @@ resource_node_start:        STR
                                mynode = hadmynode = true;
                                break;
                        default:
-                               assert(!"invalid isitme() return value");
+                               PJDLOG_ABORT("invalid isitme() return value");
                        }
                }
                free($1);
@@ -875,9 +874,9 @@ resource_node_entry:
 
 remote_statement:      REMOTE remote_str
        {
-               assert(depth == 2);
+               PJDLOG_ASSERT(depth == 2);
                if (mynode) {
-                       assert(curres != NULL);
+                       PJDLOG_ASSERT(curres != NULL);
                        if (strlcpy(curres->hr_remoteaddr, $2,
                            sizeof(curres->hr_remoteaddr)) >=
                            sizeof(curres->hr_remoteaddr)) {
@@ -898,9 +897,9 @@ remote_str:
 
 source_statement:      SOURCE STR
        {
-               assert(depth == 2);
+               PJDLOG_ASSERT(depth == 2);
                if (mynode) {
-                       assert(curres != NULL);
+                       PJDLOG_ASSERT(curres != NULL);
                        if (strlcpy(curres->hr_sourceaddr, $2,
                            sizeof(curres->hr_sourceaddr)) >=
                            sizeof(curres->hr_sourceaddr)) {

Modified: head/sbin/hastd/secondary.c
==============================================================================
--- head/sbin/hastd/secondary.c Tue Sep 27 07:52:39 2011        (r225781)
+++ head/sbin/hastd/secondary.c Tue Sep 27 07:57:15 2011        (r225782)
@@ -791,8 +791,8 @@ send_thread(void *arg)
                        length = 0;
                        break;
                default:
-                       abort();
-                       break;
+                       PJDLOG_ABORT("Unexpected command (cmd=%hhu).",
+                           hio->hio_cmd);
                }
                if (hio->hio_error != 0)
                        nv_add_int16(nvout, hio->hio_error, "error");
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to