return -r;
}
-int asynchronous_sync(void) {
+int asynchronous_sync(pid_t *ret_pid) {
int r;
/* This forks off an invocation of fork() as a child process, in order to initiate synchronization to
* original process ever, and a thread would do that as the process can't exit with threads hanging in blocking
* syscalls. */
- r = safe_fork("(sd-sync)", FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS, NULL);
+ r = safe_fork("(sd-sync)", FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS, ret_pid);
if (r < 0)
return r;
if (r == 0) {
_exit(EXIT_SUCCESS);
}
- /* We don' really care about the PID from here on. It will exit when it's done. */
return 0;
}
int asynchronous_job(void* (*func)(void *p), void *arg);
-int asynchronous_sync(void);
+int asynchronous_sync(pid_t *ret_pid);
int asynchronous_close(int fd);
if (detect_container() > 0)
return;
- (void) asynchronous_sync();
+ (void) asynchronous_sync(NULL);
}
int job_get_timeout(Job *j, usec_t *timeout) {
#include <unistd.h>
#include "alloc-util.h"
+#include "async.h"
#include "cgroup-util.h"
-#include "fd-util.h"
#include "def.h"
#include "exec-util.h"
+#include "fd-util.h"
#include "fileio.h"
#include "killall.h"
#include "log.h"
}
static void sync_with_progress(void) {
+ unsigned long long dirty = ULONG_LONG_MAX;
unsigned checks;
pid_t pid;
int r;
- unsigned long long dirty = ULONG_LONG_MAX;
BLOCK_SIGNALS(SIGCHLD);
- /* Due to the possiblity of the sync operation hanging, we fork
- * a child process and monitor the progress. If the timeout
- * lapses, the assumption is that that particular sync stalled. */
- r = safe_fork("(sd-sync)", FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS, &pid);
+ /* Due to the possiblity of the sync operation hanging, we fork a child process and monitor the progress. If
+ * the timeout lapses, the assumption is that that particular sync stalled. */
+
+ r = asynchronous_sync(&pid);
if (r < 0) {
- log_error_errno(r, "Failed to fork: %m");
+ log_error_errno(r, "Failed to fork sync(): %m");
return;
}
- if (r == 0) {
- /* Start the sync operation here in the child */
- sync();
- _exit(EXIT_SUCCESS);
- }
log_info("Syncing filesystems and block devices.");
assert_se(asynchronous_job(async_func, NULL) >= 0);
- assert_se(asynchronous_sync() >= 0);
+ assert_se(asynchronous_sync(NULL) >= 0);
sleep(1);