Tim Waugh 585f6b
Index: conf/cups-files.conf.in
Tim Waugh 585f6b
===================================================================
Tim Waugh 585f6b
--- conf/cups-files.conf.in	(revision 11192)
Tim Waugh 585f6b
+++ conf/cups-files.conf.in	(working copy)
Tim Waugh 585f6b
@@ -8,6 +8,9 @@
Tim Waugh 585f6b
 # List of events that are considered fatal errors for the scheduler...
Tim Waugh 585f6b
 #FatalErrors @CUPS_FATAL_ERRORS@
Tim Waugh 585f6b
Tim Waugh 585f6b
+# Do we call fsync() after writing configuration or status files?
Tim Waugh 585f6b
+#SyncOnClose No
Tim Waugh 585f6b
+
Tim Waugh 585f6b
 # Default user and group for filters/backends/helper programs; this cannot be
Tim Waugh 585f6b
 # any user or group that resolves to ID 0 for security reasons...
Tim Waugh 585f6b
 #User @CUPS_USER@
Tim Waugh 585f6b
Index: doc/help/ref-cups-files-conf.html.in
Tim Waugh 585f6b
===================================================================
Tim Waugh 585f6b
--- doc/help/ref-cups-files-conf.html.in	(revision 11192)
Tim Waugh 585f6b
+++ doc/help/ref-cups-files-conf.html.in	(working copy)
Tim Waugh 585f6b
@@ -429,6 +429,31 @@
Tim Waugh 585f6b
 default server directory is /etc/cups.

Tim Waugh 585f6b
Tim Waugh 585f6b
Tim Waugh 585f6b
+

CUPS 1.6.4SyncOnClose

Tim Waugh 585f6b
+
Tim Waugh 585f6b
+

Examples

Tim Waugh 585f6b
+
Tim Waugh 585f6b
+
Tim Waugh 585f6b
+SyncOnClose No
Tim Waugh 585f6b
+SyncOnClose Yes
Tim Waugh 585f6b
+
Tim Waugh 585f6b
+
Tim Waugh 585f6b
+

Description

Tim Waugh 585f6b
+
Tim Waugh 585f6b
+

The SyncOnClose directive determines whether the scheduler

Tim Waugh 585f6b
+flushes changes to configuration and state files to disk. The default is
Tim Waugh 585f6b
+No which relies on the operating system to schedule a suitable
Tim Waugh 585f6b
+time to write changes to disk.

Tim Waugh 585f6b
+
Tim Waugh 585f6b
+
Note:
Tim Waugh 585f6b
+
Tim Waugh 585f6b
+

Setting SyncOnClose to Yes makes the scheduler use the fsync(2) system call to write all changes to disk, however the drive or network file system server may still delay writing data to disk. Do not depend on this functionality to prevent data loss in the event of unexpected hardware failure.

Tim Waugh 585f6b
+
Tim Waugh 585f6b
+

Enabling SyncOnClose may also cause the scheduler to periodically become unresponsive while it waits for changes to be written.

Tim Waugh 585f6b
+
Tim Waugh 585f6b
+
Tim Waugh 585f6b
+
Tim Waugh 585f6b
+
Tim Waugh 585f6b
 

SystemGroup

Tim Waugh 585f6b
Tim Waugh 585f6b
 

Examples

Tim Waugh 585f6b
Index: man/cups-files.conf.man.in
Tim Waugh 585f6b
===================================================================
Tim Waugh 585f6b
--- man/cups-files.conf.man.in	(revision 11192)
Tim Waugh 585f6b
+++ man/cups-files.conf.man.in	(working copy)
Tim Waugh 585f6b
@@ -122,6 +122,12 @@
Tim Waugh 585f6b
 .br
Tim Waugh 585f6b
 Specifies the directory where the server configuration files can be found.
Tim Waugh 585f6b
 .TP 5
Tim Waugh 585f6b
+SyncOnClose Yes
Tim Waugh 585f6b
+.TP 5
Tim Waugh 585f6b
+SyncOnClose No
Tim Waugh 585f6b
+Specifies whether the scheduler calls \fIfsync(2)\fR after writing configuration
Tim Waugh 585f6b
+or state files. The default is No.
Tim Waugh 585f6b
+.TP 5
Tim Waugh 585f6b
 SystemGroup group-name [group-name ...]
Tim Waugh 585f6b
 .br
Tim Waugh 585f6b
 Specifies the group(s) to use for System class authentication.
