Exemplo n.º 1
0
static void set_description(struct pkginfo *dpkg, psys_pkg_t pkg)
{
	const char *pkg_summary;
	const char *pkg_description;
	char *dpkg_description;

	pkg_summary = tlist_value_c(psys_pkg_summary(pkg));
	pkg_description = tlist_value_c(psys_pkg_description(pkg));

	if (pkg_summary && pkg_description) {
		int len;
		len = snprintf(NULL, 0, "%s\n %s", pkg_summary, pkg_description);
		dpkg_description = nfmalloc(len + 1);
		snprintf(dpkg_description, len + 1, "%s\n %s", pkg_summary,
			 pkg_description);
	} else if (pkg_summary) {
		dpkg_description = nfstrsave(pkg_summary);	
	} else if (pkg_description) {
		dpkg_description = nfmalloc(strlen(pkg_description) + 2);
		dpkg_description[0] = '\n';
		strncpy(dpkg_description + 1, pkg_description,
			strlen(pkg_description));
	} else {
		dpkg_description = nfstrsave("");
	}

	dpkg->installed.description = dpkg_description;
}
Exemplo n.º 2
0
void scandepot(void) {
    DIR *depot;
    struct dirent *de;
    struct partqueue *pq;
    char *p;

    assert(!queue);
    depot = opendir(opt_depotdir);
    if (!depot)
        ohshite(_("unable to read depot directory `%.250s'"), opt_depotdir);
    while ((de= readdir(depot))) {
        if (de->d_name[0] == '.') continue;
        pq= nfmalloc(sizeof(struct partqueue));
        pq->info.fmtversion= pq->info.package= pq->info.version= NULL;
        pq->info.orglength= pq->info.thispartoffset= pq->info.thispartlen= 0;
        pq->info.headerlen= 0;
        p = nfmalloc(strlen(opt_depotdir) + strlen(de->d_name) + 1);
        strcpy(p, opt_depotdir);
        strcat(p,de->d_name);
        pq->info.filename= p;
        if (!decompose_filename(de->d_name,pq)) {
            pq->info.md5sum= NULL;
            pq->info.maxpartlen= pq->info.thispartn= pq->info.maxpartn= 0;
        }
        pq->nextinqueue= queue;
        queue= pq;
    }
    closedir(depot);
}
Exemplo n.º 3
0
Arquivo: util.c Projeto: xaiki/isync
/* Return value: 0 = ok, -1 = out found in arg, -2 = in found in arg but no out specified */
int
map_name( const char *arg, char **result, int reserve, const char *in, const char *out )
{
	char *p;
	int i, l, ll, num, inl, outl;

	l = strlen( arg );
	if (!in) {
	  copy:
		*result = nfmalloc( reserve + l + 1 );
		memcpy( *result + reserve, arg, l + 1 );
		return 0;
	}
	inl = strlen( in );
	if (out) {
		outl = strlen( out );
		if (inl == outl && !memcmp( in, out, inl ))
			goto copy;
	}
	for (num = 0, i = 0; i < l; ) {
		for (ll = 0; ll < inl; ll++)
			if (arg[i + ll] != in[ll])
				goto fout;
		num++;
		i += inl;
		continue;
	  fout:
		if (out) {
			for (ll = 0; ll < outl; ll++)
				if (arg[i + ll] != out[ll])
					goto fnexti;
			return -1;
		}
	  fnexti:
		i++;
	}
	if (!num)
		goto copy;
	if (!out)
		return -2;
	*result = nfmalloc( reserve + l + num * (outl - inl) + 1 );
	p = *result + reserve;
	for (i = 0; i < l; ) {
		for (ll = 0; ll < inl; ll++)
			if (arg[i + ll] != in[ll])
				goto rnexti;
		memcpy( p, out, outl );
		p += outl;
		i += inl;
		continue;
	  rnexti:
		*p++ = arg[i++];
	}
	*p = 0;
	return 0;
}
Exemplo n.º 4
0
void
do_split(const char *const *argv)
{
	const char *sourcefile, *prefix;
	char *palloc;
	int l;
	size_t partsize;

	sourcefile = *argv++;
	if (!sourcefile)
		badusage(_("--split needs a source filename argument"));
	prefix = *argv++;
	if (prefix && *argv)
		badusage(_("--split takes at most a source filename and destination prefix"));
	if (!prefix) {
		l = strlen(sourcefile);
		palloc = nfmalloc(l + 1);
		strcpy(palloc, sourcefile);
		if (!strcmp(palloc + l - (sizeof(DEBEXT) - 1), DEBEXT)) {
			l -= (sizeof(DEBEXT) - 1);
			palloc[l] = '\0';
		}
		prefix = palloc;
	}
	partsize = opt_maxpartsize - HEADERALLOWANCE;

	mksplit(sourcefile, prefix, partsize, opt_maxpartsize, opt_msdos);

	exit(0);
}
Exemplo n.º 5
0
/**
 * Return the package set with the given name.
 *
 * If the package already exists in the internal database, then it returns
 * the existing structure. Otherwise it allocates a new one and will return
 * it. The actual name associated to the package set is a lowercase version
 * of the name given in parameter.
 *
 * A package set (struct pkgset) can be composed of multiple package instances
 * (struct pkginfo) where each instance is distinguished by its architecture
 * (as recorded in pkg.installed.arch and pkg.available.arch).
 *
 * @param inname Name of the package set.
 *
 * @return The package set.
 */
