1 /*********************************************************************** 2 * * 3 * This software is part of the ast package * 4 * Copyright (c) 1992-2010 AT&T Intellectual Property * 5 * and is licensed under the * 6 * Common Public License, Version 1.0 * 7 * by AT&T Intellectual Property * 8 * * 9 * A copy of the License is available at * 10 * http://www.opensource.org/licenses/cpl1.0.txt * 11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 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 28 static const char usage[] = 29 "[-?\n@(#)$Id: sync (AT&T Research) 2006-10-04 $\n]" 30 USAGE_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 53 int 54 b_sync(int argc, char** argv, void* 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