pluginscheduler.c 18.4 KB
Newer Older
Lock Lin's avatar
Lock Lin committed
1
/* OpenVAS
2
* $Id: pluginscheduler.c 25491 2016-06-13 11:18:03Z kroosec $
Lock Lin's avatar
Lock Lin committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
* Description: Tells openvassd which plugin should be executed next.
*
* Authors: - Renaud Deraison <deraison@nessus.org> (Original pre-fork develoment)
*          - Tim Brown <mailto:timb@openvas.org> (Initial fork)
*          - Laban Mwangi <mailto:labanm@openvas.org> (Renaming work)
*          - Tarik El-Yassem <mailto:tarik@openvas.org> (Headers section)
*
* Copyright:
* Portions Copyright (C) 2006 Software in the Public Interest, Inc.
* Based on work Copyright (C) 1998 - 2006 Tenable Network Security, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*
*/

#include <string.h> /* for strcmp() */
31 32

#include <openvas/base/nvti.h>  /* for nvti_t */
Lock Lin's avatar
Lock Lin committed
33 34

#include <openvas/misc/nvt_categories.h>  /* for ACT_SCANNER */
35
#include <openvas/misc/plugutils.h>  /* for plug_get_launch */
Lock Lin's avatar
Lock Lin committed
36

37
#include <openvas/base/nvticache.h>     /* for nvticache_t */
Lock Lin's avatar
Lock Lin committed
38

39
#include <glib.h>
Lock Lin's avatar
Lock Lin committed
40 41 42 43 44 45 46 47 48 49 50 51

#include "pluginscheduler.h"
#include "pluginload.h"
#include "pluginlaunch.h"
#include "log.h"

/** @TODO
 * This important module needs documentation and comments.
 */

#define HASH_MAX 2713

52
struct hash
Lock Lin's avatar
Lock Lin committed
53
{
54 55 56 57 58 59 60 61 62 63
  char *name;
  struct scheduler_plugin *plugin;
  gchar **dependencies;
  int num_deps;
  struct hash **dependencies_ptr;
  gchar **ports;
  struct hash *next;
};

struct list
Lock Lin's avatar
Lock Lin committed
64
{
65 66 67 68
  struct scheduler_plugin *plugin;
  struct list *next;
  struct list *prev;
};
Lock Lin's avatar
Lock Lin committed
69

70 71 72 73 74 75 76
struct plist
{
  gchar *name;
  int occurences;
  struct plist *next;
  struct plist *prev;
};
Lock Lin's avatar
Lock Lin committed
77

78 79 80 81 82 83
struct plugins_scheduler
{
  struct hash *hash;                /**< Hash list of the plugins.   */
  struct list *list[ACT_LAST + 1];  /**< Linked list of the plugins. */
  struct plist *plist;              /**< Ports currently in use.     */
};
Lock Lin's avatar
Lock Lin committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

static unsigned int
mkhash (char *name)
{
  return g_str_hash (name) % HASH_MAX;
}


/*---------------------------------------------------------------------------*
 *
 * A minimalist HASH stucture
 *
 *---------------------------------------------------------------------------*/

static struct hash *
hash_init ()
{
101
  struct hash *h = g_malloc0 (HASH_MAX * sizeof (*h));
Lock Lin's avatar
Lock Lin committed
102 103 104 105 106 107 108 109 110 111 112 113 114

  return h;
}

static void
hash_link_destroy (struct hash *h)
{
  if (h == NULL)
    return;

  if (h->next != NULL)
    hash_link_destroy (h->next);

115
  g_free (h->dependencies_ptr);
Lock Lin's avatar
Lock Lin committed
116

117 118 119 120 121 122
  g_strfreev (h->plugin->required_ports);
  g_strfreev (h->plugin->required_udp_ports);
  g_strfreev (h->plugin->required_keys);
  g_strfreev (h->plugin->mandatory_keys);
  g_strfreev (h->plugin->excluded_keys);
  g_free (h->plugin);
Lock Lin's avatar
Lock Lin committed
123

124 125 126
  g_strfreev (h->dependencies);
  g_strfreev (h->ports);
  g_free (h);
Lock Lin's avatar
Lock Lin committed
127 128 129 130 131 132 133 134 135 136 137
}

