4
4
* Revisions by Christopher B. Browne, Liberty RMS
5
5
* Win32 Service code added by Dave Page
6
6
*
7
- * $PostgreSQL: pgsql/contrib/pg_autovacuum/pg_autovacuum.c,v 1.27 2004/12/02 22:48:10 momjian Exp $
7
+ * $PostgreSQL: pgsql/contrib/pg_autovacuum/pg_autovacuum.c,v 1.28 2005/01/24 00:13:38 neilc Exp $
8
8
*/
9
9
10
10
#include "postgres_fe.h"
22
22
#include "pg_autovacuum.h"
23
23
24
24
#ifdef WIN32
25
- unsigned int sleep ();
26
-
27
25
SERVICE_STATUS ServiceStatus ;
28
26
SERVICE_STATUS_HANDLE hStatus ;
29
27
int appMode = 0 ;
28
+ char deps [255 ];
30
29
#endif
31
30
32
31
/* define atooid */
@@ -1073,6 +1072,7 @@ get_cmd_args(int argc, char *argv[])
1073
1072
#ifndef WIN32
1074
1073
args -> daemonize = 0 ;
1075
1074
#else
1075
+ args -> service_dependencies = 0 ;
1076
1076
args -> install_as_service = 0 ;
1077
1077
args -> remove_as_service = 0 ;
1078
1078
args -> service_user = 0 ;
@@ -1166,7 +1166,17 @@ get_cmd_args(int argc, char *argv[])
1166
1166
exit (0 );
1167
1167
#ifdef WIN32
1168
1168
case 'E' :
1169
- args -> service_dependencies = optarg ;
1169
+ /*
1170
+ * CreateService() expects a list of service
1171
+ * dependencies as a NUL-separated, double-NUL
1172
+ * terminated list (although we only allow the user to
1173
+ * specify a single dependency). So we zero out the
1174
+ * list first, and make sure to leave room for two NUL
1175
+ * terminators.
1176
+ */
1177
+ ZeroMemory (deps , sizeof (deps ));
1178
+ snprintf (deps , sizeof (deps ) - 2 , "%s" , optarg );
1179
+ args -> service_dependencies = deps ;
1170
1180
break ;
1171
1181
case 'I' :
1172
1182
args -> install_as_service ++ ;
@@ -1359,7 +1369,7 @@ ControlHandler(DWORD request)
1359
1369
1360
1370
/* Register with the Service Control Manager */
1361
1371
static int
1362
- InstallService ()
1372
+ InstallService (void )
1363
1373
{
1364
1374
SC_HANDLE schService = NULL ;
1365
1375
SC_HANDLE schSCManager = NULL ;
@@ -1471,7 +1481,7 @@ InstallService()
1471
1481
1472
1482
/* Unregister from the Service Control Manager */
1473
1483
static int
1474
- RemoveService ()
1484
+ RemoveService (void )
1475
1485
{
1476
1486
SC_HANDLE schService = NULL ;
1477
1487
SC_HANDLE schSCManager = NULL ;
@@ -1699,7 +1709,7 @@ VacuumLoop(int argc, char **argv)
1699
1709
fflush (LOGOUTPUT );
1700
1710
}
1701
1711
1702
- sleep (sleep_secs ); /* Larger Pause between outer loops */
1712
+ pg_usleep (sleep_secs * 1000000 ); /* Larger Pause between outer loops */
1703
1713
1704
1714
gettimeofday (& then , 0 ); /* Reset time counter */
1705
1715
@@ -1753,15 +1763,12 @@ main(int argc, char *argv[])
1753
1763
if (InstallService () != 0 )
1754
1764
{
1755
1765
FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM , NULL , GetLastError (), MAKELANGID (LANG_NEUTRAL , SUBLANG_DEFAULT ), (LPTSTR ) & lpMsgBuf , 0 , NULL );
1756
- sprintf (logbuffer , "%s" , (char * ) lpMsgBuf );
1757
- log_entry (logbuffer , LVL_ERROR );
1758
- fflush (LOGOUTPUT );
1766
+ fprintf (stderr , "Error: %s\n" , (char * ) lpMsgBuf );
1759
1767
exit (-1 );
1760
1768
}
1761
1769
else
1762
1770
{
1763
- log_entry ("Successfully installed Windows service" , LVL_INFO );
1764
- fflush (LOGOUTPUT );
1771
+ fprintf (stderr , "Successfully installed pg_autovacuum as a service.\n" );
1765
1772
exit (0 );
1766
1773
}
1767
1774
}
@@ -1772,15 +1779,12 @@ main(int argc, char *argv[])
1772
1779
if (RemoveService () != 0 )
1773
1780
{
1774
1781
FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM , NULL , GetLastError (), MAKELANGID (LANG_NEUTRAL , SUBLANG_DEFAULT ), (LPTSTR ) & lpMsgBuf , 0 , NULL );
1775
- sprintf (logbuffer , "%s" , (char * ) lpMsgBuf );
1776
- log_entry (logbuffer , LVL_ERROR );
1777
- fflush (LOGOUTPUT );
1782
+ fprintf (stderr , "Error: %s\n" , (char * ) lpMsgBuf );
1778
1783
exit (-1 );
1779
1784
}
1780
1785
else
1781
1786
{
1782
- log_entry ("Successfully removed Windows service" , LVL_INFO );
1783
- fflush (LOGOUTPUT );
1787
+ fprintf (stderr , "Successfully removed pg_autovacuum as a service.\n" );
1784
1788
exit (0 );
1785
1789
}
1786
1790
}
0 commit comments