From: msweet Date: Fri, 26 Jul 2013 21:27:27 +0000 (+0000) Subject: Added a SyncOnClose directive to cups-files.conf to force cupsd to call fsync X-Git-Tag: release-1.7.0~21 X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fcups.git;a=commitdiff_plain;h=8a2596692595a893119a1637fd93e729f81fec66 Added a SyncOnClose directive to cups-files.conf to force cupsd to call fsync before closing any configuration/state files it writes () git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@11201 a1ca3aef-8c08-0410-bb20-df032aa958be --- diff --git a/CHANGES-1.6.txt b/CHANGES-1.6.txt index 76ac07ec8..5e2b8c087 100644 --- a/CHANGES-1.6.txt +++ b/CHANGES-1.6.txt @@ -3,6 +3,9 @@ CHANGES-1.6.txt CHANGES IN CUPS V1.6.4 + - Added a SyncOnClose directive to cups-files.conf to force cupsd to + call fsync before closing any configuration/state files it writes + () - Added USB quirk rule for Lexmark E238 () - Closed server connections were still not always detected () diff --git a/conf/cups-files.conf.in b/conf/cups-files.conf.in index 123812cf8..36afecc40 100644 --- a/conf/cups-files.conf.in +++ b/conf/cups-files.conf.in @@ -8,6 +8,9 @@ # List of events that are considered fatal errors for the scheduler... #FatalErrors @CUPS_FATAL_ERRORS@ +# Do we call fsync() after writing configuration or status files? +#SyncOnClose No + # Default user and group for filters/backends/helper programs; this cannot be # any user or group that resolves to ID 0 for security reasons... #User @CUPS_USER@ diff --git a/doc/help/ref-cups-files-conf.html.in b/doc/help/ref-cups-files-conf.html.in index 171950c54..70c996f4a 100644 --- a/doc/help/ref-cups-files-conf.html.in +++ b/doc/help/ref-cups-files-conf.html.in @@ -429,6 +429,31 @@ to resolve relative paths in the cupsd.conf file. The default server directory is /etc/cups.

+

CUPS 1.6.4SyncOnClose

+ +

Examples

+ +
+SyncOnClose No
+SyncOnClose Yes
+
+ +

Description

+ +

The SyncOnClose directive determines whether the scheduler +flushes changes to configuration and state files to disk. The default is +No which relies on the operating system to schedule a suitable +time to write changes to disk.

+ +
Note: + +

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.

+ +

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

+ +
+ +

SystemGroup

Examples

diff --git a/man/cups-files.conf.man.in b/man/cups-files.conf.man.in index 294dc0b33..c17490cf1 100644 --- a/man/cups-files.conf.man.in +++ b/man/cups-files.conf.man.in @@ -12,7 +12,7 @@ .\" which should have been included with this file. If this file is .\" file is missing or damaged, see the license at "http://www.cups.org/". .\" -.TH cups-files.conf 5 "CUPS" "8 July 2013" "Apple Inc." +.TH cups-files.conf 5 "CUPS" "26 July 2013" "Apple Inc." .SH NAME cups-files.conf \- file and directory configuration file for cups .SH DESCRIPTION @@ -122,6 +122,12 @@ ServerRoot directory .br Specifies the directory where the server configuration files can be found. .TP 5 +SyncOnClose Yes +.TP 5 +SyncOnClose No +Specifies whether the scheduler calls \fIfsync(2)\fR after writing configuration +or state files. The default is No. +.TP 5 SystemGroup group-name [group-name ...] .br Specifies the group(s) to use for System class authentication. diff --git a/scheduler/conf.c b/scheduler/conf.c index b81211935..fd1c0c027 100644 --- a/scheduler/conf.c +++ b/scheduler/conf.c @@ -3,7 +3,7 @@ * * Configuration routines for the CUPS scheduler. * - * Copyright 2007-2012 by Apple Inc. + * Copyright 2007-2013 by Apple Inc. * Copyright 1997-2007 by Easy Software Products, all rights reserved. * * These coded instructions, statements, and computer programs are the @@ -174,6 +174,7 @@ static const cupsd_var_t cupsfiles_vars[] = { "ServerRoot", &ServerRoot, CUPSD_VARTYPE_PATHNAME }, { "SMBConfigFile", &SMBConfigFile, CUPSD_VARTYPE_STRING }, { "StateDir", &StateDir, CUPSD_VARTYPE_STRING }, + { "SyncOnClose", &SyncOnClose, CUPSD_VARTYPE_BOOLEAN }, #ifdef HAVE_AUTHORIZATION_H { "SystemGroupAuthKey", &SystemGroupAuthKey, CUPSD_VARTYPE_STRING }, #endif /* HAVE_AUTHORIZATION_H */ @@ -734,6 +735,7 @@ cupsdReadConfiguration(void) ReloadTimeout = DEFAULT_KEEPALIVE; RootCertDuration = 300; StrictConformance = FALSE; + SyncOnClose = FALSE; Timeout = DEFAULT_TIMEOUT; WebInterface = CUPS_DEFAULT_WEBIF; diff --git a/scheduler/conf.h b/scheduler/conf.h index e095ecfaa..23a93d6ef 100644 --- a/scheduler/conf.h +++ b/scheduler/conf.h @@ -3,7 +3,7 @@ * * Configuration file definitions for the CUPS scheduler. * - * Copyright 2007-2012 by Apple Inc. + * Copyright 2007-2013 by Apple Inc. * Copyright 1997-2007 by Easy Software Products, all rights reserved. * * These coded instructions, statements, and computer programs are the @@ -172,6 +172,8 @@ VAR int ClassifyOverride VALUE(0), /* Which errors are fatal? */ StrictConformance VALUE(FALSE), /* Require strict IPP conformance? */ + SyncOnClosee VALUE(FALSE), + /* Call fsync() when closing files? */ LogFilePerm VALUE(0644); /* Permissions for log files */ VAR cupsd_loglevel_t LogLevel VALUE(CUPSD_LOG_WARN); diff --git a/scheduler/file.c b/scheduler/file.c index ca5aa5e2c..0d236c918 100644 --- a/scheduler/file.c +++ b/scheduler/file.c @@ -108,6 +108,29 @@ cupsdCloseCreatedConfFile( oldfile[1024]; /* filename.O */ + /* + * Synchronize changes to disk if SyncOnClose is enabled. + */ + + if (SyncOnClose) + { + if (cupsFileFlush(fp)) + { + cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to write changes to \"%s\": %s", + filename, strerror(errno)); + cupsFileClose(fp); + return (-1); + } + + if (fsync(cupsFileNumber(fp))) + { + cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to sync changes to \"%s\": %s", + filename, strerror(errno)); + cupsFileClose(fp); + return (-1); + } + } + /* * First close the file... */