static void
hash_destroy (struct hash *h)
{
  int i;

  for (i = 0; i < HASH_MAX; i++)
    {
      hash_link_destroy (h[i].next);
    }
138
  g_free (h);
Lock Lin's avatar
Lock Lin committed
139 140 141
}


142
static void
Lock Lin's avatar
Lock Lin committed
143 144
hash_add (struct hash *h, char *name, struct scheduler_plugin *plugin)
{
145 146 147
  struct hash *l = g_malloc0 (sizeof (struct hash));
  unsigned int idx = mkhash ((char *)nvticache_get_filename ((const char *)name));
  nvti_t *nvti;
Lock Lin's avatar
Lock Lin committed
148

149
  nvti = nvticache_get_by_oid_full (plugin->arglist->name);
Lock Lin's avatar
Lock Lin committed
150 151 152 153 154 155 156
  l->plugin = plugin;
  l->plugin->parent_hash = l;
  l->name = name;
  l->next = h[idx].next;
  h[idx].next = l;
  l->dependencies_ptr = NULL;

157 158
  if (nvti_required_ports (nvti) != NULL)
    l->ports = g_strsplit (nvti_required_ports (nvti), ", ", 0);
Lock Lin's avatar
Lock Lin committed
159
  else
160 161 162
    l->ports = NULL;

  if (nvti_dependencies (nvti) != NULL)
Lock Lin's avatar
Lock Lin committed
163
    {
164 165
      l->dependencies = g_strsplit (nvti_dependencies (nvti), ", ", 0);
      for (l->num_deps = 0; l->dependencies[l->num_deps] != NULL; l->num_deps ++) ;
Lock Lin's avatar
Lock Lin committed
166 167
    }
  else
168
    l->dependencies = NULL;
Lock Lin's avatar
Lock Lin committed
169

170
  nvti_free (nvti);
Lock Lin's avatar
Lock Lin committed
171 172 173 174 175 176 177 178 179 180
}


static struct hash *
_hash_get (struct hash *h, char *name)
{
  unsigned int idx = mkhash (name);
  struct hash *l = h[idx].next;
  while (l != NULL)
    {
181
      if (strcmp (nvticache_get_filename ((const char *)l->name), name) == 0)
Lock Lin's avatar
Lock Lin committed
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
        return l;
      else
        l = l->next;
    }
  return NULL;
}


static struct hash **
hash_get_deps_ptr (struct hash *h, char *name)
{
  struct hash *l = _hash_get (h, name);

  if (l == NULL)
    return NULL;

  return l->dependencies_ptr;
}

static void
hash_fill_deps (struct hash *h, struct hash *l)
{
  int i, j = 0;
205 206 207 208 209 210 211

  if (l->num_deps == 0)
    return;

  l->dependencies_ptr =
    g_malloc0 ((1 + l->num_deps) * sizeof (struct hash *));
  for (i = 0; l->dependencies[i]; i++)
Lock Lin's avatar
Lock Lin committed
212
    {
213 214 215 216
      struct hash *d = _hash_get (h, l->dependencies[i]);
      if (d != NULL)
        l->dependencies_ptr[j++] = d;
      else
Lock Lin's avatar
Lock Lin committed
217
        {
218 219 220 221 222 223 224 225 226
          gchar *path = g_path_get_dirname (nvticache_get_filename ((const char *)l->plugin->arglist->name));
          if (g_ascii_strcasecmp (path, ".") != 0)
            {
              gchar *dep_with_path =
                g_build_filename (path, l->dependencies[i], NULL);
              d = _hash_get (h, dep_with_path);
              g_free (dep_with_path);
            }
          g_free (path);
Lock Lin's avatar
Lock Lin committed
227
          if (d != NULL)
228 229 230
            {
              l->dependencies_ptr[j++] = d;
            }
Lock Lin's avatar
Lock Lin committed
231 232
          else
            {
233 234 235 236 237
              log_write ("scheduler: %s depends on %s which could not be found,"
                         " thus this dependency is not considered for execution"
                         " sequence",
                         nvticache_get_filename ((const char *)l->plugin->arglist->name),
                         l->dependencies[i]);
Lock Lin's avatar
Lock Lin committed
238 239 240
            }
        }
    }
241
  l->dependencies_ptr[j] = NULL;
Lock Lin's avatar
Lock Lin committed
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
}

