コード例 #1
0
ファイル: main.c プロジェクト: bahamat/smartos-live
static me_cb_ret_t
record_zoneinfo(manifest_ent_t *me, void *arg)
{
	tzcheck_t *tzc = arg;
	tzent_t *tze;
	avl_index_t where;

	/*
	 * We care only for records within the time zone database
	 * directory.
	 */
	if (strncmp(custr_cstr(tzc->tzc_prefix), me->me_name,
	    custr_len(tzc->tzc_prefix)) != 0) {
		return (MECB_NEXT);
	}

	if ((tze = calloc(1, sizeof (*tze))) == NULL) {
		err(1, "alloc failure");
	}

	tze->tze_path = strdup(me->me_name + custr_len(tzc->tzc_prefix));
	switch (me->me_type) {
	case ME_TYPE_HARDLINK:
		if (strncmp(me->me_target, custr_cstr(tzc->tzc_prefix),
		    custr_len(tzc->tzc_prefix)) != 0) {
			errx(1, "hardlink \"%s\" target did not begin "
			    "with correct prefix (%s)", me->me_target,
			    custr_cstr(tzc->tzc_prefix));
		}
		tze->tze_target = strdup(me->me_target +
		    custr_len(tzc->tzc_prefix));
		tze->tze_type = me->me_type;
		break;

	case ME_TYPE_SYMLINK:
		tze->tze_target = strdup(me->me_target);
		/* FALLTHRU */
	case ME_TYPE_DIRECTORY:
	case ME_TYPE_FILE:
		tze->tze_type = me->me_type;
		break;

	default:
		errx(1, "unexpected type (%d) of \"%s\" in manifest",
		    me->me_type, me->me_name);
	}

	if (avl_find(&tzc->tzc_zoneinfo_manifest, tze, &where) != NULL) {
		errx(1, "path \"%s\" in manifest twice", me->me_name);
	}

	avl_insert(&tzc->tzc_zoneinfo_manifest, tze, where);

	return (MECB_NEXT);
}
コード例 #2
0
ファイル: receipt.c プロジェクト: FilipinOTech/illumos-gate
void 
receipt(struct message *mp)
{
	char	head[LINESIZE];
	char	buf[BUFSIZ];
	FILE	*pp, *fp;
	char	*mail, *s;


	if ((mail = value("sendmail")) == 0)
#ifdef SENDMAIL
		mail = SENDMAIL;
#else
		mail = MAIL;
#endif
	if (icsubstr(hfield("default-options", mp, addone), "/receipt")
	 || icsubstr(hfield(">to", mp, addto), "/receipt")) {
		snprintf(buf, sizeof (buf), "%s %s", mail, skin(nameof(mp)));
		if (pp = npopen(buf, "w")) {
			headline_t *hl;

			if (headline_alloc(&hl) != 0) {
				err(1, "could not allocate memory");
			}

			fp = setinput(mp);
			readline(fp, head);
			if (parse_headline(head, hl) != 0) {
				headline_reset(hl);
			}
			if (custr_len(hl->hl_date) > 0) {
				fprintf(pp, "Original-Date: %s\n",
				    custr_cstr(hl->hl_date));
			}
			if (s = hfield("message-id", mp, addone))
				fprintf(pp, "Original-Message-ID: %s\n", s);
			s = hfield("subject", mp, addone);
			fprintf(pp, "Subject: RR: %s\n", s ? s : "(none)");
			npclose(pp);
			headline_free(hl);
		}
	}
}
コード例 #3
0
ファイル: parser.c プロジェクト: YuanShengzeng/smartos-live
int
split_on(const char *line, char delim, strlist_t *sl)
{
    custr_t *cu = NULL;
    int error = 0;
    const char *c = line;

    if (custr_alloc(&cu) != 0) {
        error = errno;
        goto out;
    }

    for (;;) {
        char cc = *c++;

        if (cc == '\0') {
            if (custr_len(cu) > 0 && strlist_set_tail(sl,
                    custr_cstr(cu)) != 0) {
                error = errno;
            }
            goto out;
        } else if (cc == delim) {
            if (strlist_set_tail(sl, custr_cstr(cu)) != 0) {
                error = errno;
                goto out;
            }
            custr_reset(cu);
        } else {
            if (custr_appendc(cu, cc) != 0) {
                error = errno;
                goto out;
            }
        }
    }

out:
    custr_free(cu);
    errno = error;
    return (error == 0 ? 0 : -1);
}