Thanks Rich for you quick reply. I enabled logs and the program stuck again, here is the call stack and log:
Thread 1 (Thread 0x7fac58edc8c0 (LWP 1271)):
#0  0x00007fac578fac20 in __poll_nocancel () from /lib64/libc.so.6
#1  0x00007fac56df3c5a in virNetClientIOEventLoop () from /lib64/libvirt.so.0
#2  0x00007fac56df441b in virNetClientSendInternal () from /lib64/libvirt.so.0
#3  0x00007fac56df5843 in virNetClientSendWithReply () from /lib64/libvirt.so.0
#4  0x00007fac56df6052 in virNetClientProgramCall () from /lib64/libvirt.so.0
#5  0x00007fac56dcbfe2 in callFull.isra.2 () from /lib64/libvirt.so.0
#6  0x00007fac56de213d in remoteDomainCreateXML () from /lib64/libvirt.so.0
#7  0x00007fac56d82151 in virDomainCreateXML () from /lib64/libvirt.so.0
#8  0x00007fac58acca50 in launch_libvirt () from /lib64/libguestfs.so.0
#9  0x00007fac58ac2b2b in guestfs_impl_launch () from /lib64/libguestfs.so.0
#10 0x00007fac58a5eba5 in guestfs_launch () from /lib64/libguestfs.so.0
#11 0x00000000004117ca in main ()


