#include <grp.h>
#include <libgen.h>
+#include "qemu-common.h"
/* Needed early for CONFIG_BSD etc. */
-#include "sysemu/sysemu.h"
#include "net/slirp.h"
#include "qemu-options.h"
#include "qemu/error-report.h"
#include "qemu/log.h"
+#include "sysemu/runstate.h"
#include "qemu/cutils.h"
#ifdef CONFIG_LINUX
/* Could rewrite argv[0] too, but that's a bit more complicated.
This simple way is enough for `top'. */
if (prctl(PR_SET_NAME, name)) {
- perror("unable to change process name");
+ error_report("unable to change process name: %s", strerror(errno));
exit(1);
}
#else
* Parse OS specific command line options.
* return 0 if option handled, -1 otherwise
*/
-void os_parse_cmd_args(int index, const char *optarg)
+int os_parse_cmd_args(int index, const char *optarg)
{
switch (index) {
-#ifdef CONFIG_SLIRP
- case QEMU_OPTION_smb:
- error_report("The -smb option is deprecated. "
- "Please use '-netdev user,smb=...' instead.");
- if (net_slirp_smb(optarg) < 0)
- exit(1);
- break;
-#endif
case QEMU_OPTION_runas:
user_pwd = getpwnam(optarg);
if (user_pwd) {
fips_set_state(true);
break;
#endif
+ default:
+ return -1;
}
+
+ return 0;
}
static void change_process_uid(void)
exit(1);
}
if (chdir("/")) {
- perror("not able to chdir to /");
+ error_report("not able to chdir to /: %s", strerror(errno));
exit(1);
}
}
if (daemonize) {
if (chdir("/")) {
- perror("not able to chdir to /");
+ error_report("not able to chdir to /: %s", strerror(errno));
exit(1);
}
TFR(fd = qemu_open("/dev/null", O_RDWR));
setvbuf(stdout, NULL, _IOLBF, 0);
}
-int qemu_create_pidfile(const char *filename)
-{
- char buffer[128];
- int len;
- int fd;
-
- fd = qemu_open(filename, O_RDWR | O_CREAT, 0600);
- if (fd == -1) {
- return -1;
- }
- if (lockf(fd, F_TLOCK, 0) == -1) {
- close(fd);
- return -1;
- }
- len = snprintf(buffer, sizeof(buffer), FMT_pid "\n", getpid());
- if (write(fd, buffer, len) != len) {
- close(fd);
- return -1;
- }
-
- /* keep pidfile open & locked forever */
- return 0;
-}
-
bool is_daemonized(void)
{
return daemonize;
ret = mlockall(MCL_CURRENT | MCL_FUTURE);
if (ret < 0) {
- perror("mlockall");
+ error_report("mlockall: %s", strerror(errno));
}
return ret;