Esempio n. 1
0
/*
 * FUNCTION:    read_from_dit();
 *
 * DESCRIPTION:	Read (i.e. get and map) a single NIS entry from the LDAP DIT.
 *		Also handles retry attempts, on failure, and interpretation of
 *		internal error codes.
 *
 * INPUTS:     	Map name (unqualified)
 *		Domain name
 *		Entry key
 *		Pointer to return location
 *
 * OUTPUTS:   	If successful DBM datum containing result.
 *		On error DBM datum pointing to NULL and, if the cached value
 *		is not to be used, an error code.
 */
int
read_from_dit(char *map, char *domain, datum *key, datum *value)
{
	int count;
	int res;
	__nisdb_retry_t	*retrieveRetry;

	/* Initialize tsd */
	__nisdb_get_tsd()->domainContext = 0;
	__nisdb_get_tsd()->escapeFlag = '\0';

	for (count = 0; count < ypDomains.numDomains; count++) {
		if (0 == ypDomains.domainLabels[count])
			continue;
		if (0 == strcasecmp(domain, ypDomains.domainLabels[count])) {
			__nisdb_get_tsd()->domainContext =
			    ypDomains.domains[count];
			break;
		}
	}

	retrieveRetry = &ldapDBTableMapping.retrieveErrorRetry;

	/* Loop 'attempts' times of forever if -1 */
	for (count = retrieveRetry->attempts; (0 <= count) ||
	    (-1 == retrieveRetry->attempts); count --) {
		if (TRUE == singleReadFromDIT(map, domain, key, value, &res))
			/* It worked, return value irrelevant */
			return (0);

		if (LDAP_TIMEOUT == res) { /* Exceeded search timeout */
			value->dptr = NULL;
			return (0);
		}

		if (is_fatal_error(res))
			break;

		/*
		 * Didn't work. If not the special case where no repeats are
		 * done sleep.
		 */
		if (0 != retrieveRetry->attempts)
			(void) poll(NULL, 0, retrieveRetry->timeout*1000);
	}

	/* Make sure returned pointer is NULL */
	value->dptr = NULL;

	/* If we get here access failed work out what to return */
	if (ldapDBTableMapping.retrieveError == use_cached)
		return (0);

	return (res);
}
Esempio n. 2
0
static int g_io_channel_write_block(GIOChannel *channel, void *data, int len)
{
        gsize ret;
	int err, sent;

	sent = 0;
	do {
		err = g_io_channel_write(channel, (char *) data + sent,
					 len-sent, &ret);
                sent += ret;
	} while (sent < len && !is_fatal_error(err));

	return err != 0 ? -1 : 0;
}
Esempio n. 3
0
static int g_io_channel_read_block(GIOChannel *channel, void *data, int len)
{
	time_t maxwait;
        gsize ret;
	int err, received;

	maxwait = time(NULL)+2;
	received = 0;
	do {
		err = g_io_channel_read(channel, (char *) data + received,
					len-received, &ret);
		received += ret;
	} while (received < len && time(NULL) < maxwait &&
		 (ret != 0 || !is_fatal_error(err)));

	return received < len ? -1 : 0;
}
void il_tool_event_cb(il_comp_t hComponent,
        OMX_EVENTTYPE eEvent,
        OMX_U32 Data1, OMX_OUT OMX_U32 Data2,
        OMX_PTR pEventData)
{
    ADM_ASSERT(hComponent != NULL);
    (void) pEventData;

#if 0
    {
        struct sched_param sched_param;
        int    sched_policy;
        int    nice_prio;

        pthread_getschedparam(pthread_self(), &sched_policy, &sched_param);
        ALOG_STATUS("SCHED_OTHER=%d, SCHED_FIFO=%d, SCHED_RR=%d\n", SCHED_OTHER, SCHED_FIFO, SCHED_RR);
        ALOG_STATUS("IL EVENT callback thread info: getpriority=%d pthread.policy=%d pthread.sched_priority=%d\n",
                    getpriority(PRIO_PROCESS, gettid()), sched_policy, sched_param.sched_priority);
    }
#endif

    if (eEvent == OMX_EventCmdComplete) {
        if (Data1 == OMX_CommandPortEnable ||
            Data1 == OMX_CommandPortDisable ||
            Data1 == OMX_CommandStateSet)
            {
                // Unless an error has occured (which may have aborted the
                // current command), a command must be in progress
                // TODO if (il_data->cmd_in_progress) {
                adm_sem_post(&g_adm_event_sem);
                // TODO     il_data->cmd_in_progress = 0;
                // TODO } else {
                    // TODO ALOG_ERR("Unexpected OMX_EventCmdComplete received, last_err=%d\n", il_data->last_error);
                // TODO }
            }
    }

    if (eEvent == OMX_EventError) {
        if ((AFM_ERRORTYPE) Data1 == AFM_ErrorDspPanic) {
            ALOG_ERR("AFM_ErrorDspPanic received\n");
            ste_adm_debug_reboot();
        }
        if (is_fatal_error(Data1)) {
            pthread_mutex_lock(&hComponent->mutex);
            adm_il_tool_state_t* il_data = &hComponent->callback_state;
            if (il_data->cmd_in_progress) {
                adm_sem_post(&g_adm_event_sem);
                il_data->cmd_in_progress  = 0;
                il_data->last_error       = Data1;
                il_data->last_error_Data2 = Data2;
            }
            pthread_mutex_unlock(&hComponent->mutex);
        }
    }

    int handled_event = 0;
    if ((OMX_EVENTEXTTYPE)eEvent == OMX_EventIndexSettingChanged) {
        pthread_mutex_lock(&hComponent->mutex);

        adm_il_tool_state_t* il_data = &hComponent->callback_state;
        if (il_data->waiting_for_event && il_data->waiting_for_event_idx == (int) Data2) {
            il_data->waiting_for_event = 0;
            handled_event = 1;
            adm_sem_post(&g_adm_event_sem);
        }

        pthread_mutex_unlock(&hComponent->mutex);
    }
    if (!handled_event && eEvent != OMX_EventCmdComplete) {
        srv_send_il_event_msg(hComponent, eEvent,
        Data1, Data2, pEventData);
    }

}
Esempio n. 5
0
void serial_port_ertsw (struct serial_port* port)
{
	int		r;

	DBG_LOG(fprintf(debug_log_file, "event: ertsw\n"));

	/* If no packet is in transit, scan the incoming buffer to try
	 * and get another packet ready for transmission.  This is done
	 * before attempting to do the writes below, so that if a packet
	 * is scanned out it can be sent immediately.
	 */
	if (   0 == port->incomingCurHeaderLeft
		&& 0 == port->incomingCurPacketLeft)
	{
		if (port->lastError.error_code)
		{
			uint32_t	plen;

			DBG_LOG(fprintf(debug_log_file, "sending error %i %s\n",
				port->lastError.error_code,
				port->lastError.error_msg));

			plen = sizeof(port->lastError.error_code);
			plen += (uint32_t)strlen(port->lastError.error_msg);
			
			port->incomingCurHeaderLen = 5 + plen;
			port->incomingCurHeaderLeft = 5 + plen;
			port->incomingCurPacketLeft = 0;

			plen = htonl(plen + 1);
			memcpy(port->incomingHeader, &plen, 4);
			port->incomingHeader[4] = PACKET_ERROR;
			memcpy(
				port->incomingHeader + 5,
				&port->lastError,
				sizeof(port->lastError));

			/* In case of a non-recoverable error, signal the port as dead.
			 * This will cause the port driver process to exit.
			 */
			if (is_fatal_error(port->lastError.error_code)) {
			        port->isDead = 1;
			}

			port->lastError.error_code = 0;
			port->lastError.error_msg[0] = 0;

			DBG_LOG(fprintf(debug_log_file, "    Packet: hleft=%i dleft=%i\n",
				port->incomingCurHeaderLeft, port->incomingCurPacketLeft));

		} else if (port->sendOkFor)
		{
			uint32_t	plen;

			port->incomingCurHeaderLen = 6;
			port->incomingCurHeaderLeft = 6;
			port->incomingCurPacketLeft = 0;

			plen = htonl(2);
			memcpy(port->incomingHeader, &plen, 4);
			port->incomingHeader[4] = PACKET_OK;
			port->incomingHeader[5] = port->sendOkFor;

			port->sendOkFor = 0;
			
		} else
		{
			scan_incoming(port);
		}
	}

	/* If the header has not finished writing yet, try to write
	 * both the header and some packet data at once.  This is
	 * faster on OS implementations that allow us to use a
	 * gather write event, or something like it.
	 */
	if (port->incomingCurHeaderLeft > 0)
	{
		int		headerSent = port->incomingCurHeaderLen - port->incomingCurHeaderLeft;

		r = pipe_write2(
			port->erts,
			port->incomingHeader + headerSent,
			port->incomingCurHeaderLeft,
			port->incoming + port->incomingSent,
			port->incomingCurPacketLeft);
		DBG_LOG(fprintf(debug_log_file, "pipe_write2=%i\n", r));

		if (r >= 0)
		{
			if (r >= port->incomingCurHeaderLeft)
			{
				/* If the number of bytes written is more than what
				 * was left of the header, the header has been
				 * finished and only the data part remains.
				 */
				r -= port->incomingCurHeaderLeft;

				port->incomingCurHeaderLeft = 0;
				port->incomingCurPacketLeft -= r;
				port->incomingSent += r;

			} else
			{
				/* Less than the header was written, so just update
				 * the header count.  All of the data remains.
				 */
				port->incomingCurHeaderLeft -= r;
			}

		} else if (pipe_last_error(port->erts))
		{
			int		ecode;
			char	msg[256];

			ecode = pipe_last_error(port->erts);
			pipe_format_error(port->erts, ecode, msg, sizeof(msg));
			DBG_LOG(fprintf(debug_log_file, "pipe_write2 error: %i %s\n",
				ecode, msg));
			port->isDead = 1;
			return;
		}

	/* Only packet data is left now.  Its suitable to use just
	 * a single write operation on the one buffer at this
	 * point.
	 */
	} else if (port->incomingCurPacketLeft > 0)
	{
		r = pipe_write(
			port->erts,
			port->incoming + port->incomingSent,
			port->incomingCurPacketLeft);
		DBG_LOG(fprintf(debug_log_file, "    pipe_write=%i\n", r));

		if (r > 0)
		{
			port->incomingCurPacketLeft -= r;
			port->incomingSent += r;

		} else if (pipe_last_error(port->erts))
		{
			int		ecode;
			char	msg[256];

			ecode = pipe_last_error(port->erts);
			pipe_format_error(port->erts, ecode, msg, sizeof(msg));
			DBG_LOG(fprintf(debug_log_file, "pipe_write error: %i %s\n",
				ecode, msg));
			port->isDead = 1;
			return;
		}
	}

	/* If the buffer is totally empty, or has been fully
	 * transmitted, mark it empty.  This prevents a condition
	 * occuring where the incoming buffer fills up and won't
	 * get cleared.
	 */
	if (   port->incomingLen > 0
		&& port->incomingSent == port->incomingLen)
	{
		port->incomingSent = 0;
		port->incomingLen = 0;
		port->incomingMatch = 0;
		port->incomingScan = 0;
	}
}
Esempio n. 6
0
/*
 * FUNCTION:    write_to_dit();
 *
 * DESCRIPTION:	Maps and writes a NIS entry to the LDAP DIT.
 *		Also handles retry attempts, on failure, and interpretation of
 *		internal error codes.
 *
 * INPUTS:     	Pointer to (unqualified) map name
 *		Pointer to domain name
 *		The entries key
 *		What to write
 *		Replace flag indicating
 *			TRUE = Replace (overwrite) any existing entries
 *			FALSE = Return error if there are existing entries
 *		Flag indicating if we should tolerate mapping errors.
 *
 * OUTPUTS:   	SUCCESS = Write was successful
 *		FAILURE = Write failed
 *
 */
