Beispiel #1
0
int setlogcons_main(int argc UNUSED_PARAM, char **argv)
{
	struct {
		char fn;
		char subarg;
	} arg = { 11, /* redirect kernel messages */
			  0   /* to specified console (current as default) */
			};

	if (argv[1])
		arg.subarg = xatou_range(argv[1], 0, 63);

	xioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg);

	return EXIT_SUCCESS;
}
Beispiel #2
0
void sendevent_main(void)
{
  int fd = xopen(*toys.optargs, O_RDWR);
  int version;
  struct input_event ev;

  if (ioctl(fd, EVIOCGVERSION, &version))
    perror_exit("EVIOCGVERSION failed for %s", *toys.optargs);
  
  memset(&ev, 0, sizeof(ev));
  // TODO: error checking and support for named constants.
  ev.type = atoi(toys.optargs[1]);
  ev.code = atoi(toys.optargs[2]);
  ev.value = atoi(toys.optargs[3]);
  xwrite(fd, &ev, sizeof(ev));
}
Beispiel #3
0
int			main(int ac, char **av)
{
	int		fd;
	t_raw	raw;
	t_data	data;
	t_env	env;

	read_args(&env, ac, av);
	get_env(&env, av[1]);
	fd = xopen(av[1], O_RDONLY);
	raw = read_file(fd);
	close(fd);
	data = read_raw(raw);
	display_data(data, env);
	mlx_loop(env.mlx);
	return (1);
}
Beispiel #4
0
static void open_file_and_read_lines(void)
{
    if (filename) {
        int fd = xopen(filename, O_RDONLY);
        dup2(fd, 0);
        if (fd) close(fd);
    } else {
        /* "less" with no arguments in argv[] */
        /* For status line only */
        filename = xstrdup(bb_msg_standard_input);
    }
    readpos = 0;
    readeof = 0;
    linepos = 0;
    terminated = 1;
    read_lines();
}
Beispiel #5
0
void
donefds(void)
{

    xclose(0);
    xclose(1);
    xclose(2);
    didfds = 0;
#ifdef NISPLUS
    {
	int fd = xopen(_PATH_DEVNULL, O_RDONLY|O_LARGEFILE);
	(void)dcopy(fd, 1);
	(void)dcopy(fd, 2);
	(void)dmove(fd, 0);
    }
#endif /*NISPLUS*/    
}
void syslinux_execute(void)
{
	char *device, *diskdevice;
	char *bootimages;
	int fd;

	if (strcmp(hashmapGetPrintf(ictx.opts, "none", BASE_BOOTLOADER),
				"syslinux"))
		return;

	pr_info("Writing MBR");
        diskdevice = xasprintf("/dev/block/%s",
			hashmapGetPrintf(ictx.opts, NULL, BASE_INSTALL_DISK));
	dd(SYSLINUX_MBR, diskdevice);
        free(diskdevice);

	/* SYSLINUX complains if this isn't done */
	chmod("/tmp", 01777);

	bootimages = hashmapGetPrintf(ictx.opts, NULL, BASE_BOOT_LIST);
	device = hashmapGetPrintf(ictx.opts, NULL, "partition.bootloader:device");
	pr_info("Installing ldlinux.sys onto %s", device);
	do_install_syslinux(device);

	/* In case we die() before we are finished */
	signal(SIGABRT, sighandler);
	mount_partition_device(device, "vfat", BOOTLOADER_PATH);

	pr_info("Copying syslinux support files");
	copy_file(IMAGES_PATH "vesamenu.c32", BOOTLOADER_PATH "vesamenu.c32");
	copy_file(IMAGES_PATH "android.c32", BOOTLOADER_PATH "android.c32");

	pr_info("Constructing syslinux.cfg");
	/* Put the initial template stuff in */
	copy_file(SYSLINUX_CFG_TEM_FN, SYSLINUX_CFG_FN);
	fd = xopen(SYSLINUX_CFG_FN, O_WRONLY | O_APPEND);
	put_string(fd, "menu androidcommand %s\n",
		hashmapGetPrintf(ictx.opts, NULL, "partition.misc:index"));
	string_list_iterate(bootimages, bootimage_cb, &fd);

	xclose(fd);
	umount(BOOTLOADER_PATH);
	rmdir(BOOTLOADER_PATH);
	signal(SIGABRT, SIG_DFL);
	pr_info("SYSLINUX installation complete");
}
Beispiel #7
0
static void build_code(char *str)
{
  char *args[] = {"as", "--32", SFILE_WRITE, "-o", BFILE_WRITE, NULL};
  Elf32_Ehdr  *aspElf_Header;
  Elf32_Shdr  *aspElf_Shdr;
  Elf32_Off   offset;
  struct stat sts;
  uint32_t    size;
  int         status;
  void        *map;
  pid_t       pid;
  int         fd;

  del_files();
  write_source_file(str);
  pid = fork();
  if (pid == 0)
    {
      execvp(args[0], args);
      exit(EXIT_SUCCESS);
    }
  waitpid(pid, &status, 0);

  if (stat(BFILE_WRITE, &sts) == -1)
    exit(EXIT_FAILURE);

  fd = xopen(BFILE_WRITE, O_RDONLY, 0644);
  map = xmmap(0, sts.st_size, PROT_READ, MAP_SHARED, fd, 0);

  aspElf_Header = map;
  aspElf_Shdr = (Elf32_Shdr *)((char *)map + aspElf_Header->e_shoff);

  offset = return_info_text(0, map, aspElf_Header, aspElf_Shdr);
  size = return_info_text(1, map, aspElf_Header, aspElf_Shdr);

  asm_mode.size = size;
  asm_mode.opcode = xmalloc((size * sizeof(char)) + 1);
  asm_mode.argument = str;
  memcpy((char *)asm_mode.opcode, (char *)map + offset, asm_mode.size);
  opcode_mode.flag = 1;
  opcode_mode.size = asm_mode.size;
  opcode_mode.opcode = asm_mode.opcode;

  xclose(fd);
  del_files();
}
int watchdog_main(int argc, char **argv)
{
	unsigned opts;
	unsigned timer_duration = 30000; /* Userspace timer duration, in milliseconds */
	char *t_arg;

	opt_complementary = "=1"; /* must have 1 argument */
	opts = getopt32(argv, "Ft:", &t_arg);

	if (opts & OPT_TIMER) {
		static const struct suffix_mult suffixes[] = {
			{ "ms", 1 },
			{ "", 1000 },
			{ }
		};
		timer_duration = xatou_sfx(t_arg, suffixes);
	}

	if (!(opts & OPT_FOREGROUND)) {
		bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
	}

	bb_signals(BB_FATAL_SIGS, watchdog_shutdown);

	/* Use known fd # - avoid needing global 'int fd' */
	xmove_fd(xopen(argv[argc - 1], O_WRONLY), 3);

// TODO?
//	if (!(opts & OPT_TIMER)) {
//		if (ioctl(fd, WDIOC_GETTIMEOUT, &timer_duration) == 0)
//			timer_duration *= 500;
//		else
//			timer_duration = 30000;
//	}

	while (1) {
		/*
		 * Make sure we clear the counter before sleeping, as the counter value
		 * is undefined at this point -- PFM
		 */
		write(3, "", 1); /* write zero byte */
		usleep(timer_duration * 1000L);
	}
	return EXIT_SUCCESS; /* - not reached, but gcc 4.2.1 is too dumb! */
}
Beispiel #9
0
int nohup_main(int argc, char **argv)
{
	int nullfd;
	const char *nohupout;
	char *home = NULL;

	xfunc_error_retval = 127;

	if (argc < 2) bb_show_usage();

	nullfd = xopen(bb_dev_null, O_WRONLY|O_APPEND);
	/* If stdin is a tty, detach from it. */
	if (isatty(STDIN_FILENO))
		dup2(nullfd, STDIN_FILENO);

	nohupout = "nohup.out";
	/* Redirect stdout to nohup.out, either in "." or in "$HOME". */
	if (isatty(STDOUT_FILENO)) {
		close(STDOUT_FILENO);
		if (open(nohupout, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR) < 0) {
			home = getenv("HOME");
			if (home) {
				nohupout = concat_path_file(home, nohupout);
				xopen3(nohupout, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR);
			}
		}
	} else dup2(nullfd, STDOUT_FILENO);

	/* If we have a tty on stderr, announce filename and redirect to stdout.
	 * Else redirect to /dev/null.
	 */
	if (isatty(STDERR_FILENO)) {
		bb_error_msg("appending to %s", nohupout);
		dup2(STDOUT_FILENO, STDERR_FILENO);
	} else dup2(nullfd, STDERR_FILENO);

	if (nullfd > 2)
		close(nullfd);
	signal(SIGHUP, SIG_IGN);

	BB_EXECVP(argv[1], argv+1);
	if (ENABLE_FEATURE_CLEAN_UP && home)
		free((char*)nohupout);
	bb_simple_perror_msg_and_die(argv[1]);
}
Beispiel #10
0
void cmd_scalebranch()
{
  int i;
  int nodes_count;
  FILE * out;

  /* attempt to open output file */
  out = opt_outfile ?
          xopen(opt_outfile,"w") : stdout;

  /* parse tree */
  if (!opt_quiet)
    fprintf(stdout, "Parsing tree file...\n");

  rtree_t * rtree = rtree_parse_newick(opt_treefile);

  if (!rtree)
    fatal("Tree must be rooted...");

  nodes_count = 2*rtree->leaves-1;
  rtree_t ** nodes = (rtree_t **)xmalloc(nodes_count*sizeof(rtree_t *));

  /* get all nodes */
  rtree_query_tipnodes(rtree, nodes);
  rtree_query_innernodes(rtree, nodes+rtree->leaves);

  for (i=0; i < nodes_count; ++i)
    nodes[i]->length *= opt_scalebranch_factor;

  
  char * newick = rtree_export_newick(rtree);

  fprintf(out, "%s\n", newick);

  if (opt_outfile)
    fclose(out);

  free(newick);
  
  /* deallocate tree structure */
  rtree_destroy(rtree);

  if (!opt_quiet)
    fprintf(stdout, "\nDone...\n");
}
Beispiel #11
0
int		main(int ac, char **av)
{
  t_open	*opn;
  t_list	*list;

  if (ac == 1)
    {
      my_putstr("asm: fatal error: no input file\n");
      my_putstr("Compilation terminated\n");
      return (0);
    }
  else
    {
      struct_init(&opn, &list);
      xopen(av[1], opn, list);
    }
  return (0);
}
Beispiel #12
0
/*
 * Opens the device file associated with given i2c bus.
 *
 * Upstream i2c-tools also support opening devices by i2c bus name
 * but we drop it here for size reduction.
 */