/*----------------------------------------------------------------------*/

struct plist *
pl_get (struct plist *list, char *name)
{
  while (list != NULL)
    {
      if (strcmp (list->name, name) == 0)
        return list;
      else
        list = list->next;
    }
  return NULL;
}


/*----------------------------------------------------------------------*
 *									*
 * Utilities								*
 *									*
 *----------------------------------------------------------------------*/



void
scheduler_mark_running_ports (plugins_scheduler_t sched,
                              struct scheduler_plugin *plugin)
{
  char **ports = plugin->parent_hash->ports;
  int i;

  if (ports == NULL)
    return;

  for (i = 0; ports[i] != NULL; i++)
    {
      struct plist *pl = pl_get (sched->plist, ports[i]);

      if (pl != NULL)
        pl->occurences++;
      else
        {
286 287
          pl = g_malloc0 (sizeof (struct plist));
          pl->name = g_strdup (ports[i]);
Lock Lin's avatar
Lock Lin committed
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
          pl->occurences = 1;
          pl->next = sched->plist;
          if (sched->plist != NULL)
            sched->plist->prev = pl;
          pl->prev = NULL;
          sched->plist = pl;
        }
    }
}

void
scheduler_rm_running_ports (plugins_scheduler_t sched,
                            struct scheduler_plugin *plugin)
{
  char **ports;
  int i;

  ports = plugin->parent_hash->ports;

  if (ports == NULL)
    return;

  for (i = 0; ports[i] != NULL; i++)
    {
      struct plist *pl = pl_get (sched->plist, ports[i]);

      if (pl != NULL)
        {
          pl->occurences--;
          if (pl->occurences == 0)
            {
              if (pl->next != NULL)
                pl->next->prev = pl->prev;

              if (pl->prev != NULL)
                pl->prev->next = pl->next;
              else
                sched->plist = pl->next;

327 328
              g_free (pl->name);
              g_free (pl);
Lock Lin's avatar
Lock Lin committed
329 330 331
            }
        }
      else
332 333
        log_write ("Warning: scheduler_rm_running_ports failed ?! (%s)\n",
                   ports[i]);
Lock Lin's avatar
Lock Lin committed
334 335 336 337 338
    }
}


struct scheduler_plugin *
339 340
plugin_next_unrun_dependency (plugins_scheduler_t sched,
                               struct hash **dependencies_ptr)
Lock Lin's avatar
Lock Lin committed
341 342 343 344 345 346 347 348 349
{
  int flag = 0;
  int i;

  if (dependencies_ptr == NULL)
    return NULL;

  for (i = 0; dependencies_ptr[i] != NULL; i++)
    {
350 351 352 353 354 355 356
      struct scheduler_plugin *plugin;

      plugin = dependencies_ptr[i]->plugin;
      if (plugin == NULL)
        continue;

      switch (plugin->running_state)
Lock Lin's avatar
Lock Lin committed
357
        {
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
        case PLUGIN_STATUS_UNRUN:
          {
            struct hash **deps_ptr;
            struct scheduler_plugin *ret;

            deps_ptr = dependencies_ptr[i]->dependencies_ptr;
            if (deps_ptr == NULL)
              return plugin;

            ret = plugin_next_unrun_dependency (sched, deps_ptr);
            if (ret == NULL)
              return plugin;

            if (ret == PLUG_RUNNING)
              flag = 1;
            else
              return ret;
          }
          break;
        case PLUGIN_STATUS_RUNNING:
          flag = 1;
          break;
        case PLUGIN_STATUS_DONE:
          scheduler_rm_running_ports (sched, plugin);
          plugin->running_state = PLUGIN_STATUS_DONE_AND_CLEANED;
          break;
        case PLUGIN_STATUS_DONE_AND_CLEANED:
          break;
Lock Lin's avatar
Lock Lin committed
386 387 388
        }
    }

389
  if (!flag)
Lock Lin's avatar
Lock Lin committed
390
    return NULL;
391 392

  return PLUG_RUNNING;
Lock Lin's avatar
Lock Lin committed
393 394 395 396 397 398 399 400 401
}

