Changeset 481 for trunk/src/samhain.c


Ignore:
Timestamp:
Jul 18, 2015, 5:06:52 PM (10 years ago)
Author:
katerina
Message:

Enhancements and fixes for tickets #374, #375, #376, #377, #378, and #379.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/samhain.c

    r473 r481  
    7171#include "sh_readconf.h"
    7272#include "sh_hash.h"
     73#include "sh_dbIO.h"
    7374#include "sh_restrict.h"
    7475
     
    7879#include "sh_gpg.h"
    7980#include "sh_mem.h"
    80 #include "sh_forward.h"
     81#include "sh_xfer.h"
    8182#include "sh_tools.h"
    8283#include "sh_hash.h"
     
    8889#include "sh_ignore.h"
    8990#include "sh_prelink.h"
     91#include "sh_sem.h"
    9092#endif
    9193
     
    120122volatile  int      sig_termfast;           /* SIGTERM */
    121123volatile  int      sig_force_check;        /* SIGTTOU */
     124volatile  int      sh_load_delta_flag;
    122125long int           eintr__result;
    123126char               sh_sig_msg[SH_MINIBUF];
     
    313316  ErrFlag[0] |= (1 << 11);
    314317#endif
     318
     319  sh.delayload = 0;
     320
    315321#ifdef MKA_13
    316322  ErrFlag[0] |= (1 << 12);
     
    337343  sig_termfast           = 0;           /* SIGTERM */
    338344  sig_force_check        = 0;           /* SIGTTOU */
     345  sh_load_delta_flag     = 0;
    339346  strcpy ( sh_sig_msg, _("None"));
    340347
     
    373380
    374381  sh.pid = (UINT64) getpid();
     382
     383  sh.outpath = NULL;
    375384
    376385  /* The flags.
     
    647656    {
    648657
    649       skey->mlock_failed = SL_FALSE;
     658      skey->mlock_failed = S_FALSE;
    650659      skey->rngI         = BAD;
    651660      /* properly initialized later
     
    718727#endif
    719728
    720   SL_ENTER(_("exit_handler"));
    721 
    722729#if defined(SH_WITH_SERVER)
    723730  sh_socket_remove ();
     
    751758   */
    752759  sh_html_zero();
    753   /* sh_forward_html_write(); */
    754760#endif
    755761
     
    775781#endif
    776782#if defined(SH_WITH_SERVER)
    777   sh_forward_free_all ();
     783  sh_xfer_free_all ();
    778784#endif
    779785#if defined(SH_WITH_MAIL)
     
    796802  /* --- Exit Message. ---
    797803   */
     804  if (sh.flag.exit == EXIT_FAILURE && !strcmp(sh_sig_msg, _("None")))
     805    sl_strlcpy(sh_sig_msg, _("exit_failure"), SH_MINIBUF);
     806  if (sh.flag.exit == EXIT_SUCCESS && !strcmp(sh_sig_msg, _("None")))
     807    sl_strlcpy(sh_sig_msg, _("exit_success"), SH_MINIBUF);
    798808  sh_error_handle ((-1), FIL__, __LINE__, sh.flag.exit, MSG_EXIT_NORMAL,
    799809                   sh.prg_name, sh_sig_msg);
     
    805815  /* --- Restrict error logging to stderr. ---
    806816   */
    807 #ifdef WITH_MESSAGE_QUEUE
    808817  close_ipc ();
    809 #endif
    810818  sh_error_only_stderr (S_TRUE);
    811 
    812819
    813820  /* --- Remove lock, delete critical information. ---
     
    12151222}
    12161223
     1224
     1225void do_reconf()
     1226{
     1227  int status, modnum;
     1228
     1229  sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_RECONF);
     1230 
     1231  sh_thread_pause_flag = S_TRUE;
     1232 
     1233#if defined(WITH_EXTERNAL)
     1234  /* delete list of external tasks
     1235   */
     1236  (void) sh_ext_cleanup();
     1237#endif
     1238#if defined(SH_WITH_MAIL)
     1239  sh_nmail_free();
     1240#endif
     1241 
     1242  /* delete the file list, make all database
     1243   * entries visible (allignore = FALSE)
     1244   */
     1245  (void) sh_files_deldirstack ();
     1246  (void) sh_files_delfilestack ();
     1247  (void) sh_files_delglobstack ();
     1248  (void) sh_ignore_clean ();
     1249  (void) hash_full_tree ();
     1250  sh_audit_delete_all ();
     1251 
     1252 
     1253#if defined(SH_WITH_CLIENT)
     1254  reset_count_dev_server();
     1255#endif
     1256#if defined(SH_WITH_CLIENT) || defined(SH_STANDALONE)
     1257  sh_restrict_purge ();
     1258 
     1259 
     1260  FileSchedOne = free_sched(FileSchedOne);
     1261  FileSchedTwo = free_sched(FileSchedTwo);
     1262 
     1263  for (modnum = 0; modList[modnum].name != NULL; ++modnum)
     1264    {
     1265      /* sh_thread_pause_flag is true, and we block in lock
     1266       * until check has returned, so we are sure check will
     1267       * not run until sh_thread_pause_flag is set to false
     1268       */
     1269      /* if (modList[modnum].initval >= SH_MOD_ACTIVE) */
     1270      (void) modList[modnum].mod_reconf();
     1271    }
     1272#endif
     1273 
     1274  reset_count_dev_console();
     1275  reset_count_dev_time();
     1276 
     1277  (void) sh_unix_maskreset();
     1278 
     1279#ifdef RELOAD_DATABASE
     1280  sh_hash_hashdelete();
     1281
     1282  if (0 != sl_strcmp(file_path('D', 'R'), _("REQ_FROM_SERVER")))
     1283    {
     1284      char hashbuf[KEYBUF_SIZE];
     1285      (void) sl_strlcpy(sh.data.hash,
     1286                        sh_tiger_hash (file_path('D', 'R'),
     1287                                       TIGER_FILE, TIGER_NOLIM,
     1288                                       hashbuf, sizeof(hashbuf)),
     1289                        KEY_LEN+1);
     1290    }
     1291#endif
     1292  (void) sl_trust_purge_user();
     1293  (void) sh_files_hle_reg (NULL);
     1294  (void) sh_prelink_run (NULL, NULL, 0, 0);
     1295 
     1296  /* --------------------------
     1297   * --- READ CONFIGURATION ---
     1298   * --------------------------
     1299   */
     1300  (void) sh_readconf_read ();
     1301  sig_config_read_again = 0;
     1302  (void) sh_files_setrec();
     1303  (void) sh_files_test_setup();
     1304  sh_audit_commit ();
     1305 
     1306  if (0 != sh.flag.nice)
     1307    {
     1308#ifdef HAVE_SETPRIORITY
     1309      setpriority(PRIO_PROCESS, 0, sh.flag.nice);
     1310#else
     1311      nice(sh.flag.nice);
     1312#endif
     1313    }
     1314 
     1315  if (sh.flag.checkSum == SH_CHECK_INIT)
     1316    {
     1317      sh.flag.isdaemon = S_FALSE;
     1318      sh.flag.loop     = S_FALSE;
     1319    }
     1320 
     1321 
     1322  /* --- Initialize modules. ---
     1323   */
     1324  TPT((0, FIL__, __LINE__, _("msg=<Initialize modules.>\n")));
     1325  for (modnum = 0; modList[modnum].name != NULL; ++modnum)
     1326    {
     1327      status = modList[modnum].mod_init(&(modList[modnum]));
     1328     
     1329      if (status < 0)
     1330        {
     1331          if (status == (-1)) {
     1332            sh_error_handle (SH_ERR_NOTICE, FIL__, __LINE__,
     1333                             status, MSG_MOD_FAIL,
     1334                             _(modList[modnum].name),
     1335                             status+SH_MOD_OFFSET);
     1336          } else {
     1337            sh_error_handle ((-1), FIL__, __LINE__,
     1338                             status, MSG_MOD_FAIL,
     1339                             _(modList[modnum].name),
     1340                             status+SH_MOD_OFFSET);
     1341          }
     1342          modList[modnum].initval = SH_MOD_FAILED;
     1343        }
     1344      else
     1345        {
     1346          sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_MOD_OK,
     1347                           _(modList[modnum].name));
     1348          modList[modnum].initval = status;
     1349        }
     1350    }
     1351 
     1352  /* module is properly set up now
     1353   */
     1354  sh_thread_pause_flag = S_FALSE;
     1355
     1356  return;
     1357}
     1358
     1359static void check_signals (volatile int *flag_check_1,
     1360                           volatile int * flag_check_2)
     1361{
     1362  if (sig_raised > 0)
     1363    {
     1364     
     1365      TPT((0, FIL__, __LINE__, _("msg=<Process a signal.>\n")))
     1366       
     1367        if (sig_termfast == 1)  /* SIGTERM */
     1368          {
     1369            TPT((0, FIL__, __LINE__, _("msg=<Terminate.>\n")));
     1370            --sig_raised; --sig_urgent;
     1371            aud_exit (FIL__, __LINE__, EXIT_SUCCESS);
     1372          }
     1373     
     1374      if (sig_force_check == 1) /* SIGTTOU */
     1375        {
     1376          TPT((0, FIL__, __LINE__, _("msg=<Check run triggered.>\n")));
     1377          *flag_check_1 = 1; *flag_check_2 = 1;
     1378          sig_force_check = 0; --sig_raised;
     1379          sh_sem_trylock();
     1380        }
     1381     
     1382      if (sig_config_read_again == 1 && /* SIGHUP */
     1383          sh_global_suspend_flag == 0)
     1384        {
     1385          TPT((0, FIL__, __LINE__, _("msg=<Re-read configuration.>\n")));
     1386          do_reconf();
     1387          --sig_raised;
     1388        }
     1389     
     1390      if (sig_fresh_trail == 1) /* SIGIOT */
     1391        {
     1392          if (sh_global_suspend_flag == 0)
     1393            {
     1394              SH_MUTEX_LOCK(mutex_thread_nolog);
     1395             
     1396              /* Logfile access
     1397               */
     1398#ifdef SH_USE_XML
     1399              (void) sh_log_file (NULL, NULL);
     1400#endif
     1401              TPT((0, FIL__, __LINE__, _("msg=<Logfile stop/restart.>\n")));
     1402              sh_error_only_stderr (S_TRUE);
     1403              (void) sh_unix_rm_lock_file(sh.srvlog.name);
     1404              (void) retry_msleep(3, 0);
     1405              sh.flag.log_start = S_TRUE;
     1406              sh_error_only_stderr (S_FALSE);
     1407              sh_thread_pause_flag = S_FALSE;
     1408              sig_fresh_trail       = 0;
     1409              --sig_raised;
     1410              SH_MUTEX_UNLOCK(mutex_thread_nolog);
     1411            }
     1412        }
     1413     
     1414      if (sig_terminate == 1)  /* SIGQUIT */
     1415        {
     1416          TPT((0, FIL__, __LINE__, _("msg=<Terminate.>\n")));
     1417          strncpy (sh_sig_msg, _("Quit"), 20);
     1418          --sig_raised;
     1419          aud_exit (FIL__, __LINE__, EXIT_SUCCESS);
     1420        }
     1421         
     1422      if (sig_debug_switch == 1)  /* SIGUSR1 */
     1423        {
     1424          TPT((0, FIL__, __LINE__, _("msg=<Debug switch.>\n")));
     1425          sh_error_dbg_switch();
     1426          sig_debug_switch = 0;
     1427          --sig_raised;
     1428        }
     1429         
     1430      if (sig_suspend_switch > 0)  /* SIGUSR2 */
     1431        {
     1432          TPT((0, FIL__, __LINE__, _("msg=<Suspend switch.>\n")));
     1433          if (sh_global_suspend_flag != 1) {
     1434            SH_MUTEX_LOCK_UNSAFE(mutex_thread_nolog);
     1435            sh_global_suspend_flag = 1;
     1436            sh_error_handle((-1), FIL__, __LINE__, 0, MSG_SUSPEND,
     1437                            sh.prg_name);
     1438          } else {
     1439            sh_global_suspend_flag = 0;
     1440            SH_MUTEX_UNLOCK_UNSAFE(mutex_thread_nolog);
     1441          }
     1442          --sig_suspend_switch;
     1443          --sig_raised; --sig_urgent;
     1444        }
     1445
     1446      if (sh_load_delta_flag > 0 &&
     1447          sh_global_suspend_flag == 0)  /* DELTA Command */
     1448        {
     1449          if (0 == sh_dbIO_load_delta())
     1450            {
     1451              --sh_load_delta_flag; --sig_raised;
     1452            }
     1453        }
     1454
     1455      sig_raised = (sig_raised < 0) ? 0 : sig_raised;
     1456      sig_urgent = (sig_urgent < 0) ? 0 : sig_urgent;
     1457      TPT((0, FIL__, __LINE__, _("msg=<End signal processing.>\n")));
     1458    }
     1459  return;
     1460}
     1461
     1462void check_for_delta_db()
     1463{
     1464  /* Need to contact the server.
     1465   */
     1466  sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_CHECK_2);
     1467
     1468  if (sig_raised > 0 && sh_load_delta_flag > 0)  /* DELTA Command */
     1469    {
     1470      /* There was a DELTA Command
     1471       */
     1472      if (0 == sh_dbIO_load_delta())
     1473        {
     1474          --sh_load_delta_flag; --sig_raised;
     1475        }
     1476    }
     1477  return;
     1478}
     1479
    12171480#endif
    12181481
     
    12291492{
    12301493#if defined(INET_SYSLOG)
    1231   extern int    create_syslog_socket (int flag);
     1494  extern int    sh_xfer_create_syslog_socket (int flag);
    12321495#endif
    12331496#if defined(SH_WITH_SERVER)
     
    12721535  /* --- Close all but first three file descriptors. ---
    12731536   */
    1274   sh_unix_closeall(3, -1, SL_FALSE); /* at program start */
     1537  sh_unix_closeall(3, -1, S_FALSE); /* at program start */
    12751538
    12761539
     
    15351798  /* --- load database; checksum of database
    15361799   */
    1537 #if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
    1538   TPT((0, FIL__, __LINE__, _("msg=<Get checksum of the database.>\n")))
    1539   if (sh.flag.checkSum == SH_CHECK_CHECK)
    1540     {
    1541       if (0 != sl_strcmp(file_path('D', 'R'), _("REQ_FROM_SERVER")))
    1542         {
    1543           char hashbuf[KEYBUF_SIZE];
    1544           (void) sl_strlcpy(sh.data.hash,
    1545                             sh_tiger_hash (file_path('D', 'R'),
    1546                                            TIGER_FILE, TIGER_NOLIM,
    1547                                            hashbuf, sizeof(hashbuf)),
    1548                             KEY_LEN+1);
    1549         }
    1550 
    1551       /* this eventually fetches the file from server to get checksum
    1552        */
    1553       sh_hash_init ();
    1554     }
     1800#if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
     1801  if (0 == sh.delayload)
     1802    sh_hash_init_and_checksum();
    15551803#endif
    15561804
     
    15641812    }
    15651813
     1814#if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
     1815  if (sh.delayload)
     1816    {
     1817      sleep(sh.delayload);
     1818      sh_hash_init_and_checksum();
     1819    }
     1820#endif
     1821
    15661822  /* --- drop privileges eventually ---
    15671823   */
     
    15691825  sh_create_tcp_socket ();
    15701826#if defined(INET_SYSLOG)
    1571   create_syslog_socket (S_TRUE);
     1827  sh_xfer_create_syslog_socket (S_TRUE);
    15721828#endif
    15731829  SL_REQUIRE(sl_policy_get_real(DEFAULT_IDENT) == SL_ENONE,
     
    15911847   */
    15921848#if defined(INET_SYSLOG) && defined(SH_WITH_SERVER)
    1593   create_syslog_socket (S_FALSE);
     1849  sh_xfer_create_syslog_socket (S_FALSE);
    15941850#endif
    15951851
     
    16561912
    16571913 
    1658   if ((skey == NULL) || (skey->mlock_failed == SL_TRUE))
     1914  if ((skey == NULL) || (skey->mlock_failed == S_TRUE))
    16591915    sh_error_handle ((-1), FIL__, __LINE__, EPERM, MSG_MLOCK);
    16601916
     
    16781934  if (sh.flag.isserver == S_TRUE)
    16791935    {
    1680       sh_receive();
     1936      sh_xfer_start_server();
    16811937      TPT((0, FIL__, __LINE__, _("msg=<End server.>\n")))
    16821938      aud_exit (FIL__, __LINE__, EXIT_SUCCESS);
    16831939    }
    16841940#else
    1685   sh_receive();
     1941  sh_xfer_start_server();
    16861942  TPT((0, FIL__, __LINE__, _("msg=<End server.>\n")))
    16871943  aud_exit (FIL__, __LINE__, EXIT_SUCCESS);
     
    17452001    }
    17462002
     2003  /*  --------  CREATE SEMAPHORE  ---------
     2004   */
     2005  sh_sem_open();
     2006
    17472007  /*  --------  MAIN LOOP  ---------
    17482008   */
     
    17632023      tcurrent = time (NULL);
    17642024
    1765       if (sig_raised > 0)
    1766         {
    1767 
    1768           TPT((0, FIL__, __LINE__, _("msg=<Process a signal.>\n")))
    1769 
    1770           if (sig_termfast == 1)  /* SIGTERM */
    1771             {
    1772               TPT((0, FIL__, __LINE__, _("msg=<Terminate.>\n")));
    1773               /* strncpy (sh_sig_msg, _("SIGTERM"), 20); */
    1774               --sig_raised; --sig_urgent;
    1775               aud_exit (FIL__, __LINE__, EXIT_SUCCESS);
    1776             }
    1777 
    1778           if (sig_force_check == 1) /* SIGTTOU */
    1779             {
    1780               TPT((0, FIL__, __LINE__, _("msg=<Check run triggered.>\n")));
    1781               flag_check_1 = 1;
    1782               flag_check_2 = 1;
    1783               sig_force_check = 0;
    1784               --sig_raised;
    1785             }
    1786          
    1787           if (sig_config_read_again == 1 && /* SIGHUP */
    1788               sh_global_suspend_flag == 0)
    1789             {
    1790               TPT((0, FIL__, __LINE__, _("msg=<Re-read configuration.>\n")))
    1791               sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_RECONF);
    1792 
    1793               sh_thread_pause_flag = S_TRUE;
    1794 
    1795 #if defined(WITH_EXTERNAL)
    1796               /* delete list of external tasks
    1797                */
    1798               (void) sh_ext_cleanup();
    1799 #endif
    1800 #if defined(SH_WITH_MAIL)
    1801               sh_nmail_free();
    1802 #endif
    1803 
    1804               /* delete the file list, make all database
    1805                * entries visible (allignore = FALSE)
    1806                */
    1807               (void) sh_files_deldirstack ();
    1808               (void) sh_files_delfilestack ();
    1809               (void) sh_files_delglobstack ();
    1810               (void) sh_ignore_clean ();
    1811               (void) hash_full_tree ();
    1812               sh_audit_delete_all ();
    1813 
    1814 
    1815 #if defined(SH_WITH_CLIENT)
    1816               reset_count_dev_server();
    1817 #endif
    1818 #if defined(SH_WITH_CLIENT) || defined(SH_STANDALONE)
    1819               sh_restrict_purge ();
    1820 
    1821 
    1822               FileSchedOne = free_sched(FileSchedOne);
    1823               FileSchedTwo = free_sched(FileSchedTwo);
    1824 
    1825               for (modnum = 0; modList[modnum].name != NULL; ++modnum)
    1826                 {
    1827                   /* sh_thread_pause_flag is true, and we block in lock
    1828                    * until check has returned, so we are sure check will
    1829                    * not run until sh_thread_pause_flag is set to false
    1830                    */
    1831                   /* if (modList[modnum].initval >= SH_MOD_ACTIVE) */
    1832                   (void) modList[modnum].mod_reconf();
    1833                 }
    1834 #endif
    1835 
    1836               reset_count_dev_console();
    1837               reset_count_dev_time();
    1838 
    1839               (void) sh_unix_maskreset();
    1840  
    1841               /* Should this be included ???
    1842                * (i.e. should we reload the database ?)
    1843                */
    1844 #ifdef RELOAD_DATABASE
    1845               sh_hash_hashdelete();
    1846 
    1847               if (0 != sl_strcmp(file_path('D', 'R'), _("REQ_FROM_SERVER")))
    1848                 {
    1849                   char hashbuf[KEYBUF_SIZE];
    1850                   (void) sl_strlcpy(sh.data.hash,
    1851                                     sh_tiger_hash (file_path('D', 'R'),
    1852                                                    TIGER_FILE, TIGER_NOLIM,
    1853                                                    hashbuf, sizeof(hashbuf)),
    1854                                     KEY_LEN+1);
    1855                 }
    1856 #endif
    1857               (void) sl_trust_purge_user();
    1858               (void) sh_files_hle_reg (NULL);
    1859               (void) sh_prelink_run (NULL, NULL, 0);
    1860 
    1861               /* --------------------------
    1862                * --- READ CONFIGURATION ---
    1863                * --------------------------
    1864                */
    1865               (void) sh_readconf_read ();
    1866               sig_config_read_again = 0;
    1867               (void) sh_files_setrec();
    1868               (void) sh_files_test_setup();
    1869               sh_audit_commit ();
    1870 
    1871               if (0 != sh.flag.nice)
    1872                 {
    1873 #ifdef HAVE_SETPRIORITY
    1874                   setpriority(PRIO_PROCESS, 0, sh.flag.nice);
    1875 #else
    1876                   nice(sh.flag.nice);
    1877 #endif
    1878                 }
    1879 
    1880               if (sh.flag.checkSum == SH_CHECK_INIT)
    1881                 {
    1882                   sh.flag.isdaemon = S_FALSE;
    1883                   sh.flag.loop     = S_FALSE;
    1884                 }
    1885 
    1886 
    1887               /* --- Initialize modules. ---
    1888                */
    1889               TPT((0, FIL__, __LINE__, _("msg=<Initialize modules.>\n")));
    1890               for (modnum = 0; modList[modnum].name != NULL; ++modnum)
    1891                 {
    1892                   status = modList[modnum].mod_init(&(modList[modnum]));
    1893 
    1894                   if (status < 0)
    1895                     {
    1896                       if (status == (-1)) {
    1897                         sh_error_handle (SH_ERR_NOTICE, FIL__, __LINE__,
    1898                                          status, MSG_MOD_FAIL,
    1899                                          _(modList[modnum].name),
    1900                                          status+SH_MOD_OFFSET);
    1901                       } else {
    1902                         sh_error_handle ((-1), FIL__, __LINE__,
    1903                                          status, MSG_MOD_FAIL,
    1904                                          _(modList[modnum].name),
    1905                                          status+SH_MOD_OFFSET);
    1906                       }
    1907                       modList[modnum].initval = SH_MOD_FAILED;
    1908                     }
    1909                   else
    1910                     {
    1911                       sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_MOD_OK,
    1912                                        _(modList[modnum].name));
    1913                       modList[modnum].initval = status;
    1914                     }
    1915                 }
    1916 
    1917               /* module is properly set up now
    1918                */
    1919               sh_thread_pause_flag = S_FALSE;
    1920              
    1921               --sig_raised;
    1922             }
    1923          
    1924           if (sig_fresh_trail == 1) /* SIGIOT */
    1925             {
    1926               if (sh_global_suspend_flag == 0)
    1927                 {
    1928                   SH_MUTEX_LOCK(mutex_thread_nolog);
    1929 
    1930                   /* Logfile access
    1931                    */
    1932 #ifdef SH_USE_XML
    1933                   (void) sh_log_file (NULL, NULL);
    1934 #endif
    1935                   TPT((0, FIL__, __LINE__, _("msg=<Logfile stop/restart.>\n")));
    1936                   sh_error_only_stderr (S_TRUE);
    1937                   (void) sh_unix_rm_lock_file(sh.srvlog.name);
    1938                   (void) retry_msleep(3, 0);
    1939                   sh.flag.log_start = S_TRUE;
    1940                   sh_error_only_stderr (S_FALSE);
    1941                   sh_thread_pause_flag = S_FALSE;
    1942                   sig_fresh_trail       = 0;
    1943                   --sig_raised;
    1944                   SH_MUTEX_UNLOCK(mutex_thread_nolog);
    1945                 }
    1946             }
    1947          
    1948           if (sig_terminate == 1)  /* SIGQUIT */
    1949             {
    1950               TPT((0, FIL__, __LINE__, _("msg=<Terminate.>\n")));
    1951               strncpy (sh_sig_msg, _("Quit"), 20);
    1952               --sig_raised; --sig_urgent;
    1953               aud_exit (FIL__, __LINE__, EXIT_SUCCESS);
    1954             }
    1955          
    1956           if (sig_debug_switch == 1)  /* SIGUSR1 */
    1957             {
    1958               TPT((0, FIL__, __LINE__, _("msg=<Debug switch.>\n")));
    1959               sh_error_dbg_switch();
    1960               sig_debug_switch = 0;
    1961               --sig_raised;
    1962             }
    1963          
    1964           if (sig_suspend_switch > 0)  /* SIGUSR2 */
    1965             {
    1966               TPT((0, FIL__, __LINE__, _("msg=<Suspend switch.>\n")));
    1967               if (sh_global_suspend_flag != 1) {
    1968                 SH_MUTEX_LOCK_UNSAFE(mutex_thread_nolog);
    1969                 sh_global_suspend_flag = 1;
    1970                 sh_error_handle((-1), FIL__, __LINE__, 0, MSG_SUSPEND,
    1971                                 sh.prg_name);
    1972               } else {
    1973                 sh_global_suspend_flag = 0;
    1974                 SH_MUTEX_UNLOCK_UNSAFE(mutex_thread_nolog);
    1975               }
    1976               --sig_suspend_switch;
    1977               --sig_raised; --sig_urgent;
    1978             }
    1979           sig_raised = (sig_raised < 0) ? 0 : sig_raised;
    1980           sig_urgent = (sig_urgent < 0) ? 0 : sig_urgent;
    1981           TPT((0, FIL__, __LINE__, _("msg=<End signal processing.>\n")));
    1982         }
    1983      
    1984       if (sh_global_suspend_flag == 1)
    1985         {
     2025      do {
     2026        check_signals(&flag_check_1, &flag_check_2);
     2027        if (sh_global_suspend_flag == 1)
    19862028          (void) retry_msleep (1, 0);
    1987           continue;
    1988         }
     2029      } while (sh_global_suspend_flag == 1);
    19892030     
    19902031      /* see whether its time to check files
     
    20262067          (flag_check_1 == 1 || flag_check_2 == 1))
    20272068        {
     2069          sh_sem_trylock();
     2070
     2071          /* Starting a check now, so make sure to fetch delta DB
     2072           * if there is one to download.
     2073           */
     2074          check_for_delta_db();
     2075
    20282076          SH_INOTIFY_IFUSED( sh.flag.inotify |= SH_INOTIFY_INSCAN; );
    20292077          /* Refresh list files matching glob patterns.
     
    20652113            (void) sh_files_chk ();
    20662114
    2067           if (sig_urgent > 0)
    2068             continue;
    2069 
     2115          if (sig_urgent > 0) { sh_sem_unlock(sh.statistics.files_report); continue; }
    20702116          /*
    20712117           * check for files not visited
     
    20772123            }
    20782124
    2079           if (sig_urgent > 0)
    2080             continue;
     2125          if (sig_urgent > 0) { sh_sem_unlock(sh.statistics.files_report); continue; }
    20812126
    20822127          /* reset
     
    20842129          TPT((0, FIL__, __LINE__, _("msg=<Reset status.>\n")))
    20852130          sh_dirs_reset  ();
    2086           if (sig_urgent > 0)
    2087             continue;
     2131
     2132          if (sig_urgent > 0) { sh_sem_unlock(sh.statistics.files_report); continue; }
    20882133
    20892134          sh_files_reset ();
     2135          check_done   = 1;
     2136
    20902137          flag_check_1 = 0;
    20912138          flag_check_2 = 0;
    2092           check_done   = 1;
     2139          sh_sem_unlock(sh.statistics.files_report);
     2140
    20932141          SH_INOTIFY_IFUSED( sh.flag.inotify &= ~SH_INOTIFY_INSCAN; );
    20942142          SH_INOTIFY_IFUSED( sh.flag.inotify &= ~SH_INOTIFY_DOSCAN; );
    20952143
    2096           (void) sh_prelink_run (NULL, NULL, 0);
    2097 
    2098           if (sig_urgent > 0)
    2099             continue;
     2144          (void) sh_prelink_run (NULL, NULL, 0, 0);
     2145
     2146          if (sig_urgent > 0) continue;
    21002147
    21012148          runtim = time(NULL) - sh.statistics.time_start;
     
    21302177          sh.fileCheck.alarm_last = time (NULL);
    21312178
    2132           if (sig_urgent > 0)
    2133             continue;
     2179          if (sig_urgent > 0) continue;
    21342180
    21352181          /*
     
    21422188        }
    21432189     
    2144       if (sig_urgent > 0)
    2145         continue;
     2190      if (sig_urgent > 0) continue;
    21462191     
    21472192      /* execute modules
     
    21612206       */
    21622207      if      (sh.flag.checkSum == SH_CHECK_INIT)
    2163         sh_hash_pushdata (NULL, NULL);
     2208        sh_dbIO_data_write (NULL, NULL);
    21642209
    21652210      /* write out database
     
    21682213          sh.flag.update == S_TRUE &&
    21692214          check_done == 1)
    2170         sh_hash_writeout ();
     2215        sh_dbIO_writeout_update ();
    21712216
    21722217      /* no-op unless MEM_LOG is defined in sh_mem.c
     
    21962241      /* no loop if not daemon
    21972242       */
    2198       if (sh.flag.isdaemon != S_TRUE && sh.flag.loop == S_FALSE)
    2199         break;
    2200       if (sig_urgent > 0)
    2201         continue;
     2243      if (sh.flag.isdaemon != S_TRUE && sh.flag.loop == S_FALSE) break;
     2244      if (sig_urgent > 0) continue;
    22022245
    22032246      /* see whether its time to send mail
     
    22112254        }
    22122255#endif
    2213       if (sig_urgent > 0)
    2214         continue;
     2256      if (sig_urgent > 0) continue;
    22152257           
    22162258      /* log the timestamp
     
    22322274      (void) taus_seed();
    22332275     
    2234       if (sig_urgent > 0)
    2235         continue;
     2276      if (sig_urgent > 0) continue;
    22362277     
    22372278      /* reset cache
     
    22662307#endif
    22672308
    2268 #if 0
    2269   {
    2270     char command[128];
    2271     sprintf(command, "/bin/cat /proc/%d/status", (int) getpid());
    2272     system(command); /* flawfinder: ignore *//* debug code */
    2273     malloc_stats();
    2274   }
    2275 #endif
    2276 
    22772309  aud_exit (FIL__, __LINE__, EXIT_SUCCESS);
    22782310  SL_RETURN(0, _("main"));
Note: See TracChangeset for help on using the changeset viewer.