44 *
55 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
66 *
7- * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.2 2004/05/31 17:57:31 momjian Exp $
7+ * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.3 2004/06/01 01:28:03 momjian Exp $
88 *
99 *-------------------------------------------------------------------------
1010 */
2424int optreset ;
2525#endif
2626
27+ /* PID can be negative for standalone backend */
28+ typedef long pgpid_t ;
2729
2830#define _ (x ) gettext((x))
2931
@@ -79,8 +81,8 @@ static void do_stop(void);
7981static void do_restart (void );
8082static void do_reload (void );
8183static void do_status (void );
82- static void do_kill (pid_t pid );
83- static pid_t get_pgpid (void );
84+ static void do_kill (pgpid_t pid );
85+ static pgpid_t get_pgpid (void );
8486static char * * readfile (char * path );
8587static int start_postmaster (void );
8688static bool test_postmaster_connection (void );
@@ -126,11 +128,11 @@ xstrdup(const char *s)
126128
127129
128130
129- static pid_t
131+ static pgpid_t
130132get_pgpid (void )
131133{
132134 FILE * pidf ;
133- pid_t pid ;
135+ pgpid_t pid ;
134136
135137 pidf = fopen (pid_file , "r" );
136138 if (pidf == NULL )
@@ -144,7 +146,7 @@ get_pgpid(void)
144146 exit (1 );
145147 }
146148 }
147- fscanf (pidf , "%u " , & pid );
149+ fscanf (pidf , "%ld " , & pid );
148150 fclose (pidf );
149151 return pid ;
150152}
@@ -323,8 +325,8 @@ test_postmaster_connection(void)
323325static void
324326do_start (void )
325327{
326- pid_t pid ;
327- pid_t old_pid = 0 ;
328+ pgpid_t pid ;
329+ pgpid_t old_pid = 0 ;
328330 char * optline = NULL ;
329331
330332 if (ctl_command != RESTART_COMMAND )
@@ -457,7 +459,7 @@ static void
457459do_stop (void )
458460{
459461 int cnt ;
460- pid_t pid ;
462+ pgpid_t pid ;
461463
462464 pid = get_pgpid ();
463465
@@ -472,14 +474,14 @@ do_stop(void)
472474 pid = - pid ;
473475 fprintf (stderr ,
474476 _ ("%s: cannot stop postmaster; "
475- "postgres is running (PID: %u )\n" ),
477+ "postgres is running (PID: %ld )\n" ),
476478 progname , pid );
477479 exit (1 );
478480 }
479481
480- if (kill (pid , sig ) != 0 )
482+ if (kill (( pid_t ) pid , sig ) != 0 )
481483 {
482- fprintf (stderr , _ ("stop signal failed (PID: %u ): %s\n" ), pid ,
484+ fprintf (stderr , _ ("stop signal failed (PID: %ld ): %s\n" ), pid ,
483485 strerror (errno ));
484486 exit (1 );
485487 }
@@ -537,7 +539,7 @@ static void
537539do_restart (void )
538540{
539541 int cnt ;
540- pid_t pid ;
542+ pgpid_t pid ;
541543
542544 pid = get_pgpid ();
543545
@@ -553,15 +555,15 @@ do_restart(void)
553555 pid = - pid ;
554556 fprintf (stderr ,
555557 _ ("%s: cannot restart postmaster; "
556- "postgres is running (PID: %u )\n" ),
558+ "postgres is running (PID: %ld )\n" ),
557559 progname , pid );
558560 fprintf (stderr , _ ("Please terminate postgres and try again.\n" ));
559561 exit (1 );
560562 }
561563
562- if (kill (pid , sig ) != 0 )
564+ if (kill (( pid_t ) pid , sig ) != 0 )
563565 {
564- fprintf (stderr , _ ("stop signal failed (PID: %u ): %s\n" ), pid ,
566+ fprintf (stderr , _ ("stop signal failed (PID: %ld ): %s\n" ), pid ,
565567 strerror (errno ));
566568 exit (1 );
567569 }
@@ -609,7 +611,7 @@ do_restart(void)
609611static void
610612do_reload (void )
611613{
612- pid_t pid ;
614+ pgpid_t pid ;
613615
614616 pid = get_pgpid ();
615617 if (pid == 0 ) /* no pid file */
@@ -623,15 +625,15 @@ do_reload(void)
623625 pid = - pid ;
624626 fprintf (stderr ,
625627 _ ("%s: cannot reload postmaster; "
626- "postgres is running (PID: %u )\n" ),
628+ "postgres is running (PID: %ld )\n" ),
627629 progname , pid );
628630 fprintf (stderr , _ ("Please terminate postgres and try again.\n" ));
629631 exit (1 );
630632 }
631633
632- if (kill (pid , sig ) != 0 )
634+ if (kill (( pid_t ) pid , sig ) != 0 )
633635 {
634- fprintf (stderr , _ ("reload signal failed (PID: %u ): %s\n" ), pid ,
636+ fprintf (stderr , _ ("reload signal failed (PID: %ld ): %s\n" ), pid ,
635637 strerror (errno ));
636638 exit (1 );
637639 }
@@ -647,7 +649,7 @@ do_reload(void)
647649static void
648650do_status (void )
649651{
650- pid_t pid ;
652+ pgpid_t pid ;
651653
652654 pid = get_pgpid ();
653655 if (pid == 0 ) /* no pid file */
@@ -658,13 +660,13 @@ do_status(void)
658660 else if (pid < 0 ) /* standalone backend */
659661 {
660662 pid = - pid ;
661- fprintf (stdout , _ ("%s: a standalone backend \"postgres\" is running (PID: %u )\n" ), progname , pid );
663+ fprintf (stdout , _ ("%s: a standalone backend \"postgres\" is running (PID: %ld )\n" ), progname , pid );
662664 }
663665 else /* postmaster */
664666 {
665667 char * * optlines ;
666668
667- fprintf (stdout , _ ("%s: postmaster is running (PID: %u )\n" ), progname , pid );
669+ fprintf (stdout , _ ("%s: postmaster is running (PID: %ld )\n" ), progname , pid );
668670
669671 optlines = readfile (postopts_file );
670672 if (optlines != NULL )
@@ -676,11 +678,11 @@ do_status(void)
676678
677679
678680static void
679- do_kill (pid_t pid )
681+ do_kill (pgpid_t pid )
680682{
681- if (kill (pid , sig ) != 0 )
683+ if (kill (( pid_t ) pid , sig ) != 0 )
682684 {
683- fprintf (stderr , _ ("signal %d failed (PID: %u ): %s\n" ), sig , pid ,
685+ fprintf (stderr , _ ("signal %d failed (PID: %ld ): %s\n" ), sig , pid ,
684686 strerror (errno ));
685687 exit (1 );
686688 }
@@ -813,7 +815,7 @@ main(int argc, char **argv)
813815
814816 int option_index ;
815817 int c ;
816- int killproc = 0 ;
818+ pgpid_t killproc = 0 ;
817819
818820#ifdef WIN32
819821 setvbuf (stderr , NULL , _IONBF , 0 );
0 commit comments