/*---------------------------------------------------------------------------*/

/*
 * Enables a plugin and its dependencies
 */
static void
enable_plugin_and_dependencies (plugins_scheduler_t shed,
402 403
                                struct arglist *plugin, char *name,
                                GHashTable *deps_table)
Lock Lin's avatar
Lock Lin committed
404 405 406
{
  struct hash **deps_ptr;
  int status;
407
  int i;
Lock Lin's avatar
Lock Lin committed
408 409 410 411

  if (plugin == NULL)
    return;

412 413 414 415 416
  if (g_hash_table_lookup (deps_table, name))
    return;
  else
    g_hash_table_insert (deps_table, g_strdup (name), name);

Lock Lin's avatar
Lock Lin committed
417 418 419 420
  deps_ptr = hash_get_deps_ptr (shed->hash, name);

  status = plug_get_launch (plugin);
  if (status == LAUNCH_DISABLED)
421
    plug_set_launch (plugin, LAUNCH_RUN);
Lock Lin's avatar
Lock Lin committed
422

423 424 425
  if (deps_ptr == NULL)
    return;
  for (i = 0; deps_ptr[i] != NULL; i++)
Lock Lin's avatar
Lock Lin committed
426
    {
427 428 429 430 431 432
      struct scheduler_plugin *p;
      p = deps_ptr[i]->plugin;
      if (p != NULL && p->arglist != NULL)
        enable_plugin_and_dependencies (shed, p->arglist->value,
                                        (char *)nvticache_get_filename ((const char *)p->arglist->name),
                                        deps_table);
Lock Lin's avatar
Lock Lin committed
433 434 435 436 437 438 439
    }
}

/*---------------------------------------------------------------------------*/

plugins_scheduler_t
plugins_scheduler_init (struct arglist *plugins, int autoload,
440
                        int only_network)
