1/*********************************************************************** 2* * 3* This software is part of the ast package * 4* Copyright (c) 1992-2012 AT&T Intellectual Property * 5* and is licensed under the * 6* Eclipse Public License, Version 1.0 * 7* by AT&T Intellectual Property * 8* * 9* A copy of the License is available at * 10* http://www.eclipse.org/org/documents/epl-v10.html * 11* (with md5 checksum b35adb5213ca9657e911e9befb180842) * 12* * 13* Information and Software Systems Research * 14* AT&T Research * 15* Florham Park NJ * 16* * 17* Glenn Fowler <gsf@research.att.com> * 18* David Korn <dgk@research.att.com> * 19* * 20***********************************************************************/ 21#pragma prototyped 22/* 23 * David Korn 24 * Glenn Fowler 25 * AT&T Research 26 */ 27 28static const char usage[] = 29"[-?\n@(#)$Id: sync (AT&T Research) 2006-10-04 $\n]" 30USAGE_LICENSE 31"[+NAME?sync - schedule file system updates]" 32"[+DESCRIPTION?\bsync\b calls \bsync\b(2), which causes all information " 33 "in memory that updates file systems to be scheduled for writing out to " 34 "all file systems. The writing, although scheduled, is not necessarily " 35 "complete upon return from \bsync\b.]" 36"[+?Since \bsync\b(2) has no failure indication, \bsync\b only fails for " 37 "option/operand syntax errors, or when \bsync\b(2) does not return, in " 38 "which case \bsync\b also does not return.]" 39"[+?At minimum \bsync\b should be called before halting the system. Most " 40 "systems provide graceful shutdown procedures that include \bsync\b -- " 41 "use them if possible.]" 42"[+EXIT STATUS?]" 43 "{" 44 "[+0?\bsync\b(2) returned.]" 45 "[+>0?Option/operand syntax error.]" 46 "}" 47"[+SEE ALSO?\bsync\b(2), \bshutdown\b(8)]" 48; 49 50#include <cmd.h> 51#include <ls.h> 52 53int 54b_sync(int argc, char** argv, Shbltin_t* context) 55{ 56 cmdinit(argc, argv, context, ERROR_CATALOG, 0); 57 for (;;) 58 { 59 switch (optget(argv, usage)) 60 { 61 case ':': 62 error(2, "%s", opt_info.arg); 63 break; 64 case '?': 65 error(ERROR_usage(2), "%s", opt_info.arg); 66 break; 67 } 68 break; 69 } 70 argv += opt_info.index; 71 if (error_info.errors || *argv) 72 error(ERROR_usage(2), "%s", optusage(NiL)); 73#if _lib_sync 74 sync(); 75#else 76 error(ERROR_usage(2), "failed -- the native system does not provide a sync(2) call"); 77#endif 78 return 0; 79} 80