Skip site navigation (1) Skip section navigation (2)

SVN Commit by dpage: r4199 - trunk/pgadmin3/xtra/pgagent

From: svn(at)pgadmin(dot)org
To: pgadmin-hackers(at)postgresql(dot)org
Subject: SVN Commit by dpage: r4199 - trunk/pgadmin3/xtra/pgagent
Date: 2005-05-17 20:55:04
Message-ID: 200505172055.j4HKt41V021252@developer.pgadmin.org (view raw or flat)
Thread:
Lists: pgadmin-hackers
Author: dpage
Date: 2005-05-17 21:55:04 +0100 (Tue, 17 May 2005)
New Revision: 4199

Modified:
   trunk/pgadmin3/xtra/pgagent/connection.cpp
   trunk/pgadmin3/xtra/pgagent/pgAgent.cpp
   trunk/pgadmin3/xtra/pgagent/win32.cpp
Log:
Additional debug code. Add support for the Windows event log.

Modified: trunk/pgadmin3/xtra/pgagent/connection.cpp
===================================================================
--- trunk/pgadmin3/xtra/pgagent/connection.cpp	2005-05-17 18:57:43 UTC (rev 4198)
+++ trunk/pgadmin3/xtra/pgagent/connection.cpp	2005-05-17 20:55:04 UTC (rev 4199)
@@ -38,6 +38,7 @@
 
 bool DBconn::Connect(const string &connectString)
 {
+	LogMessage("Creating DB connection: " + connectString, LOG_DEBUG);
     conn=PQconnectdb(connectString.c_str());
     if (PQstatus(conn) == CONNECTION_OK)
     {

Modified: trunk/pgadmin3/xtra/pgagent/pgAgent.cpp
===================================================================
--- trunk/pgadmin3/xtra/pgagent/pgAgent.cpp	2005-05-17 18:57:43 UTC (rev 4198)
+++ trunk/pgadmin3/xtra/pgagent/pgAgent.cpp	2005-05-17 20:55:04 UTC (rev 4199)
@@ -31,6 +31,7 @@
 
     int rc;
 
+	LogMessage("Clearing zombies", LOG_DEBUG);
     rc=serviceConn->ExecuteVoid(
         "CREATE TEMP TABLE pga_tmp_zombies(jagpid int4)");
 
@@ -78,6 +79,7 @@
     {
         bool foundJobToExecute=false;
 
+		LogMessage("Checking for jobs to run", LOG_DEBUG);
         DBresult *res=serviceConn->Execute(
             "SELECT J.jobid "
             "  FROM pgagent.pga_job J "
@@ -99,18 +101,19 @@
                 if (job.Runnable())
                 {
                     foundJobToExecute=true;
-                    LogMessage("Executing job", LOG_DEBUG);
+                    LogMessage("Running job: " + jobid, LOG_DEBUG);
                     job.Execute();
                 }
             }
             else
             {
+				LogMessage("No jobs to run - time for a pint :-)", LOG_DEBUG);
                 WaitAWhile();
             }
         }
         else
         {
-            // bad err
+            LogMessage("Failed to query jobs table!", LOG_ERROR);
         }
         if (!foundJobToExecute)
             DBconn::ClearConnections();
@@ -122,6 +125,7 @@
 void MainLoop()
 {
     // Basic sanity check
+	LogMessage("Database sanity check", LOG_DEBUG);
     DBconn *sanityConn=DBconn::Get(serviceDBname, true);
     DBresult *res=sanityConn->Execute("SELECT count(*) As count FROM pg_class cl JOIN pg_namespace ns ON ns.oid=relnamespace WHERE relname='pga_job' AND nspname='pgagent'");
     if (res)

Modified: trunk/pgadmin3/xtra/pgagent/win32.cpp
===================================================================
--- trunk/pgadmin3/xtra/pgagent/win32.cpp	2005-05-17 18:57:43 UTC (rev 4198)
+++ trunk/pgadmin3/xtra/pgagent/win32.cpp	2005-05-17 20:55:04 UTC (rev 4199)
@@ -15,9 +15,9 @@
 #error this file is for win32 only!
 #endif
 
+#include <stdio.h>
 #include <windows.h>
 #include <process.h>
-#include <stdio.h>
 
 // for debugging purposes, we can start the service paused
 
@@ -54,19 +54,22 @@
 {
     if (eventHandle)
     {
-        // FIXME - This path should use the event log!
+		char *tmp;
+		tmp = (char *)malloc(msg.length()+1);
+		sprintf(tmp, msg.c_str());
+
         switch (level)
         {
             case LOG_DEBUG:
                 if (minLogLevel >= LOG_DEBUG)
-                    fprintf(stderr, "DEBUG: %s\n", msg.c_str());
+					ReportEvent(eventHandle, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (const char **)&tmp, NULL);
                 break;
             case LOG_WARNING:
                 if (minLogLevel >= LOG_WARNING)
-                    fprintf(stderr, "WARNING: %s\n", msg.c_str());
+                    ReportEvent(eventHandle, EVENTLOG_WARNING_TYPE, 0, 0, NULL, 1, 0, (const char **)&tmp, NULL);
                 break;
             case LOG_ERROR:
-                fprintf(stderr, "ERROR: %s\n", msg.c_str());
+                ReportEvent(eventHandle, EVENTLOG_ERROR_TYPE, 0, 0, NULL, 1, 0, (const char **)&tmp, NULL);
                 exit(1);
                 break;
         }
@@ -77,14 +80,14 @@
         {
             case LOG_DEBUG:
                 if (minLogLevel >= LOG_DEBUG)
-                    fprintf(stderr, "DEBUG: %s\n", msg.c_str());
+                    printf("DEBUG: %s\n", msg.c_str());
                 break;
             case LOG_WARNING:
                 if (minLogLevel >= LOG_WARNING)
-                    fprintf(stderr, "WARNING: %s\n", msg.c_str());
+                    printf("WARNING: %s\n", msg.c_str());
                 break;
             case LOG_ERROR:
-                fprintf(stderr, "ERROR: %s\n", msg.c_str());
+                printf("ERROR: %s\n", msg.c_str());
                 exit(1);
                 break;
         }
@@ -224,7 +227,11 @@
 // installation and removal
 bool installService(const char *serviceName, const char *exePath, const char *displayname, const char *user, const char *password)
 {
+	HKEY hk; 
+    DWORD dwData; 
+    char tmp[255], buf[255]; 
     bool done=false;
+
     SC_HANDLE manager = OpenSCManager(0, 0, SC_MANAGER_ALL_ACCESS);
     if (manager)
     {
@@ -239,13 +246,36 @@
         }
         CloseServiceHandle(manager);
     }
+
+	// Setup the event message DLL 
+	_snprintf(buf, 254, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s", serviceName);
+    if (RegCreateKey(HKEY_LOCAL_MACHINE, buf, &hk)) 
+        LogMessage("Could not open the message source registry key.", LOG_WARNING); 
+ 
+    GetModuleFileName(NULL, tmp, 254);
+	(strrchr(tmp, '\\'))[0] = 0;
+	_snprintf(buf, 254, "%s\\pgaevent.dll", tmp);
+
+ 
+    if (RegSetValueEx(hk, "EventMessageFile", 0, REG_EXPAND_SZ, (LPBYTE)buf, strlen(buf) + 1)) 
+        LogMessage("Could not set the event message file registry value.", LOG_WARNING); 
+ 
+    dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE; 
+ 
+    if (RegSetValueEx(hk, "TypesSupported", 0, REG_DWORD, (LPBYTE) &dwData, sizeof(DWORD)))
+        LogMessage("Could not set the supported types.", LOG_WARNING); 
+ 
+    RegCloseKey(hk); 
+
     return done;
 }
 
 
 bool removeService(const char *serviceName)
 {
+	HKEY hk;
     bool done=false;
+
     SC_HANDLE manager = OpenSCManager(0, 0, SC_MANAGER_ALL_ACCESS);
     if (manager)
     {
@@ -273,6 +303,14 @@
         }
         CloseServiceHandle(manager);
     }
+
+	// Remove the event message DLL
+    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\", 0, KEY_ALL_ACCESS, &hk))
+        LogMessage("Could not open the message source registry key.", LOG_WARNING); 
+
+	if (RegDeleteKey(hk, serviceName))
+		LogMessage("Could not remove the event message file registry value.", LOG_WARNING); 
+
     return done;
 }
 


pgadmin-hackers by date

Next:From: Patrick HatcherDate: 2005-05-17 22:21:19
Subject: Re: App closes while trying to edit attributes
Previous:From: Florian G. PflugDate: 2005-05-17 19:48:34
Subject: Re: App closes while trying to edit attributes

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group