struct pkgset *
pkg_hash_find_set(const char *inname)
{
  struct pkgset **setp, *new_set;
  char *name = m_strdup(inname), *p;

  p= name;
  while (*p) {
    *p = c_tolower(*p);
    p++;
  }

  setp = bins + (str_fnv_hash(name) % (BINS));
  while (*setp && strcasecmp((*setp)->name, name))
    setp = &(*setp)->next;
  if (*setp) {
    free(name);
    return *setp;
  }

  new_set = nfmalloc(sizeof(*new_set));
  pkgset_blank(new_set);
  new_set->name = nfstrsave(name);
  new_set->next = NULL;
  *setp = new_set;
  nset++;
  npkg++;

  free(name);

  return new_set;
}
Exemplo n.º 6
0
static bool
decompose_filename(const char *filename, struct partqueue *pq)
{
    const char *p;
    char *q;

    if (strspn(filename, "0123456789abcdef") != MD5HASHLEN ||
            filename[MD5HASHLEN] != '.')
        return false;
    q = nfmalloc(MD5HASHLEN + 1);
    memcpy(q, filename, MD5HASHLEN);
    q[MD5HASHLEN] = '\0';
    pq->info.md5sum= q;
    p = filename + MD5HASHLEN + 1;
    pq->info.maxpartlen = strtol(p, &q, 16);
    if (q == p || *q++ != '.')
        return false;
    p = q;
    pq->info.thispartn = (int)strtol(p, &q, 16);
    if (q == p || *q++ != '.')
        return false;
    p = q;
    pq->info.maxpartn = (int)strtol(p, &q, 16);
    if (q == p || *q)
        return false;
    return true;
}
Exemplo n.º 7
0
Arquivo: util.c Projeto: xaiki/isync
static char *
my_strndup( const char *s, size_t nchars )
{
	char *r = nfmalloc( nchars + 1 );
	memcpy( r, s, nchars );
	r[nchars] = 0;
	return r;
}
Exemplo n.º 8
0
struct filenamenode *findnamenode(const char *name, enum fnnflags flags) {
  struct filenamenode **pointerp, *newnode;
  const char *orig_name = name;

  /* We skip initial slashes and ‘./’ pairs, and add our own single
   * leading slash. */
  name = path_skip_slash_dotslash(name);

  pointerp= bins + (hash(name) & (BINS-1));
  while (*pointerp) {
    /* XXX: Why is the assert needed? It's checking already added entries. */
    assert((*pointerp)->name[0] == '/');
    if (strcmp((*pointerp)->name + 1, name) == 0)
      break;
    pointerp= &(*pointerp)->next;
  }
  if (*pointerp) return *pointerp;

  if (flags & fnn_nonew)
    return NULL;

