Adds a new option: mode
[src/app-framework-binder.git] / src / main.c
1 /* 
2  * Copyright (C) 2015 "IoT.bzh"
3  * Author "Fulup Ar Foll"
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 /* 
20  * File:   main.c
21  * Author: "Fulup Ar Foll"
22  *
23  * Created on 05 December 2015, 15:38
24  */
25
26 #include "local-def.h"
27
28 #include <syslog.h>
29 #include <setjmp.h>
30 #include <signal.h>
31 #include <getopt.h>
32 #include <pwd.h>
33
34 static sigjmp_buf exitPoint; // context save for set/longjmp
35
36 /*----------------------------------------------------------
37  | printversion
38  |   print version and copyright
39  +--------------------------------------------------------- */
40  static void printVersion (void) {
41
42    fprintf (stderr,"\n----------------------------------------- \n");
43    fprintf (stderr,"|  AFB [Application Framework Binder] version=%s |\n", AJQ_VERSION);
44    fprintf (stderr,"----------------------------------------- \n");
45    fprintf (stderr,"|  Copyright(C) 2015 Fulup Ar Foll /IoT.bzh [fulup -at- iot.bzh]\n");
46    fprintf (stderr,"|  AFB comes with ABSOLUTELY NO WARRANTY.\n");
47    fprintf (stderr,"|  Licence [what ever makes you happy] until you fix bugs by yourself :)\n\n");
48    exit (0);
49  } // end printVersion
50
51
52 // Define command line option
53 #define SET_VERBOSE        101
54 #define SET_BACKGROUND     105
55 #define SET_FORGROUND      106
56 #define KILL_PREV_EXIT     107
57 #define KILL_PREV_REST     108
58 #define SET_FAKE_MOD       109
59
60 #define SET_TCP_PORT       120
61 #define SET_ROOT_DIR       121
62 #define SET_ROOT_BASE      122
63 #define SET_ROOT_API       123
64 #define SET_ROOT_ALIAS     124
65
66 #define SET_CACHE_TO       130
67 #define SET_USERID         131
68 #define SET_PID_FILE       132
69 #define SET_SESSION_DIR    133
70 #define SET_CONFIG_FILE    134
71 #define SET_CONFIG_SAVE    135
72 #define SET_CONFIG_EXIT    138
73
74 #define SET_AUTH_TOKEN     141
75 #define SET_LDPATH         142
76 #define SET_APITIMEOUT     143
77 #define SET_CNTXTIMEOUT    144
78
79 #define DISPLAY_VERSION    150
80 #define DISPLAY_HELP       151
81
82 #define SET_MODE           160
83
84
85 // Supported option
86 static  AFB_options cliOptions [] = {
87   {SET_VERBOSE      ,0,"verbose"         , "Verbose Mode"},
88
89   {SET_FORGROUND    ,0,"foreground"      , "Get all in foreground mode"},
90   {SET_BACKGROUND   ,0,"daemon"          , "Get all in background mode"},
91   {KILL_PREV_EXIT   ,0,"kill"            , "Kill active process if any and exit"},
92   {KILL_PREV_REST   ,0,"restart"         , "Kill active process if any and restart"},
93
94   {SET_TCP_PORT     ,1,"port"            , "HTTP listening TCP port  [default 1234]"},
95   {SET_ROOT_DIR     ,1,"rootdir"         , "HTTP Root Directory [default $HOME/.AFB]"},
96   {SET_ROOT_BASE    ,1,"rootbase"        , "Angular Base Root URL [default /opa]"},
97   {SET_ROOT_API     ,1,"rootapi"         , "HTML Root API URL [default /api]"},
98   {SET_ROOT_ALIAS   ,1,"alias"           , "Muliple url map outside of rootdir [eg: --alias=/icons:/usr/share/icons]"},
99   
100   {SET_APITIMEOUT   ,1,"apitimeout"      , "Plugin API timeout in seconds [default 10]"},
101   {SET_CNTXTIMEOUT  ,1,"cntxtimeout"     , "Client Session Context Timeout [default 900]"},
102   {SET_CACHE_TO     ,1,"cache-eol"       , "Client cache end of live [default 3600s]"},
103   
104   {SET_USERID       ,1,"setuid"          , "Change user id [default don't change]"},
105   {SET_PID_FILE     ,1,"pidfile"         , "PID file path [default none]"},
106   {SET_SESSION_DIR  ,1,"sessiondir"      , "Sessions file path [default rootdir/sessions]"},
107   {SET_CONFIG_FILE  ,1,"config"          , "Config Filename [default rootdir/sessions/configs/default.AFB]"},
108   {SET_CONFIG_SAVE  ,0,"save"            , "Save config on disk [default no]"},
109   {SET_CONFIG_EXIT  ,0,"saveonly"        , "Save config on disk and then exit"},
110
111   {SET_LDPATH       ,1,"ldpaths"         , "Load Plugins from dir1:dir2:... [default = PLUGIN_INSTALL_DIR"},
112   {SET_AUTH_TOKEN   ,1,"token"           , "Initial Secret [default=no-session, --token="" for session without authentication]"},
113   
114   {DISPLAY_VERSION  ,0,"version"         , "Display version and copyright"},
115   {DISPLAY_HELP     ,0,"help"            , "Display this help"},
116
117   {SET_MODE         ,1,"mode"            , "set the mode: either local, remote or global"},
118   {0, 0, 0}
119  };
120
121 static AFB_aliasdir aliasdir[MAX_ALIAS];
122 static int aliascount=0;
123
124 /*----------------------------------------------------------
125  | timeout signalQuit
126  |
127  +--------------------------------------------------------- */
128 void signalQuit (int signum) {
129
130   sigset_t sigset;
131
132   // unlock timeout signal to allow a new signal to come
133   sigemptyset (&sigset);
134   sigaddset   (&sigset, SIGABRT);
135   sigprocmask (SIG_UNBLOCK, &sigset, 0);
136
137   fprintf (stderr, "%s ERR:Received signal quit\n",configTime());
138   syslog (LOG_ERR, "Daemon got kill3 & quit [please report bug]");
139   longjmp (exitPoint, signum);
140 }
141
142
143 /*----------------------------------------------------------
144  | printHelp
145  |   print information from long option array
146  +--------------------------------------------------------- */
147
148  static void printHelp(char *name) {
149     int ind;
150     char command[20];
151
152     fprintf (stderr,"%s:\nallowed options\n", name);
153     for (ind=0; cliOptions [ind].name != NULL;ind++)
154     {
155       // display options
156       if (cliOptions [ind].has_arg == 0 )
157       {
158              fprintf (stderr,"  --%-15s %s\n", cliOptions [ind].name, cliOptions[ind].help);
159       } else {
160          sprintf(command,"%s=xxxx", cliOptions [ind].name);
161          fprintf (stderr,"  --%-15s %s\n", command, cliOptions[ind].help);
162       }
163     }
164     fprintf (stderr,"Example:\n  %s\\\n  --verbose --port=1234 --token='azerty' --ldpaths=build/plugins:/usr/lib64/agl/plugins\n", name);
165 } // end printHelp
166
167 /*----------------------------------------------------------
168  | writePidFile
169  |   write a file in /var/run/AFB with pid
170  +--------------------------------------------------------- */
171 static int writePidFile (AFB_config *config, int pid) {
172   FILE *file;
173
174   // if no pid file configure just return
175   if (config->pidfile == NULL) return 0;
176
177   // open pid file in write mode
178   file = fopen(config->pidfile,"w");
179   if (file == NULL) {
180     fprintf (stderr,"%s ERR:writePidFile fail to open [%s]\n",configTime(), config->pidfile);
181     return -1;
182   }
183
184   // write pid in file and close
185   fprintf (file, "%d\n", pid);
186   fclose  (file);
187   return 0;
188 }
189
190 /*----------------------------------------------------------
191  | readPidFile
192  |   read file in /var/run/AFB with pid
193  +--------------------------------------------------------- */
194 static int readPidFile (AFB_config *config) {
195   int  pid;
196   FILE *file;
197   int  status;
198
199   if (config->pidfile == NULL) return -1;
200
201   // open pid file in write mode
202   file = fopen(config->pidfile,"r");
203   if (file == NULL) {
204     fprintf (stderr,"%s ERR:readPidFile fail to open [%s]\n",configTime(), config->pidfile);
205     return -1;
206   }
207
208   // write pid in file and close
209   status = fscanf  (file, "%d\n", &pid);
210   fclose  (file);
211
212   // never kill pid 0
213   if (status != 1) return -1;
214
215   return (pid);
216 }
217
218 /*----------------------------------------------------------
219  | closeSession
220  |   try to close everything before leaving
221  +--------------------------------------------------------- */
222 static void closeSession (AFB_session *session) {
223
224
225 }
226
227 /*----------------------------------------------------------
228  | listenLoop
229  |   Main listening HTTP loop
230  +--------------------------------------------------------- */
231 static void listenLoop (AFB_session *session) {
232   AFB_error  err;
233
234   if (signal (SIGABRT, signalQuit) == SIG_ERR) {
235         fprintf (stderr, "%s ERR: main fail to install Signal handler\n", configTime());
236         return;
237   }
238
239   // ------ Start httpd server
240   if (session->config->httpdPort > 0) {
241
242         err = httpdStart (session);
243         if (err != AFB_SUCCESS) return;
244
245         // infinite loop
246         httpdLoop(session);
247
248         fprintf (stderr, "hoops returned from infinite loop [report bug]\n");
249   }
250 }
251   
252 /*---------------------------------------------------------
253  | main
254  |   Parse option and launch action
255  +--------------------------------------------------------- */
256
257 int main(int argc, char *argv[])  {
258   AFB_session    *session;
259   char*          programName = argv [0];
260   int            optionIndex = 0;
261   int            optc, ind, consoleFD;
262   int            pid, nbcmd, status;
263   AFB_config     cliconfig; // temp structure to store CLI option before file config upload
264
265   // ------------- Build session handler & init config -------
266   session = configInit ();
267   memset(&cliconfig,0,sizeof(cliconfig));
268   memset(&aliasdir  ,0,sizeof(aliasdir));
269   cliconfig.aliasdir = aliasdir;
270
271   // GNU CLI getopts nterface.
272   struct option ggcOption;
273   struct option *gnuOptions;
274
275   // ------------------ Process Command Line -----------------------
276
277   // if no argument print help and return
278   if (argc < 2) {
279        printHelp(programName);
280        return (-1);
281   }
282
283   // build GNU getopt info from cliOptions
284   nbcmd = sizeof (cliOptions) / sizeof (AFB_options);
285   gnuOptions = malloc (sizeof (ggcOption) * nbcmd);
286   for (ind=0; ind < nbcmd;ind++) {
287     gnuOptions [ind].name    = cliOptions[ind].name;
288     gnuOptions [ind].has_arg = cliOptions[ind].has_arg;
289     gnuOptions [ind].flag    = 0;
290     gnuOptions [ind].val     = cliOptions[ind].val;
291   }
292
293   // get all options from command line
294   while ((optc = getopt_long (argc, argv, "vsp?", gnuOptions, &optionIndex))
295         != EOF)
296   {
297     switch (optc)
298     {
299      case SET_VERBOSE:
300        verbose = 1;
301        break;
302
303     case SET_TCP_PORT:
304        if (optarg == 0) goto needValueForOption;
305        if (!sscanf (optarg, "%d", &cliconfig.httpdPort)) goto notAnInteger;
306        break;
307        
308     case SET_APITIMEOUT:
309        if (optarg == 0) goto needValueForOption;
310        if (!sscanf (optarg, "%d", &cliconfig.apiTimeout)) goto notAnInteger;
311        break;
312
313     case SET_CNTXTIMEOUT:
314        if (optarg == 0) goto needValueForOption;
315        if (!sscanf (optarg, "%d", &cliconfig.cntxTimeout)) goto notAnInteger;
316        break;
317
318     case SET_ROOT_DIR:
319        if (optarg == 0) goto needValueForOption;
320        cliconfig.rootdir   = optarg;
321        if (verbose) fprintf(stderr, "Forcing Rootdir=%s\n",cliconfig.rootdir);
322        break;       
323        
324     case SET_ROOT_BASE:
325        if (optarg == 0) goto needValueForOption;
326        cliconfig.rootbase   = optarg;
327        if (verbose) fprintf(stderr, "Forcing Rootbase=%s\n",cliconfig.rootbase);
328        break;
329
330     case SET_ROOT_API:
331        if (optarg == 0) goto needValueForOption;
332        cliconfig.rootapi   = optarg;
333        if (verbose) fprintf(stderr, "Forcing Rootapi=%s\n",cliconfig.rootapi);
334        break;
335        
336     case SET_ROOT_ALIAS:
337        if (optarg == 0) goto needValueForOption;
338        if (aliascount < MAX_ALIAS) {
339             aliasdir[aliascount].url  = strsep(&optarg,":");
340             aliasdir[aliascount].path = strsep(&optarg,":");
341             aliasdir[aliascount].len  = strlen(aliasdir[aliascount].url);
342             if (verbose) fprintf(stderr, "Alias url=%s path=%s\n", aliasdir[aliascount].url, aliasdir[aliascount].path);
343             aliascount++;
344        } else {
345            fprintf(stderr, "Too many aliases [max:%s] %s ignored\n", optarg, MAX_ALIAS-1);
346        }     
347        break;
348        
349     case SET_AUTH_TOKEN:
350        if (optarg == 0) goto needValueForOption;
351        cliconfig.token   = optarg;
352        break;
353
354     case SET_LDPATH:
355        if (optarg == 0) goto needValueForOption;
356        cliconfig.ldpaths = optarg;
357        break;
358
359     case SET_PID_FILE:
360        if (optarg == 0) goto needValueForOption;
361        cliconfig.pidfile   = optarg;
362        break;
363
364     case SET_SESSION_DIR:
365        if (optarg == 0) goto needValueForOption;
366        cliconfig.sessiondir   = optarg;
367        break;
368
369     case  SET_CONFIG_FILE:
370        if (optarg == 0) goto needValueForOption;
371        cliconfig.configfile   = optarg;
372        break;
373
374     case  SET_CACHE_TO:
375        if (optarg == 0) goto needValueForOption;
376        if (!sscanf (optarg, "%d", &cliconfig.cacheTimeout)) goto notAnInteger;
377        break;
378
379     case SET_CONFIG_EXIT:
380        if (optarg != 0) goto noValueForOption;
381        session->configsave  = 1;
382        session->forceexit   = 1;
383        break;
384
385     case SET_CONFIG_SAVE:
386        if (optarg != 0) goto noValueForOption;
387        session->configsave  = 1;
388        break;
389
390     case SET_USERID:
391        if (optarg == 0) goto needValueForOption;
392        if (!sscanf (optarg, "%s", &cliconfig.setuid)) goto notAnInteger;
393        break;
394
395     case SET_FAKE_MOD:
396        if (optarg != 0) goto noValueForOption;
397        session->fakemod  = 1;
398        break;
399
400     case SET_FORGROUND:
401        if (optarg != 0) goto noValueForOption;
402        session->foreground  = 1;
403        break;
404
405     case SET_BACKGROUND:
406        if (optarg != 0) goto noValueForOption;
407        session->background  = 1;
408        break;
409
410      case KILL_PREV_REST:
411        if (optarg != 0) goto noValueForOption;
412        session->killPrevious  = 1;
413        break;
414
415      case KILL_PREV_EXIT:
416        if (optarg != 0) goto noValueForOption;
417        session->killPrevious  = 2;
418        break;
419
420     case SET_MODE:
421        if (optarg == 0) goto needValueForOption;
422        /* TODO setting directly session->config isn't the expected path but... see configLoadFile, configStoreFile (JOBOL) */
423        if (!strcmp(optarg, "local")) session->config->mode = AFB_MODE_LOCAL;
424        else if (!strcmp(optarg, "remote")) session->config->mode = AFB_MODE_REMOTE;
425        else if (!strcmp(optarg, "global")) session->config->mode = AFB_MODE_GLOBAL;
426        else goto badMode;
427        break;
428
429     case DISPLAY_VERSION:
430        if (optarg != 0) goto noValueForOption;
431        printVersion();
432        goto normalExit;
433
434     case DISPLAY_HELP:
435      default:
436        printHelp(programName);
437        goto normalExit;
438
439     }
440   }
441  
442   // if exist merge config file with CLI arguments
443   configLoadFile  (session, &cliconfig);
444   initPlugins(session);
445
446   // ------------------ sanity check ----------------------------------------
447   if  ((session->background) && (session->foreground)) {
448     fprintf (stderr, "%s ERR: cannot select foreground & background at the same time\n",configTime());
449      exit (-1);
450   }
451
452   // ------------------ Some useful default values -------------------------
453   if  ((session->background == 0) && (session->foreground == 0)) session->foreground=1;
454
455   // open syslog if ever needed
456   openlog("AFB-log", 0, LOG_DAEMON);
457
458   // -------------- Try to kill any previous process if asked ---------------------
459   if (session->killPrevious) {
460     pid = readPidFile (session->config);  // enforce commandline option
461     switch (pid) {
462     case -1:
463       fprintf (stderr, "%s ERR:main --kill ignored no PID file [%s]\n",configTime(), session->config->pidfile);
464       break;
465     case 0:
466       fprintf (stderr, "%s ERR:main --kill ignored no active AFB process\n",configTime());
467       break;
468     default:
469       status = kill (pid,SIGINT );
470       if (status == 0) {
471              if (verbose) printf ("%s INF:main signal INTR sent to pid:%d \n", configTime(), pid);
472       } else {
473          // try kill -9
474          status = kill (pid,9);
475          if (status != 0)  fprintf (stderr, "%s ERR:main failled to killed pid=%d \n",configTime(), pid);
476       }
477     } // end switch pid
478
479     if (session->killPrevious >= 2) goto normalExit;
480   } // end killPrevious
481
482
483   // ------------------ clean exit on CTR-C signal ------------------------
484   if (signal (SIGINT, signalQuit) == SIG_ERR) {
485     fprintf (stderr, "%s Quit Signal received.",configTime());
486     return (-1);
487   }
488
489   // save exitPoint context when returning from longjmp closeSession and exit
490   status = setjmp (exitPoint); // return !+ when coming from longjmp
491   if (status != 0) {
492     if (verbose) printf ("INF:main returning from longjump after signal [%d]\n", status);
493     closeSession (session);
494     goto exitOnSignal;
495   }
496
497   // let's run this program with a low priority
498   status=nice (20);
499
500   // ------------------ Finaly Process Commands -----------------------------
501    // if --save then store config on disk upfront
502    if (session->configsave) configStoreFile (session);
503    if (session->forceexit)  exit (0);
504
505     if (session->config->setuid) {
506         int err;
507         struct passwd *passwd;
508         passwd=getpwnam(session->config->setuid);
509         
510         if (passwd == NULL) goto errorSetuid;
511         
512         err = setuid(passwd->pw_uid);
513         if (err) goto errorSetuid;
514     }
515
516     // let's not take the risk to run as ROOT
517     //if (getuid() == 0)  goto errorNoRoot;
518
519     // check session dir and create if it does not exist
520     if (sessionCheckdir (session) != AFB_SUCCESS) goto errSessiondir;
521     if (verbose) fprintf (stderr, "AFB:notice Init config done\n");
522
523
524
525     // ---- run in foreground mode --------------------
526     if (session->foreground) {
527
528         if (verbose) fprintf (stderr,"AFB:notice Foreground mode\n");
529
530         // write a pid file for --kill-previous and --raise-debug option
531         status = writePidFile (session->config, getpid());
532         if (status == -1) goto errorPidFile;
533
534         // enter listening loop in foreground
535         listenLoop(session);
536         goto exitInitLoop;
537   } // end foreground
538
539
540   // --------- run in background mode -----------
541   if (session->background) {
542
543        // if (status != 0) goto errorCommand;
544       if (verbose) printf ("AFB: Entering background mode\n");
545
546       // open /dev/console to redirect output messAFBes
547       consoleFD = open(session->config->console, O_WRONLY | O_APPEND | O_CREAT , 0640);
548       if (consoleFD < 0) goto errConsole;
549
550       // fork process when running background mode
551       pid = fork ();
552
553       // son process get all data in standalone mode
554       if (pid == 0) {
555
556              printf ("\nAFB: background mode [pid:%d console:%s]\n", getpid(),session->config->console);
557              if (verbose) printf ("AFB:info use '%s --restart --rootdir=%s # [--pidfile=%s] to restart daemon\n", programName,session->config->rootdir, session->config->pidfile);
558
559          // redirect default I/O on console
560          close (2); status=dup(consoleFD);  // redirect stderr
561          close (1); status=dup(consoleFD);  // redirect stdout
562          close (0);           // no need for stdin
563          close (consoleFD);
564
565          setsid();   // allow father process to fully exit
566              sleep (2);  // allow main to leave and release port
567
568          fprintf (stderr, "----------------------------\n");
569          fprintf (stderr, "%s INF:main background pid=%d\n", configTime(), getpid());
570          fflush  (stderr);
571
572          // if everything look OK then look forever
573          syslog (LOG_ERR, "AFB: Entering infinite loop in background mode");
574
575          // should normally never return from this loop
576          listenLoop(session);
577          syslog (LOG_ERR, "AFB:FAIL background infinite loop exited check [%s]\n", session->config->console);
578
579          goto exitInitLoop;
580       }
581
582       // if fail nothing much to do
583       if (pid == -1) goto errorFork;
584
585       // fork worked and we are in father process
586       status = writePidFile (session->config, pid);
587       if (status == -1) goto errorPidFile;
588
589       // we are in father process, we don't need this one
590       _exit (0);
591
592   } // end background-foreground
593
594 normalExit:
595   closeSession (session);   // try to close everything before leaving
596   if (verbose) printf ("\n---- Application Framework Binder Normal End ------\n");
597   exit(0);
598
599 // ------------- Fatal ERROR display error and quit  -------------
600 errorSetuid:
601   fprintf (stderr,"\nERR:AFB-daemon Failed to change UID to username=[%s]\n\n", session->config->setuid);
602   exit (-1);
603   
604 //errorNoRoot:
605 //  fprintf (stderr,"\nERR:AFB-daemon Not allow to run as root [use --seteuid=username option]\n\n");
606 //  exit (-1);
607
608 errorPidFile:
609   fprintf (stderr,"\nERR:AFB-daemon Failed to write pid file [%s]\n\n", session->config->pidfile);
610   exit (-1);
611
612 errorFork:
613   fprintf (stderr,"\nERR:AFB-daemon Failed to fork son process\n\n");
614   exit (-1);
615
616 needValueForOption:
617   fprintf (stderr,"\nERR:AFB-daemon option [--%s] need a value i.e. --%s=xxx\n\n"
618           ,gnuOptions[optionIndex].name, gnuOptions[optionIndex].name);
619   exit (-1);
620
621 noValueForOption:
622   fprintf (stderr,"\nERR:AFB-daemon option [--%s] don't take value\n\n"
623           ,gnuOptions[optionIndex].name);
624   exit (-1);
625
626 notAnInteger:
627   fprintf (stderr,"\nERR:AFB-daemon option [--%s] requirer an interger i.e. --%s=9\n\n"
628           ,gnuOptions[optionIndex].name, gnuOptions[optionIndex].name);
629   exit (-1);
630
631 badMode:
632   fprintf (stderr,"\nERR:AFB-daemon option [--%s] only accepts local, global or remote.\n\n"
633           ,gnuOptions[optionIndex].name);
634   exit (-1);
635
636 exitOnSignal:
637   fprintf (stderr,"\n%s INF:AFB-daemon pid=%d received exit signal (Hopefully crtl-C or --kill-previous !!!)\n\n"
638                  ,configTime(), getpid());
639   exit (-1);
640
641 errConsole:
642   fprintf (stderr,"\nERR:AFB-daemon cannot open /dev/console (use --foreground)\n\n");
643   exit (-1);
644
645 errSessiondir:
646   fprintf (stderr,"\nERR:AFB-daemon cannot read/write session dir\n\n");
647   exit (-1);
648
649 errSoundCard:
650   fprintf (stderr,"\nERR:AFB-daemon fail to probe sound cards\n\n");
651   exit (-1);
652
653 exitInitLoop:
654   // try to unlink pid file if any
655   if (session->background && session->config->pidfile != NULL)  unlink (session->config->pidfile);
656   exit (-1);
657
658 }; /* END AFB-daemon() */
659