Exemplo n.º 1
0
/*----------------------------------------------------------------------------*/
static void lcd_sb()
{
  E(1);
  sys_usleep(15);
  E(0);
  sys_usleep(5);
}
Exemplo n.º 2
0
static WERROR watch_service_state(struct rpc_pipe_client *pipe_hnd,
				TALLOC_CTX *mem_ctx,
				struct policy_handle *hSCM,
				const char *service,
				uint32 watch_state,
				uint32 *final_state )
{
	uint32 i;
	uint32 state = 0;
	WERROR result = WERR_GENERAL_FAILURE;


	i = 0;
	while ( (state != watch_state ) && i<30 ) {
		/* get the status */

		result = query_service_state(pipe_hnd, mem_ctx, hSCM, service, &state  );
		if ( !W_ERROR_IS_OK(result) ) {
			break;
		}

		d_printf(".");
		i++;
		sys_usleep( 100 );
	}
	d_printf("\n");

	*final_state = state;

	return result;
}
Exemplo n.º 3
0
NTSTATUS do_lock_spin(files_struct *fsp,connection_struct *conn, uint16 lock_pid,
		 SMB_BIG_UINT count,SMB_BIG_UINT offset,enum brl_type lock_type)
{
	int j, maxj = lp_lock_spin_count();
	int sleeptime = lp_lock_sleep_time();
	NTSTATUS status, ret;

	if (maxj <= 0)
		maxj = 1;

	ret = NT_STATUS_OK; /* to keep dumb compilers happy */

	for (j = 0; j < maxj; j++) {
		status = do_lock(fsp, conn, lock_pid, count, offset, lock_type);
		if (!NT_STATUS_EQUAL(status, NT_STATUS_LOCK_NOT_GRANTED) &&
		    !NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
			return status;
		}
		/* if we do fail then return the first error code we got */
		if (j == 0) {
			ret = status;
		}
		if (sleeptime)
			sys_usleep(sleeptime);
	}
	return ret;
}
Exemplo n.º 4
0
bool status_profile_rates(bool verbose)
{
	SMB_BIG_UINT remain_usec;
	SMB_BIG_UINT next_usec;
	SMB_BIG_UINT delta_usec;

	int last = 0;
	int current = 1;
	int tmp;

	if (verbose) {
	    fprintf(stderr, "Sampling stats at %d sec intervals\n",
		    usec_to_sec(sample_interval_usec));
	}

	if (!profile_setup(NULL, True)) {
		fprintf(stderr,"Failed to initialise profile memory\n");
		return False;
	}

	memcpy(&sample_data[last], profile_p, sizeof(*profile_p));
	for (;;) {
		sample_time[current] = profile_timestamp();
		next_usec = sample_time[current] + sample_interval_usec;

		/* Take a sample. */
		memcpy(&sample_data[current], profile_p, sizeof(*profile_p));

		/* Rate convert some values and print results. */
		delta_usec = sample_time[current] - sample_time[last];

		if (print_count_samples(&sample_data[current],
			&sample_data[last], delta_usec)) {
			printf("\n");
		}

		/* Swap sampling buffers. */
		tmp = last;
		last = current;
		current = tmp;

		/* Delay until next sample time. */
		remain_usec = next_usec - profile_timestamp();
		if (remain_usec > sample_interval_usec) {
			fprintf(stderr, "eek! falling behind sampling rate!\n");
		} else {
			if (verbose) {
			    fprintf(stderr,
				    "delaying for %lu msec\n",
				    (unsigned long )usec_to_msec(remain_usec));
			}

			sys_usleep(remain_usec);
		}

	}

	return True;
}
Exemplo n.º 5
0
NTSTATUS do_lock_spin(files_struct *fsp,
			uint16 lock_pid,
			SMB_BIG_UINT count,
			SMB_BIG_UINT offset,
			enum brl_type lock_type,
			enum brl_flavour lock_flav,
			BOOL *my_lock_ctx)
{
	int j, maxj = lp_lock_spin_count();
	int sleeptime = lp_lock_sleep_time();
	NTSTATUS status, ret;

	if (maxj <= 0) {
		maxj = 1;
	}

	ret = NT_STATUS_OK; /* to keep dumb compilers happy */

	for (j = 0; j < maxj; j++) {
		status = do_lock(fsp,
				lock_pid,
				count,
				offset,
				lock_type,
				lock_flav,
				my_lock_ctx);

		if (!NT_STATUS_EQUAL(status, NT_STATUS_LOCK_NOT_GRANTED) &&
		    !NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
			return status;
		}
		/* if we do fail then return the first error code we got */
		if (j == 0) {
			ret = status;
			/* Don't spin if we blocked ourselves. */
			if (*my_lock_ctx) {
				return ret;
			}

			/* Only spin for Windows locks. */
			if (lock_flav == POSIX_LOCK) {
				return ret;
			}
		}

		if (sleeptime) {
			sys_usleep(sleeptime);
		}
	}
	return ret;
}
Exemplo n.º 6
0
static FILE *startsmbfilepwent(const char *pfile, enum pwf_access_type type, int *lock_depth)
{
	FILE *fp = NULL;
	const char *open_mode = NULL;
	int race_loop = 0;
	int lock_type = F_RDLCK;

	if (!*pfile) {
		DEBUG(0, ("startsmbfilepwent: No SMB password file set\n"));
		return (NULL);
	}

	switch(type) {
		case PWF_READ:
			open_mode = "rb";
			lock_type = F_RDLCK;
			break;
		case PWF_UPDATE:
			open_mode = "r+b";
			lock_type = F_WRLCK;
			break;
		case PWF_CREATE:
			/*
			 * Ensure atomic file creation.
			 */
			{
				int i, fd = -1;

				for(i = 0; i < 5; i++) {
					if((fd = sys_open(pfile, O_CREAT|O_TRUNC|O_EXCL|O_RDWR, 0600))!=-1) {
						break;
					}
					sys_usleep(200); /* Spin, spin... */
				}
				if(fd == -1) {
					DEBUG(0,("startsmbfilepwent_internal: too many race conditions \
creating file %s\n", pfile));
					return NULL;
				}
				close(fd);
				open_mode = "r+b";
				lock_type = F_WRLCK;
				break;
			}
	}