14887Schin /***********************************************************************
24887Schin * *
34887Schin * This software is part of the ast package *
4*12068SRoger.Faulkner@Oracle.COM * Copyright (c) 1992-2010 AT&T Intellectual Property *
54887Schin * and is licensed under the *
64887Schin * Common Public License, Version 1.0 *
78462SApril.Chin@Sun.COM * by AT&T Intellectual Property *
84887Schin * *
94887Schin * A copy of the License is available at *
104887Schin * http://www.opensource.org/licenses/cpl1.0.txt *
114887Schin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
124887Schin * *
134887Schin * Information and Software Systems Research *
144887Schin * AT&T Research *
154887Schin * Florham Park NJ *
164887Schin * *
174887Schin * Glenn Fowler <gsf@research.att.com> *
184887Schin * David Korn <dgk@research.att.com> *
194887Schin * *
204887Schin ***********************************************************************/
214887Schin #pragma prototyped
224887Schin /*
234887Schin * David Korn
244887Schin * Glenn Fowler
254887Schin * AT&T Research
264887Schin */
274887Schin
284887Schin static const char usage[] =
294887Schin "[-?\n@(#)$Id: sync (AT&T Research) 2006-10-04 $\n]"
304887Schin USAGE_LICENSE
314887Schin "[+NAME?sync - schedule file system updates]"
324887Schin "[+DESCRIPTION?\bsync\b calls \bsync\b(2), which causes all information "
334887Schin "in memory that updates file systems to be scheduled for writing out to "
344887Schin "all file systems. The writing, although scheduled, is not necessarily "
354887Schin "complete upon return from \bsync\b.]"
364887Schin "[+?Since \bsync\b(2) has no failure indication, \bsync\b only fails for "
374887Schin "option/operand syntax errors, or when \bsync\b(2) does not return, in "
384887Schin "which case \bsync\b also does not return.]"
394887Schin "[+?At minimum \bsync\b should be called before halting the system. Most "
404887Schin "systems provide graceful shutdown procedures that include \bsync\b -- "
414887Schin "use them if possible.]"
424887Schin "[+EXIT STATUS?]"
434887Schin "{"
444887Schin "[+0?\bsync\b(2) returned.]"
454887Schin "[+>0?Option/operand syntax error.]"
464887Schin "}"
474887Schin "[+SEE ALSO?\bsync\b(2), \bshutdown\b(8)]"
484887Schin ;
494887Schin
504887Schin #include <cmd.h>
514887Schin #include <ls.h>
524887Schin
534887Schin int
b_sync(int argc,char ** argv,void * context)544887Schin b_sync(int argc, char** argv, void* context)
554887Schin {
564887Schin cmdinit(argc, argv, context, ERROR_CATALOG, 0);
574887Schin for (;;)
584887Schin {
594887Schin switch (optget(argv, usage))
604887Schin {
614887Schin case ':':
624887Schin error(2, "%s", opt_info.arg);
634887Schin break;
644887Schin case '?':
654887Schin error(ERROR_usage(2), "%s", opt_info.arg);
664887Schin break;
674887Schin }
684887Schin break;
694887Schin }
704887Schin argv += opt_info.index;
714887Schin if (error_info.errors || *argv)
724887Schin error(ERROR_usage(2), "%s", optusage(NiL));
734887Schin #if _lib_sync
744887Schin sync();
754887Schin #else
764887Schin error(ERROR_usage(2), "failed -- the native system does not provide a sync(2) call");
774887Schin #endif
784887Schin return 0;
794887Schin }
80