Tim Waugh 585f6b
Index: scheduler/conf.c
Tim Waugh 585f6b
===================================================================
Tim Waugh 585f6b
--- scheduler/conf.c	(revision 11192)
Tim Waugh 585f6b
+++ scheduler/conf.c	(working copy)
Tim Waugh 585f6b
@@ -174,6 +174,7 @@
Tim Waugh 585f6b
   { "ServerRoot",		&ServerRoot,		CUPSD_VARTYPE_PATHNAME },
Tim Waugh 585f6b
   { "SMBConfigFile",		&SMBConfigFile,		CUPSD_VARTYPE_STRING },
Tim Waugh 585f6b
   { "StateDir",			&StateDir,		CUPSD_VARTYPE_STRING },
Tim Waugh 585f6b
+  { "SyncOnClose",		&SyncOnClose,		CUPSD_VARTYPE_BOOLEAN },
Tim Waugh 585f6b
 #ifdef HAVE_AUTHORIZATION_H
Tim Waugh 585f6b
   { "SystemGroupAuthKey",	&SystemGroupAuthKey,	CUPSD_VARTYPE_STRING },
Tim Waugh 585f6b
 #endif /* HAVE_AUTHORIZATION_H */
Tim Waugh 585f6b
@@ -734,6 +735,7 @@
Tim Waugh 585f6b
   ReloadTimeout	           = DEFAULT_KEEPALIVE;
Tim Waugh 585f6b
   RootCertDuration         = 300;
Tim Waugh 585f6b
   StrictConformance        = FALSE;
Tim Waugh 585f6b
+  SyncOnClose              = FALSE;
Tim Waugh 585f6b
   Timeout                  = DEFAULT_TIMEOUT;
Tim Waugh 585f6b
   WebInterface             = CUPS_DEFAULT_WEBIF;
Tim Waugh 585f6b
Tim Waugh 585f6b
Index: scheduler/conf.h
Tim Waugh 585f6b
===================================================================
Tim Waugh 585f6b
--- scheduler/conf.h	(revision 11192)
Tim Waugh 585f6b
+++ scheduler/conf.h	(working copy)
Tim Waugh 585f6b
@@ -172,6 +172,8 @@
Tim Waugh 585f6b
 					/* Which errors are fatal? */
Tim Waugh 585f6b
 			StrictConformance	VALUE(FALSE),
Tim Waugh 585f6b
 					/* Require strict IPP conformance? */
Tim Waugh 585f6b
+			SyncOnClose		VALUE(FALSE),
Tim Waugh 585f6b
+					/* Call fsync() when closing files? */
Tim Waugh 585f6b
 			LogFilePerm		VALUE(0644);
Tim Waugh 585f6b
 					/* Permissions for log files */
Tim Waugh 585f6b
 VAR cupsd_loglevel_t	LogLevel		VALUE(CUPSD_LOG_WARN);
Tim Waugh 585f6b
Index: scheduler/file.c
Tim Waugh 585f6b
===================================================================
Tim Waugh 585f6b
--- scheduler/file.c	(revision 11192)
Tim Waugh 585f6b
+++ scheduler/file.c	(working copy)
Tim Waugh 585f6b
@@ -109,6 +109,29 @@
Tim Waugh 585f6b
Tim Waugh 585f6b
Tim Waugh 585f6b
  /*
Tim Waugh 585f6b
+  * Synchronize changes to disk if SyncOnClose is enabled.
Tim Waugh 585f6b
+  */
Tim Waugh 585f6b
+
Tim Waugh 585f6b
+  if (SyncOnClose)
Tim Waugh 585f6b
+  {
Tim Waugh 585f6b
+    if (cupsFileFlush(fp))
Tim Waugh 585f6b
+    {
Tim Waugh 585f6b
+      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to write changes to \"%s\": %s",
Tim Waugh 585f6b
+		      filename, strerror(errno));
Tim Waugh 585f6b
+      cupsFileClose(fp);
Tim Waugh 585f6b
+      return (-1);
Tim Waugh 585f6b
+    }
Tim Waugh 585f6b
+
Tim Waugh 585f6b
+    if (fsync(cupsFileNumber(fp)))
Tim Waugh 585f6b
+    {
Tim Waugh 585f6b
+      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to sync changes to \"%s\": %s",
Tim Waugh 585f6b
+		      filename, strerror(errno));
Tim Waugh 585f6b
+      cupsFileClose(fp);
Tim Waugh 585f6b
+      return (-1);
Tim Waugh 585f6b
+    }
Tim Waugh 585f6b
+  }
Tim Waugh 585f6b
+
Tim Waugh 585f6b
+ /*
Tim Waugh 585f6b
   * First close the file...
Tim Waugh 585f6b
   */
Tim Waugh 585f6b