~ubuntu-branches/ubuntu/quantal/wvdial/quantal

« back to all changes in this revision

Viewing changes to src/pppmon.cc

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-10-06 11:05:06 UTC
  • mfrom: (0.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20041006110506-138x19fe4q0iu46e
Tags: 1.54.0-1ubuntu1
postinst: Disable command-line configuration to not disturb installation;
the script just exits early, so the postinst code is not completely lost
(Warty bug #2069)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
 
3
 
// not finished
4
 
// author: arvin@suse.de
5
 
 
6
 
 
7
 
#include <stdio.h>
8
 
#include <unistd.h>
9
 
#include <stdlib.h>
10
 
#include <errno.h>
11
 
#include <string.h>
12
 
#include <wvstream.h>
13
 
 
14
 
#include "wvdialmon.h"
15
 
 
16
 
 
17
 
WvStream *pppd_log = NULL;      // to read messages of pppd
18
 
 
19
 
WvDialMon pppd_mon;
20
 
 
21
 
 
22
 
int main( int argc, char ** argv )
23
 
{
24
 
  int argc_ppp = 0;
25
 
  char *argv_ppp[ argc+10 ];
26
 
  
27
 
  argv_ppp[argc_ppp++] = "/usr/sbin/pppd";
28
 
  
29
 
  for( int i = 1; i < argc; i++ )
30
 
    argv_ppp[argc_ppp++] = argv[i];
31
 
  
32
 
  
33
 
  // open a pipe to access the messages of pppd
34
 
  int pppd_msgfd[2];
35
 
  if( pipe( pppd_msgfd ) == -1 ) {
36
 
    fprintf( stderr, "pipe failed: %s\n", strerror(errno) );
37
 
    exit( EXIT_FAILURE );
38
 
  }
39
 
  
40
 
  char buffer[20];
41
 
  sprintf( buffer, "%d", pppd_msgfd[1] );
42
 
  argv_ppp[argc_ppp++] = "logfd";
43
 
  argv_ppp[argc_ppp++] = buffer;
44
 
  
45
 
  pppd_log = new WvStream( pppd_msgfd[0] );
46
 
  
47
 
  pppd_mon.setconnectmsg( "Connected..." );
48
 
  
49
 
  
50
 
  /*
51
 
  for( int i = 0; i < argc_ppp; i++ )
52
 
    printf( "%s\n", argv_ppp[i] );
53
 
  */
54
 
  
55
 
 
56
 
  // fork and exec pppd
57
 
  pid_t pid = fork();
58
 
  
59
 
  if( pid == (pid_t) 0 ) {      // we are the child
60
 
    argv_ppp[argc_ppp] = NULL;
61
 
    execv( argv_ppp[0], argv_ppp );
62
 
    fprintf( stderr, "exec failed: %s\n", strerror(errno) );
63
 
    exit( EXIT_FAILURE );
64
 
  }
65
 
  
66
 
  if( pid < (pid_t) 0 ) {       // the fork failed
67
 
    fprintf( stderr, "error: can't fork child process\n" );
68
 
    exit( EXIT_FAILURE );
69
 
  }
70
 
 
71
 
  
72
 
  /*
73
 
  ppp_pipe = new WvPipe( argv_ppp[0], argv_ppp, false, false, false );
74
 
  */
75
 
  
76
 
  
77
 
  // install signals
78
 
  
79
 
  
80
 
  
81
 
  for( ;; ) {
82
 
    
83
 
    // see if pppd is still alive
84
 
    
85
 
    
86
 
    
87
 
    
88
 
    // now watch for messages and output to stdout
89
 
    
90
 
    if( pppd_log != NULL && pppd_log->isok() ) {
91
 
      
92
 
      char *line;
93
 
      
94
 
      do {
95
 
        
96
 
        line = pppd_log->getline( 100 );
97
 
        if( line != NULL ) {
98
 
          char *buffer1 = pppd_mon.analyse_line( line );
99
 
          if( buffer1 != NULL && buffer1[0] != '\0' ) {
100
 
            char buffer2[ strlen( buffer1 ) + 10 ];
101
 
            sprintf( buffer2, "pppd: %s", buffer1 );
102
 
            fprintf( stdout, "%s", buffer2 );
103
 
          }
104
 
        }
105
 
      } while( line != NULL );
106
 
      
107
 
    }
108
 
    
109
 
  }
110
 
  
111
 
  exit( EXIT_SUCCESS );
112
 
}