static int i2c_dev_open(int i2cbus)
{
	char filename[sizeof("/dev/i2c-%d") + sizeof(int)*3];
	int fd;

	sprintf(filename, "/dev/i2c-%d", i2cbus);
	fd = open(filename, O_RDWR);
	if (fd < 0) {
		if (errno == ENOENT) {
			filename[8] = '/'; /* change to "/dev/i2c/%d" */
			fd = xopen(filename, O_RDWR);
		} else {
			bb_perror_msg_and_die("can't open '%s'", filename);
		}
	}

	return fd;
}
Beispiel #13
0
void testDistrib(){
	float dd[1000]; memset(dd,0,sizeof(dd));
	for(int i=0; i<profileLength; i++){
		float xx=fProfile->get(i);
		if(xx==NA) dd[0]++;
		else{
			float x=log(1+xx);
			int k=(int)(x/10*1000)+1;
			dd[k]++;
		}
	}

	FILE *f=xopen("dstr","wt");
	for(int i=0; i<1000; i++){
		fprintf(f,"%5.2f\t%6f\n",i*10./1000.,dd[i]);
	}
	fclose(f);
}
Beispiel #14
0
bwa_seqio_t *bwa_bam_open(const char *fn, int which, char **saif,
                          gap_opt_t *o0, bam_header_t **hh)
{
    int c, b=0;
    bwa_seqio_t *bs;
    bam_header_t *h;
    bs = (bwa_seqio_t*)calloc(1, sizeof(bwa_seqio_t));
    bs->is_bam = 1;
    bs->which = which;
    bs->fp = (fn[0]!='-' || fn[1]) ? bam_open(fn, "r") : bam_dopen(0, "r") ;
    h = bam_header_read(bs->fp);
    if(hh) *hh=h;
    else bam_header_destroy(h);

    if( saif ) for(c=0; c!=3; ++c)
        {
            gap_opt_t opt;
            if( saif[c] ) {
                bs->sai[c] = xopen(saif[c], "r");
                if( 1 > fread(&opt, sizeof(gap_opt_t), 1, bs->sai[c]) )
                {
                    fclose(bs->sai[c]);
                    bs->sai[c] = 0;
                }
                opt.n_threads=o0->n_threads;
                if(o0) {
                    if(b) {
                        opt.mode=o0->mode;
                        if( memcmp(o0, &opt, sizeof(gap_opt_t)) ) {
                            fprintf( stderr, "[bwa_bam_open] options from sai file \"%s\" conflict with others.\n", saif[c] ) ;
                            exit(1);
                        }
                        fprintf( stderr, "[bwa_bam_open] options from sai file \"%s\" match.\n", saif[c] ) ;
                    }
                    else {
                        fprintf( stderr, "[bwa_bam_open] recovered options from sai file \"%s\".\n", saif[c] ) ;
                        memcpy(o0, &opt, sizeof(gap_opt_t));
                        b=1;
                    }
                }
            }
        }
    return bs;
}
Beispiel #15
0
static int write_ar_archive(archive_handle_t *handle)
{
	struct stat st;
	archive_handle_t *out_handle;

	if (fstat(handle->src_fd, &st) == -1)
		bb_simple_perror_msg_and_die(handle->ar__name);

	/* if archive exists, create a new handle for output.
	 * we create it in place of the old one.
	 */
	if (st.st_size != 0) {
		out_handle = init_handle();
		xunlink(handle->ar__name);
		out_handle->src_fd = xopen(handle->ar__name, O_WRONLY | O_CREAT | O_TRUNC);
		out_handle->accept = handle->accept;
	} else {
		out_handle = handle;
	}

	handle->ar__out = out_handle;

	xwrite(out_handle->src_fd, AR_MAGIC "\n", AR_MAGIC_LEN + 1);
	out_handle->offset += AR_MAGIC_LEN + 1;

	/* skip to the end of the archive if we have to append stuff */
	if (st.st_size != 0) {
		handle->filter = filter_replaceable;
		handle->action_data = copy_data;
		unpack_ar_archive(handle);
	}

	while (write_ar_header(out_handle) == 0)
		continue;

	/* optional, since we exit right after we return */
	if (ENABLE_FEATURE_CLEAN_UP) {
		close(handle->src_fd);
		if (out_handle->src_fd != handle->src_fd)
			close(out_handle->src_fd);
	}

	return EXIT_SUCCESS;
}
Beispiel #16
0
static int daemonize(void)
{
	int fd;
	int pid = fork();
	if (pid < 0) /* error */
		return -errno;
	if (pid > 0) /* parent */
		return 0;
	/* child */
	fd = xopen(bb_dev_null, O_RDWR);
	dup2(fd, 0);
	dup2(fd, 1);
	dup2(fd, 2);
	while (fd > 2) close(fd--);
	setsid();
	openlog(applet_name, LOG_PID, LOG_DAEMON);
	logmode = LOGMODE_SYSLOG;
	return 1;
}
int uuencode_main(int argc UNUSED_PARAM, char **argv)
{
	struct stat stat_buf;
	int src_fd = STDIN_FILENO;
	const char *tbl;
	mode_t mode;
	char src_buf[SRC_BUF_SIZE];
	char dst_buf[DST_BUF_SIZE + 1];

	tbl = bb_uuenc_tbl_std;
	mode = 0666 & ~umask(0666);
	opt_complementary = "-1:?2"; /* must have 1 or 2 args */
	if (getopt32(argv, "m")) {
		tbl = bb_uuenc_tbl_base64;
	}
	argv += optind;
	if (argv[1]) {
		src_fd = xopen(*argv, O_RDONLY);
		fstat(src_fd, &stat_buf);
		mode = stat_buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
		argv++;
	}

	printf("begin%s %o %s", tbl == bb_uuenc_tbl_std ? "" : "-base64", mode, *argv);
	while (1) {
		size_t size = full_read(src_fd, src_buf, SRC_BUF_SIZE);
		if (!size)
			break;
		if ((ssize_t)size < 0)
			bb_perror_msg_and_die(bb_msg_read_error);
		/* Encode the buffer we just read in */
		bb_uuencode(dst_buf, src_buf, size, tbl);
		bb_putchar('\n');
		if (tbl == bb_uuenc_tbl_std) {
			bb_putchar(tbl[size]);
		}
		fflush(stdout);
		xwrite(STDOUT_FILENO, dst_buf, 4 * ((size + 2) / 3));
	}
	printf(tbl == bb_uuenc_tbl_std ? "\n`\nend\n" : "\n====\n");

	fflush_stdout_and_exit(EXIT_SUCCESS);
}
Beispiel #18
0
static int
do_test (void)
{
  char *tempfile;
  int fd;

  /* Create a temporary file and open it in read-only mode.  */
  TEST_VERIFY_EXIT (create_temp_file ("tst-bz11319", &tempfile));
  fd = xopen (tempfile, O_RDONLY, 0660);

  /* Try and write to the temporary file to intentionally fail, then
     check that dprintf (or __dprintf_chk) return EOF.  */
  TEST_COMPARE (dprintf (fd, "%d", 0), EOF);

  xclose (fd);
  free (tempfile);

  return 0;
}
Beispiel #19
0
/* use `x_foo' names to avoid colliding with similarly named global
 * variables */
