コード例 #1
0
ファイル: torture_url.c プロジェクト: FreeMCU/freemcu
int test_print(void)
{
#if 0
  url_t u0[1];
  url_t *u1 = NULL;
  url_t const *u2 = (void *)-1;
  url_t const u3[1] = { URL_INIT_AS(sip) };
  char c0[] = "http://www.nokia.com/";
  char c1[] = "http://goodfeel.nokia.com/test";
  char c2[] = "/test2/";
  char c3[] = "///file/";

  tagi_t *lst;

  BEGIN();

  TEST(register_printf_function('U', printf_url, printf_url_info), 0);

  TEST(url_d(u0, c0), 0);
  printf("URL is %U\n", u0);

  TEST(url_d(u0, c1), 0);
  printf("URL is %U\n", u0);

  TEST(url_d(u0, c2), 0);
  printf("URL is %U\n", u0);

  TEST(url_d(u0, c3), 0);
  printf("URL is %U\n", u0);
#else
  BEGIN();
#endif

  END();
}
コード例 #2
0
/* We let the system close the LOG itself
   (Otherwise functions called by destructor can't use LOG File */
static void
mpfr_log_begin (void)
{
  const char *var;
  time_t tt;

  /* Grab some information */
  var = getenv ("MPFR_LOG_BASE");
  mpfr_log_base = var == NULL || *var == 0 ? 10 : atoi (var);

  var = getenv ("MPFR_LOG_LEVEL");
  mpfr_log_level = var == NULL || *var == 0 ? 7 : atoi (var);
  mpfr_log_current = 0;

  var = getenv ("MPFR_LOG_PREC");
  mpfr_log_prec = var == NULL || *var == 0 ? 0 : atol (var);

  /* Get what we need to log */
  mpfr_log_type = 0;
  if (getenv ("MPFR_LOG_INPUT") != NULL)
    mpfr_log_type |= MPFR_LOG_INPUT_F;
  if (getenv ("MPFR_LOG_OUTPUT") != NULL)
    mpfr_log_type |= MPFR_LOG_OUTPUT_F;
  if (getenv ("MPFR_LOG_TIME") != NULL)
    mpfr_log_type |= MPFR_LOG_TIME_F;
  if (getenv ("MPFR_LOG_INTERNAL") != NULL)
    mpfr_log_type |= MPFR_LOG_INTERNAL_F;
  if (getenv ("MPFR_LOG_MSG") != NULL)
    mpfr_log_type |= MPFR_LOG_MSG_F;
  if (getenv ("MPFR_LOG_ZIV") != NULL)
    mpfr_log_type |= MPFR_LOG_BADCASE_F;
  if (getenv ("MPFR_LOG_STAT") != NULL)
    mpfr_log_type |= MPFR_LOG_STAT_F;
  if (getenv ("MPFR_LOG_ALL") != NULL)
    mpfr_log_type = MPFR_LOG_INPUT_F|MPFR_LOG_OUTPUT_F|MPFR_LOG_TIME_F
      |MPFR_LOG_INTERNAL_F|MPFR_LOG_MSG_F|MPFR_LOG_BADCASE_F|MPFR_LOG_STAT_F;

  /* Register printf functions */
  register_printf_function ('R', mpfr_printf_mpfr_print,
                            mpfr_printf_mpfr_arginfo);

  /* Open filename if needed */
  var = getenv ("MPFR_LOG_FILE");
  if (var == NULL || *var == 0)
    var = "mpfr.log";
  if (mpfr_log_type != 0)
    {
      mpfr_log_file = fopen (var, "w");
      if (mpfr_log_file == NULL)
        {
          fprintf (stderr, "MPFR LOG: Can't open '%s' with w.\n", var);
          abort ();
        }
      time (&tt);
      fprintf (mpfr_log_file, "MPFR LOG FILE %s\n", ctime (&tt));
    }
}
コード例 #3
0
ファイル: rprintf.c プロジェクト: Xilinx/eglibc
int
main (void)
{
  /* Make a widget to print. */
  Widget mywidget;
  mywidget.name = "mywidget";

  /* Register the print function for widgets. */
  register_printf_function ('W', print_widget, print_widget_arginfo);

  /* Now print the widget. */
  printf ("|%W|\n", &mywidget);
  printf ("|%35W|\n", &mywidget);
  printf ("|%-35W|\n", &mywidget);

  return 0;
}
コード例 #4
0
ファイル: aroop_txt.c プロジェクト: kamanashisroy/aroop
void aroop_txt_system_init() {
	SYNC_ASSERT(!OPP_PFACTORY_CREATE(&txt_pool,
#ifdef AROOP_LOW_MEMORY
		 128
#else
		 1024
#endif
		, sizeof(aroop_txt_t)+32, OPP_CB_FUNC(aroop_txt)));
	BLANK_STRING = aroop_txt_new_set_content("", 0, NULL, 0);
	ASTERISKS_STRING = aroop_txt_new_set_content("***********************************************", 30, NULL, 0);
	DOT = aroop_txt_new_set_content(".", 1, NULL, 0);
	aroop_txt_equals_cb.aroop_closure_data = NULL;
	aroop_txt_equals_cb.aroop_cb = aroop_txt_equals_cb_impl;
	aroop_txt_get_hash_cb.aroop_closure_data = NULL;
	aroop_txt_get_hash_cb.aroop_cb = aroop_txt_get_hash_cb_impl;
#ifndef AROOP_BASIC
	register_printf_function ('T', print_etxt, print_etxt_arginfo);
#endif
}
コード例 #5
0
ファイル: prints.c プロジェクト: BackupTheBerlios/wl530g-svn
void reiserfs_warning (FILE * fp, const char * fmt, ...)
{
    static int registered = 0;
    va_list args;

#ifndef EMBED
    if (!registered) {
	registered = 1;
	
	register_printf_function ('K', print_short_key, _arginfo);
	register_printf_function ('k', print_key, _arginfo);
	register_printf_function ('H', print_item_head, _arginfo);
	register_printf_function ('b', print_block_head, _arginfo);
	register_printf_function ('y', print_disk_child, _arginfo);
	register_printf_function ('M', print_sd_mode, _arginfo);
    }
#endif

    va_start (args, fmt);
    vfprintf (fp, fmt, args);
    va_end (args);
}
コード例 #6
0
ファイル: guestfsd.c プロジェクト: gaowanlong/libguestfs
int
main (int argc, char *argv[])
{
  static const char *options = "rv?";
  static const struct option long_options[] = {
    { "help", 0, 0, '?' },
    { "verbose", 0, 0, 'v' },
    { 0, 0, 0, 0 }
  };
  int c;
  char *cmdline;

  ignore_value (chdir ("/"));

  if (winsock_init () == -1)
    error (EXIT_FAILURE, 0, "winsock initialization failed");

#ifdef HAVE_REGISTER_PRINTF_SPECIFIER
  /* http://udrepper.livejournal.com/20948.html */
  register_printf_specifier ('Q', print_shell_quote, print_arginfo);
  register_printf_specifier ('R', print_sysroot_shell_quote, print_arginfo);
#else
#ifdef HAVE_REGISTER_PRINTF_FUNCTION
  register_printf_function ('Q', print_shell_quote, print_arginfo);
  register_printf_function ('R', print_sysroot_shell_quote, print_arginfo);
#else
#error "HAVE_REGISTER_PRINTF_{SPECIFIER|FUNCTION} not defined"
#endif
#endif

  struct stat statbuf;
  if (stat ("/", &statbuf) == 0)
    root_device = statbuf.st_dev;

  for (;;) {
    c = getopt_long (argc, argv, options, long_options, NULL);
    if (c == -1) break;

    switch (c) {
      /* The -r flag is used when running standalone.  It changes
       * several aspects of the daemon.
       */
    case 'r':
      sysroot = "";
      sysroot_len = 0;
      autosync_umount = 0;
      break;

    case 'v':
      verbose = 1;
      break;

    case '?':
      usage ();
      exit (EXIT_SUCCESS);

    default:
      fprintf (stderr, "guestfsd: unexpected command line option 0x%x\n", c);
      exit (EXIT_FAILURE);
    }
  }

  if (optind < argc) {
    usage ();
    exit (EXIT_FAILURE);
  }

  cmdline = read_cmdline ();

  /* Set the verbose flag. */
  verbose = verbose ||
    (cmdline && strstr (cmdline, "guestfs_verbose=1") != NULL);
  if (verbose)
    printf ("verbose daemon enabled\n");

  if (verbose) {
    if (cmdline)
      printf ("linux commmand line: %s\n", cmdline);
    else
      printf ("could not read linux command line\n");
  }

#ifndef WIN32
  /* Make sure SIGPIPE doesn't kill us. */
  struct sigaction sa;
  memset (&sa, 0, sizeof sa);
  sa.sa_handler = SIG_IGN;
  sa.sa_flags = 0;
  if (sigaction (SIGPIPE, &sa, NULL) == -1)
    perror ("sigaction SIGPIPE"); /* but try to continue anyway ... */
#endif

#ifdef WIN32
# define setenv(n,v,f) _putenv(n "=" v)
#endif
  /* Set up a basic environment.  After we are called by /init the
   * environment is essentially empty.
   * https://bugzilla.redhat.com/show_bug.cgi?id=502074#c5
   *
   * NOTE: if you change $PATH, you must also change 'prog_exists'
   * function below.
   */
  setenv ("PATH", "/sbin:/usr/sbin:/bin:/usr/bin", 1);
  setenv ("SHELL", "/bin/sh", 1);
  setenv ("LC_ALL", "C", 1);
  setenv ("TERM", "dumb", 1);

#ifndef WIN32
  /* We document that umask defaults to 022 (it should be this anyway). */
  umask (022);
#else
  /* This is the default for Windows anyway.  It's not even clear if
   * Windows ever uses this -- the MSDN documentation for the function
   * contains obvious errors.
   */
  _umask (0);
#endif

  /* Make a private copy of /etc/lvm so we can change the config (see
   * daemon/lvm-filter.c).
   */
  copy_lvm ();

  /* Connect to virtio-serial channel. */
  int sock = open (VIRTIO_SERIAL_CHANNEL, O_RDWR | O_CLOEXEC);
  if (sock == -1) {
    fprintf (stderr,
             "\n"
             "Failed to connect to virtio-serial channel.\n"
             "\n"
             "This is a fatal error and the appliance will now exit.\n"
             "\n"
             "Usually this error is caused by either QEMU or the appliance\n"
             "kernel not supporting the vmchannel method that the\n"
             "libguestfs library chose to use.  Please run\n"
             "'libguestfs-test-tool' and provide the complete, unedited\n"
             "output to the libguestfs developers, either in a bug report\n"
             "or on the libguestfs redhat com mailing list.\n"
             "\n");
    perror (VIRTIO_SERIAL_CHANNEL);
    exit (EXIT_FAILURE);
  }

  /* Send the magic length message which indicates that
   * userspace is up inside the guest.
   */
  char lenbuf[4];
  XDR xdr;
  uint32_t len = GUESTFS_LAUNCH_FLAG;
  xdrmem_create (&xdr, lenbuf, sizeof lenbuf, XDR_ENCODE);
  xdr_u_int (&xdr, &len);

  if (xwrite (sock, lenbuf, sizeof lenbuf) == -1) {
    perror ("xwrite");
    exit (EXIT_FAILURE);
  }

  xdr_destroy (&xdr);

  /* Enter the main loop, reading and performing actions. */
  main_loop (sock);

  exit (EXIT_SUCCESS);
}
コード例 #7
0
ファイル: guestfsd.c プロジェクト: DanLipsitt/libguestfs
int
main (int argc, char *argv[])
{
  static const char *options = "rv?";
  static const struct option long_options[] = {
    { "help", 0, 0, '?' },
    { "verbose", 0, 0, 'v' },
    { 0, 0, 0, 0 }
  };
  int c;
  char *cmdline;

  ignore_value (chdir ("/"));

  if (winsock_init () == -1)
    error (EXIT_FAILURE, 0, "winsock initialization failed");

#ifdef HAVE_REGISTER_PRINTF_SPECIFIER
  /* http://udrepper.livejournal.com/20948.html */
  register_printf_specifier ('Q', print_shell_quote, print_arginfo);
  register_printf_specifier ('R', print_sysroot_shell_quote, print_arginfo);
#else
#ifdef HAVE_REGISTER_PRINTF_FUNCTION
  register_printf_function ('Q', print_shell_quote, print_arginfo);
  register_printf_function ('R', print_sysroot_shell_quote, print_arginfo);
#else
#error "HAVE_REGISTER_PRINTF_{SPECIFIER|FUNCTION} not defined"
#endif
#endif

  /* XXX The appliance /init script sets LD_PRELOAD=../libSegFault.so.
   * However if we CHROOT_IN to the sysroot that file might not exist,
   * resulting in all commands failing.  What we'd really like to do
   * is to have LD_PRELOAD only set while outside the chroot.  I
   * suspect the proper way to solve this is to remove the
   * CHROOT_IN/_OUT hack and replace it properly (fork), but that is
   * for another day.
   */
  unsetenv ("LD_PRELOAD");

  struct stat statbuf;
  if (stat ("/", &statbuf) == 0)
    root_device = statbuf.st_dev;

  for (;;) {
    c = getopt_long (argc, argv, options, long_options, NULL);
    if (c == -1) break;

    switch (c) {
      /* The -r flag is used when running standalone.  It changes
       * several aspects of the daemon.
       */
    case 'r':
      sysroot = "";
      sysroot_len = 0;
      autosync_umount = 0;
      break;

    case 'v':
      verbose = 1;
      break;

    case '?':
      usage ();
      exit (EXIT_SUCCESS);

    default:
      fprintf (stderr, "guestfsd: unexpected command line option 0x%x\n", c);
      exit (EXIT_FAILURE);
    }
  }

  if (optind < argc) {
    usage ();
    exit (EXIT_FAILURE);
  }

  cmdline = read_cmdline ();

  /* Set the verbose flag. */
  verbose = verbose ||
    (cmdline && strstr (cmdline, "guestfs_verbose=1") != NULL);
  if (verbose)
    printf ("verbose daemon enabled\n");

  if (verbose) {
    if (cmdline)
      printf ("linux commmand line: %s\n", cmdline);
    else
      printf ("could not read linux command line\n");
  }

  enable_network = cmdline && strstr (cmdline, "guestfs_network=1") != NULL;

#ifndef WIN32
  /* Make sure SIGPIPE doesn't kill us. */
  struct sigaction sa;
  memset (&sa, 0, sizeof sa);
  sa.sa_handler = SIG_IGN;
  sa.sa_flags = 0;
  if (sigaction (SIGPIPE, &sa, NULL) == -1)
    perror ("sigaction SIGPIPE"); /* but try to continue anyway ... */
#endif

#ifdef WIN32
# define setenv(n,v,f) _putenv(n "=" v)
#endif
  /* Set up a basic environment.  After we are called by /init the
   * environment is essentially empty.
   * https://bugzilla.redhat.com/show_bug.cgi?id=502074#c5
   *
   * NOTE: if you change $PATH, you must also change 'prog_exists'
   * function below.
   */
  setenv ("PATH", "/sbin:/usr/sbin:/bin:/usr/bin", 1);
  setenv ("SHELL", "/bin/sh", 1);
  setenv ("LC_ALL", "C", 1);
  setenv ("TERM", "dumb", 1);

#ifndef WIN32
  /* We document that umask defaults to 022 (it should be this anyway). */
  umask (022);
#else
  /* This is the default for Windows anyway.  It's not even clear if
   * Windows ever uses this -- the MSDN documentation for the function
   * contains obvious errors.
   */
  _umask (0);
#endif

  /* Make a private copy of /etc/lvm so we can change the config (see
   * daemon/lvm-filter.c).
   */
  copy_lvm ();

  /* Connect to virtio-serial channel. */
  char *channel, *p;
  if (cmdline && (p = strstr (cmdline, "guestfs_channel=")) != NULL) {
    p += 16;
    channel = strndup (p, strcspn (p, " \n"));
  }
  else
    channel = strdup (VIRTIO_SERIAL_CHANNEL);
  if (!channel) {
    perror ("strdup");
    exit (EXIT_FAILURE);
  }

  if (verbose)
    printf ("trying to open virtio-serial channel '%s'\n", channel);

  int sock = open (channel, O_RDWR|O_CLOEXEC);
  if (sock == -1) {
    fprintf (stderr,
             "\n"
             "Failed to connect to virtio-serial channel.\n"
             "\n"
             "This is a fatal error and the appliance will now exit.\n"
             "\n"
             "Usually this error is caused by either QEMU or the appliance\n"
             "kernel not supporting the vmchannel method that the\n"
             "libguestfs library chose to use.  Please run\n"
             "'libguestfs-test-tool' and provide the complete, unedited\n"
             "output to the libguestfs developers, either in a bug report\n"
             "or on the libguestfs redhat com mailing list.\n"
             "\n");
    perror (channel);
    exit (EXIT_FAILURE);
  }

  /* If it's a serial-port like device then it probably has echoing
   * enabled.  Put it into complete raw mode.
   */
  if (STRPREFIX (channel, "/dev/ttyS"))
    makeraw (channel, sock);

  /* cmdline, channel not used after this point */
  free (cmdline);
  free (channel);

  /* Wait for udev devices to be created.  If you start libguestfs,
   * especially with disks that contain complex (eg. mdadm) data
   * already, then it is possible for the 'mdadm' and LVM commands
   * that the init script runs to have not completed by the time the
   * daemon starts executing library commands.  (This is very rare and
   * hard to test however, but we have seen it in 'brew').  Run
   * udev_settle, but do it as late as possible to minimize the chance
   * that we'll have to do any waiting here.
   */
  udev_settle ();

  /* Send the magic length message which indicates that
   * userspace is up inside the guest.
   */
  char lenbuf[4];
  XDR xdr;
  uint32_t len = GUESTFS_LAUNCH_FLAG;
  xdrmem_create (&xdr, lenbuf, sizeof lenbuf, XDR_ENCODE);
  xdr_u_int (&xdr, &len);

  if (xwrite (sock, lenbuf, sizeof lenbuf) == -1) {
    perror ("xwrite");
    exit (EXIT_FAILURE);
  }

  xdr_destroy (&xdr);

  /* Enter the main loop, reading and performing actions. */
  main_loop (sock);

  exit (EXIT_SUCCESS);
}
コード例 #8
0
ファイル: puppy.c プロジェクト: silid/libpuppy
int main(int argc, char *argv[])
{
    struct usb_device_descriptor devDesc;
    int fd = -1;
    int r;

    /* Initialise timezone handling. */
    tzset();

    register_printf_function('W', quote_xml, quote_xml_arginfo);

    lockFd = open("/tmp/puppy", O_CREAT, S_IRUSR | S_IWUSR);
    if(lockFd < 0)
    {
        fprintf(stderr, "ERROR: Can not open lock file /tmp/puppy: %s\n",
                strerror(errno));
        return E_LOCK_FILE;
    }

    r = parseArgs(argc, argv);
    if(r != 0)
    {
        return E_INVALID_ARGS;
    }

    /* Create a lock, so that other instances of puppy can detect this one. */
    if(0 != flock(lockFd, LOCK_SH | LOCK_NB))
    {
        fprintf(stderr,
                "ERROR: Can not obtain shared lock on /tmp/puppy: %s\n",
                strerror(errno));
        return E_GLOBAL_LOCK;
    }

    trace(2, fprintf(stderr, "cmd %04x on %s\n", cmd, devPath));

    fd = open(devPath, O_RDWR);
    if(fd < 0)
    {
        fprintf(stderr, "ERROR: Can not open %s for read/write: %s\n",
                devPath, strerror(errno));
        return E_READ_DEVICE;
    }

    if(0 != flock(fd, LOCK_EX | LOCK_NB))
    {
        fprintf(stderr, "ERROR: Can not get exclusive lock on %s\n", devPath);
        close(fd);
        return E_DEVICE_LOCK;
    }

    r = read_device_descriptor(fd, &devDesc);
    if(r < 0)
    {
        close(fd);
        return E_READ_DEVICE;
    }

    if(!isToppy(&devDesc))
    {
        fprintf(stderr, "ERROR: Could not find a Topfield TF5000PVRt\n");
        close(fd);
        return E_NOT_TF5000PVR;
    }

    trace(1, fprintf(stderr, "Found a Topfield TF5000PVRt\n"));

    trace(2, fprintf(stderr, "USBDEVFS_RESET\n"));
    r = ioctl(fd, USBDEVFS_RESET, NULL);
    if(r < 0)
    {
        fprintf(stderr, "ERROR: Can not reset device: %s\n", strerror(errno));
        close(fd);
        return E_RESET_DEVICE;
    }

    {
        int interface = 0;

        trace(2, fprintf(stderr, "USBDEVFS_CLAIMINTERFACE\n"));
        r = ioctl(fd, USBDEVFS_CLAIMINTERFACE, &interface);
        if(r < 0)
        {
            fprintf(stderr, "ERROR: Can not claim interface 0: %s\n",
                    strerror(errno));
            close(fd);
            return E_CLAIM_INTERFACE;
        }
    }

    {
        struct usbdevfs_setinterface interface0 = { 0, 0 };

        trace(2, fprintf(stderr, "USBDEVFS_SETNTERFACE\n"));
        r = ioctl(fd, USBDEVFS_SETINTERFACE, &interface0);
        if(r < 0)
        {
            fprintf(stderr, "ERROR: Can not set interface zero: %s\n",
                    strerror(errno));
            close(fd);
            return E_SET_INTERFACE;
        }
    }

    switch (cmd)
    {
        case CANCEL:
            r = do_cancel(fd);
            break;

        case CMD_RESET:
            r = do_cmd_reset(fd);
            break;

        case CMD_HDD_SIZE:
            r = do_hdd_size(fd);
            break;

        case CMD_HDD_DIR:
            r = do_hdd_dir(fd, arg1);
            break;

        case CMD_HDD_FILE_SEND:
            if(sendDirection == PUT)
            {
                r = do_hdd_file_put(fd, arg1, arg2);
            }
            else
            {
                r = do_hdd_file_get(fd, arg1, arg2);
            }
            break;

        case CMD_HDD_DEL:
            r = do_hdd_del(fd, arg1);
            break;

        case CMD_HDD_RENAME:
            r = do_hdd_rename(fd, arg1, arg2);
            break;

        case CMD_HDD_CREATE_DIR:
            r = do_hdd_mkdir(fd, arg1);
            break;

        case CMD_TURBO:
            r = do_cmd_turbo(fd, arg1);
            break;

        default:
            fprintf(stderr, "BUG: Command 0x%08x not implemented\n", cmd);
            r = -EINVAL;
    }

    {
        int interface = 0;

        ioctl(fd, USBDEVFS_RELEASEINTERFACE, &interface);
        close(fd);
    }
    return r;
}
コード例 #9
0
ファイル: op_query.c プロジェクト: ystk/debian-ocfs2-tools
/*
 * When creating printf fields for ourselves, we need to avoid the
 * standard specifiers.  All lowercase specifiers are reserved by C99.
 * Reserved uppercase specifiers are: E, F, G, A, C, S, X, L
 */