Log:
2016-Aug-29 15:02:07 main:1385 Entering main()
2016-Aug-29 15:02:07 main:1393 guestfs_create succeeded
2016-Aug-29 15:02:07 main:1398 guestfs_set_network ok
2016-Aug-29 15:02:07 main:1406 Trying to add drive /dev/xvdc
libguestfs: trace: add_drive "/dev/xvdc" "format:raw"
libguestfs: trace: add_drive = 0
2016-Aug-29 15:02:07 main:1413 guestfs_add_drive_opts succeeded for drive: /dev/xvdc
libguestfs: trace: launch
libguestfs: trace: get_tmpdir
libguestfs: trace: get_tmpdir = "/tmp"
libguestfs: trace: version
libguestfs: trace: version = <struct guestfs_version *>
libguestfs: trace: get_backend
libguestfs: trace: get_backend = "libvirt"
libguestfs: launch: program=linuxxenfix
libguestfs: launch: version=1.28.1rhel=7,release=1.55.el7.centos.2,libvirt
libguestfs: launch: backend registered: unix
libguestfs: launch: backend registered: uml
libguestfs: launch: backend registered: libvirt
libguestfs: launch: backend registered: direct
libguestfs: launch: backend=libvirt
libguestfs: launch: tmpdir=/tmp/libguestfsWmxUbv
libguestfs: launch: umask=0022
libguestfs: launch: euid=0
libguestfs: libvirt version = 1002017 (1.2.17)
libguestfs: guest random name = guestfs-0h3k91d5369tcde3
libguestfs: [00009ms] connect to libvirt
libguestfs: opening libvirt handle: URI = qemu:///system, auth = default+wrapper, flags = 0
libguestfs: successfully opened libvirt handle: conn = 0xd84c40
libguestfs: qemu version (reported by libvirt) = 1005003 (1.5.3)
libguestfs: [00010ms] get libvirt capabilities
libguestfs: [00012ms] parsing capabilities XML
libguestfs: trace: get_backend_setting "force_tcg"
libguestfs: trace: get_backend_setting = NULL (error)
libguestfs: trace: get_backend_setting "internal_libvirt_label"
libguestfs: trace: get_backend_setting = NULL (error)
libguestfs: trace: get_backend_setting "internal_libvirt_imagelabel"
libguestfs: trace: get_backend_setting = NULL (error)
libguestfs: trace: get_backend_setting "internal_libvirt_norelabel_disks"
libguestfs: trace: get_backend_setting = NULL (error)
libguestfs: [00012ms] build appliance
libguestfs: trace: get_cachedir
libguestfs: trace: get_cachedir = "/var/tmp"
libguestfs: [00030ms] begin building supermin appliance
libguestfs: [00030ms] run supermin
libguestfs: command: run: /usr/bin/supermin5
libguestfs: command: run: \ --build
libguestfs: command: run: \ --verbose
libguestfs: command: run: \ --if-newer
libguestfs: command: run: \ --lock /var/tmp/.guestfs-0/lock
libguestfs: command: run: \ --copy-kernel
libguestfs: command: run: \ -f ext2
libguestfs: command: run: \ --host-cpu x86_64
libguestfs: command: run: \ /usr/lib64/guestfs/supermin.d
libguestfs: command: run: \ -o /var/tmp/.guestfs-0/appliance.d
supermin: version: 5.1.10
supermin: rpm: detected RPM version 4.11
supermin: package handler: fedora/rpm
supermin: acquiring lock on /var/tmp/.guestfs-0/lock
supermin: build: /usr/lib64/guestfs/supermin.d
supermin: build: visiting /usr/lib64/guestfs/supermin.d/base.tar.gz type gzip base image (tar)
supermin: build: visiting /usr/lib64/guestfs/supermin.d/daemon.tar.gz type gzip base image (tar)
supermin: build: visiting /usr/lib64/guestfs/supermin.d/excludefiles type uncompressed excludefiles
supermin: build: visiting /usr/lib64/guestfs/supermin.d/hostfiles type uncompressed hostfiles
supermin: build: visiting /usr/lib64/guestfs/supermin.d/init.tar.gz type gzip base image (tar)
supermin: build: visiting /usr/lib64/guestfs/supermin.d/packages type uncompressed packages
supermin: build: visiting /usr/lib64/guestfs/supermin.d/udev-rules.tar.gz type gzip base image (tar)
supermin: build: 184 packages, including dependencies
supermin: build: 30935 files
supermin: build: 12031 files, after removing unreadable files
supermin: build: 9035 files, after matching excludefiles
supermin: build: 9039 files, after adding hostfiles
supermin: build: 9068 files, after munging
supermin: kernel: picked kernel vmlinuz-3.10.0-327.13.1.el7.x86_64
supermin: kernel: picked modules path /lib/modules/3.10.0-327.13.1.el7.x86_64
supermin: kernel: kernel_version 3.10.0-327.13.1.el7.x86_64
supermin: kernel: modules /lib/modules/3.10.0-327.13.1.el7.x86_64
supermin: ext2: creating empty ext2 filesystem '/var/tmp/.guestfs-0/appliance.d.omlxj0zh/root'
supermin: ext2: populating from base image
supermin: ext2: copying files from host filesystem
supermin: ext2: copying kernel modules
supermin: ext2: creating minimal initrd '/var/tmp/.guestfs-0/appliance.d.omlxj0zh/initrd'
supermin: ext2: wrote 34 modules to minimal initrd
supermin: renaming /var/tmp/.guestfs-0/appliance.d.omlxj0zh to /var/tmp/.guestfs-0/appliance.d
libguestfs: [62773ms] finished building supermin appliance
libguestfs: trace: disk_create "/tmp/libguestfsWmxUbv/overlay1" "qcow2" -1 "backingfile:/var/tmp/.guestfs-0/appliance.d/root" "backingformat:raw"
libguestfs: command: run: qemu-img
libguestfs: command: run: \ create
libguestfs: command: run: \ -f qcow2
libguestfs: command: run: \ -o backing_file=/var/tmp/.guestfs-0/appliance.d/root,backing_fmt=raw
libguestfs: command: run: \ /tmp/libguestfsWmxUbv/overlay1
Formatting '/tmp/libguestfsWmxUbv/overlay1', fmt=qcow2 size=4294967296 backing_file='/var/tmp/.guestfs-0/appliance.d/root' backing_fmt='raw' encryption=off cluster_size=65536 lazy_refcounts=off 
libguestfs: trace: disk_create = 0
libguestfs: set_socket_create_context: context_new failed: kernel: Invalid argument [you can ignore this UNLESS using SELinux + sVirt]
libguestfs: [62889ms] create libvirt XML
libguestfs: command: run: dmesg | grep -Eoh 'lpj=[[:digit:]]+'
libguestfs: read_lpj_from_dmesg: calculated lpj=2394042
libguestfs: trace: get_cachedir
libguestfs: trace: get_cachedir = "/var/tmp"
libguestfs: libvirt XML:\n<?xml version="1.0"?>\n<domain type="qemu" xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0">\n  <name>guestfs-0h3k91d5369tcde3</name>\n  <memory unit="MiB">500</memory>\n  <currentMemory unit="MiB">500</currentMemory>\n  <vcpu>1</vcpu>\n  <clock offset="utc">\n    <timer name="rtc" tickpolicy="catchup"/>\n    <timer name="pit" tickpolicy="delay"/>\n    <timer name="hpet" present="no"/>\n  </clock>\n  <os>\n    <type>hvm</type>\n    <kernel>/var/tmp/.guestfs-0/appliance.d/kernel</kernel>\n    <initrd>/var/tmp/.guestfs-0/appliance.d/initrd</initrd>\n    <cmdline>panic=1 console=ttyS0 udevtimeout=6000 udev.event-timeout=6000 no_timer_check lpj=2394042 acpi=off printk.time=1 cgroup_disable=memory root=/dev/sdb selinux=0 guestfs_verbose=1 guestfs_network=1 TERM=linux</cmdline>\n    <bios useserial="yes"/>\n  </os>\n  <on_reboot>destroy</on_reboot>\n  <devices>\n    <controller type="scsi" index="0" model="virtio-scsi"/>\n    <disk device="disk" type="block">\n      <source dev="/dev/xvdc"/>\n      <target dev="sda" bus="scsi"/>\n      <driver name="qemu" type="raw" cache="writeback"/>\n      <address type="drive" controller="0" bus="0" target="0" unit="0"/>\n    </disk>\n    <disk type="file" device="disk">\n      <source file="/tmp/libguestfsWmxUbv/overlay1"/>\n      <target dev="sdb" bus="scsi"/>\n      <driver name="qemu" type="qcow2" cache="unsafe"/>\n      <address type="drive" controller="0" bus="0" target="1" unit="0"/>\n      <shareable/>\n    </disk>\n    <serial type="unix">\n      <source mode="connect" path="/tmp/libguestfsWmxUbv/console.sock"/>\n      <target port="0"/>\n    </serial>\n    <channel type="unix">\n      <source mode="connect" path="/tmp/libguestfsWmxUbv/guestfsd.sock"/>\n      <target type="virtio" name="org.libguestfs.channel.0"/>\n    </channel>\n  </devices>\n  <qemu:commandline>\n    <qemu:env name="TMPDIR" value="/var/tmp"/>\n    <qemu:arg value="-netdev"/>\n    <qemu:arg value="user,id=usernet,net=169.254.0.0/16"/>\n    <qemu:arg value="-device"/>\n    <qemu:arg value="virtio-net-pci,netdev=usernet"/>\n  </qemu:commandline>\n</domain>\n
libguestfs: trace: get_cachedir
libguestfs: trace: get_cachedir = "/var/tmp"
libguestfs: command: run: ls
libguestfs: command: run: \ -a
libguestfs: command: run: \ -l
libguestfs: command: run: \ -Z /var/tmp/.guestfs-0
libguestfs: drwxr-xr-x root root ?                                .
libguestfs: drwxrwxrwt root root ?                                ..
libguestfs: drwxr-xr-x root root ?                                appliance.d
libguestfs: -rw-r--r-- root root ?                                lock
libguestfs: command: run: ls
libguestfs: command: run: \ -a
libguestfs: command: run: \ -l
libguestfs: command: run: \ -Z /tmp/libguestfsWmxUbv
libguestfs: drwxr-xr-x root root ?                                .
libguestfs: drwxrwxrwt root root ?                                ..
libguestfs: srw-rw---- root qemu ?                                console.sock
libguestfs: srw-rw---- root qemu ?                                guestfsd.sock
libguestfs: -rw-r--r-- root root ?                                overlay1
libguestfs: -rwxr-xr-x root root ?                                umask-check
libguestfs: [62900ms] launch libvirt guest

