- if((old_fd2 = dup(2)) < 0) {
- error("cannot dup2 fd2");
- }
- close(2);
- if((new_fd2 = open(dbname, O_RDWR|O_APPEND, 0600)) != 2) {
- int save_errno = errno;
- FILE *f;
-
- if((f = fdopen(old_fd2, "a")) == NULL) {
- /* give up */
- return 3;
- }
- fprintf(f, "%s: cannot open %s: ", get_pname(), dbname);
- if(new_fd2 < 0) {
- fputs(strerror(save_errno), f);
- } else {
- fprintf(f, "got %d instead of 2", new_fd2);
- }
- fputc('\n', f);
- fclose(f);
- }
- /*
- * Because we have not called dbopen(), dbclose() will write the
- * end line to stderr, which we just redirected to the file on
- * the command line.
- */