Commit 5d98cf67 authored by Mark Andrews's avatar Mark Andrews
Browse files

white space cleanup

parent 454c78d0
......@@ -15,12 +15,12 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: os.c,v 1.59 2002/07/03 05:09:43 marka Exp $ */
/* $Id: os.c,v 1.60 2002/07/10 01:13:42 marka Exp $ */
#include <config.h>
#include <stdarg.h>
#include <sys/types.h> /* dev_t FreeBSD 2.1 */
#include <sys/types.h> /* dev_t FreeBSD 2.1 */
#include <sys/stat.h>
#include <ctype.h>
......@@ -58,36 +58,36 @@ static char *pidfile = NULL;
/*
* Linux defines:
* (T) HAVE_LINUXTHREADS
* (C) HAVE_LINUX_CAPABILITY_H
* (P) HAVE_SYS_PRCTL_H
* (T) HAVE_LINUXTHREADS
* (C) HAVE_LINUX_CAPABILITY_H
* (P) HAVE_SYS_PRCTL_H
* The possible cases are:
* none: setuid() normally
* T: no setuid()
* C: setuid() normally, drop caps (keep CAP_SETUID)
* T+C: no setuid(), drop caps (don't keep CAP_SETUID)
* T+C+P: setuid() early, drop caps (keep CAP_SETUID)
* C+P: setuid() normally, drop caps (keep CAP_SETUID)
* none: setuid() normally
* T: no setuid()
* C: setuid() normally, drop caps (keep CAP_SETUID)
* T+C: no setuid(), drop caps (don't keep CAP_SETUID)
* T+C+P: setuid() early, drop caps (keep CAP_SETUID)
* C+P: setuid() normally, drop caps (keep CAP_SETUID)
* P: not possible
* T+P: not possible
*
* if (C)
* caps = BIND_SERVICE + CHROOT + SETGID
* if ((T && C && P) || !T)
* caps += SETUID
* endif
* capset(caps)
* caps = BIND_SERVICE + CHROOT + SETGID
* if ((T && C && P) || !T)
* caps += SETUID
* endif
* capset(caps)
* endif
* if (T && C && P && -u)
* setuid()
* setuid()
* else if (T && -u)
* fail
* fail
* --> start threads
* if (!T && -u)
* setuid()
* setuid()
* if (C && (P || !-u))
* caps = BIND_SERVICE
* capset(caps)
* caps = BIND_SERVICE
* capset(caps)
* endif
*
* It will be nice when Linux threads work properly with setuid().
......@@ -311,7 +311,7 @@ ns_os_daemonize(void) {
mainpid = getpid();
#endif
if (setsid() == -1) {
if (setsid() == -1) {
isc__strerror(errno, strbuf, sizeof(strbuf));
ns_main_earlyfatal("setsid(): %s", strbuf);
}
......@@ -442,23 +442,23 @@ ns_os_minprivs(void) {
static int
safe_open(const char *filename, isc_boolean_t append) {
int fd;
struct stat sb;
struct stat sb;
if (stat(filename, &sb) == -1) {
if (errno != ENOENT)
if (stat(filename, &sb) == -1) {
if (errno != ENOENT)
return (-1);
} else if ((sb.st_mode & S_IFREG) == 0) {
} else if ((sb.st_mode & S_IFREG) == 0) {
errno = EOPNOTSUPP;
return (-1);
}
if (append)
fd = open(filename, O_WRONLY|O_CREAT|O_APPEND,
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
else {
(void)unlink(filename);
fd = open(filename, O_WRONLY|O_CREAT|O_EXCL,
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
}
return (fd);
}
......@@ -474,7 +474,7 @@ cleanup_pidfile(void) {
void
ns_os_writepidfile(const char *filename, isc_boolean_t first_time) {
int fd;
int fd;
FILE *lockfile;
size_t len;
pid_t pid;
......@@ -496,22 +496,22 @@ ns_os_writepidfile(const char *filename, isc_boolean_t first_time) {
pidfile = malloc(len + 1);
if (pidfile == NULL) {
isc__strerror(errno, strbuf, sizeof(strbuf));
(*report)("couldn't malloc '%s': %s", filename, strbuf);
(*report)("couldn't malloc '%s': %s", filename, strbuf);
return;
}
/* This is safe. */
strcpy(pidfile, filename);
fd = safe_open(filename, ISC_FALSE);
if (fd < 0) {
fd = safe_open(filename, ISC_FALSE);
if (fd < 0) {
isc__strerror(errno, strbuf, sizeof(strbuf));
(*report)("couldn't open pid file '%s': %s", filename, strbuf);
(*report)("couldn't open pid file '%s': %s", filename, strbuf);
free(pidfile);
pidfile = NULL;
return;
}
lockfile = fdopen(fd, "w");
if (lockfile == NULL) {
lockfile = fdopen(fd, "w");
if (lockfile == NULL) {
isc__strerror(errno, strbuf, sizeof(strbuf));
(*report)("could not fdopen() pid file '%s': %s",
filename, strbuf);
......@@ -524,14 +524,14 @@ ns_os_writepidfile(const char *filename, isc_boolean_t first_time) {
#else
pid = getpid();
#endif
if (fprintf(lockfile, "%ld\n", (long)pid) < 0) {
(*report)("fprintf() to pid file '%s' failed", filename);
if (fprintf(lockfile, "%ld\n", (long)pid) < 0) {
(*report)("fprintf() to pid file '%s' failed", filename);
(void)fclose(lockfile);
cleanup_pidfile();
return;
}
if (fflush(lockfile) == EOF) {
(*report)("fflush() to pid file '%s' failed", filename);
if (fflush(lockfile) == EOF) {
(*report)("fflush() to pid file '%s' failed", filename);
(void)fclose(lockfile);
cleanup_pidfile();
return;
......@@ -547,7 +547,7 @@ ns_os_shutdown(void) {
isc_result_t
ns_os_gethostname(char *buf, size_t len) {
int n;
int n;
n = gethostname(buf, len);
return ((n == 0) ? ISC_R_SUCCESS : ISC_R_FAILURE);
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: os.c,v 1.14 2002/05/03 05:28:27 marka Exp $ */
/* $Id: os.c,v 1.15 2002/07/10 01:13:44 marka Exp $ */
#include <config.h>
#include <stdarg.h>
......@@ -131,21 +131,21 @@ ns_os_minprivs(void) {
static int
safe_open(const char *filename, isc_boolean_t append) {
int fd;
struct stat sb;
struct stat sb;
if (stat(filename, &sb) == -1) {
if (errno != ENOENT)
if (stat(filename, &sb) == -1) {
if (errno != ENOENT)
return (-1);
} else if ((sb.st_mode & S_IFREG) == 0)
} else if ((sb.st_mode & S_IFREG) == 0)
return (-1);
if (append)
fd = open(filename, O_WRONLY|O_CREAT|O_APPEND,
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
else {
(void)unlink(filename);
fd = open(filename, O_WRONLY|O_CREAT|O_EXCL,
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
}
return (fd);
}
......@@ -161,7 +161,7 @@ cleanup_pidfile(void) {
void
ns_os_writepidfile(const char *filename, isc_boolean_t first_time) {
int fd;
int fd;
FILE *lockfile;
size_t len;
pid_t pid;
......@@ -182,22 +182,22 @@ ns_os_writepidfile(const char *filename, isc_boolean_t first_time) {
pidfile = malloc(len + 1);
if (pidfile == NULL) {
isc__strerror(errno, strbuf, sizeof(strbuf));
(*report)("couldn't malloc '%s': %s", filename, strbuf);
(*report)("couldn't malloc '%s': %s", filename, strbuf);
return;
}
/* This is safe. */
strcpy(pidfile, filename);
fd = safe_open(filename, ISC_FALSE);
if (fd < 0) {
fd = safe_open(filename, ISC_FALSE);
if (fd < 0) {
isc__strerror(errno, strbuf, sizeof(strbuf));
(*report)("couldn't open pid file '%s': %s", filename, strbuf);
(*report)("couldn't open pid file '%s': %s", filename, strbuf);
free(pidfile);
pidfile = NULL;
return;
}
lockfile = fdopen(fd, "w");
if (lockfile == NULL) {
lockfile = fdopen(fd, "w");
if (lockfile == NULL) {
isc__strerror(errno, strbuf, sizeof(strbuf));
(*report)("could not fdopen() pid file '%s': %s",
filename, strbuf);
......@@ -208,14 +208,14 @@ ns_os_writepidfile(const char *filename, isc_boolean_t first_time) {
pid = getpid();
if (fprintf(lockfile, "%ld\n", (long)pid) < 0) {
(*report)("fprintf() to pid file '%s' failed", filename);
if (fprintf(lockfile, "%ld\n", (long)pid) < 0) {
(*report)("fprintf() to pid file '%s' failed", filename);
(void)fclose(fd);
cleanup_pidfile();
return;
}
if (fflush(lockfile) == EOF) {
(*report)("fflush() to pid file '%s' failed", filename);
if (fflush(lockfile) == EOF) {
(*report)("fflush() to pid file '%s' failed", filename);
(void)fclose(fd);
cleanup_pidfile();
return;
......@@ -232,7 +232,7 @@ ns_os_shutdown(void) {
isc_result_t
ns_os_gethostname(char *buf, size_t len) {
int n;
int n;
n = gethostname(buf, len);
return ((n == 0) ? ISC_R_SUCCESS : ISC_R_FAILURE);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment