diff options
author | Federico G. Schwindt <fgsch@cvs.openbsd.org> | 2002-03-27 02:19:58 +0000 |
---|---|---|
committer | Federico G. Schwindt <fgsch@cvs.openbsd.org> | 2002-03-27 02:19:58 +0000 |
commit | 88e4952ed13a3c75a7f6cbaafc0ccde952474646 (patch) | |
tree | 7f24fec7728a2efc9624c8f30c5873a149e33a64 /usr.sbin | |
parent | 3666c06ca267606a11141438c8eb67a444502809 (diff) |
instead of using mkstemp() to get a temporary name, use the created file,
so we don't end with ypdbXXXXXX files around; maja@ ok.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ypserv/mkalias/mkalias.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/usr.sbin/ypserv/mkalias/mkalias.c b/usr.sbin/ypserv/mkalias/mkalias.c index d3135d532dd..408a1917822 100644 --- a/usr.sbin/ypserv/mkalias/mkalias.c +++ b/usr.sbin/ypserv/mkalias/mkalias.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mkalias.c,v 1.7 2001/11/19 09:01:28 deraadt Exp $ */ +/* $OpenBSD: mkalias.c,v 1.8 2002/03/27 02:19:57 fgsch Exp $ */ /* * Copyright (c) 1997 Mats O Jansson <moj@stacken.kth.se> @@ -32,7 +32,7 @@ */ #ifndef LINT -static char rcsid[] = "$OpenBSD: mkalias.c,v 1.7 2001/11/19 09:01:28 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: mkalias.c,v 1.8 2002/03/27 02:19:57 fgsch Exp $"; #endif #include <ctype.h> @@ -248,16 +248,17 @@ main(argc, argv) exit(1); } - snprintf(db_tempname, sizeof(db_tempname), "%s%s", output, - mapname); - fd = mkstemp(db_tempname); + snprintf(db_tempname, sizeof(db_tempname), "%s%s%s", output, + mapname, YPDB_SUFFIX); + fd = mkstemps(db_tempname, 3); if (fd == -1) goto fail; close(fd); - snprintf(db_mapname, sizeof(db_mapname), "%s%s", db_tempname, - YPDB_SUFFIX); - new_db = ypdb_open(db_tempname, O_RDWR|O_CREAT, 0444); + strncpy(db_mapname, db_tempname, strlen(db_tempname) - 3); + db_mapname[sizeof(db_mapname) - 1] = '\0'; + + new_db = ypdb_open(db_mapname, O_RDWR|O_TRUNC, 0444); if (new_db == NULL) { fail: if (fd != -1) @@ -355,10 +356,10 @@ fail: if (new_db != NULL) { ypdb_close(new_db); - if (rename(db_mapname, db_outfile) < 0) { + if (rename(db_tempname, db_outfile) < 0) { perror("rename"); - fprintf(stderr,"rename %s -> %s failed!\n", db_mapname, - db_outfile); + fprintf(stderr,"rename %s -> %s failed!\n", + db_tempname, db_outfile); exit(1); } } |