Commits

Daniel Cid  committed 3a0793e

Description: Adding foreground mode.
Reviewed by:
Bug:

  • Participants
  • Parent commits 6e8fde6

Comments (0)

Files changed (11)

File src/agentlessd/main.c

 
 int main(int argc, char **argv)
 {
-    int c, test_config = 0;
+    int c, test_config = 0, run_foreground = 0;
     int uid=0,gid=0;
     char *dir  = DEFAULTDIR;
     char *user = USER;
     OS_SetName(ARGV0);
         
 
-    while((c = getopt(argc, argv, "Vdhtu:g:D:c:")) != -1){
+    while((c = getopt(argc, argv, "Vdhtfu:g:D:c:")) != -1){
         switch(c){
             case 'V':
                 print_version();
             case 'd':
                 nowDebug();
                 break;
+            case 'f':
+                run_foreground = 1;
+            break;
             case 'u':
                 if(!optarg)
                     ErrorExit("%s: -u needs an argument",ARGV0);
 
         
     /* Going on daemon mode */
-    nowDaemon();
-    goDaemonLight();
+    if(!run_foreground) 
+    {
+        nowDaemon();
+        goDaemonLight();
+    }
     chdir(dir);
 
     

File src/analysisd/analysisd.c

 int main_analysisd(int argc, char **argv)
 #endif
 {
-    int c = 0, m_queue = 0, test_config = 0;
+    int c = 0, m_queue = 0, test_config = 0,run_foreground = 0;
     char *dir = DEFAULTDIR;
     char *user = USER;
     char *group = GROUPGLOBAL;
     hourly_syscheck = 0;
     hourly_firewall = 0;
 
-    while((c = getopt(argc, argv, "Vtdhu:g:D:c:")) != -1){
+    while((c = getopt(argc, argv, "Vtdhfu:g:D:c:")) != -1){
         switch(c){
 	    case 'V':
 		print_version();
             case 'd':
                 nowDebug();
                 break;
+            case 'f':
+                run_foreground = 1;
+                break;
             case 'u':
                 if(!optarg)
                     ErrorExit("%s: -u needs an argument",ARGV0);
     }
     
     /* going on Daemon mode */
-    if(!test_config)
+    if(!test_config || !run_foreground)
     {
         nowDaemon();
         goDaemon();

File src/logcollector/main.c

 {
     int c;
     int debug_flag = 0;
-    int test_config = 0;
+    int test_config = 0,run_foreground = 0;
     char *cfg = DEFAULTCPATH;
     char *dir = DEFAULTDIR;
 
     OS_SetName(ARGV0);
         
 
-    while((c = getopt(argc, argv, "VtdhD:c:")) != -1)
+    while((c = getopt(argc, argv, "VtdhfD:c:")) != -1)
     {
         switch(c)
         {
             case 'd':
                 nowDebug();
                 break;
+            case 'f':
+                run_foreground = 1;
+                break;
             case 'D':
                 if(!optarg)
                     ErrorExit("%s: -D needs an argument",ARGV0);
     StartSIG(ARGV0);	
 
 
-    /* Going on daemon mode */
-    nowDaemon();
-    goDaemon();
+    if (!run_foreground) 
+    {
+        /* Going on daemon mode */
+        nowDaemon();
+        goDaemon();
+    }
 
 
     /* Creating PID file */

File src/monitord/main.c

 
 int main(int argc, char **argv)
 {
-    int c, test_config = 0;
+    int c, test_config = 0, run_foreground = 0;
     int uid=0,gid=0;
     char *dir  = DEFAULTDIR;
     char *user = USER;
     OS_SetName(ARGV0);
         
 
-    while((c = getopt(argc, argv, "Vdhtu:g:D:c:")) != -1){
+    while((c = getopt(argc, argv, "Vdhtfu:g:D:c:")) != -1){
         switch(c){
             case 'V':
                 print_version();
             case 'd':
                 nowDebug();
                 break;
+            case 'f':
+                run_foreground = 1;
+                break;
             case 'u':
                 if(!optarg)
                     ErrorExit("%s: -u needs an argument",ARGV0);
         exit(0);
 
         
-    /* Going on daemon mode */
-    nowDaemon();
-    goDaemon();
+    if (!run_foreground) 
+    {
+        /* Going on daemon mode */
+        nowDaemon();
+        goDaemon();
+    }
 
     
     /* Privilege separation */	

File src/os_csyslogd/main.c

 
 int main(int argc, char **argv)
 {
-    int c, test_config = 0;
+    int c, test_config = 0,run_foreground = 0;
     int uid = 0,gid = 0;
 
     /* Using MAILUSER (read only) */
     OS_SetName(ARGV0);
         
 
-    while((c = getopt(argc, argv, "vVdhtu:g:D:c:")) != -1){
+    while((c = getopt(argc, argv, "vVdhtfu:g:D:c:")) != -1){
         switch(c){
             case 'V':
                 print_version();
             case 'd':
                 nowDebug();
                 break;
+            case 'f':
+                run_foreground = 1;
+                break;
             case 'u':
                 if(!optarg)
                     ErrorExit("%s: -u needs an argument",ARGV0);
         exit(0);
         
         
-    /* Going on daemon mode */
-    nowDaemon();
-    goDaemon();
+    if (!run_foreground) 
+    {
+        /* Going on daemon mode */
+        nowDaemon();
+        goDaemon();
+    }
 
 
     

File src/os_dbd/main.c

 
 int main(int argc, char **argv)
 {
-    int c, test_config = 0;
+    int c, test_config = 0, run_foreground = 0;
     int uid = 0,gid = 0;
 
     /* Using MAILUSER (read only) */
     OS_SetName(ARGV0);
         
 
-    while((c = getopt(argc, argv, "vVdhtu:g:D:c:")) != -1){
+    while((c = getopt(argc, argv, "vVdhtfu:g:D:c:")) != -1){
         switch(c){
             case 'V':
                 db_info();
             case 'd':
                 nowDebug();
                 break;
+            case 'f':
+                run_foreground = 1;
+                break;
             case 'u':
                 if(!optarg)
                     ErrorExit("%s: -u needs an argument",ARGV0);
         exit(0);
         
         
-    /* Going on daemon mode */
-    nowDaemon();
-    goDaemon();
+    if(!run_foreground) 
+    {
+        /* Going on daemon mode */
+        nowDaemon();
+        goDaemon();
+    }
 
 
     

File src/os_execd/execd.c

 int main(int argc, char **argv)
 {
     int c;
-    int test_config = 0;
+    int test_config = 0,run_foreground = 0;
     int gid = 0,m_queue = 0;
 
     char *dir  = DEFAULTDIR;
     OS_SetName(ARGV0);
         
 
-    while((c = getopt(argc, argv, "Vtdhu:g:D:c:")) != -1){
+    while((c = getopt(argc, argv, "Vtdhfu:g:D:c:")) != -1){
         switch(c){
             case 'V':
                 print_version();
             case 'd':
                 nowDebug();
                 break;
+            case 'f':
+                run_foreground = 1;
+                break;
             case 'g':
                 if(!optarg)
                     ErrorExit("%s: -g needs an argument.",ARGV0);
     StartSIG2(ARGV0, execd_shutdown);
 
     
-    /* Going daemon */
-    nowDaemon();
-    goDaemon();
+    if (!run_foreground) 
+    {
+        /* Going daemon */
+        nowDaemon();
+        goDaemon();
+    } 
 
 
     /* Active response disabled */

File src/os_maild/maild.c

 
 int main(int argc, char **argv)
 {
-    int c, test_config = 0;
+    int c, test_config = 0,run_foreground = 0;
     int uid = 0,gid = 0;
     char *dir  = DEFAULTDIR;
     char *user = MAILUSER;
     OS_SetName(ARGV0);
         
 
-    while((c = getopt(argc, argv, "Vdhtu:g:D:c:")) != -1){
+    while((c = getopt(argc, argv, "Vdhtfu:g:D:c:")) != -1){
         switch(c){
             case 'V':
                 print_version();
             case 'd':
                 nowDebug();
                 break;
+            case 'f':
+                run_foreground = 1;
+                break;
             case 'u':
                 if(!optarg)
                     ErrorExit("%s: -u needs an argument",ARGV0);
         exit(0);
 
         
-    /* Going on daemon mode */
-    nowDaemon();
-    goDaemon();
+    if(!run_foreground) 
+    {
+        nowDaemon();
+        goDaemon();
+    }
 
     
     /* Privilege separation */	

File src/remoted/main.c

 {
     int i = 0,c = 0;
     int uid = 0, gid = 0;
-    int test_config = 0;
+    int test_config = 0,run_foreground = 0;
     
     char *cfg = DEFAULTCPATH;
     char *dir = DEFAULTDIR;
     OS_SetName(ARGV0);
 
     
-    while((c = getopt(argc, argv, "Vdthu:g:c:D:")) != -1){
+    while((c = getopt(argc, argv, "Vdthfu:g:c:D:")) != -1){
         switch(c){
             case 'V':
                 print_version();
             case 'd':
                 nowDebug();
                 break;
+            case 'f':
+                run_foreground = 1;
+                break;
             case 'u':
                 if(!optarg)
                     ErrorExit("%s: -u needs an argument",ARGV0);
     i = getpid();
 
 
-    /* Going on daemon */
-    nowDaemon();
-    goDaemon();
+    if(!run_foreground) 
+    {
+        nowDaemon();
+        goDaemon();
+    }
 
     
     /* Setting new group */

File src/shared/help.c

     print_out("    -h          This help message");
     print_out("    -d          Execute in debug mode");
     print_out("    -t          Test configuration");
+    print_out("    -f          Run in foreground");
     print_out("    -u <user>   Run as 'user'");
     print_out("    -g <group>  Run as 'group'");
     print_out("    -c <config> Read the 'config' file");

File src/syscheckd/syscheck.c

 int main(int argc, char **argv)
 {
     int c,r;
-    int test_config = 0;
+    int test_config = 0,run_foreground = 0;
     
     char *cfg = DEFAULTCPATH;
     
     OS_SetName(ARGV0);
         
     
-    while((c = getopt(argc, argv, "VtdhD:c:")) != -1)
+    while((c = getopt(argc, argv, "VtdhfD:c:")) != -1)
     {
         switch(c)
         {
             case 'd':
                 nowDebug();
                 break;
+            case 'f':
+                run_foreground = 1;
+                break;
             case 'D':
                 if(!optarg)
                     ErrorExit("%s: -D needs an argument",ARGV0);
 
 
 
-    /* Setting daemon flag */
-    nowDaemon();
-
-
-    /* Entering in daemon mode now */
-    goDaemon();
-
+    if (!run_foreground) 
+    {
+        nowDaemon();
+        goDaemon();
+    }
    
     /* Initial time to settle */
     sleep(syscheck.tsleep + 2);