Index: bin/sync/sync.8 =================================================================== --- bin/sync/sync.8 +++ bin/sync/sync.8 @@ -29,7 +29,7 @@ .\" @(#)sync.8 8.1 (Berkeley) 5/31/93 .\" $FreeBSD$ .\" -.Dd May 31, 1993 +.Dd September 14, 2019 .Dt SYNC 8 .Os .Sh NAME @@ -37,6 +37,9 @@ .Nd force completion of pending disk writes (flush cache) .Sh SYNOPSIS .Nm +.Op Ar number +.Nm +.Op arg .Sh DESCRIPTION The .Nm @@ -61,6 +64,29 @@ utility utilizes the .Xr sync 2 function call. +.Pp +If +.Nm +is given a single numeric argument, it will call the +.Xr sync 2 +function call that number of times; if it is given a non-numeric +argument, or the number is 0 or negative, then +.Nm +will call the +.Xr sync 2 +function call once for each argument, and one additional time. +.Sh EXAMPLES +Call the +.Xr sync 2 +function once: +.Dl $ sync +.Pp +Call the +.Xr sync 2 +function three times: +.Dl $ sync 3 +or: +.Dl $ sync sync sync .Sh SEE ALSO .Xr fsync 2 , .Xr sync 2 , Index: bin/sync/sync.c =================================================================== --- bin/sync/sync.c +++ bin/sync/sync.c @@ -47,6 +47,24 @@ int main(int argc __unused, char *argv[] __unused) { - sync(); + long sync_count; + + if (argc == 1) + sync_count = 1; + else { + sync_count = strtol(argv[1], NULL, 0); + /* + * If argv[1] isn't a valid number -- or + * if it's 0, or negative -- then we simply use + * the number of arguments, including argv[0], + * to indicate how many times to sync. + * This allows "sync 10" and "sync sync sync" + * (as examples) to work as expected. + */ + if (sync_count <= 0) + sync_count = argc; + } + while (sync_count--) + sync(); exit(0); }