  newnode= nfmalloc(sizeof(struct filenamenode));
  newnode->packages = NULL;
  if((flags & fnn_nocopy) && name > orig_name && name[-1] == '/')
    newnode->name = name - 1;
  else {
    char *newname= nfmalloc(strlen(name)+2);
    newname[0]= '/'; strcpy(newname+1,name);
    newnode->name= newname;
  }
  newnode->flags= 0;
  newnode->next = NULL;
  newnode->divert = NULL;
  newnode->statoverride = NULL;
  newnode->oldhash = NULL;
  newnode->newhash = EMPTYHASHFLAG;
  newnode->filestat = NULL;
  newnode->trig_interested = NULL;
  *pointerp= newnode;
  nfiles++;

  return newnode;
}
Exemplo n.º 9
0
Arquivo: util.c Projeto: xaiki/isync
void
add_string_list_n( string_list_t **list, const char *str, int len )
{
	string_list_t *elem;

	elem = nfmalloc( sizeof(*elem) + len );
	elem->next = *list;
	*list = elem;
	memcpy( elem->string, str, len );
	elem->string[len] = 0;
}
Exemplo n.º 10
0
static char *dpkg_name(const char *vendor, const char *name)
{
	size_t len;
	char *dpkgname;

	len = snprintf(NULL, 0, "lsb-%s-%s", vendor, name);
	dpkgname = nfmalloc(len + 1);
	snprintf(dpkgname, len + 1, "lsb-%s-%s", vendor, name);

	return dpkgname;
}
Exemplo n.º 11
0
/*
 * Called by various people with signum -1 and +1 to mean remove and add
 * and also by trig_file_interests_ensure() with signum +2 meaning add
 * but die if already present.
 */
static void
trk_file_interest_change(const char *trig, struct pkginfo *pkg,
                         struct pkgbin *pkgbin, int signum,
                         enum trig_options opts)
{
	struct fsys_namenode *fnn;
	struct trigfileint **search, *tfi;

	fnn = trigh.namenode_find(trig, signum <= 0);
	if (!fnn) {
		if (signum >= 0)
			internerr("lost filename node '%s' for package %s "
			          "triggered to add", trig,
			          pkgbin_name(pkg, pkgbin, pnaw_always));
		return;
	}

	for (search = trigh.namenode_interested(fnn);
	     (tfi = *search);
	     search = &tfi->samefile_next)
		if (tfi->pkg == pkg)
			goto found;

	/* Not found. */
	if (signum < 0)
		return;

	tfi = nfmalloc(sizeof(*tfi));
	tfi->pkg = pkg;
	tfi->pkgbin = pkgbin;
	tfi->fnn = fnn;
	tfi->options = opts;
	tfi->samefile_next = *trigh.namenode_interested(fnn);
	*trigh.namenode_interested(fnn) = tfi;

	LIST_LINK_TAIL_PART(filetriggers, tfi, inoverall);
	goto edited;

found:
	tfi->options = opts;
	if (signum > 1)
		ohshit(_("duplicate file trigger interest for filename '%.250s' "
		         "and package '%.250s'"), trig,
		       pkgbin_name(pkg, pkgbin, pnaw_nonambig));
	if (signum > 0)
		return;

	/* Remove it: */
	*search = tfi->samefile_next;
	LIST_UNLINK_PART(filetriggers, tfi, inoverall);
edited:
	filetriggers_edited = 1;
}
Exemplo n.º 12
0
Arquivo: util.c Projeto: gburd/isync
void
add_string_list( string_list_t **list, const char *str )
{
	string_list_t *elem;
	int len;

	len = strlen( str );
	elem = nfmalloc( sizeof(*elem) + len );
	elem->next = *list;
	*list = elem;
	memcpy( elem->string, str, len + 1 );
}
Exemplo n.º 13
0
/**
 * Parse the field and value into the package being constructed.
 */
