~ubuntu-branches/ubuntu/oneiric/pgpool2/oneiric

« back to all changes in this revision

Viewing changes to pcp_child.c

  • Committer: Bazaar Package Importer
  • Author(s): Marc Gariepy
  • Date: 2010-02-17 13:58:08 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20100217135808-vqxtfe80r5z8toje
Tags: 2.3.2.1-0ubuntu1
* New upstream release (2.3.2.1)
 * Lots of bug fixes
 * Add SSL support
 * Add support for large object replication
 * Enhanced replication (TIMESTAMP, DATES)
 * Save node status on restart
 * Some other minor changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*-pgsql-c-*- */
2
2
/*
3
 
 * $Header: /cvsroot/pgpool/pgpool-II/pcp_child.c,v 1.11 2008/03/27 16:04:01 y-asaba Exp $
4
 
 * 
5
 
 * pgpool: a language independent connection pool server for PostgreSQL 
 
3
 * $Header: /cvsroot/pgpool/pgpool-II/pcp_child.c,v 1.12 2009/08/22 04:04:21 t-ishii Exp $
 
4
 *
 
5
 * pgpool: a language independent connection pool server for PostgreSQL
6
6
 * written by Tatsuo Ishii
7
7
 *
8
8
 * Copyright (c) 2003-2008      PgPool Global Development Group
108
108
        signal(SIGUSR2, wakeup_handler);
109
109
        signal(SIGPIPE, SIG_IGN);
110
110
        signal(SIGALRM, SIG_IGN);
111
 
        
 
111
 
112
112
        for(;;)
113
113
        {
114
114
                errno = 0;
177
177
                /* is this connection authenticated? if not disconnect immediately*/
178
178
                if ((! authenticated) && (tos != 'R' && tos != 'M'))
179
179
                {
180
 
                        pool_debug("pcp_child: connection not authorized");                                     
 
180
                        pool_debug("pcp_child: connection not authorized");
181
181
                        free(buf);
182
182
                        buf = NULL;
183
183
                        pcp_close(frontend);
190
190
                pool_debug("pcp_child: received PCP packet type of service '%c'", tos);
191
191
 
192
192
                set_ps_display("PCP: processing a request", false);
193
 
                        
 
193
 
194
194
                switch (tos)
195
195
                {
196
196
                        case 'R':                       /* authentication */
199
199
 
200
200
                                if (random_salt)
201
201
                                {
202
 
                                        authenticated = user_authenticate(buf, pcp_conf_file, salt, 4);                                 
 
202
                                        authenticated = user_authenticate(buf, pcp_conf_file, salt, 4);
203
203
                                }
204
204
                                if (!random_salt || !authenticated)
205
205
                                {
270
270
                                char mesg[16];
271
271
 
272
272
                                snprintf(mesg, sizeof(mesg), "%d", node_count);
273
 
                                
 
273
 
274
274
                                pcp_write(frontend, "l", 1);
275
275
                                wsize = htonl(sizeof(code) +
276
276
                                                          strlen(mesg)+1 +
291
291
                        {
292
292
                                int node_id;
293
293
                                int wsize;
294
 
                                
 
294
 
295
295
                                BackendInfo *bi = NULL;
296
296
 
297
297
                                node_id = atoi(buf);
322
322
                                        snprintf(port_str, sizeof(port_str), "%d", bi->backend_port);
323
323
                                        snprintf(status, sizeof(status), "%d", bi->backend_status);
324
324
                                        snprintf(weight_str, sizeof(weight_str), "%f", bi->backend_weight);
325
 
                                
 
325
 
326
326
                                        pcp_write(frontend, "i", 1);
327
327
                                        wsize = htonl(sizeof(code) +
328
328
                                                                  strlen(bi->backend_hostname)+1 +
376
376
                                        snprintf(mesg+total_port_len, strlen(port)+1, "%s", port);
377
377
                                        total_port_len += strlen(port)+1;
378
378
                                }
379
 
                                
 
379
 
380
380
                                pcp_write(frontend, "n", 1);
381
381
                                wsize = htonl(sizeof(code) +
382
382
                                                          strlen(process_count_str)+1 +
391
391
                                        pool_error("pcp_child: pcp_flush() failed. reason: %s", strerror(errno));
392
392
                                        exit(1);
393
393
                                }
394
 
                                
 
394
 
395
395
                                free(process_list);
396
396
                                free(mesg);
397
397
 
398
398
                                pool_debug("pcp_child: %d process(es) found", process_count);
399
399
                                break;
400
400
                        }
401
 
                                
 
401
 
402
402
                        case 'P':                       /* process info */
403
403
                        {
404
404
                                int proc_id;
405
405
                                int wsize;
406
 
                                
 
406
 
407
407
                                ProcessInfo *pi = NULL;
408
408
 
409
409
                                proc_id = atoi(buf);
510
510
                        case 'S':                       /* SystemDB info */
511
511
                        {
512
512
                                int wsize;
513
 
                                
 
513
 
514
514
                                SystemDBInfo *si = NULL;
515
515
                                si = pool_get_system_db_info();
516
516
 
585
585
                                                int type_list_offset;
586
586
                                                DistDefInfo *ddi;
587
587
                                                int i, j;
588
 
                                        
 
588
 
589
589
                                                for (i = 0; i < si->dist_def_num; i++)
590
590
                                                {
591
591
                                                        ddi = &si->dist_def_slot[i];
605
605
                                                                pool_error("pcp_child: malloc() failed. reason: %s", strerror(errno));
606
606
                                                                exit(1);
607
607
                                                        }
608
 
                                                
 
608
 
609
609
                                                        col_list_offset = type_list_offset = 0;
610
610
                                                        for (j = 0; j < ddi->col_num; j++)
611
611
                                                        {
664
664
                                }
665
665
                                break;
666
666
                        }
667
 
                        
 
667
 
668
668
                        case 'D':                       /* detach node */
669
669
                        {
670
670
                                int node_id;
671
671
                                int wsize;
672
672
                                char code[] = "CommandComplete";
673
 
                                
 
673
 
674
674
                                node_id = atoi(buf);
675
675
                                pool_debug("pcp_child: detaching Node ID %d", node_id);
676
676
                                notice_backend_error(node_id);
692
692
                                int node_id;
693
693
                                int wsize;
694
694
                                char code[] = "CommandComplete";
695
 
                                
 
695
 
696
696
                                node_id = atoi(buf);
697
697
                                pool_debug("pcp_child: attaching Node ID %d", node_id);
698
698
                                send_failback_request(node_id);
708
708
                                }
709
709
                                break;
710
710
                        }
711
 
                        
 
711
 
712
712
                        case 'T':
713
713
                        {
714
714
                                char mode = buf[0];
754
754
                                }
755
755
                                else
756
756
                                {
757
 
                                        pool_debug("pcp_child: start online recovery");                         
 
757
                                        pool_debug("pcp_child: start online recovery");
758
758
                                        node_id = atoi(buf);
759
759
 
760
760
                                        r = start_recovery(node_id);
787
787
                        case 'F':
788
788
                                pool_debug("pcp_child: stop online recovery");
789
789
                                break;
790
 
                        
 
790
 
791
791
                        case 'X':                       /* disconnect */
792
792
                                pool_debug("pcp_child: client disconnecting. close connection");
793
793
                                authenticated = 0;
866
866
        {
867
867
                if (errno == EAGAIN || errno == EINTR)
868
868
                        return NULL;
869
 
                
 
869
 
870
870
                pool_error("pcp_child: select() failed. reason: %s", strerror(errno));
871
871
                return NULL;
872
872
        }