void os_setup_early_signal_handling(void);
char *os_find_datadir(void);
void os_parse_cmd_args(int index, const char *optarg);
-void os_pidfile_error(void);
/* Convert a byte between binary and BCD. */
static inline uint8_t to_bcd(uint8_t val)
do {
len = read(fds[0], &status, 1);
} while (len < 0 && errno == EINTR);
- if (len != 1) {
- exit(1);
- }
- else if (status == 1) {
- fprintf(stderr, "Could not acquire pidfile\n");
- exit(1);
- } else {
- exit(0);
- }
- } else if (pid < 0) {
- exit(1);
- }
+
+ /* only exit successfully if our child actually wrote
+ * a one-byte zero to our pipe, upon successful init */
+ exit(len == 1 && status == 0 ? 0 : 1);
+
+ } else if (pid < 0) {
+ exit(1);
+ }
close(fds[0]);
daemon_pipe = fds[1];
}
}
-void os_pidfile_error(void)
-{
- if (daemonize) {
- uint8_t status = 1;
- if (write(daemon_pipe, &status, 1) != 1) {
- perror("daemonize. Writing to pipe\n");
- }
- } else
- fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
-}
-
void os_set_line_buffering(void)
{
setvbuf(stdout, NULL, _IOLBF, 0);
return;
}
-void os_pidfile_error(void)
-{
- fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
-}
-
int qemu_create_pidfile(const char *filename)
{
char buffer[128];
#endif
if (pid_file && qemu_create_pidfile(pid_file) != 0) {
- os_pidfile_error();
+ fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
exit(1);
}