static void
pkg_parse_field(struct parsedb_state *ps, struct field_state *fs,
                void *parse_obj)
{
  struct pkg_parse_object *pkg_obj = parse_obj;
  const struct nickname *nick;
  const struct fieldinfo *fip;
  int *ip;

  for (nick = nicknames; nick->nick; nick++)
    if (strncasecmp(nick->nick, fs->fieldstart, fs->fieldlen) == 0 &&
        nick->nick[fs->fieldlen] == '\0')
      break;
  if (nick->nick) {
    fs->fieldstart = nick->canon;
    fs->fieldlen = strlen(fs->fieldstart);
  }

  for (fip = fieldinfos, ip = fs->fieldencountered; fip->name; fip++, ip++)
    if (strncasecmp(fip->name, fs->fieldstart, fs->fieldlen) == 0)
      break;
  if (fip->name) {
    if ((*ip)++)
      parse_error(ps,
                  _("duplicate value for `%s' field"), fip->name);

    varbuf_reset(&fs->value);
    varbuf_add_buf(&fs->value, fs->valuestart, fs->valuelen);
    varbuf_end_str(&fs->value);

    fip->rcall(pkg_obj->pkg, pkg_obj->pkgbin, ps, fs->value.buf, fip);
  } else {
    struct arbitraryfield *arp, **larpp;

    if (fs->fieldlen < 2)
      parse_error(ps,
                  _("user-defined field name `%.*s' too short"),
                  fs->fieldlen, fs->fieldstart);
    larpp = &pkg_obj->pkgbin->arbs;
    while ((arp = *larpp) != NULL) {
      if (!strncasecmp(arp->name, fs->fieldstart, fs->fieldlen))
        parse_error(ps,
                   _("duplicate value for user-defined field `%.*s'"),
                   fs->fieldlen, fs->fieldstart);
      larpp = &arp->next;
    }
    arp = nfmalloc(sizeof(struct arbitraryfield));
    arp->name = nfstrnsave(fs->fieldstart, fs->fieldlen);
    arp->value = nfstrnsave(fs->valuestart, fs->valuelen);
    arp->next = NULL;
    *larpp = arp;
  }
}
Exemplo n.º 14
0
void
statusfd_add(int fd)
{
	struct pipef *pipe_new;

	setcloexec(fd, _("<package status and progress file descriptor>"));

	pipe_new = nfmalloc(sizeof(struct pipef));
	pipe_new->fd = fd;
	pipe_new->next = status_pipes;
	status_pipes = pipe_new;
}
Exemplo n.º 15
0
static struct file_stat *
statdb_node_new(const char *user, const char *group, const char *mode)
{
	struct file_stat *filestat;

	filestat = nfmalloc(sizeof(*filestat));

	filestat->uid = statdb_parse_uid(user);
	filestat->gid = statdb_parse_gid(group);
	filestat->mode = statdb_parse_mode(mode);

	return filestat;
}
Exemplo n.º 16
0
void
ensure_package_clientdata(struct pkginfo *pkg)
{
  if (pkg->clientdata)
    return;
  pkg->clientdata = nfmalloc(sizeof(struct perpackagestate));
  pkg->clientdata->istobe = itb_normal;
  pkg->clientdata->color = white;
  pkg->clientdata->fileslistvalid = false;
  pkg->clientdata->files = NULL;
  pkg->clientdata->listfile_phys_offs = 0;
  pkg->clientdata->trigprocdeferred = NULL;
}
Exemplo n.º 17
0
void add_dependencies(struct pkginfo *dpkg, psys_pkg_t pkg)
{
	struct dependency *dep;
	struct deppossi *depp;

	dep = nfmalloc(sizeof(*dep));
	dep->up = dpkg;
	dep->next = NULL;
	dep->type = dep_depends;

	depp = nfmalloc(sizeof(*depp));
	depp->up = dep;
	depp->next = NULL;
	depp->nextrev = NULL;
	depp->backrev = NULL;
	depp->ed = findpackage("lsb");
	depp->verrel = dvr_laterequal;
	parseversion(&depp->version, psys_pkg_lsbversion(pkg));

	dep->list = depp;
	dpkg->installed.depends = dep;
}
Exemplo n.º 18
0
static char *info_file_path(struct pkginfo *dpkg, const char *extension)
{
	size_t len;
	char *path;

	len = snprintf(NULL, 0, "/var/lib/dpkg/info/%s.%s", dpkg->name,
		       extension);
	path = nfmalloc(len + 1);
	snprintf(path, len + 1, "/var/lib/dpkg/info/%s.%s", dpkg->name,
		 extension);

	return path;
}
Exemplo n.º 19
0
static void
set_invoke_hook(const struct cmdinfo *cip, const char *value)
{
  struct invoke_list *hook_list = cip->arg_ptr;
  struct invoke_hook *hook_new;

  hook_new = nfmalloc(sizeof(struct invoke_hook));
  hook_new->command = nfstrsave(value);
  hook_new->next = NULL;

  /* Add the new hook at the tail of the list to preserve the order. */
  *hook_list->tail = hook_new;
  hook_list->tail = &hook_new->next;
}
Exemplo n.º 20
0
static int
msgs_flags_set( sync_vars_t *svars, int t )
{
	message_t *tmsg;
	copy_vars_t *cv;

	if (!(svars->state[t] & ST_SENT_FLAGS) || svars->flags_done[t] < svars->flags_total[t])
		return 0;

	if ((svars->chan->ops[t] & OP_EXPUNGE) &&
	    (svars->ctx[t]->conf->trash || (svars->ctx[1-t]->conf->trash && svars->ctx[1-t]->conf->trash_remote_new))) {
		debug( "trashing in %s\n", str_ms[t] );
		for (tmsg = svars->ctx[t]->msgs; tmsg; tmsg = tmsg->next)
			if (tmsg->flags & F_DELETED) {
				if (svars->ctx[t]->conf->trash) {
					if (!svars->ctx[t]->conf->trash_only_new || !tmsg->srec || tmsg->srec->uid[1-t] < 0) {
						debug( "%s: trashing message %d\n", str_ms[t], tmsg->uid );
						svars->trash_total[t]++;
						stats( svars );
						sync_ref( svars );
						svars->drv[t]->trash_msg( svars->ctx[t], tmsg, msg_trashed, AUX );
						if (deref_check_cancel( svars ))
							return -1;
					} else
						debug( "%s: not trashing message %d - not new\n", str_ms[t], tmsg->uid );
				} else {
					if (!tmsg->srec || tmsg->srec->uid[1-t] < 0) {
						if (!svars->ctx[1-t]->conf->max_size || tmsg->size <= svars->ctx[1-t]->conf->max_size) {
							debug( "%s: remote trashing message %d\n", str_ms[t], tmsg->uid );
							svars->trash_total[t]++;
							stats( svars );
							cv = nfmalloc( sizeof(*cv) );
							cv->cb = msg_rtrashed;
							cv->aux = INV_AUX;
							cv->srec = 0;
							cv->msg = tmsg;
							if (copy_msg( cv ))
								return -1;
						} else
							debug( "%s: not remote trashing message %d - too big\n", str_ms[t], tmsg->uid );
					} else
						debug( "%s: not remote trashing message %d - not new\n", str_ms[t], tmsg->uid );
				}
			}
	}
	svars->state[t] |= ST_SENT_TRASH;
	sync_close( svars, t );
	return 0;
}
Exemplo n.º 21
0
/*
 * Note: This is also called from fields.c where *pend is a temporary!
 *
 * trig is not copied!
 */
