6
6
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
7
7
* Portions Copyright (c) 1994, Regents of the University of California
8
8
*
9
- * $Id: user.c,v 1.52 2000/04/12 17:14:59 momjian Exp $
9
+ * $Id: user.c,v 1.53 2000/05/04 20:06:07 tgl Exp $
10
10
*
11
11
*-------------------------------------------------------------------------
12
12
*/
@@ -56,6 +56,7 @@ write_password_file(Relation rel)
56
56
* tempname ;
57
57
int bufsize ;
58
58
FILE * fp ;
59
+ int flagfd ;
59
60
mode_t oumask ;
60
61
HeapScanDesc scan ;
61
62
HeapTuple tuple ;
@@ -75,7 +76,7 @@ write_password_file(Relation rel)
75
76
fp = AllocateFile (tempname ,"w" );
76
77
umask (oumask );
77
78
if (fp == NULL )
78
- elog (ERROR ,"%s: %s " ,tempname , strerror ( errno ) );
79
+ elog (ERROR ,"%s: %m " ,tempname );
79
80
80
81
/* read table */
81
82
scan = heap_beginscan (rel , false,SnapshotSelf ,0 ,NULL );
@@ -129,29 +130,38 @@ write_password_file(Relation rel)
129
130
null_v ?"\\N" :nabstimeout ((AbsoluteTime )datum_v )/* this is how the
130
131
* parser wants it */
131
132
);
132
- if (ferror (fp ))
133
- elog (ERROR ,"%s: %s" ,tempname ,strerror (errno ));
134
- fflush (fp );
135
133
}
136
134
heap_endscan (scan );
135
+
136
+ fflush (fp );
137
+ if (ferror (fp ))
138
+ elog (ERROR ,"%s: %m" ,tempname );
137
139
FreeFile (fp );
138
140
139
141
/*
140
142
* And rename the temp file to its final name, deleting the old
141
143
* pg_pwd.
142
144
*/
143
- rename (tempname ,filename );
145
+ if (rename (tempname ,filename ))
146
+ elog (ERROR ,"rename %s to %s: %m" ,tempname ,filename );
147
+
148
+ pfree ((void * )tempname );
149
+ pfree ((void * )filename );
144
150
145
151
/*
146
152
* Create a flag file the postmaster will detect the next time it
147
153
* tries to authenticate a user. The postmaster will know to reload
148
- * the pg_pwd file contents.
154
+ * the pg_pwd file contents. Note: we used to elog(ERROR) if the
155
+ * creat() call failed, but it's a little silly to abort the transaction
156
+ * at this point, so let's just make it a NOTICE.
149
157
*/
150
158
filename = crypt_getpwdreloadfilename ();
151
- if (creat (filename ,S_IRUSR |S_IWUSR )== -1 )
152
- elog (ERROR ,"%s: %s" ,filename ,strerror (errno ));
153
-
154
- pfree ((void * )tempname );
159
+ flagfd = creat (filename ,S_IRUSR |S_IWUSR );
160
+ if (flagfd == -1 )
161
+ elog (NOTICE ,"%s: %m" ,filename );
162
+ else
163
+ close (flagfd );
164
+ pfree ((void * )filename );
155
165
}
156
166
157
167