MCPcopy Create free account
hub / github.com/OpenPrinting/cups / cupsdCloseCreatedConfFile

Function cupsdCloseCreatedConfFile

scheduler/file.c:89–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87 */
88
89int /* O - 0 on success, -1 on error */
90cupsdCloseCreatedConfFile(
91 cups_file_t *fp, /* I - File to close */
92 const char *filename) /* I - Filename */
93{
94 char newfile[1024], /* filename.N */
95 oldfile[1024]; /* filename.O */
96
97
98 /*
99 * Synchronize changes to disk if SyncOnClose is enabled.
100 */
101
102 if (SyncOnClose)
103 {
104 if (cupsFileFlush(fp))
105 {
106 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to write changes to \"%s\": %s",
107 filename, strerror(errno));
108 cupsFileClose(fp);
109 return (-1);
110 }
111
112 if (fsync(cupsFileNumber(fp)))
113 {
114 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to sync changes to \"%s\": %s",
115 filename, strerror(errno));
116 cupsFileClose(fp);
117 return (-1);
118 }
119 }
120
121 /*
122 * First close the file...
123 */
124
125 if (cupsFileClose(fp))
126 return (-1);
127
128 /*
129 * Then remove "filename.O", rename "filename" to "filename.O", and rename
130 * "filename.N" to "filename".
131 */
132
133 snprintf(newfile, sizeof(newfile), "%s.N", filename);
134 snprintf(oldfile, sizeof(oldfile), "%s.O", filename);
135
136 if ((cupsdUnlinkOrRemoveFile(oldfile) && errno != ENOENT) ||
137 (rename(filename, oldfile) && errno != ENOENT) ||
138 rename(newfile, filename))
139 {
140 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to finalize \"%s\": %s",
141 filename, strerror(errno));
142 return (-1);
143 }
144
145 return (0);
146}

Callers 10

install_cupsd_confFunction · 0.85
copy_fileFunction · 0.85
copy_modelFunction · 0.85
create_local_bg_threadFunction · 0.85
cupsdSaveAllJobsFunction · 0.85
cupsdSaveJobFunction · 0.85
cupsdSaveAllClassesFunction · 0.85
cupsdSaveAllPrintersFunction · 0.85
cupsdUpdatePrinterPPDFunction · 0.85

Calls 5

cupsFileFlushFunction · 0.85
cupsdLogMessageFunction · 0.85
cupsFileCloseFunction · 0.85
cupsFileNumberFunction · 0.85
cupsdUnlinkOrRemoveFileFunction · 0.85

Tested by

no test coverage detected