bool
trig_note_pend_core(struct pkginfo *pend, const char *trig)
{
	struct trigpend *tp;

	for (tp = pend->trigpend_head; tp; tp = tp->next)
		if (strcmp(tp->name, trig) == 0)
			return false;

	tp = nfmalloc(sizeof(*tp));
	tp->name = trig;
	tp->next = pend->trigpend_head;
	pend->trigpend_head = tp;

	return true;
}
Exemplo n.º 22
0
/*
 * Called by various people with signum -1 and +1 to mean remove and add
 * and also by trig_file_interests_ensure() with signum +2 meaning add
 * but die if already present.
 */
static void
trk_file_interest_change(const char *trig, struct pkginfo *pkg, int signum,
                         enum trig_options opts)
{
	struct filenamenode *fnn;
	struct trigfileint **search, *tfi;

	fnn = trigh.namenode_find(trig, signum <= 0);
	if (!fnn) {
		assert(signum < 0);
		return;
	}

	for (search = trigh.namenode_interested(fnn);
	     (tfi = *search);
	     search = &tfi->samefile_next)
		if (tfi->pkg == pkg)
			goto found;

	/* Not found. */
	if (signum < 0)
		return;

	tfi = nfmalloc(sizeof(*tfi));
	tfi->pkg = pkg;
	tfi->fnn = fnn;
	tfi->options = opts;
	tfi->samefile_next = *trigh.namenode_interested(fnn);
	*trigh.namenode_interested(fnn) = tfi;

