@@ -2771,6 +2771,54 @@ fio_get_lsn_map_impl(int out, char *buf)
27712771}
27722772}
27732773
2774+ /*
2775+ * Return pid of postmaster process running in given pgdata on local machine.
2776+ * Return 0 if there is none.
2777+ * Return 1 if postmaster.pid is mangled.
2778+ */
2779+ static pid_t
2780+ local_check_postmaster (const char * pgdata )
2781+ {
2782+ FILE * fp ;
2783+ pid_t pid ;
2784+ char pid_file [MAXPGPATH ];
2785+
2786+ join_path_components (pid_file ,pgdata ,"postmaster.pid" );
2787+
2788+ fp = fopen (pid_file ,"r" );
2789+ if (fp == NULL )
2790+ {
2791+ /* No pid file, acceptable*/
2792+ if (errno == ENOENT )
2793+ return 0 ;
2794+ else
2795+ elog (ERROR ,"Cannot open file \"%s\": %s" ,
2796+ pid_file ,strerror (errno ));
2797+ }
2798+
2799+ if (fscanf (fp ,"%i" ,& pid )!= 1 )
2800+ {
2801+ /* something is wrong with the file content */
2802+ pid = 1 ;
2803+ }
2804+
2805+ if (pid > 1 )
2806+ {
2807+ if (kill (pid ,0 )!= 0 )
2808+ {
2809+ /* process no longer exists */
2810+ if (errno == ESRCH )
2811+ pid = 0 ;
2812+ else
2813+ elog (ERROR ,"Failed to send signal 0 to a process %d: %s" ,
2814+ pid ,strerror (errno ));
2815+ }
2816+ }
2817+
2818+ fclose (fp );
2819+ return pid ;
2820+ }
2821+
27742822/*
27752823 * Go to the remote host and get postmaster pid from file postmaster.pid
27762824 * and check that process is running, if process is running, return its pid number.
@@ -2793,7 +2841,7 @@ fio_check_postmaster(const char *pgdata, fio_location location)
27932841return hdr .arg ;
27942842}
27952843else
2796- return check_postmaster (pgdata );
2844+ return local_check_postmaster (pgdata );
27972845}
27982846
27992847static void
@@ -2803,7 +2851,7 @@ fio_check_postmaster_impl(int out, char *buf)
28032851pid_t postmaster_pid ;
28042852char * pgdata = (char * )buf ;
28052853
2806- postmaster_pid = check_postmaster (pgdata );
2854+ postmaster_pid = local_check_postmaster (pgdata );
28072855
28082856/* send arrays of checksums to main process */
28092857hdr .arg = postmaster_pid ;