Lock Lin's avatar
Lock Lin committed
441
{
442
  plugins_scheduler_t ret;
Lock Lin's avatar
Lock Lin committed
443 444 445 446 447 448 449 450
  struct arglist *arg;
  int i;
  struct hash *l;

  if (plugins == NULL)
    return NULL;

  /* Fill our lists */
451
  ret = g_malloc0 (sizeof (*ret));
Lock Lin's avatar
Lock Lin committed
452 453 454 455 456 457
  ret->hash = hash_init ();
  arg = plugins;
  while (arg->next != NULL)
    {
      struct scheduler_plugin *scheduler_plugin;
      struct list *dup;
458 459 460 461 462 463 464 465 466
      char *oid = arg->name;
      nvti_t *nvti;
      int category;

      if (!oid)
        continue; // This would be a serious problem as it shouldn't be
      nvti = nvticache_get_by_oid_full (oid);
      category = nvti_category (nvti);
      scheduler_plugin = g_malloc0 (sizeof (struct scheduler_plugin));
Lock Lin's avatar
Lock Lin committed
467 468
      scheduler_plugin->arglist = arg;
      scheduler_plugin->running_state = PLUGIN_STATUS_UNRUN;
469 470 471 472 473 474 475
      scheduler_plugin->category = category;
      scheduler_plugin->timeout = nvti_timeout (nvti);

      if (nvti_required_ports (nvti) != NULL)
        scheduler_plugin->required_ports = g_strsplit (nvti_required_ports (nvti), ", ", 0);
      else
        scheduler_plugin->required_ports = NULL;
Lock Lin's avatar
Lock Lin committed
476

477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
      if (nvti_required_udp_ports (nvti) != NULL)
        scheduler_plugin->required_udp_ports = g_strsplit (nvti_required_udp_ports (nvti), ", ", 0);
      else
        scheduler_plugin->required_udp_ports = NULL;

      if (nvti_required_keys (nvti) != NULL)
        scheduler_plugin->required_keys = g_strsplit (nvti_required_keys (nvti), ", ", 0);
      else
        scheduler_plugin->required_keys = NULL;

      if (nvti_mandatory_keys (nvti) != NULL)
        scheduler_plugin->mandatory_keys = g_strsplit (nvti_mandatory_keys (nvti), ", ", 0);
      else
        scheduler_plugin->mandatory_keys = NULL;

      if (nvti_excluded_keys (nvti) != NULL)
        scheduler_plugin->excluded_keys = g_strsplit (nvti_excluded_keys (nvti), ", ", 0);
      else
        scheduler_plugin->excluded_keys = NULL;
Lock Lin's avatar
Lock Lin committed
496

497
      nvti_free (nvti);
Lock Lin's avatar
Lock Lin committed
498 499 500

      if (category > ACT_LAST)
        category = ACT_LAST;
501
      dup = g_malloc0 ( sizeof (struct list));
Lock Lin's avatar
Lock Lin committed
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
      dup->plugin = scheduler_plugin;
      dup->prev = NULL;
      dup->next = ret->list[category];
      if (ret->list[category] != NULL)
        ret->list[category]->prev = dup;
      ret->list[category] = dup;

      hash_add (ret->hash, arg->name, scheduler_plugin);
      arg = arg->next;
    }

  for (i = 0; i < HASH_MAX; i++)
    {
      l = &ret->hash[i];
      while (l != NULL)
        {
          hash_fill_deps (ret->hash, l);
          l = l->next;
        }
    }

  if (autoload != 0)
    {
      arg = plugins;
      while (arg->next != NULL)
        {
528 529 530 531 532
          /* deps_table is used to prevent circular dependencies. */
          GHashTable *deps_table;

          deps_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
                                              NULL);
Lock Lin's avatar
Lock Lin committed
533
          if (plug_get_launch (arg->value) != LAUNCH_DISABLED)
534 535 536
            enable_plugin_and_dependencies
             (ret, arg->value, (char *) nvticache_get_filename (arg->name),
              deps_table);
Lock Lin's avatar
Lock Lin committed
537
          arg = arg->next;
538
          g_hash_table_destroy (deps_table);
Lock Lin's avatar
Lock Lin committed
539 540 541 542 543 544 545 546 547
        }
    }

  /* Now, remove the plugins that won't be launched */
  for (i = ACT_FIRST; i <= ACT_LAST; i++)
    {
      struct list *l = ret->list[i];
      while (l != NULL)
        {
548
          if (plug_get_launch (l->plugin->arglist->value) == LAUNCH_DISABLED)
Lock Lin's avatar
Lock Lin committed
549 550 551 552 553 554 555 556 557 558 559
            {
              struct list *old = l->next;

              if (l->prev != NULL)
                l->prev->next = l->next;
              else
                ret->list[i] = l->next;

              if (l->next != NULL)
                l->next->prev = l->prev;

560
              g_free (l);
Lock Lin's avatar
Lock Lin committed
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
              l = old;
              continue;
            }
          l = l->next;
        }
    }

  if (only_network)
    {
      for (i = ACT_GATHER_INFO; i <= ACT_LAST; i++)
        {
          ret->list[i] = NULL;
        }
    }
  return ret;
}



