return 1;
}
-/*
- * Update the "ok" file.
- */
-void update_ok_file (file_name)
- char *file_name;
+
+/* Create the .dump_ok file. */
+static int
+prep_ok_file(krb5_context context, char *file_name, int *fd)
{
- /* handle slave locking/failure stuff */
- char *file_ok;
- int fd;
static char ok[]=".dump_ok";
+ krb5_error_code retval;
+ char *file_ok;
if (asprintf(&file_ok, "%s%s", file_name, ok) < 0) {
- com_err(progname, ENOMEM,
- _("while allocating filename for update_ok_file"));
+ com_err(progname, ENOMEM, _("while allocating dump_ok filename"));
exit_status++;
- return;
+ return 0;
}
- if ((fd = open(file_ok, O_WRONLY|O_CREAT|O_TRUNC, 0600)) < 0) {
- com_err(progname, errno, _("while creating 'ok' file, '%s'"),
- file_ok);
+
+ *fd = open(file_ok, O_WRONLY | O_CREAT | O_TRUNC, 0600);
+ if (*fd == -1) {
+ com_err(progname, errno, _("while creating 'ok' file, '%s'"), file_ok);
exit_status++;
free(file_ok);
- return;
+ return 0;
}
- if (write(fd, "", 1) != 1) {
- com_err(progname, errno, _("while writing to 'ok' file, '%s'"),
- file_ok);
- exit_status++;
- free(file_ok);
- return;
+ retval = krb5_lock_file(context, *fd, KRB5_LOCKMODE_EXCLUSIVE);
+ if (retval) {
+ com_err(progname, retval, _("while locking 'ok' file, '%s'"), file_ok);
+ return 0;
}
+ return 1;
+}
- free(file_ok);
+/*
+ * Update the "ok" file.
+ */
+static void
+update_ok_file(krb5_context context, int fd)
+{
+ write(fd, "", 1);
+ krb5_lock_file(context, fd, KRB5_LOCKMODE_UNLOCK);
close(fd);
- return;
}
/*
dump_version *dump;
int aindex;
int conditional = 0;
+ int ok_fd = -1;
char *new_mkey_file = 0;
bool_t dump_sno = FALSE;
kdb_log_context *log_ctx;
*/
if (ofile[0] == '-')
usage();
+ if (!prep_ok_file(util_context, ofile, &ok_fd))
+ return; /* prep_ok_file() bumps exit_status */
f = create_ofile(ofile, &tmpofile);
if (f == NULL) {
fprintf(stderr, ofopen_error,
progname, ofile, error_message(errno));
- return;
+ goto error;
}
} else {
f = stdout;
if (ofile && f != stdout) {
fclose(f);
finish_ofile(ofile, &tmpofile);
- update_ok_file(ofile);
+ update_ok_file(util_context, ok_fd);
}
return;
}
exit_status++;
return;
}
- if ((kret = krb5_lock_file(kcontext, fileno(f),
- KRB5_LOCKMODE_SHARED))) {
- fprintf(stderr, _("%s: Cannot lock %s: %s\n"), progname,
- dumpfile, error_message(errno));
- exit_status++;
- return;
- }
} else
f = stdin;