void
init(int x_startlab, int x_keep_comments, const char *x_filename)
{
    FILE *x_infile;

    x_infile = xopen(x_filename, IO_MODE_READ, fatal);
    if (STREQ(x_filename, "-"))
        x_filename = "(stdin)"; /* this is clearer in error messages */

    inclevel = 0;               /* count of inclusion levels */
    lineno[0] = 1;              /* line count of first file */
    filename[0] = x_filename;   /* filename of first file */
    infile[0] = x_infile;       /* file handle of first file */
    keep_comments = x_keep_comments;
    current_subprogram_name[0] = EOS;
    current_subprogram_type = SUBPRG_NONE;
    reading_parenthesized_macro_definition = false;
    set_starting_label(x_startlab);
}
Beispiel #20
0
/* file utilities */
static uint8_t *
readall(const char *filename, unsigned long long *msglenp)
{
	unsigned long long msglen = 0;
	uint8_t *msg = NULL;
	struct stat sb;
	ssize_t x, space;
	int fd;
	const unsigned long long maxmsgsize = 1UL << 30;

	fd = xopen(filename, O_RDONLY | O_NOFOLLOW, 0);
	if (fstat(fd, &sb) == 0 && S_ISREG(sb.st_mode)) {
		if (sb.st_size > maxmsgsize)
			errx(1, "msg too large in %s", filename);
		space = sb.st_size + 1;
	} else {
		space = 64 * 1024;
	}

	msg = xmalloc(space + 1);
	while (1) {
		if (space == 0) {
			if (msglen * 2 > maxmsgsize)
				errx(1, "msg too large in %s", filename);
			space = msglen;
			if (!(msg = realloc(msg, msglen + space + 1)))
				errx(1, "realloc");
		}
		if ((x = read(fd, msg + msglen, space)) == -1)
			err(1, "read from %s", filename);
		if (x == 0)
			break;
		space -= x;
		msglen += x;
	}

	msg[msglen] = 0;
	close(fd);

	*msglenp = msglen;
	return msg;
}
Beispiel #21
0
static int
do_test (void)
{
  char *dir = support_create_temp_directory ("tst-xreadlink-");
  char *symlink_name = xasprintf ("%s/symlink", dir);
  add_temp_file (symlink_name);

  /* The limit 10000 is arbitrary and simply there to prevent an
     attempt to exhaust all available disk space.  */
  for (int size = 1; size < 10000; ++size)
    {
      char *contents = xmalloc (size + 1);
      for (int i = 0; i < size; ++i)
        contents[i] = 'a' + (rand () % 26);
      contents[size] = '\0';
      if (symlink (contents, symlink_name) != 0)
        {
          if (errno == ENAMETOOLONG)
            {
              printf ("info: ENAMETOOLONG failure at %d bytes\n", size);
              free (contents);
              break;
            }
          FAIL_EXIT1 ("symlink (%d bytes): %m", size);
        }

      char *readlink_result = xreadlink (symlink_name);
      TEST_VERIFY (strcmp (readlink_result, contents) == 0);
      free (readlink_result);
      xunlink (symlink_name);
      free (contents);
    }

  /* Create an empty file to suppress the temporary file deletion
     warning.  */
  xclose (xopen (symlink_name, O_WRONLY | O_CREAT, 0));

  free (symlink_name);
  free (dir);

  return 0;
}
Beispiel #22
0
/*
 * can write a few different file types
 */