	LIST_LINK_TAIL_PART(filetriggers, tfi, inoverall.);
	goto edited;

found:
	tfi->options = opts;
	if (signum > 1)
		ohshit(_("duplicate file trigger interest for filename `%.250s' "
		         "and package `%.250s'"), trig, pkg->name);
	if (signum > 0)
		return;

	/* Remove it: */
	*search = tfi->samefile_next;
	LIST_UNLINK_PART(filetriggers, tfi, inoverall.);
edited:
	filetriggers_edited = 1;
}
Exemplo n.º 23
0
Arquivo: main.c Projeto: jtniehof/dpkg
static void setpipe(const struct cmdinfo *cip, const char *value) {
  struct pipef **pipe_head = cip->parg;
  struct pipef *pipe_new;
  unsigned long v;
  char *ep;

  v= strtoul(value,&ep,0);
  if (value == ep || *ep || v > INT_MAX)
    badusage(_("invalid integer for --%s: `%.250s'"),cip->olong,value);

  setcloexec(v, _("<package status and progress file descriptor>"));

  pipe_new = nfmalloc(sizeof(struct pipef));
  pipe_new->fd = v;
  pipe_new->next = *pipe_head;
  *pipe_head = pipe_new;
}
Exemplo n.º 24
0
static void set_installed_size(struct pkginfo *dpkg, psys_flist_t files)
{
	off_t installedsize;
	psys_flist_t f;
	size_t len;
	char *installedsize_str;

	installedsize = 0;
	for (f = files; f; f = psys_flist_next(f))
		installedsize += psys_flist_stat(f)->st_size;
	installedsize /= 1000;

	len = snprintf(NULL, 0, "%llu", (long long unsigned) installedsize);
	installedsize_str = nfmalloc(len + 1);
	snprintf(installedsize_str, len + 1, "%llu",
		 (long long unsigned) installedsize);

	dpkg->installed.installedsize = installedsize_str;
}
Exemplo n.º 25
0
/**
 * Return the package instance in a set with the given architecture.
 *
 * It traverse the various instances to find out whether there's one
 * matching the given architecture. If found, it returns it. Otherwise it
 * allocates a new instance and registers it in the package set before
 * returning it.
 *
 * @param set  The package set to use.
 * @param arch The requested architecture.
 *
 * @return The package instance.
 */
struct pkginfo *
pkg_hash_get_pkg(struct pkgset *set, const struct dpkg_arch *arch)
{
  struct pkginfo *pkg, **pkgp;

  if (arch == NULL)
    internerr("arch argument is NULL");
  if (arch->type == DPKG_ARCH_NONE)
    internerr("arch argument is none");

  pkg = &set->pkg;

  /* If there's a single unused slot, let's use that. */
  if (pkg->installed.arch->type == DPKG_ARCH_NONE && pkg->arch_next == NULL) {
    /* We can only initialize the arch pkgbin members, because those are used
     * to find instances, anything else will be overwritten at parse time. */
    pkg->installed.arch = arch;
    pkg->available.arch = arch;
    return pkg;
  }

  /* Match the slot with the most appropriate architecture. The installed
   * architecture always has preference over the available one, as there's
   * a small time window on cross-grades, where they might differ. */
  for (pkgp = &pkg; *pkgp; pkgp = &(*pkgp)->arch_next) {
    if ((*pkgp)->installed.arch == arch)
      return *pkgp;
  }

  /* Need to create a new instance for the wanted architecture. */
  pkg = nfmalloc(sizeof(*pkg));
  pkg_blank(pkg);
  pkg->set = set;
  pkg->arch_next = NULL;
  /* We can only initialize the arch pkgbin members, because those are used
   * to find instances, anything else will be overwritten at parse time. */
  pkg->installed.arch = arch;
  pkg->available.arch = arch;
  *pkgp = pkg;
  npkg++;

  return pkg;
}
Exemplo n.º 26
0
static struct file_stat *
statdb_node_new(const char *user, const char *group, const char *mode)
{
	struct file_stat *filestat;

	filestat = nfmalloc(sizeof(*filestat));

	filestat->uid = statdb_parse_uid(user);
	if (filestat->uid == (uid_t)-1)
		ohshit(_("user '%s' does not exist"), user);
	filestat->uname = NULL;
	filestat->gid = statdb_parse_gid(group);
	if (filestat->gid == (gid_t)-1)
		ohshit(_("group '%s' does not exist"), group);
	filestat->gname = NULL;
	filestat->mode = statdb_parse_mode(mode);

	return filestat;
}
Exemplo n.º 27
0
/*
 * Note: This is called also from fields.c where *aw is a temporary
 * but pend is from pkg_db_find()!
 *
 * @retval true  For done.
 * @retval false For already noted.
 */
