diff -rpcd a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml *** a/doc/src/sgml/config.sgml 2013-12-02 09:17:05.000000000 +0900 --- b/doc/src/sgml/config.sgml 2013-12-20 11:56:39.000000000 +0900 *************** local0.* /var/log/postgresql *** 3555,3561 **** When logging to event log is enabled, this parameter determines the program name used to identify PostgreSQL messages in ! the log. The default is PostgreSQL. This parameter can only be set in the postgresql.conf file or on the server command line. --- 3555,3561 ---- When logging to event log is enabled, this parameter determines the program name used to identify PostgreSQL messages in ! the log. The default is PostgreSQL &majorversion;. This parameter can only be set in the postgresql.conf file or on the server command line. diff -rpcd a/doc/src/sgml/runtime.sgml b/doc/src/sgml/runtime.sgml *** a/doc/src/sgml/runtime.sgml 2013-12-02 09:17:05.000000000 +0900 --- b/doc/src/sgml/runtime.sgml 2013-12-20 11:57:22.000000000 +0900 *************** ssh -L 63333:db.foo.com:5432 joe@shell.f *** 2258,2264 **** regsvr32 pgsql_library_directory/pgevent.dll This creates registry entries used by the event viewer, under the default ! event source named PostgreSQL. --- 2258,2264 ---- regsvr32 pgsql_library_directory/pgevent.dll This creates registry entries used by the event viewer, under the default ! event source named PostgreSQL &majorversion;. diff -rpcd a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c *** a/src/backend/utils/error/elog.c 2013-12-02 09:17:05.000000000 +0900 --- b/src/backend/utils/error/elog.c 2013-12-20 12:00:24.000000000 +0900 *************** write_eventlog(int level, const char *li *** 1933,1939 **** if (evtHandle == INVALID_HANDLE_VALUE) { ! evtHandle = RegisterEventSource(NULL, event_source ? event_source : "PostgreSQL"); if (evtHandle == NULL) { evtHandle = INVALID_HANDLE_VALUE; --- 1933,1940 ---- if (evtHandle == INVALID_HANDLE_VALUE) { ! evtHandle = RegisterEventSource(NULL, ! event_source ? event_source : DEFAULT_EVENT_SOURCE); if (evtHandle == NULL) { evtHandle = INVALID_HANDLE_VALUE; diff -rpcd a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c *** a/src/backend/utils/misc/guc.c 2013-12-02 09:17:05.000000000 +0900 --- b/src/backend/utils/misc/guc.c 2013-12-20 12:00:06.000000000 +0900 *************** static struct config_string ConfigureNam *** 2926,2932 **** NULL }, &event_source, ! "PostgreSQL", NULL, NULL, NULL }, --- 2926,2932 ---- NULL }, &event_source, ! DEFAULT_EVENT_SOURCE, NULL, NULL, NULL }, diff -rpcd a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c *** a/src/bin/pg_ctl/pg_ctl.c 2013-12-02 09:17:05.000000000 +0900 --- b/src/bin/pg_ctl/pg_ctl.c 2013-12-20 11:49:05.000000000 +0900 *************** static char recovery_file[MAXPGPATH]; *** 103,108 **** --- 103,109 ---- static char promote_file[MAXPGPATH]; #if defined(WIN32) || defined(__CYGWIN__) + static char event_source[256]; static DWORD pgctl_start_type = SERVICE_AUTO_START; static SERVICE_STATUS status; static SERVICE_STATUS_HANDLE hStatus = (SERVICE_STATUS_HANDLE) 0; *************** static void do_status(void); *** 132,137 **** --- 133,139 ---- static void do_promote(void); static void do_kill(pgpid_t pid); static void print_msg(const char *msg); + static void get_config_value(const char *name, char *buf, int buf_size); static void adjust_data_dir(void); #if defined(WIN32) || defined(__CYGWIN__) *************** write_eventlog(int level, const char *li *** 170,176 **** if (evtHandle == INVALID_HANDLE_VALUE) { ! evtHandle = RegisterEventSource(NULL, "PostgreSQL"); if (evtHandle == NULL) { evtHandle = INVALID_HANDLE_VALUE; --- 172,179 ---- if (evtHandle == INVALID_HANDLE_VALUE) { ! evtHandle = RegisterEventSource(NULL, ! *event_source ? event_source : DEFAULT_EVENT_SOURCE); if (evtHandle == NULL) { evtHandle = INVALID_HANDLE_VALUE; *************** set_starttype(char *starttypeopt) *** 1902,1907 **** --- 1905,1942 ---- } #endif + static void + get_config_value(const char *name, char *buf, int buf_size) + { + char cmd[MAXPGPATH], + *my_exec_path; + FILE *fd; + + /* we use a private my_exec_path to avoid interfering with later uses */ + if (exec_path == NULL) + my_exec_path = find_other_exec_or_die(argv0, "postgres", PG_BACKEND_VERSIONSTR); + else + my_exec_path = pg_strdup(exec_path); + + snprintf(cmd, MAXPGPATH, SYSTEMQUOTE "\"%s\" %s%s -C %s" SYSTEMQUOTE, + my_exec_path, pgdata_opt ? pgdata_opt : "", post_opts ? + post_opts : "", name); + + fd = popen(cmd, "r"); + if (fd == NULL || fgets(buf, buf_size, fd) == NULL) + { + write_stderr(_("%s: could not execute command \"%s\": %s\n"), + progname, cmd, strerror(errno)); + exit(1); + } + pclose(fd); + free(my_exec_path); + + /* Remove trailing newline */ + if (strchr(buf, '\n') != NULL) + *strchr(buf, '\n') = '\0'; + } + /* * adjust_data_dir * *************** set_starttype(char *starttypeopt) *** 1910,1918 **** static void adjust_data_dir(void) { ! char cmd[MAXPGPATH], ! filename[MAXPGPATH], ! *my_exec_path; FILE *fd; /* do nothing if we're working without knowledge of data dir */ --- 1945,1951 ---- static void adjust_data_dir(void) { ! char filename[MAXPGPATH]; FILE *fd; /* do nothing if we're working without knowledge of data dir */ *************** adjust_data_dir(void) *** 1934,1962 **** } /* Must be a configuration directory, so find the data directory */ ! ! /* we use a private my_exec_path to avoid interfering with later uses */ ! if (exec_path == NULL) ! my_exec_path = find_other_exec_or_die(argv0, "postgres", PG_BACKEND_VERSIONSTR); ! else ! my_exec_path = pg_strdup(exec_path); ! ! snprintf(cmd, MAXPGPATH, SYSTEMQUOTE "\"%s\" %s%s -C data_directory" SYSTEMQUOTE, ! my_exec_path, pgdata_opt ? pgdata_opt : "", post_opts ? ! post_opts : ""); ! ! fd = popen(cmd, "r"); ! if (fd == NULL || fgets(filename, sizeof(filename), fd) == NULL) ! { ! write_stderr(_("%s: could not determine the data directory using command \"%s\"\n"), progname, cmd); ! exit(1); ! } ! pclose(fd); ! free(my_exec_path); ! ! /* Remove trailing newline */ ! if (strchr(filename, '\n') != NULL) ! *strchr(filename, '\n') = '\0'; free(pg_data); pg_data = pg_strdup(filename); --- 1967,1973 ---- } /* Must be a configuration directory, so find the data directory */ ! get_config_value("data_directory", filename, sizeof(filename)); free(pg_data); pg_data = pg_strdup(filename); *************** main(int argc, char **argv) *** 2194,2199 **** --- 2205,2215 ---- /* -D might point at config-only directory; if so find the real PGDATA */ adjust_data_dir(); + #if defined(WIN32) || defined(__CYGWIN__) + /* Get event source from postgresql.conf for eventlog output */ + get_config_value("event_source", event_source, sizeof(event_source)); + #endif + /* Complain if -D needed and not provided */ if (pg_config == NULL && ctl_command != KILL_COMMAND && ctl_command != UNREGISTER_COMMAND) diff -rpcd a/src/bin/pgevent/pgevent.c b/src/bin/pgevent/pgevent.c *** a/src/bin/pgevent/pgevent.c 2013-12-02 09:17:05.000000000 +0900 --- b/src/bin/pgevent/pgevent.c 2013-12-20 11:47:44.000000000 +0900 *************** *** 12,17 **** --- 12,19 ---- */ + #include "postgres_fe.h" + #include #include #include *************** HANDLE g_module = NULL; /* hModule of D *** 26,32 **** * The maximum length of a registry key is 255 characters. * http://msdn.microsoft.com/en-us/library/ms724872(v=vs.85).aspx */ ! char event_source[256] = "PostgreSQL"; /* Prototypes */ HRESULT DllInstall(BOOL bInstall, LPCWSTR pszCmdLine); --- 28,34 ---- * The maximum length of a registry key is 255 characters. * http://msdn.microsoft.com/en-us/library/ms724872(v=vs.85).aspx */ ! char event_source[256] = DEFAULT_EVENT_SOURCE; /* Prototypes */ HRESULT DllInstall(BOOL bInstall, LPCWSTR pszCmdLine); *************** DllInstall(BOOL bInstall, *** 54,60 **** * * This strange behavior forces us to specify -n (i.e. "regsvr32 /n /i"). * Without -n, DllRegisterServer called before DllInstall would mistakenly ! * overwrite the default "PostgreSQL" event source registration. */ if (bInstall) DllRegisterServer(); --- 56,62 ---- * * This strange behavior forces us to specify -n (i.e. "regsvr32 /n /i"). * Without -n, DllRegisterServer called before DllInstall would mistakenly ! * overwrite the default event source registration. */ if (bInstall) DllRegisterServer(); diff -rpcd a/src/include/pg_config_manual.h b/src/include/pg_config_manual.h *** a/src/include/pg_config_manual.h 2013-12-02 09:17:04.000000000 +0900 --- b/src/include/pg_config_manual.h 2013-12-20 11:47:09.000000000 +0900 *************** *** 147,152 **** --- 147,157 ---- #define DEFAULT_PGSOCKET_DIR "/tmp" /* + * This is the default event source for Windows event log. + */ + #define DEFAULT_EVENT_SOURCE "PostgreSQL " PG_MAJORVERSION + + /* * The random() function is expected to yield values between 0 and * MAX_RANDOM_VALUE. Currently, all known implementations yield * 0..2^31-1, so we just hardwire this constant. We could do a