示例#1
0
/*
 * Enumerate over all elements in a container.
 */
static void *
enum_start(void *arg)
{
    char *err;
    uint64_t   num = 0;
    fdf.ctr_t *ctr = arg;

    zs_iter_t *iter = zs_iter_init(ctr, &err);
    if (!iter)
        die_err(err, "zs_iter_init failed");

    for (;;) {
        char *key;
        char *data;
        uint64_t keylen;
        uint64_t datalen;

        int s = zs_iter_next(iter, &key, &keylen, &data, &datalen, &err);
        if (s < 0)
            die_err(err, "zs_iter_next failed");
        if (s == 0)
            break;
        num++;
    }

    if (!zs_iter_done(iter, &err))
        die_err(err, "zs_iter_done failed");
    if (num != Objects)
        die("enumerated %ld/%ld objects", num, Objects);
    printv("enumerated %ld/%ld objects", num, Objects);
    return NULL;
}
示例#2
0
文件: exec.c 项目: Cougar/pwm
void wm_exec(const char *cmd)
{
	int pid;
	char *tmp;
	int tmp_len;

	pid=fork();
	
	if(pid<0)
		warn_err();
	
	if(pid!=0)
		return;
	
	setup_environ(SCREEN->xscr);
	
	close(wglobal.conn);
	
	tmp_len = strlen(cmd)+8;
	tmp=ALLOC_N(char, tmp_len);
	
	if(tmp==NULL)
		die_err();
	
	snprintf(tmp, tmp_len, "exec %s", cmd);
	
	do_exec(tmp);
}
示例#3
0
文件: avl.c 项目: seemuch/avl
int main(int argc, char *argv[])
{
	parse_command_line(argc, argv);

	yyin = fopen(input_file, "r");
	if (!yyin)
		die_err("can not open input file");

	if (translate_flag) {
		yyout = fopen(translate_file, "w");
		if (!yyout)
			die_err("can not open translate file");
	}
	else {
		int fd = mkstemp(temp_file);
		if (fd < 0)
			die_err("mkstemp() failed");
		yyout = fdopen(fd, "w");
		if (!yyout)
			die_err("can not open temporary file");
	}

	if (yyparse() != 0)
		die("Parsing failed.");

	if (typeCheckingFail)
		die("Sorry, type checking failed.");

	fclose(yyin);
	fclose(yyout);

	/* code formatting */
	if (translate_flag)
		strcpy(format_file, translate_file);
	else
		strcpy(format_file, temp_file);

	execute_program(ASTYLE_OPTIONS);

	/* invoking g++ */
	if (!translate_flag)
		execute_program(CXX_OPTIONS);

	return 0;
}
示例#4
0
文件: buffer.c 项目: micha/json-table
ssize_t buf_append_read(Buffer *b, FILE *in) {
  char tmp[BUFSIZ];
  ssize_t bytes_r = 0;
  int fd = fileno(in);

  if ((bytes_r = read(fd, tmp, sizeof(tmp))) > 0)
    buf_append(b, (const char*) tmp, bytes_r);

  if (bytes_r < 0) die_err("can't read input");

  return bytes_r;
}
示例#5
0
文件: avl.c 项目: seemuch/avl
void execute_program(char *const *options)
{
	pid_t pid = fork();

	if (pid < 0)
		die_err("fork() failed");
	else if (pid == 0) {
		char *const *s = options;
		while (*s)
			printf("%s ", *s++);
		printf("\n");

		if (execvp(options[0], options) < 0)
			die_err("execvp() failed");
	}

	int status;
	if (waitpid(pid, &status, 0) != pid)
		die_err("waitpid() failed");
	if (WEXITSTATUS(status))
		die("failed to execute %s.", options[0]);
}
示例#6
0
文件: avl.c 项目: seemuch/avl
void parse_command_line(int argc, char *argv[])
{
	memset(input_file, 0, MAX_FILENAME);
	memset(output_file, 0, MAX_FILENAME);
	memset(translate_file, 0, MAX_FILENAME);
	memset(temp_file, 0, MAX_FILENAME);
	memset(format_file, 0, MAX_FILENAME);
	strcpy(output_file, DEFAULT_OUTPUT);
	strcpy(temp_file, DEFAULT_TEMP);

	while (1) {
		int option_index = 0;
		char c = getopt_long(argc, argv, "ho:t", long_options, &option_index);
		if (c == -1)
			break;

		switch (c) {
			case 'h':
				usage();
				exit(EXIT_SUCCESS);
			case 'o':
				if (!optarg) {
					usage();
					exit(EXIT_FAILURE);
				}
				if (strlen(optarg) <= 0)
					die("no output filename.");
				else if (strlen(optarg) >= MAX_FILENAME)
					die("output filename too long: %s.", optarg);
				strcpy(output_file, optarg);
				output_flag = 1;
				break;
			case 't':
				translate_flag = 1;
				break;
			default:
				usage();
				exit(EXIT_FAILURE);
		}
	}

	if (output_flag && translate_flag)
		die("Please specify at most one option at a time.");

	if (optind != argc - 1) {
		usage();
		exit(EXIT_FAILURE);
	}
	if (strlen(argv[optind]) <= strlen(DEFAULT_EXT)
			|| strlen(argv[optind]) >= MAX_FILENAME)
		die("invalid input filename: %s.", argv[optind]);
	strcpy(input_file, argv[optind]);
	if (strcmp(input_file + strlen(input_file) - strlen(DEFAULT_EXT),
				DEFAULT_EXT) != 0)
		die("not a valid avl source file: %s.", input_file);

	struct stat buf;
	if (stat(input_file, &buf) != 0)
		die_err("invalid input file");

	if (translate_flag) {
		strcpy(translate_file, input_file);
		strcpy(translate_file + strlen(translate_file) - strlen(DEFAULT_EXT),
				TRANSLATE_EXT);
	}
}
示例#7
0
int main(int argc, char *argv[])
{
    static unsigned char sectbuf[SECTOR_SIZE];
    int dev_fd;
    struct stat st;
    int status;
    const char *tmpdir;
    char *mtools_conf;
    int mtc_fd;
    FILE *mtc, *mtp;
    struct libfat_filesystem *fs;
    libfat_sector_t s, *secp;
    libfat_sector_t *sectors;
    int32_t ldlinux_cluster;
    int nsectors;
    const char *errmsg;
    int ldlinux_sectors, patch_sectors;
    int i;

    (void)argc;			/* Unused */

    mypid = getpid();
    program = argv[0];

    parse_options(argc, argv, MODE_SYSLINUX);

    if (!opt.device)
	usage(EX_USAGE, MODE_SYSLINUX);

    if (opt.sectors || opt.heads || opt.reset_adv || opt.set_once
	|| (opt.update_only > 0) || opt.menu_save) {
	fprintf(stderr,
		"At least one specified option not yet implemented"
		" for this installer.\n");
	exit(1);
    }

    /*
     * Temp directory of choice...
     */
    tmpdir = getenv("TMPDIR");
    if (!tmpdir) {
#ifdef P_tmpdir
	tmpdir = P_tmpdir;
#elif defined(_PATH_TMP)
	tmpdir = _PATH_TMP;
#else
	tmpdir = "/tmp";
#endif
    }

    /*
     * First make sure we can open the device at all, and that we have
     * read/write permission.
     */
    dev_fd = open(opt.device, O_RDWR);
    if (dev_fd < 0 || fstat(dev_fd, &st) < 0) {
	die_err(opt.device);
	exit(1);
    }

    if (!opt.force && !S_ISBLK(st.st_mode) && !S_ISREG(st.st_mode)) {
	fprintf(stderr,
		"%s: not a block device or regular file (use -f to override)\n",
		opt.device);
	exit(1);
    }

    xpread(dev_fd, sectbuf, SECTOR_SIZE, opt.offset);

    /*
     * Check to see that what we got was indeed an MS-DOS boot sector/superblock
     */
    if ((errmsg = syslinux_check_bootsect(sectbuf, NULL))) {
	die(errmsg);
    }

    /*
     * Create an mtools configuration file
     */
    if (asprintf(&mtools_conf, "%s//syslinux-mtools-XXXXXX", tmpdir) < 0 ||
	!mtools_conf)
	die_err(tmpdir);

    mtc_fd = mkstemp(mtools_conf);
    if (mtc_fd < 0 || !(mtc = fdopen(mtc_fd, "w")))
	die_err(mtools_conf);

    fprintf(mtc,
	    /* These are needed for some flash memories */
	    "MTOOLS_SKIP_CHECK=1\n"
	    "MTOOLS_FAT_COMPATIBILITY=1\n"
	    "drive s:\n"
	    "  file=\"/proc/%lu/fd/%d\"\n"
	    "  offset=%llu\n",
	    (unsigned long)mypid,
	    dev_fd, (unsigned long long)opt.offset);

    if (ferror(mtc) || fclose(mtc))
	die_err(mtools_conf);

    /*
     * Run mtools to create the LDLINUX.SYS file
     */
    if (setenv("MTOOLSRC", mtools_conf, 1)) {
	perror(program);
	exit(1);
    }

    /*
     * Create a vacuous ADV in memory.  This should be smarter.
     */
    syslinux_reset_adv(syslinux_adv);

    /* This command may fail legitimately */
    status = system("mattrib -h -r -s s:/ldlinux.sys 2>/dev/null");
    (void)status;		/* Keep _FORTIFY_SOURCE happy */

    mtp = popen("mcopy -D o -D O -o - s:/ldlinux.sys", "w");
    if (!mtp ||
	fwrite((const void _force *)syslinux_ldlinux,
	       1, syslinux_ldlinux_len, mtp)
		!= syslinux_ldlinux_len ||
	fwrite((const void _force *)syslinux_adv,
	       1, 2 * ADV_SIZE, mtp)
		!= 2 * ADV_SIZE ||
	(status = pclose(mtp), !WIFEXITED(status) || WEXITSTATUS(status))) {
	die("failed to create ldlinux.sys");
    }

    /*
     * Now, use libfat to create a block map
     */
    ldlinux_sectors = (syslinux_ldlinux_len + 2 * ADV_SIZE
		       + SECTOR_SIZE - 1) >> SECTOR_SHIFT;
    sectors = calloc(ldlinux_sectors, sizeof *sectors);
    fs = libfat_open(libfat_xpread, dev_fd);
    ldlinux_cluster = libfat_searchdir(fs, 0, "LDLINUX SYS", NULL);
    secp = sectors;
    nsectors = 0;
    s = libfat_clustertosector(fs, ldlinux_cluster);
    while (s && nsectors < ldlinux_sectors) {
	*secp++ = s;
	nsectors++;
	s = libfat_nextsector(fs, s);
    }
    libfat_close(fs);

    /* Patch ldlinux.sys and the boot sector */
    i = syslinux_patch(sectors, nsectors, opt.stupid_mode, opt.raid_mode,
		       opt.directory, NULL);
    patch_sectors = (i + SECTOR_SIZE - 1) >> SECTOR_SHIFT;

    /* Write the now-patched first sectors of ldlinux.sys */
    for (i = 0; i < patch_sectors; i++) {
	xpwrite(dev_fd, (const char _force *)syslinux_ldlinux
		+ i * SECTOR_SIZE, SECTOR_SIZE,
		opt.offset + ((off_t) sectors[i] << SECTOR_SHIFT));
    }

    /* Move ldlinux.sys to the desired location */
    if (opt.directory) {
	status = move_file("ldlinux.sys");
    } else {
	status = system("mattrib +r +h +s s:/ldlinux.sys");
    }

    if (!WIFEXITED(status) || WEXITSTATUS(status)) {
	fprintf(stderr,
		"%s: warning: failed to set system bit on ldlinux.sys\n",
		program);
    }

    /* This command may fail legitimately */
    status = system("mattrib -h -r -s s:/ldlinux.c32 2>/dev/null");
    (void)status;		/* Keep _FORTIFY_SOURCE happy */

    mtp = popen("mcopy -D o -D O -o - s:/ldlinux.c32", "w");
    if (!mtp ||	fwrite((const char _force *)syslinux_ldlinuxc32,
		       1, syslinux_ldlinuxc32_len, mtp)
	!= syslinux_ldlinuxc32_len ||
	(status = pclose(mtp), !WIFEXITED(status) || WEXITSTATUS(status))) {
	die("failed to create ldlinux.c32");
    }

    /* Move ldlinux.c32 to the desired location */
    if (opt.directory) {
	status = move_file("ldlinux.c32");
    } else {
	status = system("mattrib +r +h +s s:/ldlinux.c32");
    }

    if (!WIFEXITED(status) || WEXITSTATUS(status)) {
	fprintf(stderr,
		"%s: warning: failed to set system bit on ldlinux.c32\n",
		program);
    }

    /*
     * Cleanup
     */
    unlink(mtools_conf);

    /*
     * To finish up, write the boot sector
     */

    /* Read the superblock again since it might have changed while mounted */
    xpread(dev_fd, sectbuf, SECTOR_SIZE, opt.offset);

    /* Copy the syslinux code into the boot sector */
    syslinux_make_bootsect(sectbuf, VFAT);

    /* Write new boot sector */
    xpwrite(dev_fd, sectbuf, SECTOR_SIZE, opt.offset);

    close(dev_fd);
    sync();

    /* Done! */

    return 0;
}