Example #1
0
int sys_select_intr(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval)
{
	int ret;
	fd_set *readfds2, readfds_buf, *writefds2, writefds_buf, *errorfds2, errorfds_buf;
	struct timeval tval2, *ptval, end_time;

	readfds2 = (readfds ? &readfds_buf : NULL);
	writefds2 = (writefds ? &writefds_buf : NULL);
	errorfds2 = (errorfds ? &errorfds_buf : NULL);
	if (tval) {
		GetTimeOfDay(&end_time);
		end_time.tv_sec += tval->tv_sec;
		end_time.tv_usec += tval->tv_usec;
		end_time.tv_sec += end_time.tv_usec / 1000000;
		end_time.tv_usec %= 1000000;
		errno = 0;
		tval2 = *tval;
		ptval = &tval2;
	} else {
		ptval = NULL;
	}

	do {
		if (readfds)
			readfds_buf = *readfds;
		if (writefds)
			writefds_buf = *writefds;
		if (errorfds)
			errorfds_buf = *errorfds;
		if (ptval && (errno == EINTR)) {
			struct timeval now_time;
			SMB_BIG_INT tdif;

			GetTimeOfDay(&now_time);
			tdif = usec_time_diff(&end_time, &now_time);
			if (tdif <= 0) {
				ret = 0; /* time expired. */
				break;
			}
			ptval->tv_sec = tdif / 1000000;
			ptval->tv_usec = tdif % 1000000;
		}

		/* We must use select and not sys_select here. If we use
		   sys_select we'd lose the fact a signal occurred when sys_select
		   read a byte from the pipe. Fix from Mark Weaver
		   <*****@*****.**>
		*/
		ret = select(maxfd, readfds2, writefds2, errorfds2, ptval);
	} while (ret == -1 && errno == EINTR);

	if (readfds)
		*readfds = readfds_buf;
	if (writefds)
		*writefds = writefds_buf;
	if (errorfds)
		*errorfds = errorfds_buf;

	return ret;
}
Example #2
0
static BOOL timeout_until(struct timeval *timeout, const struct timeval *endtime)
{
	struct timeval now;
	SMB_BIG_INT t_dif;

	GetTimeOfDay(&now);

	t_dif = usec_time_diff(endtime, &now);
	if (t_dif <= 0) {
		return False;
	}

	timeout->tv_sec = (t_dif / (SMB_BIG_INT)1000000);
	timeout->tv_usec = (t_dif % (SMB_BIG_INT)1000000);
	return True;
}
Example #3
0
static double rate_convert_secs(unsigned count,
		const struct timeval *start, const struct timeval *end)
{
	return (double)count /
		usec_to_sec((double)usec_time_diff(end, start));
}
Example #4
0
NTSTATUS smbXsrv_open_cleanup(uint64_t persistent_id)
{
	NTSTATUS status = NT_STATUS_OK;
	TALLOC_CTX *frame = talloc_stackframe();
	struct smbXsrv_open_global0 *op = NULL;
	TDB_DATA val;
	struct db_record *rec;
	bool delete_open = false;
	uint32_t global_id = persistent_id & UINT32_MAX;

	rec = smbXsrv_open_global_fetch_locked(smbXsrv_open_global_db_ctx,
					       global_id,
					       frame);
	if (rec == NULL) {
		status = NT_STATUS_NOT_FOUND;
		goto done;
	}

	val = dbwrap_record_get_value(rec);
	if (val.dsize == 0) {
		DEBUG(10, ("smbXsrv_open_cleanup[global: 0x%08x] "
			  "empty record in %s, skipping...\n",
			   global_id, dbwrap_name(smbXsrv_open_global_db_ctx)));
		goto done;
	}

	status = smbXsrv_open_global_parse_record(talloc_tos(), rec, &op);
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(1, ("smbXsrv_open_cleanup[global: 0x%08x] "
			  "failed to read record: %s\n",
			  global_id, nt_errstr(status)));
		goto done;
	}

	if (server_id_is_disconnected(&op->server_id)) {
		struct timeval now, disconnect_time;
		int64_t tdiff;
		now = timeval_current();
		nttime_to_timeval(&disconnect_time, op->disconnect_time);
		tdiff = usec_time_diff(&now, &disconnect_time);
		delete_open = (tdiff >= 1000*op->durable_timeout_msec);

		DEBUG(10, ("smbXsrv_open_cleanup[global: 0x%08x] "
			   "disconnected at [%s] %us ago with "
			   "timeout of %us -%s reached\n",
			   global_id,
			   nt_time_string(frame, op->disconnect_time),
			   (unsigned)(tdiff/1000000),
			   op->durable_timeout_msec / 1000,
			   delete_open ? "" : " not"));
	} else if (!serverid_exists(&op->server_id)) {
		struct server_id_buf idbuf;
		DEBUG(10, ("smbXsrv_open_cleanup[global: 0x%08x] "
			   "server[%s] does not exist\n",
			   global_id,
			   server_id_str_buf(op->server_id, &idbuf)));
		delete_open = true;
	}

	if (!delete_open) {
		goto done;
	}

	status = dbwrap_record_delete(rec);
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(1, ("smbXsrv_open_cleanup[global: 0x%08x] "
			  "failed to delete record"
			  "from %s: %s\n", global_id,
			  dbwrap_name(smbXsrv_open_global_db_ctx),
			  nt_errstr(status)));
		goto done;
	}

	DEBUG(10, ("smbXsrv_open_cleanup[global: 0x%08x] "
		   "delete record from %s\n",
		   global_id,
		   dbwrap_name(smbXsrv_open_global_db_ctx)));

done:
	talloc_free(frame);
	return status;
}