+void
+debug_rename(
+ char *config,
+ char *subdir)
+{
+ int fd = -1;
+ int i;
+ char *s = NULL;
+ mode_t mask;
+
+ if (!db_filename)
+ return;
+
+ /*
+ * Do initial setup.
+ */
+ debug_setup_1(config, subdir);
+
+ s = newvstralloc(s, dbgdir, db_name, NULL);
+
+ if (strcmp(db_filename, s) == 0) {
+ amfree(s);
+ return;
+ }
+
+ mask = (mode_t)umask((mode_t)0037);
+ /* check if a file with the same name already exist */
+ if ((fd = open(s, O_WRONLY|O_CREAT|O_EXCL|O_APPEND, 0640)) < 0) {
+ for(i = 0; fd < 0; i++) {
+ amfree(db_name);
+ if ((db_name = get_debug_name(curtime, i)) == NULL) {
+ dbprintf(("Cannot create %s debug file", get_pname()));
+ break;
+ }
+
+ s = newvstralloc(s, dbgdir, db_name, NULL);
+ if ((fd = open(s, O_WRONLY|O_CREAT|O_EXCL|O_APPEND, 0640)) < 0) {
+ if (errno != EEXIST) {
+ dbprintf(("Cannot create %s debug file: %s", get_pname(),
+ strerror(errno)));
+ break;
+ }
+ }
+ }
+ }
+
+ if (fd >= 0) {
+ rename(db_filename, s);
+ }
+ (void)umask(mask); /* Restore mask */
+ close(fd);
+ /*
+ * Finish setup.
+ *
+ * Note: we release control of the string 's' points to.
+ */
+ debug_setup_2(s, -1, "rename");
+}
+
+void
+debug_close(void)