aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxl/libxl_exec.c
Commit message (Collapse)AuthorAgeFilesLines
* libxl: correctly handle readlink() errorsMatthew Daley2013-09-131-1/+1
| | | | | | | | readlink() returns a ssize_t with a negative value on failure. Coverity-ID: 1055566 Signed-off-by: Matthew Daley <mattjd@gmail.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
* libxl: Enable -Wshadow.Ian Campbell2012-09-171-4/+4
| | | | | | | | | | | | | | | | | | | | | | It was convenient to invent $(CFLAGS_LIBXL) to do this. Various renamings to avoid shadowing standard functions: - index(3) - listen(2) - link(2) - abort(3) - abs(3) Reduced the scope of some variables to avoid conflicts. Change to libxc is due to the nested hypercall buf macros in set_xen_guest_handle (used in libxl) using the same local private vars. Build tested only. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> Committed-by: Ian Campbell <ian.campbell@citrix.com>
* libxl: do not leak spawned middle childrenIan Jackson2012-06-281-53/+77
| | | | | | | | | | | | | | | | | | | | | | | libxl__spawn_spawn would, when libxl__spawn_detach was called, make the spawn become idle immediately. However it still has a child process which needs to be waited for: the `detachable' spawned child. This is wrong because the ultimate in-libxl caller may return to the application, with a child process still forked but not reaped libxl contrary to the documented behaviour of libxl. Instead, replace libxl__spawn_detach with libxl__spawn_initiate_detach which is asynchronous. The detachable spawned children are abolished; instead, we defer calling back to the in-libxl user until the middle child has been reaped. Also, remove erroneous comment suggesting that `death' callback parameter to libxl__ev_child_fork may be NULL. It may not, and there are no callers which pass NULL. Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com> Acked-by: Ian Campbell <ian.campbell@citrix.com>
* libxl: Do not pass NULL as gc_opt; introduce NOGCIan Jackson2012-06-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In 25182:6c3345d7e9d9 the practice of passing NULL to gc-using memory allocation functions was introduced. However, the arrangements there were not correct as committed, because the error handling and logging depends on getting a ctx from the gc - so an allocation error would in fact result in libxl dereferencing NULL. Instead, provide a special dummy gc in the ctx, called `nogc_gc'. It is marked out specially by having alloc_maxsize==-1, which is otherwise invalid. Functions which need to actually look into the gc use the new test function gc_is_real (whose purpose is mainly clarity of the code) to check whether the gc is the dummy one, and do nothing if it is. And we provide a helper macro NOGC which uses the in-scope real gc to find the ctx and hence the dummy gc (and which replaces the previous #define NOGC NULL). Change all callers which pass 0 or NULL to an allocation function to use NOGC or &ctx->nogc_gc, as applicable in the context. We add a comment near the definition of LIBXL_INIT_GC pointing out that it isn't any more the only place a libxl__gc struct is initialised, for the benefit of anyone changing the contents of gc's in the future. Also, actually document that libxl__ptr_add is legal with ptr==NULL, and change a couple of calls not to check for NULL argument. Reported-by: Bamvor Jian Zhang <bjzhang@suse.com> Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com> Cc: Bamvor Jian Zhang <bjzhang@suse.com> Acked-by: Ian Campbell <Ian.Campbell@citrix.com> Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
* libxl: pass env vars to libxl__execRoger Pau Monne2012-05-231-2/+12
| | | | | | | | | Add another parameter to libxl__exec call that contains the environment variables to use when performing the execvp call. Signed-off-by: Roger Pau Monne <roger.pau@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> Committed-by: Ian Campbell <ian.campbell@citrix.com>
* libxl: child processes cleanupsIan Jackson2012-05-111-19/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | Abolish libxl_fork. Its only callers were in xl. Its functionality is now moved elsewhere, as follows: * The "logging version of fork", which is what it was billed as, is now xl_fork, which also dies on failure. * Closing the xenstore handle in the child is now done in libxl__ev_child_fork, which is the only remaining place where fork is called in libxl. * We provide a new function libxl__ev_child_xenstore_reopen for in-libxl children to make the ctx useable for xenstore again. * Consequently libxl__spawn_record_pid now no longer needs to mess about with its own xenstore handle. As a bonus it can now just use libxl__xs_write. Also, since we have now converted all the forkers in libxl, we can always honour the fork_replacement childproc hook - so do so. Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com> Acked-by: Ian Campbell <ian.campbell@citrix.com> Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
* libxl: ao: convert libxl__spawn_*Ian Jackson2012-05-111-176/+178
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | libxl__spawn_spawn becomes a callback-style asynchronous function. The implementation is now in terms of libxl__ev_* including libxl_ev_child. All the callers need to be updated. This includes the device model spawning functions libxl__create_device_model and libxl__create_stubdom; these are replaced with libxl__spawn_local_dm and libxl__spawn_stubdom. libxl__confirm_device_model_startup is abolished; instead the dm spawner calls back. (The choice of which kind of device model to create is lifted out of what used to be libxl__create_device_model, because that function was indirectly recursive. Recursive callback-style operations are clumsy because they require a pointer indirection for the nested states.) Waiting for proper device model startup it is no longer notionally optional. Previously the code appeared to tolerate this by passing NULL for various libxl__spawner_starting* parameters to device model spawners. However, this was not used anywhere. Conversely, the "for_spawn" parameter to libxl__wait_for_offspring is no longer supported. It remains as an unused formal parameter to avoid updating, in this patch, all the call sites which pass NULL. libxl__wait_for_offspring is in any case itself an obsolete function, so this wrinkle will go away when its callers are updated to use the event system. Consequently libxl__spawn_check is also abolished. The "console ready" callback also remains unchanged in this patch. The API for this needs to be reviewed in the context of the event series and its reentrancy restrictions documented. Thus their callers need to be updated. These are the domain creation functions libxl_domain_create_new and _restore. These functions now take ao_hows, and have a private state structure. However domain creation remains not completely converted to the event mechanism; in particular it runs the outward-facing function libxl_run_bootloader with a NULL ao_how, which is quite wrong. As it happens in the current code this is not a bug because none of the rest of the functionality surrounding the bootloader call will mind if the event loop is reentered in the middle of its execution. The file-scope function libxl__set_fd_flag which was used by the previous spawn arrangements becomes unused and is removed; other places in libxl can use libxl_fd_set_nonblock and libxl_fd_set_cloexec, which of course remain. Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com> Acked-by: Ian Campbell <ian.campbell@citrix.com> Changes since v8: * Make midproc_cb callback with correct pid (that of the grandchild, not "middle" which is zero). Reported by Roger Pau Monne. Changes since v7: * Rename libxl__spawn_stubdom to libxl__spawn_stub_dm (and ..._state); rename the state's stubdom_* members to dm_*. * Eliminate the union between the two dm creation states in libxl__domain_create_state. Instead, the domain creation code simply uses libxl__stub_dm_spawn_state.dm directly, if we're taking the local dm path. * Remove a spurious "break". * In domain creation, move the PV non-qemu case into the switch. * Code style fixes. * Constify some convenience aliases. * Improve comments (including typo fixes). Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
* libxl: remove ctx->waitpid_insteadIan Jackson2012-05-111-9/+3
| | | | | | | | | | | | Remove this obsolete hook. Callers inside libxl which create and reap children should use the mechanisms provided by the event system. (This has no functional difference since there is no way for ctx->waitpid_instead ever to become set.) Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com> Acked-by: Ian Campbell <ian.campbell@citrix.com> Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
* libxl: move a lot more includes into libxl_internal.hIan Jackson2012-01-131-12/+1
| | | | | | | | | | | | | | | | | Move a lot of #include <stdfoo.h> from individual files into libxl_internal.h. This helps avoid portability mistakes where necessary system headers are omitted from individual files, and is also of course a convenience when developing. Also add #include "libxl_osdeps.h" /* must come before any other headers */ to the top of most libxl*.c files, so that anyone who adds any headers before libxl_internal.h will put the in the right place. Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com> Acked-by: Ian Campbell <ian.campbell@citrix.com> Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
* libxl: Rationalise #includesIan Jackson2011-12-121-1/+0
| | | | | | | | | | | | | | | | | | | | libxl_internal.h now #includes libxl.h and various system headers. This 1. makes the order of header inclusion more predictable 2. explicitly allows libxl_internal.h to use objects defined in libxl.h 3. removes the need for individual files to include these headers Also - remove some unnecessary #includes of libxl_utils.h, flexarray.h, etc. in some libxl*.c files, - include libxl_osdeps.h at the top of libxl_internal.h - add missing includes of libxl_osdeps.h to a couple of files - change libxl.h to libxl_internal.h in a couple of files Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com> Acked-by: Ian Campbell <ian.campbell@citrix.com> Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
* libxl: update prototype of libxl__spawn_checkOlaf Hering2011-10-271-2/+1
| | | | | | | | | | | libxl__spawn_check expects a malloc'd libxl__spawn_starting. The currently only user of libxl__spawn_check gets a libxl__spawn_starting and passes it on. Update prototype to not take a void pointer, and also update comment in header file. Signed-off-by: Olaf Hering <olaf@aepfle.de> Acked-by: Ian Jackson <ian.jackson.citrix.com> Committed-by: Ian Jackson <ian.jackson.citrix.com>
* libxl: add libxl__spawn_confirm_offspring_startupOlaf Hering2011-10-271-0/+24
| | | | | | | | | | | libxl__spawn_confirm_offspring_startup() is a generic version of libxl__confirm_device_model_startup(). Use libxl__spawn_confirm_offspring_startup for device model. Signed-off-by: Olaf Hering <olaf@aepfle.de> Acked-by: Ian Jackson <ian.jackson.citrix.com> Committed-by: Ian Jackson <ian.jackson.citrix.com>
* libxl: add libxl__wait_for_offspring functionOlaf Hering2011-10-271-0/+93
| | | | | | | | | | | libxl__wait_for_offspring() is a generic version of libxl__wait_for_device_model(). Use libxl__wait_for_offspring for device model. Signed-off-by: Olaf Hering <olaf@aepfle.de> Acked-by: Ian Jackson <ian.jackson.citrix.com> Committed-by: Ian Jackson <ian.jackson.citrix.com>
* libxl: add pid path to libxl__spawner_startingOlaf Hering2011-10-271-1/+1
| | | | | | | | | | | libxl_spawner_record_pid() should be able to write the pid to arbitrary paths. v2: - use const char* for ->pid_path, and update comment Signed-off-by: Olaf Hering <olaf@aepfle.de> Acked-by: Ian Jackson <ian.jackson.citrix.com> Committed-by: Ian Jackson <ian.jackson.citrix.com>
* libxl: rename dm_xenstore_record_pid to libxl_spawner_record_pidOlaf Hering2011-10-271-0/+25
| | | | | | Signed-off-by: Olaf Hering <olaf@aepfle.de> Acked-by: Ian Jackson <ian.jackson.citrix.com> Committed-by: Ian Jackson <ian.jackson.citrix.com>
* libxl: fixup incorrect indentationIan Campbell2011-10-121-0/+8
| | | | | | | | | Several places which were previsously indented using hard tabs are now incorrectly indented. Fix them up. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
* libxl: check return values of read/writeIan Campbell2011-06-021-2/+4
| | | | | | | | | | | | | | Some distros enable -D_FORTIFY_SOURCE=2 by default (https://wiki.ubuntu.com/CompilerFlags) which adds the warn_unused_result attribute to several functions including read(2) and write(2) Although we don't really care about error reading or writing the libxl spawn fd catch them anyway to keep this warning happy. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> Tested-by: Olaf Hering <olaf@aepfle.de> Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
* libxl: remove stray "atoi" in debug code.Ian Campbell2011-06-021-1/+1
| | | | | | | | I switched from atoi to strtol but failed to actually remove it... Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
* libxl: fix build failure (unused variables) for non-Linux platformsChristoph Egger2011-05-261-2/+2
| | | | | | | | | Move variable definitions into Linux-specific sections where they are actually used. Fixes warning about unused variables. Signed-off-by: Christoph Egger <Christoph.Egger@amd.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
* libxl: don't close file descriptors 4..255 in libxl__execIan Campbell2011-05-241-4/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It prevents callers from deliberately passing file descriptors to the child, hides any callers who erroneously do so and doesn't deal with all file descriptors in any case. Rather than remove it all together replace it with some debug code which checks for open file handles which do not have either O_CLOEXEC or FD_CLOEXEC set. To enable the debug set _LIBXL_DEBUG_EXEC_FDS=1 to print any open and non-CLOEXEC non-stdio FDs just before libxl__exec actualy calls exec. Set _LIBXL_DEBUG_EXEC_FDS=2 to abort if any of these exist. On the basis of this debugging fix some leaked filehandles: * The read end of the pipe used to wake the parent from the intermediate process during libxl__spawn_spawn was leaked into the intermediate process. * The file descriptor representing the xl lock was not marked O_CLOEXEC (the lock itself is already specified to not be inherited across a fork). * The file descriptors passed to libxl__exec to be dup'd as std{in,out,err} were leaked at their original number. They are harmless (an attacker can just as easily use fd 0..2) but close anyway since it removes a case which a person evaluating open fd's needs to consider. * libxl_run_bootloader was leaking the xenconsole pty master into the bootloader child process. * If the bootloader fails to get as far as opening its end of the FIFO then we can also hang, check that the process has not exited as part of that loop. (we actually block opening the FIFO too so this is only a partial fix for the case where the bootlader has crashed quickly). With these fixes I have tested that device models, bootloaders (pygrub) and vncviewers which are spawned via libxl__exec with no unexpected file descriptors open, at least in my configuration. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
* libxl: add statup checks to libxl__wait_for_device_modelIan Campbell2011-05-241-8/+52
| | | | | | | | | | | | | | | When the device model is starting up push checks for spawn failure down into libxl__wait_for_device_model, allowing us to fail more quickly when the device model fails to start (e.g. due to a missing library or an early setup error etc). In order to allow the select loop in libxl__wait_for_device_model to wake when the child dies add pipe between the parent and the intermediate process which the intermediate process can use to signal the parent. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
* libxl: pass libxl__spawn_starting to libxl__spawn_spawn.Ian Campbell2011-05-241-4/+4
| | | | | | | | | | | | | | | | Passing a libxl__device_model_starting to a generic function and expecting it to scrobble inside for the generic data structure is a strange interface. Instead pass in a libxl__spawn_starting and an opaque hook data pointer. The for_spawn member of libxl__device_model_starting was annotated with "first!", suggesting that someone intended to use pointer casting tricks to move between the outer and inner struct. However the field is a pointer not a inline struct so this doesn't work (and it isn't used this way anyhow). Remove the comment, and move the field away from the front for good measure. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
* libxl: Make all hidden/static functions take a gc not a ctxIan Campbell2011-03-151-8/+12
| | | | | | | | | | | | | | | | Also ensure that static and hidden functions use the libxl__ prefix not just libxl_ (in the case of static functions only when they use a libxl prefix to start with). This follows the policy described in libxl.h "libxl memory management". Based on a manual audit of: grep ^static tools/libxl/libxl*.[ch]| grep libxl_ctx grep libxl__ tools/libxl/*.h| grep libxl_ctx Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
* libxl: actually print an error when execve (in libxl__exec) failsIan Jackson2011-02-041-0/+2
| | | | | | | | The header comment says libxl__exec logs errors. So it should do so. Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com> Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
* libxl: Introduce libxl_domain_create_new() and libxl_domain_create_restore()Gianni Tedesco2011-01-111-1/+1
| | | | | | | | | | | | | | | | | | | | | These functions are introduced as the new way to create domains with libxl they prevent the callers from need to know about low-level implementation details such as: - libxl_domain_make() - libxl_domain_build() - libxl_domain_restore() - when to attach the console - how to start the device model Above mentioned functions and all API's for the device model, which are now redundant, have been made internal to libxl and no longer accessible. The ocaml binding for libxl has not been properly updated to reflect the changes, wrappers for the old functions have been removed but the code to wrap the new functions has not been added. Signed-off-by: Gianni Tedesco <gianni.tedesco@citrix.com> Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
* libxl: fix compiler warning with fork_exec_bootloaderAndre Przywara2010-09-161-1/+2
| | | | | | | | | | | At least one of my compilers complains about the broken const qualifier in the fork_exec_bootloader() call (despite the cast). Fix this properly by propagating the const attribute down the call stack. Signed-off-by: Andre Przywara <andre.przywara@amd.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
* libxl: Use libxl__ namespace for internal typesIan Campbell2010-09-081-4/+4
| | | | | | | | | | | | | | It's not clear that the namespace rules described in libxl.h are intended to apply to internal types but I don't see why not. sed -i -e 's/\<libxl_device\>/libxl__device/g' tools/libxl/*.[ch] sed -i -e 's/\<libxl_device_kinds\>/libxl__device_kinds/g' tools/libxl/*.[ch] sed -i -e 's/\<libxl_gc\>/libxl__gc/g' tools/libxl/*.[ch] sed -i -e 's/\<libxl_gc_owner\>/libxl__gc_owner/g' tools/libxl/*.[ch] sed -i -e 's/\<libxl_spawn_starting\>/libxl__spawn_starting/g' tools/libxl/*.[ch] Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
* libxl: Ensure all _hidden functions use libxl__ prefix (manual part)Ian Campbell2010-09-081-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | This patch covers the remaining functions identified by: rgrep _hidden tools/libxl/*.h | grep -v libxl__ sed -i -e 's/XL_LOG/LIBXL__LOG/g' tools/libxl/*.[ch] sed -i -e 's/xl_log/libxl__log/g' tools/libxl/*.[ch] sed -i -e 's/\(build_\(pre\|post\|pv\|hvm\)\)/libxl__\1/g' tools/libxl/*.[ch] sed -i -e 's/is_hvm/libxl__domain_is_hvm/g' tools/libxl/*.[ch] sed -i -e 's/get_shutdown_reason/libxl__domain_shutdown_reason/g' tools/libxl/*.[ch] sed -i -e 's/restore_common/libxl__domain_restore_common/g' tools/libxl/*.[ch] sed -i -e 's/core_suspend/libxl__domain_suspend_common/g' tools/libxl/*.[ch] sed -i -e 's/save_device_model/libxl__domain_save_device_model/g' tools/libxl/*.[ch] sed -i -e 's/device_disk_backend_type_of_phystype/libxl__device_disk_backend_type_of_phystype/g' tools/libxl/*.[ch] sed -i -e 's/\<libxl_blktap_enabled\>/libxl__blktap_enabled/g' tools/libxl/*.[ch] sed -i -e 's/\<libxl_blktap_devpath\>/libxl__blktap_devpath/g' tools/libxl/*.[ch] Add _hidden to libxl__blktap_enabled and libxl__blktap_devpath Inline dominfo_libxl__domain_shutdown_reason(info) into libxl__domain_shutdown_reason, its only caller. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
* libxl: Ensure all _hidden functions use libxl__ prefix (autogenerated patch)Ian Campbell2010-09-081-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | This patch covers all those which could be trivially converted automatically. sed -n -e 's/_hidden.*[ \*]libxl_\([^_][^()]*\)(.*/\1/pg' tools/libxl/*.h | \ while read i ; do \ sed -i -e "s/libxl_$i/libxl__$i/g" tools/libxl/*.[ch]; \ done sed -n -e 's/_hidden.*_libxl_\([^_][^()]*\)(.*/\1/pg' tools/libxl/*.h | \ while read i ; do \ sed -i -e "s/_libxl_$i/libxl__$i/g" tools/libxl/*.[ch]; \ done Check that diffstat includes libxl but not xl. Fixup tools/libxl/xl_cmdimpl.c which used libxl_device_del instead of libxl_device_disk_del in a printf. (Patch runes re-run by Ian Jackson to refresh against tip libxl.) Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
* xl: Implement per-API-call garbage-collection lifetimeGianni Tedesco2010-08-121-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | Currently scratch variables allocated by libxl have the same lifetime as the context. While this is suitable for one off invocations of xl. It is not so great for a daemon process linking to libxl. In that case there will be prolific leakage of heap memory. My proposed solution involves create a new libxl_gc structure, which contains a pointer to an owning context as well as the garbage collection data. Top-level library functions which expect to do a lot of scratch allocations put gc struct on the stack and initialize it with a macro. Before returning they then call libxl_free_all on this struct. This means that static helper functions called by such functions will usually take a gc instead of a ctx as a first parameter. The patch touches almost every code-path so a close review and testing would be much appreciated. I have tested with valgrind all of the parts I could which looked non-straightforward. Suffice to say that it seems crash-free even if we have exposed a few real memory leaks. These are for cases where we return eg. block list to an xl caller but there is no appropriate block_list_free() function to call. Ian Campbells work in this area should sew up all these loose ends. Signed-off-by: Gianni Tedesco <gianni.tedesco@citrix.com> committer: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
* libxl: consistently use typedef struct {} libxl_$typeIan Campbell2010-07-281-9/+9
| | | | | | | | typedef struct seems to be the dominant idiom in the mixture currently in use. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
* execute command by execvp() so can search command in PATH.Stefano Stabellini2010-07-191-1/+1
| | | | Signed-off-by: Yu Zhiguo <yuzg@cn.fujitsu.com>
* libxl: add libxl_strdup convenience functionIan Jackson2010-07-141-1/+1
| | | | | | Use in preference to libxl_sprintf(..., "%s", "...") Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
* libxl: Use the caller's logger (xentoollog)Keir Fraser2010-05-281-1/+2
| | | | | | | | | | We now require callers to provide a xentoollog_logger* for libxl_ctx_init, and use that for all our own logging and also for xc_interface_open. Corresponding change to xl.c. Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
* libxl: Expose libxl_report_exitstatusKeir Fraser2010-04-121-9/+7
| | | | | | | | xl would like to use libxl_report_exitstatus, so expose it in libxl_utils.h to avoid having to write it twice. Also, give it a "level" argument to set the loglevel of the resulting message. Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
* libxl: Expose functions for helping with subprocesses.Keir Fraser2010-04-121-13/+5
| | | | | | | | | | | | | | | | | | | | * Expose libxl_fork in libxl_utils.h * Expose libxl_pipe in libxl_utils.h * Make libxl_exec put SIGPIPE back (so that libxl callers may have SIGPIPE ignored) xl would like to use libxl_fork (which is like fork(2) except that it logs errors) and also a similar function libxl_pipe. So put these in libxl_utils.[ch] and use them in libxl.c as appropriate, to avoid having to duplicate code between xl and libxl. Also, make sure that subprocesses spawned by libxl have SIGPIPE set back to SIG_DFL as they are entitled to expect. This means that a libxl caller which sets SIGPIPE to SIG_IGN is no longer buggy. (This is relevant for xl migration, because xl would like to be such a caller.) Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
* libxenlight: remove ctx dangerously passed to childrenKeir Fraser2010-01-121-7/+7
| | | | | | | apart from ctx->waitpid, it's potentially harmful to call into logging. Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
* libxenlight: remove ctx argument to execKeir Fraser2010-01-121-3/+1
| | | | Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
* libxenlight: typo in old patch, lead to waitpid forever instead ofKeir Fraser2010-01-121-2/+2
| | | | | | | | waitpid with WNOHANG fixes qemu starting problem Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
* libxl: remove waitpid wrapper that's doesn't do anythingKeir Fraser2009-12-301-8/+8
| | | | | | if the waitpid callback isn't defined just call normal waitpid Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
* libxl: coding styles cleanupKeir Fraser2009-12-301-22/+25
| | | | | | | simplify some lines, and keep the xl style consistant with itself. use libxl_sprintf instead of snprintf/sprintf Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
* libxl: include signal.h, required for SIGKILL definitionKeir Fraser2009-12-021-0/+1
| | | | | | ...makes libxl build on NetBSD. Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
* libxenlight: wait for pv qemu initializationKeir Fraser2009-12-011-3/+4
| | | | | | | | | | | this patch makes libxl_create_stubdom wait for pv qemu to be properly initialized before unpausing the stubdom. A new libxl_device_model_starting pointer is used to wait for pv qemu initialization while the libxl_device_model_starting pointer given by the user is initialized to a new structure with an empty for_spawn member, because nothing that was spawn has to be waited for anymore. Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
* libxenlight: check for early failures of qemu-dmKeir Fraser2009-11-231-16/+173
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch makes xl create check whether qemu-dm has started correctly, and causes it to fail immediately with appropriate errors if not. There are other bugfixes too. More specifically: * libxl_create_device_model forks twice rather than once so that the process which calls libxl does not end up being the actual parent of qemu. That avoids the need for the qemu-dm process to be reaped at some indefinite time in the future. * The first fork generates an intermediate process which is responsible for writing the qemu-dm pid to xenstore and then merely waits to collect and report on qemu-dm's exit status during startup. New arguments to libxl_create_device_model allow the preservation of its pid so that a later call can check whether the startup is successful. * The core of this functionality (the double fork, waitpid, signal handling and so forth) is abstracted away into a new facility libxl_spawn_... in libxl_exec.c. Consequential changes: * libxl_wait_for_device_model now takes a callback function parameter which is called repeatedly in the loop iteration and allows the caller to abort the wait. * libxl_exec no longer calls fork; there is a new libxl_fork. * There is a hook to override waitpid, which will be necessary for some callers. Remaining problems and other issues I noticed or we found: * The error handling is rather inconsistent still and lacking in places. * destroy_device_model can kill random dom0 processes (!) Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
* libxenlight: correct broken osdeps.[ch] and make #includes consistentKeir Fraser2009-11-231-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | osdeps.[hc] previously mistakenly declared and defined [v]asprintf. These functions are available in the libc on most platforms. Also, osdeps.h is used by xc.c but xc.c is not part of the library, so osdeps.h is part of the public interface and should have a better name. So now, instead: * osdeps.h is libxl_osdeps.h. * _GNU_SOURCE is #defined in libxl_osdeps.h so that we get the system [v]asprintf (and various other functions) * libxl_osdeps.h is included first in every libxl*.c file (it needs to be before any system headers so that _GNU_SOURCE) takes effect. * osdeps.[hc] only provide their own reimplementation of [v]asprintf if NEED_OWN_ASPRINTF is defined. Currently it is not ever defined but this is provided for any platform which needs it. * While I was editing the #includes in each .c file, I put them all into the same order: "libxl_osdeps.h", then system headers, then local headers. * xs.h is included in libxl.h. This is needed for "bool"; it has to not be typedefed in libxl.h because otherwise we get a duplicate definition when including xs.h. Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
* libxenlight: Clean up logging arrangementsKeir Fraser2009-11-231-1/+1
| | | | | | | | | | | | | | | | | | | | * Introduce new variants of the logging functions which include errno values (converted using strerror) in the messages passed to the application's logging callback. * Use the new errno-including logging functions everywhere where appropriate. In general, xc_... functions return errno values or 0; xs_... functions return 0 or -1 (or some such) setting errno. * When libxl_xs_get_dompath fails, do not treat it as an allocation error. It isn't: it usually means xenstored failed. * Remove many spurious \n's from log messages. (The applications log callback is expected to add a \n if it wants to do that, so libxl's logging functions should be passed strings without \n.) Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
* libxenlight: initial libxenlight implementation under tools/libxlKeir Fraser2009-11-091-0/+48
Signed-off-by: Vincent Hanquez <Vincent.Hanquez@eu.citrix.com> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>