summaryrefslogtreecommitdiffstats
path: root/os-posix.c
Commit message (Collapse)AuthorAgeFilesLines
* rcu: do not create thread in pthread_atfork callbackPaolo Bonzini2015-04-011-0/+2
| | | | | | | | | | | | | | | | | | | | | If QEMU forks after the CPU threads have been created, qemu_mutex_lock_iothread will not be able to do qemu_cpu_kick_thread. There is no solution other than assuming that forks after the CPU threads have been created will end up in an exec. Forks before the CPU threads have been created (such as -daemonize) have to call rcu_after_fork manually. Notably, the oxygen theme for GTK+ forks and shows a "No such process" error without this patch. This patch can be reverted once the iothread loses the "kick the TCG thread" magic. User-mode emulation does not use the iothread, so it can also call rcu_after_fork. Reported by: Dr. David Alan Gilbert <dgilbert@redhat.com> Tested by: Dr. David Alan Gilbert <dgilbert@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* os-posix: reorder parent notification for -daemonizeMichael Tokarev2014-11-021-9/+10
| | | | | | | | | | Put "success" parent reporting in os_setup_post() to after all other initializers which may also fail, to the very end, so more possible failure cases are reported properly to the calling process. Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> Reviewed-by: Gonglei <arei.gonglei@huawei.com>
* pidfile: stop making pidfile error a special caseMichael Tokarev2014-11-021-23/+8
| | | | | | | | | | | | | | | | | | In case of -daemonize, we write non-zero to the daemon pipe only if pidfile creation failed, so the parent will report error about pidfile problem. There's no need to make special case for this, since all other errors are reported by the child just fine. Let the parent report error and simplify logic in os_daemonize(). This way, we don't need os_pidfile_error() function, since it only prints error now, so put the error reporting printf into the only place where qemu_create_pidfile() is called, in vl.c. While at it, fix wrong indentation in os_daemonize(). Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
* os-posix: replace goto again with a proper loopMichael Tokarev2014-11-021-10/+6
| | | | | | | | Eliminiate two fullwrite implementations with goto replacing them with a proper do..while loop. Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> Reviewed-by: Gonglei <arei.gonglei@huawei.com>
* os-posix: use global daemon_pipe instead of cryptic fds[1]Michael Tokarev2014-11-021-4/+6
| | | | | | | | | | | | When asked to -daemonize, we fork a child and setup a pipe between it and parent to pass exit status. os-posix.c used global fds[2] array for that, but actually only the writing side of the pipe is needed to be global, and this name is really too generic. Use just one interger for the writing side of the pipe, and name it daemon_pipe to be more understandable than cryptic fds[1]. Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> Reviewed-by: Gonglei <arei.gonglei@huawei.com>
* Revert "os-posix: report error message when lock file failed"Michael Tokarev2014-11-021-2/+0
| | | | | | | | | | | | | | | | | | | | | | This reverts commit e5048d15ce6addae869f23514b2a1f0d4466418a. qemu_create_pidfile() is only created from main(), and there, if that function returns failure, os_pidfile_error() function is called, to, guess that, report error (which is done differently whenever we're daemonizing or not). qemu_create_pidfile() function has several error returns, this lockf() failure is one of them, there are others (another shown in the patch context too). So this patch makes whole thing inconsistent at least. If we need to show error message when we're daemonizing, it looks like we should modify os_pidfile_error() routine to always report error and only after that check for daemon mode. This way all errors will be reported the same way. Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
* os-posix: report error message when lock file failedGonglei2014-09-261-0/+2
| | | | | | | | | | | | It will cause that create vm failed When manager tool is killed forcibly (kill -9 libvirtd_pid), the file not was unlink, and unlock. It's better that report the error message for users. Signed-off-by: Huangweidong <weidong.huang@huawei.com> Signed-off-by: Gonglei <arei.gonglei@huawei.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
* os-posix: remove confused errnoGonglei2014-09-261-1/+1
| | | | | | | | | | | | If we get inside the 'else if (status == 1)' conditional, then we know that read() succeeded, and therefore errno is unspecified. Printing strerror(errno) on a random value is not helpful. Cc: Eric Blake <eblake@redhat.com> Signed-off-by: Gonglei <arei.gonglei@huawei.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
* os-posix: change tab to space avoid violating coding styleGonglei2014-09-261-37/+42
| | | | | | | Cc: Eric Blake <eblake@redhat.com> Signed-off-by: Gonglei <arei.gonglei@huawei.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
* oslib-posix: Fix build on FreeBSDAndreas Färber2014-03-131-4/+0
| | | | | | | | | | | | | Commit 10f5bff622cad71645e22c027b77ac31e51008ef (util: Split out exec_dir from os_find_datadir) moved code from os-posix.c to util/oslib-posix.c but forgot to move a FreeBSD #include alongside, needed for CTL_KERN among others. Cc: Fam Zheng <famz@redhat.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andreas Färber <andreas.faerber@web.de> Message-id: 1394717279-23406-1-git-send-email-andreas.faerber@web.de Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
* util: Split out exec_dir from os_find_datadirFam Zheng2014-02-201-35/+7
| | | | | | | | | With this change, main() calls qemu_init_exec_dir and uses argv[0] to init exec_dir. The saved value can be retrieved with qemu_get_exec_dir later. It will be reused by module loading. Signed-off-by: Fam Zheng <famz@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* Add option to mlock qemu and guest memorySatoru Moriya2013-04-221-0/+12
| | | | | | | | | | | | | | | | | | In certain scenario, latency induced by paging is significant and memory locking is needed. Also, in the scenario with untrusted guests, latency improvement due to mlock is desired. This patch introduces a following new option to mlock guest and qemu memory: -realtime mlock=on|off Signed-off-by: Satoru Moriya <satoru.moriya@hds.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-id: 1366382526-26146-1-git-send-email-pbonzini@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* softmmu: move include files to include/sysemu/Paolo Bonzini2012-12-191-1/+1
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* Merge branch 'trivial-patches' of git://github.com/stefanha/qemuAurelien Jarno2012-10-061-1/+0
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 'trivial-patches' of git://github.com/stefanha/qemu: versatilepb: Use symbolic indices for ARM PIC qdev: kill bogus comment qemu-barrier: Fix compiler version check for future gcc versions hw: Add missing 'static' attribute for QEMUMachine cleanup useless return sentence qemu-sockets: Fix compiler warning (regression for MinGW) vnc: Fix spelling (hellmen -> hellman) in comment slirp: Fix spelling in comment (enought -> enough, insure -> ensure) tcg/arm: Use tcg_out_mov_reg rather than inline equivalent code cpu: Add missing 'static' attribute to qemu_global_mutex configure: Support empty target list (--target-list=) hw: Fix return value check for bdrv_read, bdrv_write
| * cleanup useless return sentenceAmos Kong2012-10-051-1/+0
| | | | | | | | | | | | | | | | This patch cleans up return sentences in the end of void functions. Reported-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Amos Kong <akong@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
* | os-posix: avoid buffer overrunJim Meyering2012-10-051-2/+1
|/ | | | | | | | os_set_proc_name: Use pstrcpy, in place of strncpy and the ineffectual preceding assignment: name[sizeof(name) - 1] = 0; Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* curses: don't initialize curses when qemu is daemonizedHitoshi Mitake2012-09-231-0/+5
| | | | | | | | | | | | | | | | | | | | | | Current qemu initializes curses even if -daemonize option is passed. This cause problem because shell prompt appears without calling endwin(). This patch adds new function, is_daemonized(), to OS dependent code. With this function, curses_display_init() can check that qemu is daemonized or not. If daemonized, curses_display_init() isn't called and the problem is avoided. Of course, -daemonize && -curses doesn't make sense. Users shouldn't pass the arguments at the same time. But the problem is very painful because Ctrl-C cannot be delivered to the terminal. Cc: Andrzej Zaborowski <balrog@zabor.org> Cc: Stefan Hajnoczi <stefanha@gmail.com> Cc: Anthony Liguori <aliguori@us.ibm.com> Cc: Michael Roth <mdroth@linux.vnet.ibm.com> Signed-off-by: Hitoshi Mitake <h.mitake@gmail.com> Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
* fips: fix build on !LinuxAnthony Liguori2012-08-031-0/+5
| | | | | | | | | | Commit 0f66998 makes -enable-fips conditional on Linux hosts but then uses it unconditionally in vl.c. Fix this by moving the fips handling to os-posix.c and adding a condition. Cc: Paul Moore <pmoore@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* os-posix: Fix build on FreeBSDNathan Whitehorn2012-04-261-0/+4
| | | | | | | | Add an include for a header required to build on recent FreeBSD. Signed-off-by: Nathan Whitehorn <nwhitehorn@freebsd.org> Signed-off-by: Andreas Färber <andreas.faerber@web.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* keep the PID file locked for the lifetime of the processLaszlo Ersek2012-02-011-1/+1
| | | | | | | | | | | | | | | | | | | | | The lockf() call in qemu_create_pidfile() aims at ensuring mutual exclusion. We shouldn't close the pidfile on success (as introduced by commit 1bbd1592), because that drops the lock as well [1]: "File locks shall be released on first close by the locking process of any file descriptor for the file." Coverity may complain again about the leaked file descriptor; let's worry about that later. v1->v2: - add reference to 1bbd1592 - explain the intentional fd leak in the source [1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/lockf.html Signed-off-by: Laszlo Ersek <lersek@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* link the main loop and its dependencies into the toolsPaolo Bonzini2011-12-221-42/+0
| | | | | | | | Using the main loop code from QEMU enables tools to operate fully asynchronously. Advantages include better Windows portability (for some definition of portability) over glib's. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* os-posix: Plug fd leak in qemu_create_pidfile()Markus Armbruster2011-11-111-0/+3
| | | | | | | Spotted by Coverity. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Use glib memory allocation and free functionsAnthony Liguori2011-08-201-2/+2
| | | | | | qemu_malloc/qemu_free no longer exist after this commit. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* os-posix: set groups properly for -runasStefan Hajnoczi2011-07-121-0/+6
| | | | | | | | | | | | | Andrew Griffiths reports that -runas does not set supplementary group IDs. This means that gid 0 (root) is not dropped when switching to an unprivileged user. Add an initgroups(3) call to use the -runas user's /etc/groups membership to update the supplementary group IDs. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Acked-by: Chris Wright <chrisw@sous-sol.org> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Introduce format string for pid_tAndreas Färber2011-06-151-1/+1
| | | | | | | | | | | | | | | | | | | | | BeOS and Haiku on i386 use long for 32-bit types, including pid_t. Using %d with pid_t therefore results in a warning. Unfortunately POSIX:2008 does not define a PRId* string for pid_t. In some places pid_t was previously casted to long and %ld hardcoded. The predecessor of this patch added another upcast for the simpletrace filename but was not applied to date. Since new uses of pid_t with %d keep creeping in, let's instead define an OS-dependent format string and use that consistently. Cc: Stefan Hajnoczi <stefanha@gmail.com> Cc: Blue Swirl <blauwirbel@gmail.com> Cc: Ingo Weinhold <ingo_weinhold@gmx.de> Cc: Gleb Natapov <gleb@redhat.com> Signed-off-by: Andreas Färber <andreas.faerber@web.de> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* add a service to reap zombies, use it in SLIRPPaolo Bonzini2011-03-291-9/+0
| | | | | | | | | | | | | SLIRP -smb support wants to fork a process and forget about reaping it. To please it, add a generic service to register a process id and let QEMU reap it. In the future it could be enhanced to pass a status, but this would be unused. With this in place, the SIGCHLD signal handler would not stomp on pclose anymore. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* report that QEMU process was killed by a signalGleb Natapov2011-03-261-3/+4
| | | | | | | | | Currently when rogue script kills QEMU process (using TERM/INT/HUP signal) it looks indistinguishable from system shutdown. Lets report that QEMU was killed and leave some clues about the killer identity. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Expose thread_id in info cpusJan Kiszka2011-03-161-0/+10
| | | | | | | | | | | Based on patch by Glauber Costa: To allow management applications like libvirt to apply CPU affinities to the VCPU threads, expose their ID via info cpus. This patch provides the pre-existing and used interface from qemu-kvm. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
* Separate qemu_pidfile() into OS specific versionsJes Sorensen2010-10-301-0/+21
| | | | | Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* We only support eventfd under POSIX, move qemu_eventfd() to os-posix.cJes Sorensen2010-10-301-0/+32
| | | | | Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Use ARRAY_SIZE macroBlue Swirl2010-08-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Replace array size calculations with ARRAY_SIZE macro. Implemented with this Coccinelle semantic patch, adapted from Linux kernel: @@ type T; T[] E; @@ - (sizeof(E)/sizeof(*E)) + ARRAY_SIZE(E) @@ type T; T[] E; @@ - (sizeof(E)/sizeof(E[...])) + ARRAY_SIZE(E) @@ type T; T[] E; @@ - (sizeof(E)/sizeof(T)) + ARRAY_SIZE(E) Some files (*-dis.c, tests/*) had to be filtered out. Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Include sys/mman.h before qemu-options.hJes Sorensen2010-07-061-0/+2
| | | | | | | | | | | The result of parsing qemu-options.def depends on whehter or not MAP_POPULATE is defined, so make sure to include sys/mman.h before including qemu-options.h. Reported by Frank Arnold. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Move set_proc_name() to OS specific files.Jes Sorensen2010-06-121-0/+24
| | | | | | | | | | | Move handling to change process name to POSIX specific files plus add a better error message to cover the case where the feature isn't supported. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Acked-by: Juan Quintela <quintela@redhat.com> Acked-by: Richard Henderson <rth@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Move line-buffering setup to OS specific files.Jes Sorensen2010-06-121-0/+5
| | | | | | | | | Move line-buffering setup to OS specific files. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Acked-by: Juan Quintela <quintela@redhat.com> Acked-by: Richard Henderson <rth@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Make os_change_process_uid and os_change_root os-posix.c localJes Sorensen2010-06-121-4/+4
| | | | | | | | | | os_change_process_uid() and os_change_root() are now only called from os-posix.c, so no need to keep win32 stubs for them. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Acked-by: Juan Quintela <quintela@redhat.com> Acked-by: Richard Henderson <rth@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Move daemonize handling to OS specific filesJes Sorensen2010-06-121-0/+102
| | | | | | | | | | Move daemonize handling from vl.c to OS specific files. Provide dummy stubs for Win32. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Acked-by: Juan Quintela <quintela@redhat.com> Acked-by: Richard Henderson <rth@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Move chroot handling to OS specific files.Jes Sorensen2010-06-121-0/+19
| | | | | | | | | Move chroot handling to OS specific files. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Acked-by: Juan Quintela <quintela@redhat.com> Acked-by: Richard Henderson <rth@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Move runas handling from vl.c to OS specific files.Jes Sorensen2010-06-121-0/+28
| | | | | | | | | | Move code to handle runas, ie. change of user id of QEMU process to OS specific files and provide dummy stub for Win32. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Acked-by: Juan Quintela <quintela@redhat.com> Acked-by: Richard Henderson <rth@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Introduce OS specific cmdline argument handling and move SMB arg to os-posix.cJes Sorensen2010-06-121-0/+19
| | | | | | | | | | | | | | Introduce OS specific cmdline argument handling by calling os_parse_cmd_args() at the end of switch() statement. Move option enum to qemu-options.h and have it included from os-posix.c and os-win32.c in addition to vl.c. In addition move SMB argument to os-posix.c Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Acked-by: Juan Quintela <quintela@redhat.com> Acked-by: Richard Henderson <rth@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Move find_datadir to OS specific files.Jes Sorensen2010-06-121-0/+64
| | | | | | | | | | This moves the win32 and POSIX versions of find_datadir() to OS specific files, and removes some #ifdef clutter from vl.c Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Acked-by: Juan Quintela <quintela@redhat.com> Acked-by: Richard Henderson <rth@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Move main signal handler setup to os specificfiles.Jes Sorensen2010-06-121-0/+27
| | | | | | | | | Move main signal handler setup to os specific files. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Acked-by: Juan Quintela <quintela@redhat.com> Acked-by: Richard Henderson <rth@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Rename os_setup_signal_handling() to os_setup_early_signal_handling()Jes Sorensen2010-06-121-1/+1
| | | | | | | | | Rename os_setup_signal_handling() to os_setup_early_signal_handling() Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Acked-by: Juan Quintela <quintela@redhat.com> Acked-by: Richard Henderson <rth@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Introduce os-posix.c and create os_setup_signal_handling()Jes Sorensen2010-06-121-0/+41
Introcuce os-posix.c and move posix specific signal handling there. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Acked-by: Juan Quintela <quintela@redhat.com> Acked-by: Richard Henderson <rth@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
OpenPOWER on IntegriCloud