e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * CDDL HEADER START
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * The contents of this file are subject to the terms of the
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * Common Development and Distribution License (the "License").
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * You may not use this file except in compliance with the License.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * See the License for the specific language governing permissions
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * and limitations under the License.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * When distributing Covered Code, include this CDDL HEADER in each
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * If applicable, add the following below this CDDL HEADER, with the
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * fields enclosed by brackets "[]" replaced with your own identifying
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * information: Portions Copyright [yyyy] [name of copyright owner]
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * CDDL HEADER END
b57459abfba36eb3068cfe44c6921168b4c4f774Julian Pullen * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * Use is subject to license terms.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth /* waiting for change or */
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth /* copying data */
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth /* waiting for another main */
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth /* nscd thread to be cleaned */
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57ethstatic chg_info_t chg = { DEFAULTMUTEX, DEFAULTCV, 0, NULL, NULL, NULL, 0 };
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * The cookie of the configuration and its mutex
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57ethstatic void
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57ethchg_cookie_equal(ldap_get_chg_cookie_t *c1, ldap_get_chg_cookie_t *c2)
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth if (c1->mgr_pid == c2->mgr_pid && c1->seq_num == c2->seq_num)
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * Create a node in the list and output the node. The caller can NOT free it.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57ethwaiting_list_add(chg_info_t *info, pid_t pid, thread_t tid,
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth if ((wl = (waiting_list_t *)calloc(1, sizeof (waiting_list_t)))
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * Find a node with matching tid in the list and remove it from the list.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth for (wl = info->chg_w_first; wl != NULL; wl = wl->next) {
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * Delete the thread from the waiting list and remove data when the list
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * is empty.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57ethstatic void
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * Set flag by pid so it can be cleaned up.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57ethstatic void
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth for (wl = info->chg_w_first; wl != NULL; wl = wl->next) {
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * Return: 1 - door client is dead, 0 - door client is alive
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth return (rc);
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * This function handles GETSTATUSCHANGE call from main nscd.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * The call can be a START op or STOP op. A cookie is sent from main nscd too.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * The static global variable main_nscd keeps record of pid, tid and some flags.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * If the thread is door_return(), main_nscd.pid, main_nscd.tid are set to 0.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * When the call is START op, it checks if main_nscd.pid is 0. If it is, it
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * proceeds to wait for the change notification. If it's not, which means
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * another main nscd handling thread is still around. It sends broadcast to
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * clean up that thread and wait until the cleanup is done then proceeds to
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * wait for the change notification. If same main nscd sends START op
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * repeatedly, it'll be rejected.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * It also checks the cookie from main nscd. If it's not the same as
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * ldap_cachemgr's cookie, door returns config change.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * If the door call is STOP op, it creates a thread to clean up main nscd START
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * thread so it won't be blocking.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * In waiting for the change notification phase, the thread is waken up by
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * the notification threads or by the cleanup threads.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * If it's a notification, it copies data to the stack then door return.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * If it's a cleanup, door_client_dead() is called to verify it then
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * door return.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57ethchg_get_statusChange(LineBuf *info, ldap_call_t *in, pid_t nscd_pid)
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth int rc = CHG_SUCCESS, another_main_nscd_thread_alive = 0;
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth if (in->ldap_u.get_change.op == NS_STATUS_CHANGE_OP_START) {
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * This is the case that nscd doesn't shut down
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * properly(e.g. core) and STOP op is not sent,
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * the thread handling it is still around and
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * not cleaned up yet.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * Test if the thread is still alive.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * If it is, clean it up.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * For thr_kill, if sig is 0, a validity check
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * is done for the existence of the target
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * thread; no signal is sent.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * Same nscd pid can only send door call
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * one at a time and wait for ldap_cachemgr to
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * return change data. If it's the same pid
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * again, it's an nscd error.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * Wait for another thread to be cleaned up if it's alive.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * After that this cond var is waken up.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * Replace pid and tid and set the flag.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth if (!chg_cookie_equal(&cookie, &in->ldap_u.get_change.cookie)) {
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * different cookie, set new cookie and
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * return door call right away
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth /* wait for the change notification */
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth /* Check if door client is still alive again */
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth /* copy data to buffer */
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * Reset pid, tid and flag, send wakeup signal.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth } else if (in->ldap_u.get_change.op == NS_STATUS_CHANGE_OP_STOP) {
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth return (rc);
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * This function copies the header and data stream to the buffer
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * then send broadcast to wake up the chg_get_statusChange() threads.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth ldap_get_change_out_t *cout = (ldap_get_change_out_t *)str;
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth /* NS_STATUS_CHANGE_TYPE_SERVER */
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * This is called when the configuration is refreshed.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * The new configuration is different from the current one, a notification
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * is sent tochg_get_statusChange() threads.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57ethchg_test_config_change(ns_config_t *new, int *change_status)
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * Flatten the config data of the newly downloaded config and
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * current default config and compare both.
b57459abfba36eb3068cfe44c6921168b4c4f774Julian Pullen if ((errp = __ns_ldap_LoadDoorInfo(&new_cfg, NULL, new, 0)) != NULL) {
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth /* error, assume the config is changed */
b57459abfba36eb3068cfe44c6921168b4c4f774Julian Pullen } else if ((errp = __ns_ldap_LoadDoorInfo(&cur_cfg, NULL, NULL, 0))
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth /* error, assume the config is changed */
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth if (changed == 0) {
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth if (strcmp(new_out->config_str, cur_out->config_str) != 0) {
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * Replace the currentdefault config with the new
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * cout->cookie is set by
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * chg_notify_statusChange
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * Wake up chg_get_statusChange() threads to clean up the threads
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * that main nscd doesn't exist on the other of door anymore or
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * the thread is marked as cleanup.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57ethstatic void
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57ethcleanup_threads(chg_info_t *chg, pid_t pid, cleanup_type_t type)
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * wake up threads without setting chg.chg_wakeup.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * It's for cleanup purpose, not for notifying changes.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * If arg is NULL, it loops forever,
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * else it calls cleanup_threads once and exits.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * The door server thead which has the door client pid will be marked
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * as to be clean up. If pid is 0, no marking and just clean up all.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57ethstatic void
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth /* clean up all if pid is 0 */
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth logit("thr_create failed for cleanup_thread_by_pid(%ld)\n",
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * Output a psinfo of an nscd process with process id pid
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * Return: 0 - Can't find the process or it's not nscd
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * 1 - psinfo found
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * Note: If info is NULL, returns 0 or 1 only and no output from info.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth if (snprintf(fname, MAXPATHLEN, "/proc/%d/psinfo", pid) > 0) {
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth return (1);
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth return (0);
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * If the parent process is nscd and euid is 0, it's a peruser nscd.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * get psinfo of parent forker nscd
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth return (1);
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth return (0);
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth return (0);
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * Check if the door client making door call is a nscd or peruser nscd and
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth * output door client's pid.
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57ethchg_is_called_from_nscd_or_peruser_nscd(char *dc_str, pid_t *pidp)
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth return (0);
e1dd0a2f3a26050d1f183c1cafae42c4e3a0b57eth return (rc);