bool
trig_note_aw(struct pkginfo *pend, struct pkginfo *aw)
{
	struct trigaw *ta;

	/* We search through aw's list because that's probably shorter. */
	for (ta = aw->trigaw.head; ta; ta = ta->sameaw.next)
		if (ta->pend == pend)
			return false;

	ta = nfmalloc(sizeof(*ta));
	ta->aw = aw;
	ta->pend = pend;
	ta->samepend_next = pend->othertrigaw_head;
	pend->othertrigaw_head = ta;
	LIST_LINK_TAIL_PART(aw->trigaw, ta, sameaw.);

	return true;
}
Exemplo n.º 28
0
int
main( int argc, char **argv )
{
	int i;

	for (i = 1; i < argc; i++) {
		char *val = argv[i];
		struct tst *timer = nfmalloc( sizeof(*timer) );
		init_wakeup( &timer->timer, timed_out, timer );
		init_wakeup( &timer->morph_timer, morph_timed_out, timer );
		timer->id = ++nextid;
		timer->first = strtol( val, &val, 0 );
		if (*val == '@') {
			timer->other = timer->first;
			timer->first = strtol( ++val, &val, 0 );
		} else {
			timer->other = -1;
		}
		if (*val == ':') {
			timer->morph_to = strtol( ++val, &val, 0 );
			if (*val != '@')
				goto fail;
			timer->morph_at = strtol( ++val, &val, 0 );
		} else {
			timer->morph_at = -1;
		}
		if (*val) {
		  fail:
			fprintf( stderr, "Fatal: syntax error in %s, use <timeout>[@<delay>][:<newtimeout>@<delay>]\n", argv[i] );
			return 1;
		}
		timer_start( timer, timer->first );
		if (timer->morph_at >= 0) {
			printf( "timer %d, should morph after %d\n", timer->id, timer->morph_at );
			conf_wakeup( &timer->morph_timer, timer->morph_at );
		}
	}

	main_loop();
	return 0;
}
Exemplo n.º 29
0
static const char *
summarize_filename(const char *filename)
{
  const char *pfilename;
  char *pfilenamebuf;

  for (pfilename = filename;
       pfilename && strlen(pfilename) > 30 && strchr(pfilename, '/') != NULL;
       pfilename++)
    pfilename = strchr(pfilename, '/');

  if (pfilename && pfilename != filename) {
    pfilenamebuf = nfmalloc(strlen(pfilename) + 5);
    sprintf(pfilenamebuf, _(".../%s"), pfilename);
    pfilename = pfilenamebuf;
  } else {
    pfilename = filename;
  }

  return pfilename;
}
Exemplo n.º 30
0
static struct filenamenode *
th_simple_nn_find(const char *name, bool nonew)
{
	struct filenamenode *search;

	for (search = trigger_files; search; search = search->next)
		if (!strcmp(search->name, name))
			return search;

	/* Not found. */
	if (nonew)
		return NULL;

	search = nfmalloc(sizeof(*search));
	search->name = nfstrsave(name);
	search->trig_interested = NULL;
	search->next = trigger_files;
	trigger_files = search;

	return search;
}