Ejemplo n.º 1
0
void
blacklist_init(void)
{

	if (options.use_blacklist)
		blstate = bl_create(false, NULL, im_log);
}
Ejemplo n.º 2
0
/*
 * This constructs, maintains and returns pointers into a growable array of
 * pointers to structures of the form
 *	struct something *array[n]
 * The last element in the array is always NULL.
 */
int
ar_create(int count_per_block, int struct_size, char *desc)
{
	int data_handle, retval;
	char ar_desc[60];
	struct blk_list_cs *array_ptr;

	if ((data_handle = bl_create(count_per_block, struct_size, desc)) == -1)
		return (-1);

	sprintf(ar_desc, "%s pointer", desc);
	if ((retval = bl_create(count_per_block, sizeof (char *),
	    ar_desc)) == -1)
		return (-1);

	array_ptr = bl_cs_array[retval];

	array_ptr->contiguous = 1;
	array_ptr->data_handle = data_handle;

	return (retval);
}
Ejemplo n.º 3
0
static void
addfd(struct pollfd **pfdp, bl_t **blp, size_t *nfd, size_t *maxfd,
    const char *path)
{
	bl_t bl = bl_create(true, path, vflag ? vdlog : vsyslog);
	if (bl == NULL || !bl_isconnected(bl))
		exit(EXIT_FAILURE);
	if (*nfd >= *maxfd) {
		*maxfd += 10;
		*blp = realloc(*blp, sizeof(**blp) * *maxfd);
		if (*blp == NULL)
			err(EXIT_FAILURE, "malloc");
		*pfdp = realloc(*pfdp, sizeof(**pfdp) * *maxfd);
		if (*pfdp == NULL)
			err(EXIT_FAILURE, "malloc");
	}

	(*pfdp)[*nfd].fd = bl_getfd(bl);
	(*pfdp)[*nfd].events = POLLIN;
	(*blp)[*nfd] = bl;
	*nfd += 1;
}
Ejemplo n.º 4
0
static void
add_pkg_to_list(char *pkgname)
{
	struct dr_pkg_entry **pkg_entry;

	if (pkg_handle == -1) {
		if ((pkg_handle = bl_create(MALCOUNT,
		    sizeof (struct dr_pkg_entry), "package dryrun")) == -1)
			return;
	}

	pkg_entry = &(dr_info.packages);

	while (*pkg_entry != NULL)
		pkg_entry = &((*pkg_entry)->next);

	/* LINTED pointer cast may result in improper alignment */
	*pkg_entry = (struct dr_pkg_entry *)bl_next_avail(pkg_handle);
	dr_info.total_pkgs++;

	(void) snprintf((*pkg_entry)->pkginst, PKGNAMESIZE, "%s%s",
		(pkgname ? pkgname : ""), ((this_exitcode == 0) ? "" : "-"));
}
Ejemplo n.º 5
0
static void bitfields_option(pTHX_ BitfieldLayouter *layouter, SV *sv_val, SV **rval)
{
  BitfieldLayouter bl_new = NULL;
  BitfieldLayouter bl = *layouter;

  if(sv_val)
  {
    if (SvROK(sv_val))
    {
      sv_val = SvRV(sv_val);

      if (SvTYPE(sv_val) == SVt_PVHV)
      {
        HV *hv = (HV *) sv_val;
        HE *entry;
        SV **engine = hv_fetch(hv, "Engine", 6, 0);
        int noptions;
        const BLOption *options;

        if (engine && *engine)
        {
          const char *name = SvPV_nolen(*engine);
          bl = bl_new = bl_create(name);
          if (bl_new == NULL)
            Perl_croak(aTHX_ "Unknown bitfield layout engine '%s'", name);
        }

        (void) hv_iterinit(hv);

        options = bl->m->options(bl, &noptions);

        while ((entry = hv_iternext(hv)) != NULL)
        {
          SV *value;
          I32 keylen;
          int i;
          const char *prop_string = hv_iterkey(entry, &keylen);
          BLProperty prop;
          BLPropValue prop_value;
          const BLOption *opt = NULL;
          enum BLError error;

          if (strEQ(prop_string, "Engine"))
            continue;

          prop = bl_property(prop_string);

          for (i = 0; i < noptions; i++)
            if (options[i].prop == prop)
            {
              opt = &options[i];
              break;
            }

          if (opt == NULL)
            FAIL_CLEAN((aTHX_ "Invalid option '%s' for bitfield layout engine '%s'",
                              prop_string, bl->m->class_name(bl)));

          value = hv_iterval(hv, entry);
          prop_value.type = opt->type;

          switch (opt->type)
          {
            case BLPVT_INT:
              prop_value.v.v_int = SvIV(value);

              if (opt->nval)
              {
                const BLPropValInt *pval = opt->pval;

                for (i = 0; i < opt->nval; i++)
                  if (pval[i] == prop_value.v.v_int)
                    break;
              }
              break;

            case BLPVT_STR:
              prop_value.v.v_str = bl_propval(SvPV_nolen(value));

              if (opt->nval)
              {
                const BLPropValStr *pval = opt->pval;

                for (i = 0; i < opt->nval; i++)
                  if (pval[i] == prop_value.v.v_str)
                    break;
              }
              break;

            default:
              fatal("unknown opt->type (%d) in bitfields_option()", opt->type);
              break;
          }

          if (opt->nval && i == opt->nval)
            FAIL_CLEAN((aTHX_ "Invalid value '%s' for option '%s'",
                              SvPV_nolen(value), prop_string));

          error = bl->m->set(bl, prop, &prop_value);

          switch (error)
          {
            case BLE_NO_ERROR:
              break;

            case BLE_INVALID_PROPERTY:
              FAIL_CLEAN((aTHX_ "Invalid value '%s' for option '%s'",
                                SvPV_nolen(value), prop_string));
              break;

            default:
              fatal("unknown error code (%d) returned by set method", error);
              break;
          }
        }

        if (bl_new)
        {
          (*layouter)->m->destroy(*layouter);
          *layouter = bl_new;
        }
      }
      else
        Perl_croak(aTHX_ "Bitfields wants a hash reference");
    }
    else
      Perl_croak(aTHX_ "Bitfields wants a hash reference");
  }

  if (rval)
  {
    int noptions;
    const BLOption *opt;
    int i;
    HV *hv = newHV();
    SV *sv = newSVpv(bl->m->class_name(bl), 0);

    if (hv_store(hv, "Engine", 6, sv, 0) == NULL)
      SvREFCNT_dec(sv);

    opt = bl->m->options(bl, &noptions);

    for (i = 0; i < noptions; i++, opt++)
    {
      BLPropValue value;
      enum BLError error;
      const char *prop_string;

      error = bl->m->get(bl, opt->prop, &value);

      if (error != BLE_NO_ERROR)
        fatal("unexpected error (%d) returned by get method", error);

      assert(value.type == opt->type);

      switch (opt->type)
      {
        case BLPVT_INT:
          sv = newSViv(value.v.v_int);
          break;

        case BLPVT_STR:
          {
            const char *valstr = bl_propval_string(value.v.v_str);
            assert(valstr != NULL);
            sv = newSVpv(valstr, 0);
          }
          break;

        default:
          fatal("unknown opt->type (%d) in bitfields_option()", opt->type);
          break;
      }

      prop_string = bl_property_string(opt->prop);
      assert(prop_string != NULL);

      if (hv_store(hv, prop_string, strlen(prop_string), sv, 0) == NULL)
        SvREFCNT_dec(sv);
    }

    *rval = newRV_noinc((SV *) hv);
  }
}
Ejemplo n.º 6
0
struct blacklist *
blacklist_open(void) {
	return bl_create(false, NULL, vsyslog);
}
Ejemplo n.º 7
0
/*
 * This function manipulates the pinfo entry corresponding to the package
 * indicated on the command line.
 */
