Skip to content

Commit d3c6a6c

Browse files
committed
fixup! rc_unmount: add parallel unmounting
use timeutils.h
1 parent 88ba55a commit d3c6a6c

File tree

2 files changed

+15
-32
lines changed

2 files changed

+15
-32
lines changed

src/mountinfo/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
foreach exec : ['mountinfo', 'rc_unmount']
22
executable(exec,
3-
['mountinfo.c', rc_exec_c, misc_c, usage_c, version_h],
3+
['mountinfo.c', rc_exec_c, timeutils_c, misc_c, usage_c, version_h],
44
c_args : cc_branding_flags,
55
include_directories: [incdir, einfo_incdir, rc_incdir],
66
link_with: [libeinfo, librc],

src/mountinfo/mountinfo.c

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,10 @@
4444
#include "queue.h"
4545
#include "rc.h"
4646
#include "rc_exec.h"
47+
#include "timeutils.h"
4748
#include "_usage.h"
4849
#include "helpers.h"
4950

50-
/* on linux CLOCK_BOOTTIME provides proper POSIX CLOCK_MONOTONIC behavior. */
51-
#if defined(__linux__)
52-
# undef CLOCK_MONOTONIC
53-
# define CLOCK_MONOTONIC CLOCK_BOOTTIME
54-
#endif
55-
5651
const char *applet = NULL;
5752
const char *procmounts = "/proc/mounts";
5853
const char *extraopts = "[mount1] [mount2] ...";
@@ -386,21 +381,6 @@ find_mounts(struct args *args, size_t *num_mounts)
386381
# error "Operating system not supported!"
387382
#endif
388383

389-
static int64_t clock_ms(void)
390-
{
391-
struct timespec t;
392-
clock_gettime(CLOCK_MONOTONIC, &t);
393-
return (t.tv_sec * 1000) + (t.tv_nsec / 1000000);
394-
}
395-
396-
static int sleep_ms(int64_t ms)
397-
{
398-
struct timespec t;
399-
t.tv_sec = ms / 1000;
400-
t.tv_nsec = (ms % 1000) * 1000000l;
401-
return clock_nanosleep(CLOCK_MONOTONIC, 0, &t, NULL);
402-
}
403-
404384
static int is_prefix(const char *needle, const char *hay)
405385
{
406386
size_t nlen = strlen(needle);
@@ -494,7 +474,7 @@ static void fuser_run(struct run_queue *rp, const char *fuser_opt)
494474
} else {
495475
rp->fuser_pid = res.pid;
496476
rp->fuser_stdoutfd = res.proc_stdout;
497-
rp->fuser_exec_time = clock_ms();
477+
rp->fuser_exec_time = tm_now();
498478
}
499479
}
500480

@@ -587,7 +567,7 @@ int main(int argc, char **argv)
587567
pid_t pid;
588568
int status, flags;
589569
int64_t tmp, next_retry, now;
590-
int rc_fuser_timeout;
570+
int64_t rc_fuser_timeout = -1;
591571
const char *umount_args[UMOUNT_ARGS_MAX];
592572
int umount_args_num = 0;
593573
const char **mounts = NULL;
@@ -627,8 +607,11 @@ int main(int argc, char **argv)
627607
}
628608

629609
tmps = rc_conf_value("rc_fuser_timeout");
630-
if (!tmps || sscanf(tmps, "%d", &rc_fuser_timeout) != 1)
631-
rc_fuser_timeout = 60;
610+
if (tmps && (rc_fuser_timeout = parse_duration(tmps)) < 0)
611+
ewarn("%s: Invalid rc_fuser_timeout value: `%s`. "
612+
"Defaulting to 60", applet, tmps);
613+
if (rc_fuser_timeout < 0)
614+
rc_fuser_timeout = 60 * 1000;
632615

633616
tmps = getenv("RC_UNAME");
634617
if (!tmps || strcmp(tmps, "Linux") == 0) {
@@ -771,7 +754,7 @@ int main(int argc, char **argv)
771754
}
772755
rp = running + num_running++;
773756
rp->mntpath = mounts[unmount_index];
774-
rp->last_exec_time = clock_ms();
757+
rp->last_exec_time = tm_now();
775758
rp->try_count = 0;
776759
rp->pid = run_umount(rp->mntpath, umount_args, umount_args_num);
777760
rp->fuser_pid = -1;
@@ -818,7 +801,7 @@ int main(int argc, char **argv)
818801
if (running[i].pid > 0)
819802
continue;
820803
if (running[i].fuser_pid > 0)
821-
tmp = running[i].fuser_exec_time + (rc_fuser_timeout * UINT64_C(1000));
804+
tmp = running[i].fuser_exec_time + rc_fuser_timeout;
822805
else
823806
tmp = running[i].last_exec_time + TRY_DELAY_MS;
824807
if (tmp < next_retry) {
@@ -830,11 +813,11 @@ int main(int argc, char **argv)
830813
state = (num_mounts > 0) ? STATE_RUN : STATE_END;
831814
break;
832815
}
833-
now = clock_ms();
816+
now = tm_now();
834817
if (next_retry > now) {
835-
if (sleep_ms(MIN(next_retry - now, 1000)) < 0 && errno == EINTR)
818+
if (tm_sleep(MIN(next_retry - now, 1000), 0) != 0 && errno == EINTR)
836819
state = STATE_REAP;
837-
now = clock_ms();
820+
now = tm_now();
838821
}
839822
if (next_retry <= now) {
840823
if (rp->fuser_pid > 0) {
@@ -846,7 +829,7 @@ int main(int argc, char **argv)
846829
*rp = running[--num_running];
847830
result = EXIT_FAILURE;
848831
} else { /* retry */
849-
rp->last_exec_time = clock_ms();
832+
rp->last_exec_time = tm_now();
850833
rp->pid = run_umount(rp->mntpath,
851834
umount_args, umount_args_num);
852835
}

0 commit comments

Comments
 (0)