2016-08-29 21:42 GMT+08:00 Richard W.M. Jones <rjones@redhat.com>:
On Mon, Aug 29, 2016 at 08:24:43PM +0800, Baochuan Wu wrote:
> Hello everyone,
>
> I am using libguestfs on CentOS 7.2. I am trying to modify Red Hat 5.4
> disks. I am using C/C++. I found the process gets stuck
> inside guestfs_launch:
>
> Thread 1 (Thread 0x7fe3aa6148c0 (LWP 1265)):
> #0  0x00007fe3a9032c20 in __poll_nocancel () from /lib64/libc.so.6
> #1  0x00007fe3aa1e5ea4 in read_data () from /lib64/libguestfs.so.0
> #2  0x00007fe3aa20af0c in guestfs_int_recv_from_daemon () from
> /lib64/libguestfs.so.0
> #3  0x00007fe3aa204ae0 in launch_libvirt () from /lib64/libguestfs.so.0
> #4  0x00007fe3aa1fab2b in guestfs_impl_launch () from /lib64/libguestfs.so.0
> #5  0x00007fe3aa196b4d in guestfs_launch () from /lib64/libguestfs.so.0
> #6  0x00000000004116f8 in main ()

Before you call guestfs_launch(), call:

  guestfs_set_verbose (1);
  guestfs_set_trace (1);

That should print (on stderr) a lot more information about what is
going on. (http://libguestfs.org/guestfs-faq.1.html#how-do-i-debug-when-using-the-api)

If printing on stderr is not convenient from your program, then you
can also set up logging.  See the example here:

https://github.com/libguestfs/libguestfs/blob/master/examples/debug-logging.c

The libguestfs-test-tool output looks fine BTW.

Rich.

--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v