struct pinfo *
eptstat(struct cfent *entry, char *pkg, char c)
{
	struct pinfo *pinfo, *last, *me, *myparent;

	otherstoo = 0;
	useclass = entry->pkg_class;

	me = myparent = last = (struct pinfo *)0;

	if (pinfo_handle == -1) {
		pinfo_handle = bl_create(PINFOALLOC, sizeof (struct pinfo),
		    "package data");
	}

	for (pinfo = entry->pinfo; pinfo; pinfo = pinfo->next) {
		if (strcmp(pkg, pinfo->pkg) == 0) {
			if (*pinfo->aclass)
				useclass = pinfo->aclass;
			myparent = last;
			me = pinfo;
		} else
			otherstoo++;
		last = pinfo;
	}

	if (c) {
		/*
		 * use a delete/add strategy to keep package list
		 * ordered by modification time
		 */
		if (me) {
			/* remove from list first */
			if (myparent)
				myparent->next = me->next;
			else
				entry->pinfo = me->next;
			if (me == last)
				last = myparent;
			entry->npkgs--;
			/* leave 'me' around until later! */
		}
		if ((c != STAT_NEXT) && (me || (c != RM_RDY))) {
			/* need to add onto end */
			entry->npkgs++;
			if (me == NULL) {
				/* LINTED pointer cast may result in impro... */
				me = (struct pinfo *)
				    bl_next_avail(pinfo_handle);
				if (me == NULL) {
					progerr(gettext(ERR_MEMORY), errno);
					quit(99);
				}
			} else {
				me->next = (struct pinfo *)NULL;
				if (entry->npkgs == 1) {
					if (me->aclass[0])
						(void) strcpy(entry->pkg_class,
							me->aclass);
					useclass = entry->pkg_class;
				} else
					useclass = me->aclass;
			}
			(void) strncpy(me->pkg, pkg, PKGSIZ);

			/*
			 * Only change status for local objects.  Need
			 * to maintain "shared" status for objects that
			 * are provided from a server.
			 */
			if (me->status != SERVED_FILE)
				me->status = ((c == DUP_ENTRY) ? '\0' : c);

			if (last)
				last->next = me; /* add to end */
			else
				entry->pinfo = me; /* only item */
		} else {
			/* just wanted to remove this package from list */
			if (me) {
				free(me);
				me = (struct pinfo *)0;
			}
		}
	}
	return (me);
}