/*
* Linux defines:
- * (T) HAVE_LINUXTHREADS
* (C) HAVE_SYS_CAPABILITY_H
* (P) HAVE_SYS_PRCTL_H
* The possible cases are:
* It will be nice when Linux threads work properly with setuid().
*/
-#ifdef HAVE_LINUXTHREADS
-static pid_t mainpid = 0;
-#endif
-
static struct passwd *runas_pw = NULL;
static bool done_setuid = false;
static int dfd[2] = { -1, -1 };
*/
SET_CAP(CAP_SYS_CHROOT);
-#if defined(HAVE_SYS_PRCTL_H) || !defined(HAVE_LINUXTHREADS)
+#if defined(HAVE_SYS_PRCTL_H)
/*
* We can setuid() only if either the kernel supports keeping
* capabilities after setuid() (which we don't know until we've
#ifdef HAVE_SYS_CAPABILITY_H
linux_initialprivs();
#endif
-#ifdef HAVE_LINUXTHREADS
- mainpid = getpid();
-#endif
#ifdef SIGXFSZ
signal(SIGXFSZ, SIG_IGN);
#endif
* We're the child.
*/
-#ifdef HAVE_LINUXTHREADS
- mainpid = getpid();
-#endif
-
if (setsid() == -1) {
strerror_r(errno, strbuf, sizeof(strbuf));
named_main_earlyfatal("setsid(): %s", strbuf);
done_setuid = true;
-#ifdef HAVE_LINUXTHREADS
-#ifdef HAVE_SYS_CAPABILITY_H
- if (!non_root_caps) {
- named_main_earlyfatal("-u with Linux threads not supported: "
- "requires kernel support for "
- "prctl(PR_SET_KEEPCAPS)");
- }
-#else
- named_main_earlyfatal("-u with Linux threads not supported: "
- "no capabilities support or capabilities "
- "disabled at build time");
-#endif
-#endif
-
if (setgid(runas_pw->pw_gid) < 0) {
strerror_r(errno, strbuf, sizeof(strbuf));
named_main_earlyfatal("setgid(): %s", strbuf);
strbuf);
}
#endif
-#if defined(HAVE_SYS_CAPABILITY_H) && !defined(HAVE_LINUXTHREADS)
+#if defined(HAVE_SYS_CAPABILITY_H)
linux_minprivs();
#endif
}
void
named_os_adjustnofile(void) {
-#ifdef HAVE_LINUXTHREADS
+#if defined(__linux__)
isc_result_t result;
isc_resourcevalue_t newvalue;
linux_keepcaps();
#endif
-#ifdef HAVE_LINUXTHREADS
- named_os_changeuser(); /* Call setuid() before threads are started */
-#endif
-
-#if defined(HAVE_SYS_CAPABILITY_H) && defined(HAVE_LINUXTHREADS)
+#if defined(HAVE_SYS_CAPABILITY_H)
linux_minprivs();
#endif
}
free(f);
if (switch_user && runas_pw != NULL) {
-#ifndef HAVE_LINUXTHREADS
gid_t oldgid = getgid();
-#endif
/* Set UID/GID to the one we'll be running with eventually */
setperms(runas_pw->pw_uid, runas_pw->pw_gid);
fd = safe_open(filename, mode, false);
-#ifndef HAVE_LINUXTHREADS
/* Restore UID/GID to root */
setperms(0, oldgid);
-#endif /* HAVE_LINUXTHREADS */
if (fd == -1) {
-#ifndef HAVE_LINUXTHREADS
fd = safe_open(filename, mode, false);
if (fd != -1) {
named_main_earlywarning("Required root "
named_main_earlywarning("Please check file and "
"directory permissions "
"or reconfigure the filename.");
-#else /* HAVE_LINUXTHREADS */
- named_main_earlywarning("Could not open "
- "'%s'.", filename);
- named_main_earlywarning("Please check file and "
- "directory permissions "
- "or reconfigure the filename.");
-#endif /* HAVE_LINUXTHREADS */
}
} else {
fd = safe_open(filename, mode, false);
cleanup_pidfile();
return;
}
-#ifdef HAVE_LINUXTHREADS
- pid = mainpid;
-#else
pid = getpid();
-#endif
if (fprintf(fh, "%ld\n", (long)pid) < 0) {
(*report)("fprintf() to pid file '%s' failed", filename);
(void)fclose(fh);
return;
}
-#ifdef HAVE_LINUXTHREADS
- pid = mainpid;
-#else
pid = getpid();
-#endif
(void)isc_buffer_printf(text, "pid: %ld", (long)pid);
}
(void *)isc__app_unblock
};
-#ifdef HAVE_LINUXTHREADS
-/*!
- * Linux has sigwait(), but it appears to prevent signal handlers from
- * running, even if they're not in the set being waited for. This makes
- * it impossible to get the default actions for SIGILL, SIGSEGV, etc.
- * Instead of messing with it, we just use sigsuspend() instead.
- */
-#undef HAVE_SIGWAIT
-/*!
- * We need to remember which thread is the main thread...
- */
-static pthread_t main_thread;
-#endif
-
#ifndef HAVE_SIGWAIT
static void
exit_action(int arg) {
* Start an ISC library application.
*/
-#ifdef HAVE_LINUXTHREADS
- main_thread = pthread_self();
-#endif /* HAVE_LINUXTHREADS */
-
result = isc_mutex_init(&ctx->readylock);
if (result != ISC_R_SUCCESS)
return (result);
REQUIRE(VALID_APPCTX(ctx));
-#ifdef HAVE_LINUXTHREADS
- REQUIRE(main_thread == pthread_self());
-#endif
-
LOCK(&ctx->lock);
if (!ctx->running) {
/* BIND9 internal, but using multiple contexts */
ctx->want_shutdown = true;
else {
-#ifdef HAVE_LINUXTHREADS
- if (isc_bind9) {
- /* BIND9 internal, single context */
- int result;
-
- result = pthread_kill(main_thread, SIGTERM);
- if (result != 0) {
- strerror_r(result,
- strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "isc_app_shutdown() "
- "pthread_kill: %s",
- strbuf);
- return (ISC_R_UNEXPECTED);
- }
- }
-#else
if (isc_bind9) {
/* BIND9 internal, single context */
if (kill(getpid(), SIGTERM) < 0) {
return (ISC_R_UNEXPECTED);
}
}
-#endif /* HAVE_LINUXTHREADS */
else {
/* External, multiple contexts */
LOCK(&ctx->readylock);
ctx->want_reload = true;
else {
ctx->want_reload = true;
-#ifdef HAVE_LINUXTHREADS
- if (isc_bind9) {
- /* BIND9 internal, single context */
- int result;
-
- result = pthread_kill(main_thread, SIGHUP);
- if (result != 0) {
- strerror_r(result,
- strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "isc_app_reload() "
- "pthread_kill: %s",
- strbuf);
- return (ISC_R_UNEXPECTED);
- }
- }
-#else
if (isc_bind9) {
/* BIND9 internal, single context */
if (kill(getpid(), SIGHUP) < 0) {
return (ISC_R_UNEXPECTED);
}
}
-#endif /* HAVE_LINUXTHREADS */
else {
/* External, multiple contexts */
LOCK(&ctx->readylock);