static int query_run(struct tunefs_operation *op, ocfs2_filesys *fs,
		     int flags)
{
	char *queryfmt = op->to_private;
	char *fmt;

	fmt = process_escapes(queryfmt);
	if (!fmt) {
		tcom_err(TUNEFS_ET_NO_MEMORY,
			 "while escaping the query format");
		return 1;
	}

	register_printf_function('B', handle_blocksize, handle_arginfo);
	register_printf_function('T', handle_clustersize, handle_arginfo);
	register_printf_function('N', handle_numslots, handle_arginfo);
	register_printf_function('R', handle_rootdir, handle_arginfo);
	register_printf_function('Y', handle_sysdir, handle_arginfo);
	register_printf_function('P', handle_clustergroup, handle_arginfo);

	register_printf_function('V', handle_label, handle_arginfo);
	register_printf_function('U', handle_uuid, handle_arginfo);

	register_printf_function('M', handle_compat, handle_arginfo);
	register_printf_function('H', handle_incompat, handle_arginfo);
	register_printf_function('O', handle_ro_compat, handle_arginfo);

	query_fs = fs;
	fprintf(stdout, fmt);
	query_fs = NULL;

	ocfs2_free(&fmt);

	return 0;
}
コード例 #10
0
// register printf conversion specifiers
void string_helper_init()
{
  register_printf_function('M', print_xml, print_xml_arginfo);
  register_printf_function('N', print_xml, print_xml_arginfo);
}