suc_code
write_to_dit(char *map, char *domain, datum key, datum value,
					bool_t replace, bool_t ignore_map_errs)
{
	int count;
	int res;
	__nisdb_retry_t	*storeRetry = &ldapDBTableMapping.storeErrorRetry;

	/* Initialize tsd */
	__nisdb_get_tsd()->domainContext = 0;
	__nisdb_get_tsd()->escapeFlag = '\0';

	for (count = 0; count < ypDomains.numDomains; count++) {
		if (0 == ypDomains.domainLabels[count])
			continue;
		if (0 == strcasecmp(domain, ypDomains.domainLabels[count])) {
			__nisdb_get_tsd()->domainContext =
			    ypDomains.domains[count];
			break;
		}
	}

	storeRetry = &ldapDBTableMapping.storeErrorRetry;

	/* Loop 'attempts' times of forever if -1 */
	for (count = storeRetry->attempts; (0 <= count) ||
	    (-1 == storeRetry->attempts); count --) {
		res = singleWriteToDIT(map, domain, &key, &value, replace);
		if (LDAP_SUCCESS == res)
			return (SUCCESS);

		if (is_fatal_error(res)) {
			/*
			 * The mapping failed and will fail again if it is
			 * retried. However there are some cases where an
			 * actual mapping fault (rather than a LDAP problem)
			 * may be ignored.
			 */
			if (ignore_map_errs) {
				switch (res) {
					case LDAP_INVALID_DN_SYNTAX:
					case LDAP_OBJECT_CLASS_VIOLATION:
					case LDAP_NOT_ALLOWED_ON_RDN:
					case MAP_NAMEFIELD_MATCH_ERROR:
					case MAP_NO_DN:
						return (SUCCESS);
					default:
						break;
				}
			}
			return (FAILURE);
		}

		if (ldapDBTableMapping.storeError != sto_retry)
			return (FAILURE);

		/*
		 * Didn't work. If not the special case where no repeats are
		 * done sleep.
		 */
		if (0 != storeRetry->attempts)
			(void) poll(NULL, 0, storeRetry->timeout*1000);

	}
	return (FAILURE);
}