struct scheduler_plugin *
plugins_scheduler_next (plugins_scheduler_t h)
{
  struct list *l;
  int category;
  int running_category = ACT_LAST;
  int flag = 0;

  if (h == NULL)
    return NULL;

  for (category = ACT_FIRST; category <= ACT_LAST; category++)
    {
      l = h->list[category];

      /*
       * Scanners (and DoS) must not be run in parallel
       */
      if ((category == ACT_SCANNER) || (category == ACT_KILL_HOST)
          || (category == ACT_FLOOD) || (category == ACT_DENIAL))
        pluginlaunch_disable_parrallel_checks ();
      else
        pluginlaunch_enable_parrallel_checks ();

      while (l != NULL)
        {
606
          switch (l->plugin->running_state)
Lock Lin's avatar
Lock Lin committed
607 608 609 610 611 612 613 614 615
            {
            case PLUGIN_STATUS_UNRUN:
              {
                struct hash **deps_ptr =
                  l->plugin->parent_hash->dependencies_ptr;

                if (deps_ptr != NULL)
                  {
                    struct scheduler_plugin *p =
616
                      plugin_next_unrun_dependency (h, deps_ptr);
Lock Lin's avatar
Lock Lin committed
617 618 619 620 621

                    switch (GPOINTER_TO_SIZE (p))
                      {
                      case GPOINTER_TO_SIZE (NULL):
                        scheduler_mark_running_ports (h, l->plugin);
622
                        l->plugin->running_state = PLUGIN_STATUS_RUNNING;
Lock Lin's avatar
Lock Lin committed
623 624 625 626 627
                        return l->plugin;

                        break;
                      case GPOINTER_TO_SIZE (PLUG_RUNNING):
                        {
628
                          /* One of the dependency is still running  -  we write down its category */
Lock Lin's avatar
Lock Lin committed
629 630 631 632 633 634 635
                          if (l->plugin->category < running_category)
                            running_category = l->plugin->category;
                          flag++;
                        }
                        break;
                      default:
                        {
636
                          /* Launch a dependency  - don't pay attention to the type */
Lock Lin's avatar
Lock Lin committed
637
                          scheduler_mark_running_ports (h, p);
638
                          p->running_state = PLUGIN_STATUS_RUNNING;
Lock Lin's avatar
Lock Lin committed
639 640 641 642 643 644 645
                          return p;
                        }
                      }
                  }
                else            /* No dependencies */
                  {
                    scheduler_mark_running_ports (h, l->plugin);
646
                    l->plugin->running_state = PLUGIN_STATUS_RUNNING;
Lock Lin's avatar
Lock Lin committed
647 648 649 650 651 652 653 654 655 656 657 658 659 660
                    return l->plugin;
                  }
              }
              break;
            case PLUGIN_STATUS_RUNNING:
              {
                if (l->plugin->category < running_category)
                  running_category = l->plugin->category;
                flag++;
              }
              break;

            case PLUGIN_STATUS_DONE:
              scheduler_rm_running_ports (h, l->plugin);
661
              l->plugin->running_state = PLUGIN_STATUS_DONE_AND_CLEANED;
Lock Lin's avatar
Lock Lin committed
662 663 664 665 666 667 668 669 670 671 672 673 674
              /* no break - we remove it right away */
            case PLUGIN_STATUS_DONE_AND_CLEANED:
              {
                struct list *old = l->next;

                if (l->prev != NULL)
                  l->prev->next = l->next;
                else
                  h->list[category] = l->next;

                if (l->next != NULL)
                  l->next->prev = l->prev;

675
                g_free (l);
Lock Lin's avatar
Lock Lin committed
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
                l = old;

                continue;
              }
              break;
            }
          l = l->next;
        }


      /* Could not find anything */
      if ((category == ACT_SCANNER || category == ACT_INIT
           || category == ACT_SETTINGS) && flag != 0)
        {
          pluginlaunch_wait_for_free_process ();
          flag = 0;
          category--;
        }

      if (category + 1 >= ACT_DENIAL && flag && running_category < ACT_DENIAL)
        {
          return PLUG_RUNNING;
        }
    }


  return flag != 0 ? PLUG_RUNNING : NULL;
}


void
list_destroy (struct list *list)
{
  while (list != NULL)
    {
      struct list *next = list->next;
712
      g_free (list);
Lock Lin's avatar
Lock Lin committed
713 714 715 716 717 718 719 720 721 722 723 724
      list = next;
    }
}


void
plugins_scheduler_free (plugins_scheduler_t sched)
{
  int i;
  hash_destroy (sched->hash);
  for (i = ACT_FIRST; i < ACT_LAST; i++)
    list_destroy (sched->list[i]);
725
  g_free (sched);
Lock Lin's avatar
Lock Lin committed
726
}