/[pengfork]/pengfork/src/main.c
ViewVC logotype

Diff of /pengfork/src/main.c

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

revision 1.16 by chupa, Sat Nov 30 13:24:43 2002 UTC revision 1.17 by chupa, Sun Dec 1 01:19:07 2002 UTC
# Line 51  Line 51 
51  #include <unistd.h>  #include <unistd.h>
52  #include <errno.h>  #include <errno.h>
53  #include <string.h>  #include <string.h>
54    #include <libintl.h>
55  #ifdef WITH_MODEM  #ifdef WITH_MODEM
56  #  include <guile/gh.h>  #  include <guile/gh.h>
57  #endif  #endif
# Line 83  daemon_mode (void) Line 84  daemon_mode (void)
84  {  {
85    int pid;    int pid;
86    int f;    int f;
87      
88    pid=fork();    pid = fork ();
89    if(pid == 0)    if (pid == 0)
90      {      {
91        f=open("/dev/null", O_RDWR);        f = open ("/dev/null", O_RDWR);
92        if(f<0)        if (f < 0)
93          log (LOG_ERR, "Unable to open /dev/null: %s (%d)\n", strerror(errno), errno);          log (LOG_WARNING, gettext ("Unable to open /dev/null: %s (%d)\n"),
94                 strerror (errno), errno);
95        else        else
96          {          {
97          if(dup2(f, 0) < 0)            if (dup2 (f, 0) < 0)
98            log (LOG_ERR, "Error calling dup2 stdin: %s (%d)\n", strerror(errno), errno);              log (LOG_WARNING, gettext ("Error calling dup2 stdin: %s (%d)\n"),
99          if(dup2(f, 1) < 0)                   strerror (errno), errno);
100            log (LOG_ERR, "Error calling dup2 stdout: %s (%d)\n", strerror(errno), errno);            if (dup2 (f, 1) < 0)
101          if(dup2(f, 2) < 0 )              log (LOG_WARNING,
102            log (LOG_ERR, "Error calling dup2 stderr: %s (%d)\n", strerror(errno), errno);                   gettext ("Error calling dup2 stdout: %s (%d)\n"),
103          if(close(f) < 0)                   strerror (errno), errno);
104            log (LOG_ERR, "Error calling close /dev/null: %s (%d)\n", strerror(errno), errno);            if (dup2 (f, 2) < 0)
105                log (LOG_WARNING,
106                     gettext ("Error calling dup2 stderr: %s (%d)\n"),
107                     strerror (errno), errno);
108              if (close (f) < 0)
109                log (LOG_WARNING,
110                     gettext ("Error calling close /dev/null: %s (%d)\n"),
111                     strerror (errno), errno);
112          }          }
113        if( setsid() <0 )        if (setsid () < 0)
114          log (LOG_ERR, "Error calling setsid: %s (%d)\n", strerror(errno), errno);          log (LOG_WARNING, gettext ("Error calling setsid: %s (%d)\n"),
115                 strerror (errno), errno);
116      }      }
117    else if(pid > 0)    else if (pid > 0)
118      {      {
119        exit(0);        exit (0);
120      }      }
121    else    else
122      {      {
123        log (LOG_ERR, "Unable to fork: %s (%d)\n", strerror(errno), errno);        log (LOG_ERR, gettext ("Unable to fork: %s (%d)\n"), strerror (errno),
124        exit(1);             errno);
125          exit (1);
126      }      }
127  }  }
128    
# Line 129  main2 (argc, argv) Line 140  main2 (argc, argv)
140  {  {
141    program_name = argv[0];    program_name = argv[0];
142    
143      init_parameters();
144    init_log ();    init_log ();
145    
146    if (!parse_command_line (argc, argv))    if (!parse_command_line (argc, argv))
147      {      {
148        log (LOG_ERR, "Error parsing command line, exiting !\n");        log (LOG_ERR, gettext ("Error parsing command line, exiting !\n"));
149        exit (1);        exit (1);
150      }      }
151    
152    if (!parse_config ())    if (!parse_config ())
153      {      {
154        log (LOG_ERR, "Error parsing configuration files, exiting !\n");        log (LOG_ERR,
155               gettext ("Error parsing configuration files, exiting !\n"));
156        exit (1);        exit (1);
157      }      }
158      
159    if(!check_config ())    if (!check_config ())
160      {      {
161        log (LOG_ERR, "Bad configuration, exiting !\n");        log (LOG_ERR, gettext ("Bad configuration, exiting !\n"));
162        exit (1);        exit (1);
163      }      }
164    
165    if(PARAM_DAEMON)    if (PARAM_DAEMON)
166      daemon_mode();      daemon_mode ();
167    
168    handle_signals ();    handle_signals ();
169    
170    if (!resolve_functions ())    if (!resolve_functions ())
171      {      {
172        log (LOG_ERR, "Fatal error, exiting.\n");        log (LOG_ERR, gettext ("Fatal error, exiting.\n"));
173        exit (1);        exit (1);
174      }      }
175      
176    if (iface->connect () && haccess->connect ())    if (iface->connect () && haccess->connect ())
177      {      {
178        if (!engine_init ())        if (!engine_init ())
179          {          {
180          /* Should not happen */            /* Should not happen */
181            log (LOG_ERR, "Unable to init engine, exiting.\n");            log (LOG_ERR, gettext ("Unable to init engine, exiting.\n"));
182            exit (1);            exit (1);
183          }          }
184    
# Line 177  main2 (argc, argv) Line 190  main2 (argc, argv)
190      }      }
191    else    else
192      {      {
193        log (LOG_ERR, "Fatal error, exiting.\n");        log (LOG_ERR, gettext ("Fatal error, exiting.\n"));
194        exit (1);        exit (1);
195      }      }
196    
197  #ifndef WITH_MODEM  #ifndef WITH_MODEM
198    return 0;    return 0;
199  #else  #else
200    exit(0);    exit (0);
201  #endif  #endif
202  }  }
203    
# Line 194  main (argc, argv) Line 207  main (argc, argv)
207       int argc;       int argc;
208       char **argv;       char **argv;
209  {  {
210    gh_enter(argc, argv, main2);    gh_enter (argc, argv, main2);
211    return 0; /* never reached */    return 0;                     /* never reached */
212  }  }
213  #endif  #endif

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.17

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