static void
writekeyfile(const char *filename, const char *info, const void *key,
    size_t keylen, const char *ident, int oflags, mode_t mode)
{
	char header[1024];
	char b64[1024];
	int fd;

	fd = xopen(filename, O_CREAT|oflags|O_NOFOLLOW|O_WRONLY, mode);
	snprintf(header, sizeof(header), "-----BEGIN REOP %s-----\nident:%s\n",
	    info, ident);
	writeall(fd, header, strlen(header), filename);
	if (b64_ntop(key, keylen, b64, sizeof(b64)) == -1)
		errx(1, "b64 encode failed");
	writeb64data(fd, filename, b64);
	explicit_bzero(b64, sizeof(b64));
	snprintf(header, sizeof(header), "-----END REOP %s-----\n", info);
	writeall(fd, header, strlen(header), filename);
	close(fd);
}
t_history *history_create_list(t_config *config, t_history **history)
{
  int		fd;
  char		*tmp;
  int		id_command;
  int		flag;

  id_command = 0;
  if ((fd = xopen(".history", O_RDONLY, 0, NO)) != -1)
    while ((tmp = get_next_line(fd)))
      {
	if ((flag = history_fill_list(history, tmp, fd, id_command)) == -1)
	  return (NULL);
	else if (flag == 1)
	  return (history_list_config(config, *history, 0));
	id_command++;
      }
  close(fd);
  return (history_list_config(config, *history, 0));
}
Beispiel #24
0
int	my_script_command(char *command)
{
  int	fd_file;
  char	buff[512];
  time_t	date;

  fd_file = xopen("typescript", O_WRONLY | O_CREAT | O_TRUNC, 0644);
  printf("Script started, file is typescript\n");
  time(&date);
  strcpy(buff, "Script started on ");
  strcat(buff, ctime(&date));
  xwrite(fd_file, buff, strlen(buff));
  exec_command(command);
  printf("Script done, file is typescript\n");
  strcpy(buff, "Script done on ");
  strcat(buff, ctime(&date));
  xwrite(fd_file, buff, strlen(buff));
  xclose(fd_file);
  return (EXIT_SUCCESS);
}
Beispiel #25
0
void	init_object(t_env *raytracer, const char *file)
{
  int	elem;
  char	*tmp;
  int	i;

  elem = xopen(file, O_RDONLY);
  while ((tmp = get_next_line(elem)))
    {
      i = -1;
      while (++i < MAX && my_strncmp(tmp, functions[i].object_name, my_strlen(functions[i].object_name)) != 1);
      if (i < MAX)
	push_front(&(raytracer->objects[i]), (*(functions[i].init_func))(tmp));
      else if (my_strncmp(tmp, "camera", 6) != 0)
	init_cam(&raytracer->camera, tmp);
      else if (my_strncmp(tmp, "plan", 4) != 0)
	init_plan(&raytracer->plan, tmp);
      printf("%s\n", tmp);
    }
}
Beispiel #26
0
static void write_source_file(char *str)
{
  int fd;
  int i;

  i = 0;
  fd = xopen(SFILE_WRITE, O_WRONLY | O_CREAT | O_APPEND, 0755);
  if (syntaxins.type == INTEL)
    write(fd, ".intel_syntax noprefix\n", 23);
  while (str[i] != '\0')
    {
      if (str[i] == ';')
        write(fd, "\n", 1);
      else
        write(fd, &str[i], 1);
      i++;
    }
  write(fd, "\n", 1);
  xclose(fd);
}
Beispiel #27
0
static unsigned int write_file(char *file, char *base, unsigned int offset)
{
	int fd;
	char *buf;

	fd = xopen(file, O_RDONLY, 0);
	buf = mmap(NULL, image_length, PROT_READ, MAP_PRIVATE, fd, 0);
	if (buf == MAP_FAILED) {
		error_msg_and_die("mmap failed");
	}
	memcpy(base + offset, buf, image_length);
	munmap(buf, image_length);
	close (fd);
	/* Pad up the image_length to a 4-byte boundary */
	while (image_length & 3) {
		*(base + offset + image_length) = '\0';
		image_length++;
	}
	return (offset + image_length);
}
Beispiel #28
0
static char *
xgetpass(const char *prm)
{
    static struct strbuf pass; /* = strbuf_INIT; */
    int fd;
    sigset_t oset, set;
    struct sigaction sa, osa;

    sa.sa_handler = SIG_IGN;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0;
    (void)sigaction(SIGINT, &sa, &osa);

    sigemptyset(&set);
    sigaddset(&set, SIGINT);
    (void)sigprocmask(SIG_UNBLOCK, &set, &oset);

    cleanup_push(&osa, sigint_cleanup);
    cleanup_push(&oset, sigprocmask_cleanup);
    (void) Rawmode();	/* Make sure, cause we want echo off */
    fd = xopen("/dev/tty", O_RDWR|O_LARGEFILE);
    if (fd == -1)
	fd = SHIN;
    else
	cleanup_push(&fd, open_cleanup);

    xprintf("%s", prm); flush();
    pass.len = 0;
    for (;;)  {
	char c;

	if (xread(fd, &c, 1) < 1 || c == '\n') 
	    break;
	strbuf_append1(&pass, c);
    }
    strbuf_terminate(&pass);

    cleanup_until(&osa);

    return pass.s;
}
Beispiel #29
0
void cmd_extract_rtips()
{
  unsigned int i;
  FILE * out;

  /* attempt to open output file */
  out = opt_outfile ?
          xopen(opt_outfile,"w") : stdout;

  /* parse tree */
  if (!opt_quiet)
    fprintf(stdout, "Parsing tree file...\n");

  rtree_t * rtree = rtree_parse_newick(opt_treefile);

  if (!rtree)
    fatal("Tree must be rooted...");
  
  if (!opt_quiet)
    fprintf(out,"Tip labels for left subtree:\n");

  /* allocate list of tip nodes in left subtree */
  rtree_t ** node_list = (rtree_t **)calloc(rtree->right->leaves,
                                            sizeof(rtree_t *)); 
  rtree_query_tipnodes(rtree->right, node_list);

  /* print tip-node labels */
  for (i = 0; i < rtree->right->leaves; ++i)
    fprintf(out, "%s\n", node_list[i]->label);

  /* deallocate tree structure */
  rtree_destroy(rtree);

  free(node_list);

  if (opt_outfile)
    fclose(out);

  if (!opt_quiet)
    fprintf(stdout, "\nDone...\n");
}
Beispiel #30
0
int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
{
	struct rpm_lead lead;
	unsigned pos;

	if (argv[1]) {
		xmove_fd(xopen(argv[1], O_RDONLY), rpm_fd);
	}
	xread(rpm_fd, &lead, sizeof(lead));

	/* Just check the magic, the rest is irrelevant */
	if (lead.magic != htonl(RPM_LEAD_MAGIC)) {
		bb_error_msg_and_die("invalid RPM magic");
	}

	/* Skip the signature header, align to 8 bytes */
	pos = skip_header();
	seek_by_jump(rpm_fd, (-(int)pos) & 7);

	/* Skip the main header */
	skip_header();

	//if (SEAMLESS_COMPRESSION)
	//	/* We need to know whether child (gzip/bzip/etc) exits abnormally */
	//	signal(SIGCHLD, check_errors_in_children);

	/* This works, but doesn't report uncompress errors (they happen in child) */
	setup_unzip_on_fd(rpm_fd, /*fail_if_not_compressed:*/ 1);
	if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
		bb_error_msg_and_die("error unpacking");

	if (ENABLE_FEATURE_CLEAN_UP) {
		close(rpm_fd);
	}

	if (SEAMLESS_COMPRESSION) {
		check_errors_in_children(0);
		return bb_got_signal;
	}
	return EXIT_SUCCESS;
}