diff options
| author | dholland <dholland@NetBSD.org> | 2008-05-27 01:25:46 +0000 |
|---|---|---|
| committer | dholland <dholland@NetBSD.org> | 2008-05-27 01:25:46 +0000 |
| commit | 7edb76a2e69a3b1fe8e39e704c00ffb4ceff17ed (patch) | |
| tree | d3731bdcd7de13f77826d796b02062edac9d7841 /libexec | |
| parent | b63851a8b9d693d2e1803ed8c281b4334531d481 (diff) | |
Update whatis.db atomically, by dumping out into whatis.db.new and
renaming. PR 35619 from uwe@.
Diffstat (limited to 'libexec')
| -rw-r--r-- | libexec/makewhatis/makewhatis.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/libexec/makewhatis/makewhatis.c b/libexec/makewhatis/makewhatis.c index 0e4447d17a1..6e1dd00156b 100644 --- a/libexec/makewhatis/makewhatis.c +++ b/libexec/makewhatis/makewhatis.c @@ -1,4 +1,4 @@ -/* $NetBSD: makewhatis.c,v 1.41 2008/04/28 20:23:04 martin Exp $ */ +/* $NetBSD: makewhatis.c,v 1.42 2008/05/27 01:25:46 dholland Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #if !defined(lint) __COPYRIGHT("@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\n\ All rights reserved.\n"); -__RCSID("$NetBSD: makewhatis.c,v 1.41 2008/04/28 20:23:04 martin Exp $"); +__RCSID("$NetBSD: makewhatis.c,v 1.42 2008/05/27 01:25:46 dholland Exp $"); #endif /* not lint */ #include <sys/types.h> @@ -113,6 +113,7 @@ static char * const default_manpath[] = { static const char *sectionext = "0123456789ln"; static const char *whatisdb = _PATH_WHATIS; +static const char *whatisdb_new = _PATH_WHATIS ".new"; static int dowarn = 0; #define ISALPHA(c) isalpha((unsigned char)(c)) @@ -327,15 +328,19 @@ makewhatis(char * const * manpath) if (chdir(manpath[0]) == -1) err(EXIT_FAILURE, "Cannot change dir to `%s'", manpath[0]); - (void)unlink(whatisdb); - if ((out = fopen(whatisdb, "w")) == NULL) - err(EXIT_FAILURE, "Cannot open `%s'", whatisdb); + (void)unlink(whatisdb_new); + if ((out = fopen(whatisdb_new, "w")) == NULL) + err(EXIT_FAILURE, "fdopen"); dumpwhatis(out, dest); if (fchmod(fileno(out), S_IRUSR|S_IRGRP|S_IROTH) == -1) - err(EXIT_FAILURE, "Cannot chmod `%s'", whatisdb); + err(EXIT_FAILURE, "Cannot chmod `%s'", whatisdb_new); if (fclose(out) != 0) - err(EXIT_FAILURE, "Cannot close `%s'", whatisdb); + err(EXIT_FAILURE, "Cannot close `%s'", whatisdb_new); + + if (rename(whatisdb_new, whatisdb) == -1) + err(EXIT_FAILURE, "Could not rename `%s' to `%s'", + whatisdb_new, whatisdb); return EXIT_SUCCESS; } |
