]> code.citadel.org Git - citadel.git/blobdiff - citadel/sysdep.c
* Updated some of the docs. Bumped version number to 5.80 in anticipation
[citadel.git] / citadel / sysdep.c
index 74a71d63b9c3507987d0fe90c8097076e565cfd6..51439c3ce862c98339334b1ac4f32ebc119d0829 100644 (file)
@@ -85,17 +85,33 @@ static pthread_t initial_thread;            /* tid for main() thread */
 
 /*
  * lprintf()  ...   Write logging information
+ * 
+ * Note: the variable "buf" below needs to be large enough to handle any
+ * log data sent through this function.  BE CAREFUL!
  */
 void lprintf(int loglevel, const char *format, ...) {   
         va_list arg_ptr;
-       char buf[512];
+       char buf[4096];
   
         va_start(arg_ptr, format);   
         vsprintf(buf, format, arg_ptr);   
         va_end(arg_ptr);   
 
        if (loglevel <= verbosity) { 
-               fprintf(stderr, "%s", buf);
+               struct timeval tv;
+               struct tm *tim;
+
+               gettimeofday(&tv, NULL);
+               tim = localtime(&(tv.tv_sec));
+               /*
+                * Log provides millisecond accuracy.  If you need
+                * microsecond accuracy and your OS supports it, change
+                * %03ld to %06ld and remove " / 1000" after tv.tv_usec.
+                */
+               fprintf(stderr, "%04d/%02d/%02d %2d:%02d:%02d.%03ld %s",
+                       tim->tm_year + 1900, tim->tm_mon + 1, tim->tm_mday,
+                       tim->tm_hour, tim->tm_min, tim->tm_sec,
+                       tv.tv_usec / 1000, buf);
                fflush(stderr);
        }
 
@@ -248,6 +264,9 @@ void init_sysdep(void) {
 void begin_critical_section(int which_one)
 {
        /* lprintf(9, "begin_critical_section(%d)\n", which_one); */
+       /* ensure nobody ever tries to do a critical section within a
+          transaction; this could lead to deadlock. */
+       cdb_check_handles();
        pthread_mutex_lock(&Critters[which_one]);
 }
 
@@ -281,8 +300,7 @@ int ig_tcp_server(int port_number, int queue_len)
        sin.sin_addr.s_addr = INADDR_ANY;
        sin.sin_port = htons((u_short)port_number);
 
-       s = socket(PF_INET, SOCK_STREAM,
-               (getprotobyname("tcp")->p_proto));
+       s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
 
        if (s < 0) {
                lprintf(1, "citserver: Can't create a socket: %s\n",
@@ -430,6 +448,7 @@ void client_write(char *buf, int nbytes)
        int retval;
        int sock;
 
+
        if (CC->redirect_fp != NULL) {
                fwrite(buf, nbytes, 1, CC->redirect_fp);
                return;
@@ -961,7 +980,7 @@ int main(int argc, char **argv)
        /* Tell 'em who's in da house */
        lprintf(1,
 "\nMultithreaded message server for Citadel/UX\n"
-"Copyright (C) 1987-2000 by the Citadel/UX development team.\n"
+"Copyright (C) 1987-2001 by the Citadel/UX development team.\n"
 "Citadel/UX is free software, covered by the GNU General Public License, and\n"
 "you are welcome to change it and/or distribute copies of it under certain\n"
 "conditions.  There is absolutely no warranty for this software.  Please\n"
@@ -1127,7 +1146,7 @@ void *worker_thread(void *arg) {
                /* make doubly sure we're not holding any stale db handles
                 * which might cause a deadlock.
                 */
-               cdb_release_handles();
+               cdb_check_handles();
 
                begin_critical_section(S_I_WANNA_SELECT);
 SETUP_FD:      memcpy(&readfds, &masterfds, sizeof masterfds);
@@ -1267,7 +1286,7 @@ SETUP_FD: memcpy(&readfds, &masterfds, sizeof masterfds);
                dead_session_purge();
                if ((time(NULL) - last_timer) > 60L) {
                        last_timer = time(NULL);
-                       cdb_release_handles(); /* suggested by Justin Case */
+                       cdb_check_handles(); /* suggested by Justin Case */
                        PerformSessionHooks(EVT_TIMER);
                }