diff options
Diffstat (limited to 'lib/commonio.c')
-rw-r--r-- | lib/commonio.c | 68 |
1 files changed, 23 insertions, 45 deletions
diff --git a/lib/commonio.c b/lib/commonio.c index cef404b9..9e0fde60 100644 --- a/lib/commonio.c +++ b/lib/commonio.c @@ -1,33 +1,10 @@ /* - * Copyright (c) 1990 - 1994, Julianne Frances Haugh - * Copyright (c) 1996 - 2001, Marek Michałkiewicz - * Copyright (c) 2001 - 2006, Tomasz Kłoczko - * Copyright (c) 2007 - 2011, Nicolas François - * All rights reserved. + * SPDX-FileCopyrightText: 1990 - 1994, Julianne Frances Haugh + * SPDX-FileCopyrightText: 1996 - 2001, Marek Michałkiewicz + * SPDX-FileCopyrightText: 2001 - 2006, Tomasz Kłoczko + * SPDX-FileCopyrightText: 2007 - 2011, Nicolas François * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the copyright holders or contributors may not be used to - * endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * SPDX-License-Identifier: BSD-3-Clause */ #include <config.h> @@ -51,6 +28,7 @@ #endif /* WITH_TCB */ #include "prototypes.h" #include "commonio.h" +#include "shadowlog_internal.h" /* local function prototypes */ static int lrename (const char *, const char *); @@ -146,7 +124,7 @@ static int do_lock_file (const char *file, const char *lock, bool log) if (log) { (void) fprintf (shadow_logfd, "%s: %s: %s\n", - Prog, file, strerror (errno)); + shadow_progname, file, strerror (errno)); } return 0; } @@ -158,7 +136,7 @@ static int do_lock_file (const char *file, const char *lock, bool log) if (log) { (void) fprintf (shadow_logfd, "%s: %s file write error: %s\n", - Prog, file, strerror (errno)); + shadow_progname, file, strerror (errno)); } (void) close (fd); unlink (file); @@ -168,7 +146,7 @@ static int do_lock_file (const char *file, const char *lock, bool log) if (log) { (void) fprintf (shadow_logfd, "%s: %s file sync error: %s\n", - Prog, file, strerror (errno)); + shadow_progname, file, strerror (errno)); } (void) close (fd); unlink (file); @@ -181,7 +159,7 @@ static int do_lock_file (const char *file, const char *lock, bool log) if ((0==retval) && log) { (void) fprintf (shadow_logfd, "%s: %s: lock file already used\n", - Prog, file); + shadow_progname, file); } unlink (file); return retval; @@ -192,7 +170,7 @@ static int do_lock_file (const char *file, const char *lock, bool log) if (log) { (void) fprintf (shadow_logfd, "%s: %s: %s\n", - Prog, lock, strerror (errno)); + shadow_progname, lock, strerror (errno)); } unlink (file); errno = EINVAL; @@ -204,7 +182,7 @@ static int do_lock_file (const char *file, const char *lock, bool log) if (log) { (void) fprintf (shadow_logfd, "%s: existing lock file %s without a PID\n", - Prog, lock); + shadow_progname, lock); } unlink (file); errno = EINVAL; @@ -215,7 +193,7 @@ static int do_lock_file (const char *file, const char *lock, bool log) if (log) { (void) fprintf (shadow_logfd, "%s: existing lock file %s with an invalid PID '%s'\n", - Prog, lock, buf); + shadow_progname, lock, buf); } unlink (file); errno = EINVAL; @@ -225,7 +203,7 @@ static int do_lock_file (const char *file, const char *lock, bool log) if (log) { (void) fprintf (shadow_logfd, "%s: lock %s already used by PID %lu\n", - Prog, lock, (unsigned long) pid); + shadow_progname, lock, (unsigned long) pid); } unlink (file); errno = EEXIST; @@ -235,7 +213,7 @@ static int do_lock_file (const char *file, const char *lock, bool log) if (log) { (void) fprintf (shadow_logfd, "%s: cannot get lock %s: %s\n", - Prog, lock, strerror (errno)); + shadow_progname, lock, strerror (errno)); } unlink (file); return 0; @@ -247,13 +225,13 @@ static int do_lock_file (const char *file, const char *lock, bool log) if ((0==retval) && log) { (void) fprintf (shadow_logfd, "%s: %s: lock file already used\n", - Prog, file); + shadow_progname, file); } } else { if (log) { (void) fprintf (shadow_logfd, "%s: cannot get lock %s: %s\n", - Prog, lock, strerror (errno)); + shadow_progname, lock, strerror (errno)); } } @@ -403,11 +381,11 @@ int commonio_lock_nowait (struct commonio_db *db, bool log) file_len = strlen(db->filename) + 11;/* %lu max size */ lock_file_len = strlen(db->filename) + 6; /* sizeof ".lock" */ file = (char*)malloc(file_len); - if(file == NULL) { + if (file == NULL) { goto cleanup_ENOMEM; } lock = (char*)malloc(lock_file_len); - if(lock == NULL) { + if (lock == NULL) { goto cleanup_ENOMEM; } snprintf (file, file_len, "%s.%lu", @@ -419,9 +397,9 @@ int commonio_lock_nowait (struct commonio_db *db, bool log) err = 1; } cleanup_ENOMEM: - if(file) + if (file) free(file); - if(lock) + if (lock) free(lock); return err; } @@ -448,7 +426,7 @@ int commonio_lock (struct commonio_db *db) if (geteuid () != 0) { (void) fprintf (shadow_logfd, "%s: Permission denied.\n", - Prog); + shadow_progname); } return 0; /* failure */ } @@ -483,7 +461,7 @@ int commonio_lock (struct commonio_db *db) /* no unnecessary retries on "permission denied" errors */ if (geteuid () != 0) { (void) fprintf (shadow_logfd, "%s: Permission denied.\n", - Prog); + shadow_progname); return 0; } } |