/[radius]/radius/radiusd/rpp.c
ViewVC logotype

Diff of /radius/radiusd/rpp.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by gray, Fri Apr 18 05:35:51 2003 UTC revision 1.2 by gray, Fri Apr 25 22:50:32 2003 UTC
# Line 177  rpp_start_process(rpp_proc_t *proc, int Line 177  rpp_start_process(rpp_proc_t *proc, int
177          proc->pid = pid;          proc->pid = pid;
178          proc->p[0] = inp[0];          proc->p[0] = inp[0];
179          proc->p[1] = outp[1];          proc->p[1] = outp[1];
180            proc->ready = 1;
181          return 0;          return 0;
182  }  }
183    
# Line 304  rpp_read_set(fd_set *fds, void *data, si Line 305  rpp_read_set(fd_set *fds, void *data, si
305  static int rpp_request_handler(void *arg);  static int rpp_request_handler(void *arg);
306    
307  int  int
308  rpp_ready()  rpp_ready(pid_t pid)
309  {  {
310          rpp_proc_t *p = rpp_lookup_ready(rpp_request_handler, NULL);          if (pid == 0) {  
311          return p != NULL;                  if (rpp_lookup_ready(rpp_request_handler, NULL))
312                            return 1;
313            } else {
314                    rpp_proc_t *p;
315    
316                    for (p = list_first(process_list);
317                         p;
318                         p = list_next(process_list)) {
319                            if (p->pid == pid) {
320                                    if (p->ready)
321                                            return 1;
322                                    break;
323                            }
324                    }
325            }
326            return 0;
327  }  }
328    
329  void  void
# Line 349  rpp_kill(pid_t pid, int signo) Line 365  rpp_kill(pid_t pid, int signo)
365          list_iterate(process_list, _kill_itr, &signo);          list_iterate(process_list, _kill_itr, &signo);
366  }  }
367    
368  struct fwd_request {  struct rpp_request {
369          int type;                  /* Request type */          int type;                  /* Request type */
370          struct sockaddr_in addr;   /* Sender address */          struct sockaddr_in addr;   /* Sender address */
371          int fd;                    /* Source descriptor */          int fd;                    /* Source descriptor */
# Line 357  struct fwd_request { Line 373  struct fwd_request {
373          /* Raw data follow */          /* Raw data follow */
374  };  };
375    
376    struct rpp_reply {
377            int code;
378            size_t size;
379            /* Data follows */
380    };
381    
382  int  int
383  rpp_forward_request(REQUEST *req)  rpp_forward_request(REQUEST *req)
384  {  {
385          rpp_proc_t *p;          rpp_proc_t *p;
386          struct fwd_request frq;          struct rpp_request frq;
387    
388          if (req->child_id)          if (req->child_id)
389                  p = rpp_lookup_pid(req->child_id);                  p = rpp_lookup_pid(req->child_id);
390          else          else
391                  p = rpp_lookup_ready(rpp_request_handler, NULL);                  p = rpp_lookup_ready(rpp_request_handler, NULL);
392    
393          if (!p)          if (!p)
394                  return 1;                  return 1;
395            radlog(L_DEBUG, "sending request to %d", p->pid);
396            
397          frq.type = req->type;          frq.type = req->type;
398          frq.addr = req->addr;          frq.addr = req->addr;
399          frq.fd = req->fd;          frq.fd = req->fd;
# Line 426  sig_handler(int sig) Line 451  sig_handler(int sig)
451          signal(sig, sig_handler);          signal(sig, sig_handler);
452  }  }
453    
   
454  int  int
455  rpp_request_handler(void *arg ARG_UNUSED)  rpp_request_handler(void *arg ARG_UNUSED)
456  {  {
457          struct fwd_request frq;          struct rpp_request frq;
458            struct rpp_reply repl;
459          char *data = NULL;          char *data = NULL;
460          size_t datasize = 0;          size_t datasize = 0;
         int true = 1;  
461          REQUEST *req;          REQUEST *req;
462    
463          radiusd_signal_init(sig_handler);          radiusd_signal_init(sig_handler);
464          request_init_queue();          request_init_queue();
465            
466          while (1) {          while (1) {
467                  if (rpp_fd_read(0, &frq, sizeof frq) != sizeof frq) {                  if (rpp_fd_read(0, &frq, sizeof frq) != sizeof frq) {
468                          abort();                          abort();
# Line 460  rpp_request_handler(void *arg ARG_UNUSED Line 484  rpp_request_handler(void *arg ARG_UNUSED
484                  req = request_create(frq.type, frq.fd, &frq.addr,                  req = request_create(frq.type, frq.fd, &frq.addr,
485                                       data, frq.size);                                       data, frq.size);
486                  req->status = RS_COMPLETED;                  req->status = RS_COMPLETED;
487                  if (request_handle(req, request_respond))                  repl.code = request_handle(req, request_respond);
488                          request_free(req);                          
489                    /* Inform the master */
490                    repl.size = req->update_size;
491                    rpp_fd_write(1, &repl, sizeof repl);
492                    if (req->update) {
493                            rpp_fd_write(1, req->update, req->update_size);
494                            efree(req->update);
495                            req->update = NULL;
496                            req->update_size = 0;
497                    }
498    
499                  /* Inform master */                  if (repl.code)
500                  rpp_fd_write(1, &true, sizeof true);                          request_free(req);
                 exit(10);  
501          }          }
502          return 0;          return 0;
503  }  }
# Line 474  int Line 506  int
506  rpp_input_handler(int fd, void *data)  rpp_input_handler(int fd, void *data)
507  {  {
508          int true = 0;          int true = 0;
509            struct rpp_reply repl;
510                    
511          rpp_fd_read(fd, &true, sizeof(true));          if (rpp_fd_read(fd, &repl, sizeof(repl)) == sizeof(repl)) {
         if (true) {  
512                  rpp_proc_t *p = rpp_lookup_fd(fd);                  rpp_proc_t *p = rpp_lookup_fd(fd);
513                    void *data = NULL;
514    
515                    if (repl.size) {
516                            data = emalloc(repl.size);
517                            rpp_fd_read(fd, data, repl.size);
518                    }
519                    
520                  if (p) {                  if (p) {
521                          p->ready = 1;                          p->ready = 1;
522                          request_set_status(p->pid, RS_COMPLETED);                          request_update(p->pid, RS_COMPLETED, data);
523                  }                  }
524                    efree(data);
525          }          }
526          return 0;          return 0;
527  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26