コード例 #1
0
int mutex_lock(mutex_t* mtx) {
	if(unlikely(!mtx))
		return E_ERR;

	if(mtx->owner != sys_getpid()) {
#if CONFIG_IPC_DEBUG
		if(likely(mtx->name))
			kprintf(LOG, "[%d] %s: LOCKED from %d\n", mtx->owner, mtx->name, sys_getpid());
#endif	
		spinlock_lock(&mtx->lock);

		mtx->owner = sys_getpid();
		mtx->recursion = 0;
	} else if(mtx->kind == MTX_KIND_ERRORCHECK) {
#if CONFIG_IPC_DEBUG
		if(likely(mtx->name))
			kprintf(ERROR, "[%d] %s: DEADLOCK from %d\n", mtx->owner, mtx->name, sys_getpid());
#endif
		return E_ERR;
	}

	if(mtx->kind == MTX_KIND_RECURSIVE)
		mtx->recursion += 1;

	return E_OK;
}
コード例 #2
0
ファイル: restorer.c プロジェクト: kunalkushwaha/crtools
static int restore_signals(siginfo_t *ptr, int nr, bool group)
{
	int ret, i;
	k_rtsigset_t to_block;

	ksigfillset(&to_block);
	ret = sys_sigprocmask(SIG_SETMASK, &to_block, NULL, sizeof(k_rtsigset_t));
	if (ret) {
		pr_err("Unable to block signals %d", ret);
		return -1;
	}

	for (i = 0; i < nr; i++) {
		siginfo_t *info = ptr + i;

		pr_info("Restore signal %d group %d\n", info->si_signo, group);
		if (group)
			ret = sys_rt_sigqueueinfo(sys_getpid(), info->si_signo, info);
		else
			ret = sys_rt_tgsigqueueinfo(sys_getpid(),
						sys_gettid(), info->si_signo, info);
		if (ret) {
			pr_err("Unable to send siginfo %d %x with code %d\n",
					info->si_signo, info->si_code, ret);
			return -1;;
		}
	}

	return 0;
}
コード例 #3
0
ファイル: restorer.c プロジェクト: kunalkushwaha/crtools
static void sigchld_handler(int signal, siginfo_t *siginfo, void *data)
{
	char *r;

	if (futex_get(&task_entries->start) == CR_STATE_RESTORE_SIGCHLD) {
		pr_debug("%ld: Collect a zombie with (pid %d, %d)\n",
			sys_getpid(), siginfo->si_pid, siginfo->si_pid);
		futex_dec_and_wake(&task_entries->nr_in_progress);
		futex_dec_and_wake(&zombies_inprogress);
		task_entries->nr_threads--;
		task_entries->nr_tasks--;
		mutex_unlock(&task_entries->zombie_lock);
		return;
	}

	if (siginfo->si_code & CLD_EXITED)
		r = " exited, status=";
	else if (siginfo->si_code & CLD_KILLED)
		r = " killed by signal ";
	else
		r = "disappeared with ";

	pr_info("Task %d %s %d\n", siginfo->si_pid, r, siginfo->si_status);

	futex_abort_and_wake(&task_entries->nr_in_progress);
	/* sa_restorer may be unmaped, so we can't go back to userspace*/
	sys_kill(sys_getpid(), SIGSTOP);
	sys_exit_group(1);
}
コード例 #4
0
ファイル: p-forkexit.c プロジェクト: noorzaman/CS61
void process_main(void) {
    while (1) {
        if (rand() % ALLOC_SLOWDOWN == 0) {
            if (sys_fork() == 0) {
                break;
            }
        } else {
            sys_yield();
        }
    }

    pid_t p = sys_getpid();
    srand(p);

    // The heap starts on the page right after the 'end' symbol,
    // whose address is the first address not allocated to process code
    // or data.
    heap_top = ROUNDUP((uint8_t*) end, PAGESIZE);

    // The bottom of the stack is the first address on the current
    // stack page (this process never needs more than one stack page).
    stack_bottom = ROUNDDOWN((uint8_t*) read_rsp() - 1, PAGESIZE);

    // Allocate heap pages until (1) hit the stack (out of address space)
    // or (2) allocation fails (out of physical memory).
    while (1) {
        int x = rand() % (8 * ALLOC_SLOWDOWN);
        if (x < 8 * p) {
            if (heap_top == stack_bottom || sys_page_alloc(heap_top) < 0) {
                break;
            }
            *heap_top = p;      /* check we have write access to new page */
            heap_top += PAGESIZE;
            if (console[CPOS(24, 0)]) {
                /* clear "Out of physical memory" msg */
                console_printf(CPOS(24, 0), 0, "\n");
            }
        } else if (x == 8 * p) {
            if (sys_fork() == 0) {
                p = sys_getpid();
            }
        } else if (x == 8 * p + 1) {
            sys_exit();
        } else {
            sys_yield();
        }
    }

    // After running out of memory
    while (1) {
        if (rand() % (2 * ALLOC_SLOWDOWN) == 0) {
            sys_exit();
        } else {
            sys_yield();
        }
    }
}
コード例 #5
0
ファイル: mutex.c プロジェクト: forhappy/libloader
void
xmutex_unlock(struct xmutex * lock, sigset_t sigset)
{
	TRACE(MUTEX, "thread %d:%d is unlocking %p\n",
			sys_getpid(), sys_gettid(), lock);
	/* atomic_dec(&lock->val) != 1 */
	if (!atomic_dec_and_test(&lock->val)) {
		atomic_set(&lock->val, 0);
		futex_wake(&lock->val, 1);
	}
	restore_signals(sigset);
	TRACE(MUTEX, "thread %d:%d unlocked %p\n",
			sys_getpid(), sys_gettid(), lock);
}
void sys__exit(int exitcode)
{
	pid_t pid = sys_getpid();

    struct processhandler *ph;
    ph = pidmanager_get(pidmgr, pid);

    //kprintf("HERE1\n");
    assert(ph != NULL);
    //kprintf("HERE2\n");

    lock_acquire(ph->ph_exitlock);

	//kprintf("exiting here on this pid %d with exitcode %d\n", pid, exitcode);
    ph->ph_status = PH_EXITED;
    ph->ph_exitcode = exitcode;

    // wakes up all threads sleeping on the exit lock
    cv_signal(ph->ph_exitcv, ph->ph_exitlock);
    lock_release(ph->ph_exitlock);

    // exit the thread
	//int s = splhigh();
	//kprintf ("exiting: %d\n", curthread->t_pid);
	//splx(s);

    thread_exit();

    return;
}
コード例 #7
0
ファイル: network.c プロジェクト: WareX97/aPlus
static void tcpip_init_done(void* arg) {
    current_task->name = "[tcpipd]";
    current_task->description = "TCP/IP Stack daemon";
    current_task->priority = TASK_PRIO_MIN;


#if DEBUG
    kprintf(LOG "[%d] tcpip: initialized in %d MS\n", sys_getpid(), (uintptr_t) (timer_getms() - (uintptr_t) arg));
#else
    (void) arg;
#endif



    struct netif* lo = netif_find("lo0");
    if(likely(lo)) {
        netif_set_up(lo);
        netif_set_default(lo);
    } else
        kprintf(WARN "netif: Loopback interface not found\n");




    ip_addr_t dns[2];
    IP4_ADDR(&dns[0], 8, 8, 8, 8);
    IP4_ADDR(&dns[1], 8, 8, 4, 4);

    dns_setserver(0, &dns[0]);
    dns_setserver(1, &dns[1]);
}
コード例 #8
0
static BOOL retrieve_all_messages(char **msgs_buf, size_t *total_len)
{
	TDB_DATA kbuf;
	TDB_DATA dbuf;
	TDB_DATA null_dbuf;

	ZERO_STRUCT(null_dbuf);

	*msgs_buf = NULL;
	*total_len = 0;

	kbuf = message_key_pid(pid_to_procid(sys_getpid()));

	if (tdb_chainlock(tdb, kbuf) == -1)
		return False;

	dbuf = tdb_fetch(tdb, kbuf);
	/*
	 * Replace with an empty record to keep the allocated
	 * space in the tdb.
	 */
	tdb_store(tdb, kbuf, null_dbuf, TDB_REPLACE);
	tdb_chainunlock(tdb, kbuf);

	if (dbuf.dptr == NULL || dbuf.dsize == 0) {
		SAFE_FREE(dbuf.dptr);
		return False;
	}

	*msgs_buf = dbuf.dptr;
	*total_len = dbuf.dsize;

	return True;
}
コード例 #9
0
ファイル: server.c プロジェクト: chazikai24/asuswrt
static void msg_inject_fault(int msg_type, struct process_id src,
			    void *buf, size_t len, void *private_data)
{
	int sig;

	if (len != sizeof(int)) {
		
		DEBUG(0, ("Process %llu sent bogus signal injection request\n",
			(unsigned long long)src.pid));
		return;
	}

	sig = *(int *)buf;
	if (sig == -1) {
		exit_server("internal error injected");
		return;
	}

#if HAVE_STRSIGNAL
	DEBUG(0, ("Process %llu requested injection of signal %d (%s)\n",
		    (unsigned long long)src.pid, sig, strsignal(sig)));
#else
	DEBUG(0, ("Process %llu requested injection of signal %d\n",
		    (unsigned long long)src.pid, sig));
#endif

	kill(sys_getpid(), sig);
}
コード例 #10
0
ファイル: fault.c プロジェクト: DeezNuts12/freestyledash
/*******************************************************************
report a fault
********************************************************************/
static void fault_report(int sig)
{
	static int counter;

	if (counter) _exit(1);

	counter++;

	DEBUGSEP(0);
	DEBUG(0,("INTERNAL ERROR: Signal %d in pid %d (%s)",sig,(int)sys_getpid(),SAMBA_VERSION_STRING));
	DEBUG(0,("\nPlease read the Trouble-Shooting section of the Samba3-HOWTO\n"));
	DEBUG(0,("\nFrom: http://www.samba.org/samba/docs/Samba3-HOWTO.pdf\n"));
	DEBUGSEP(0);
  
	smb_panic("internal error");

	if (cont_fn) {
		cont_fn(NULL);
#ifdef SIGSEGV
		CatchSignal(SIGSEGV,SIGNAL_CAST SIG_DFL);
#endif
#ifdef SIGBUS
		CatchSignal(SIGBUS,SIGNAL_CAST SIG_DFL);
#endif
#ifdef SIGABRT
		CatchSignal(SIGABRT,SIGNAL_CAST SIG_DFL);
#endif
		return; /* this should cause a core dump */
	}
	exit(1);
}
コード例 #11
0
ファイル: mpos-app.c プロジェクト: jamesbvaughan/cs111
void
start(void)
{
	volatile int checker = 0; /* This variable checks that you correctly
								gave the child process a new stack. */
	pid_t p;
	int status;

	app_printf("About to start a new process...\n");

	p = sys_fork();
	if (p == 0)
		run_child();
	else if (p > 0) {
		app_printf("Main process %d!\n", sys_getpid());
		do {
			status = sys_wait(p);
			app_printf("W");
		} while (status == WAIT_TRYAGAIN);
		app_printf("Child %d exited with status %d!\n", p, status);

		// Check whether the child process corrupted our stack.
		// (This check doesn't find all errors, but it helps.)
		if (checker != 0) {
			app_printf("Error: stack collision!\n");
			sys_exit(1);
		} else
			sys_exit(0);

	} else {
		app_printf("Error!\n");
		sys_exit(1);
	}
}
コード例 #12
0
ファイル: oplock_irix.c プロジェクト: jophxy/samba
static BOOL irix_oplocks_available(void)
{
	int fd;
	int pfd[2];
	pstring tmpname;

	oplock_set_capability(True, False);

	slprintf(tmpname,sizeof(tmpname)-1, "%s/koplock.%d", lp_lockdir(), (int)sys_getpid());

	if(pipe(pfd) != 0) {
		DEBUG(0,("check_kernel_oplocks: Unable to create pipe. Error was %s\n",
			 strerror(errno) ));
		return False;
	}

	if((fd = sys_open(tmpname, O_RDWR|O_CREAT|O_EXCL|O_TRUNC, 0600)) < 0) {
		DEBUG(0,("check_kernel_oplocks: Unable to open temp test file %s. Error was %s\n",
			 tmpname, strerror(errno) ));
		unlink( tmpname );
		close(pfd[0]);
		close(pfd[1]);
		return False;
	}

	unlink(tmpname);

	if(sys_fcntl_long(fd, F_OPLKREG, pfd[1]) == -1) {
		DEBUG(0,("check_kernel_oplocks: Kernel oplocks are not available on this machine. \
Disabling kernel oplock support.\n" ));
		close(pfd[0]);
		close(pfd[1]);
		close(fd);
		return False;
	}
コード例 #13
0
ファイル: locking.c プロジェクト: pombredanne/cliffs
BOOL is_locked(uint16 smbpid,
		files_struct * fsp, struct vfs_connection_struct *conn,
	       SMB_BIG_UINT count, SMB_BIG_UINT offset,
	       enum brl_type lock_type)
{
	int snum = conn->snum;
	BOOL ret;

	if (count == 0)
		return (False);

	if (!lp_locking(snum) || !lp_strict_locking(snum))
		return (False);

	ret = !brl_locktest(fsp->sbuf.st_dev, fsp->sbuf.st_ino, fsp->fnum,
			    smbpid, sys_getpid(), conn->snum,
			    offset, count, lock_type);

	/*
	 * There is no lock held by an SMB daemon, check to
	 * see if there is a POSIX lock from a UNIX or NFS process.
	 */

	if (!ret && lp_posix_locking(snum))
		ret = is_posix_locked(fsp, offset, count, lock_type);

	return ret;
}
コード例 #14
0
ファイル: smbcontrol.c プロジェクト: hajuuk/R7000
static pid_t parse_dest(const char *dest)
{
	pid_t pid;

	/* Zero is a special return value for broadcast smbd */

	if (strequal(dest, "smbd"))
		return 0;

	/* Try self - useful for testing */

	if (strequal(dest, "self"))
		return sys_getpid();

	/* Check for numeric pid number */

	if ((pid = atoi(dest)) != 0)
		return pid;

	/* Look up other destinations in pidfile directory */

	if ((pid = pidfile_pid(dest)) != 0)
		return pid;

	fprintf(stderr,"Can't find pid for destination '%s'\n", dest);

	return -1;
}	
コード例 #15
0
static void msg_inject_fault(struct messaging_context *msg,
			     void *private_data,
			     uint32_t msg_type,
			     struct server_id src,
			     DATA_BLOB *data)
{
	int sig;

	if (data->length != sizeof(sig)) {
		DEBUG(0, ("Process %s sent bogus signal injection request\n",
			  procid_str_static(&src)));
		return;
	}

	sig = *(int *)data->data;
	if (sig == -1) {
		exit_server("internal error injected");
		return;
	}

#if HAVE_STRSIGNAL
	DEBUG(0, ("Process %s requested injection of signal %d (%s)\n",
		  procid_str_static(&src), sig, strsignal(sig)));
#else
	DEBUG(0, ("Process %s requested injection of signal %d\n",
		  procid_str_static(&src), sig));
#endif

	kill(sys_getpid(), sig);
}
コード例 #16
0
ファイル: p-fork.c プロジェクト: johnlinew/CS61-psets
void process_main(void) {
    // Fork a total of three new copies.
    pid_t p = sys_fork();
    assert(p >= 0);
    p = sys_fork();
    assert(p >= 0);

    // The rest of this code is like p-allocator.c.

    p = sys_getpid();
    srand(p);

    heap_top = ROUNDUP((uint8_t *) end, PAGESIZE);
    stack_bottom = ROUNDDOWN((uint8_t *) read_esp() - 1, PAGESIZE);

    while (1) {
	if ((rand() % ALLOC_SLOWDOWN) < p) {
	    if (heap_top == stack_bottom || sys_page_alloc(heap_top) < 0)
		break;
	    *heap_top = p;	/* check we have write access to new page */
	    heap_top += PAGESIZE;
	}
	sys_yield();
    }

    // After running out of memory, do nothing forever
    while (1)
	sys_yield();
}
コード例 #17
0
ファイル: smbcontrol.c プロジェクト: gojdic/samba
static bool do_winbind_onlinestatus(struct messaging_context *msg_ctx,
				    const struct server_id pid,
				    const int argc, const char **argv)
{
	struct server_id myid;

	myid = pid_to_procid(sys_getpid());

	if (argc != 1) {
		fprintf(stderr, "Usage: smbcontrol winbindd onlinestatus\n");
		return False;
	}

	messaging_register(msg_ctx, NULL, MSG_WINBIND_ONLINESTATUS,
			   print_pid_string_cb);

	if (!send_message(msg_ctx, pid, MSG_WINBIND_ONLINESTATUS, &myid,
			  sizeof(myid)))
		return False;

	wait_replies(msg_ctx, procid_to_pid(&pid) == 0);

	/* No replies were received within the timeout period */

	if (num_replies == 0)
		printf("No replies received\n");

	messaging_deregister(msg_ctx, MSG_WINBIND_ONLINESTATUS, NULL);

	return num_replies;
}
コード例 #18
0
ファイル: smbcontrol.c プロジェクト: gojdic/samba
static bool do_winbind_validate_cache(struct messaging_context *msg_ctx,
				      const struct server_id pid,
				      const int argc, const char **argv)
{
	struct server_id myid = pid_to_procid(sys_getpid());

	if (argc != 1) {
		fprintf(stderr, "Usage: smbcontrol winbindd validate-cache\n");
		return False;
	}

	messaging_register(msg_ctx, NULL, MSG_WINBIND_VALIDATE_CACHE,
			   winbind_validate_cache_cb);

	if (!send_message(msg_ctx, pid, MSG_WINBIND_VALIDATE_CACHE, &myid,
			  sizeof(myid))) {
		return False;
	}

	wait_replies(msg_ctx, procid_to_pid(&pid) == 0);

	if (num_replies == 0) {
		printf("No replies received\n");
	}

	messaging_deregister(msg_ctx, MSG_WINBIND_VALIDATE_CACHE, NULL);

	return num_replies;
}
コード例 #19
0
// P2 - setting priority
int
sys_setpri(void)
{
  //return -10;
  int num = -1;
  argint(0, &num);
  //return num;

  if ((num != 1) && (num != 2)) {
    return -1;
  }

  int pid = sys_getpid();
  struct proc *p;

  //return NPROC;

  acquire(&ptable.lock);
  for (p = ptable.proc; p < &ptable.proc[NPROC]; p++) {
    if (p -> pid == pid) {
      if (p -> priority != num) {
	p -> priority = num;
	break;
      }
    }
  }
  release(&ptable.lock);
  return 0;
}
コード例 #20
0
ファイル: fault.c プロジェクト: livebox/livebox2
/*******************************************************************
report a fault
********************************************************************/
static void fault_report(int sig)
{
	static int counter;

	if (counter) _exit(1);

	counter++;

	DEBUG(0,("===============================================================\n"));
	DEBUG(0,("INTERNAL ERROR: Signal %d in pid %d (%s)",sig,(int)sys_getpid(),VERSION));
	DEBUG(0,("\nPlease read the file BUGS.txt in the distribution\n"));
	DEBUG(0,("===============================================================\n"));
  
	smb_panic("internal error");

	if (cont_fn) {
		cont_fn(NULL);
#ifdef SIGSEGV
		CatchSignal(SIGSEGV,SIGNAL_CAST SIG_DFL);
#endif
#ifdef SIGBUS
		CatchSignal(SIGBUS,SIGNAL_CAST SIG_DFL);
#endif
		return; /* this should cause a core dump */
	}
	exit(1);
}
コード例 #21
0
/*****************************************************************************
 函 数 名  : trace_counter
 功能描述  : Add log with the "counter format" to trace_marker which will
             be dumped by systrace.
 输入参数  : 无
 输出参数  : 无
 返 回 值  :
 调用函数  :
 被调函数  :

 修改历史      :
  1.日    期   : 2014年5月29日
    作    者   : shiwanglai
    修改内容   : 新生成函数

*****************************************************************************/
void trace_counter(int tag, const char*name, int value)
{
    char buf[MAX_LEN];

    snprintf(buf, MAX_LEN, "C|%ld|%s|%d", sys_getpid(), name, value);
    trace_printk(buf);

}
コード例 #22
0
/*****************************************************************************
 函 数 名  : trace_begin
 功能描述  : Add log with the "begin format" to trace_marker which will
             be dumped by systrace.
 输入参数  : i
 输出参数  : 无
 返 回 值  : i
 调用函数  :
 被调函数  :

 修改历史      :
  1.日    期   : 2014年5月29日
    作    者   : shiwanglai
    修改内容   : 新生成函数

*****************************************************************************/
void trace_begin(int tag, const char* name)
{
    char buf[MAX_LEN];

    snprintf(buf, MAX_LEN, "B|%ld|%s", sys_getpid(), name);
    trace_printk(buf);

}
コード例 #23
0
ファイル: mutex.c プロジェクト: forhappy/libloader
sigset_t
xmutex_lock(struct xmutex * lock)
{
	TRACE(MUTEX, "thread %d:%d is locking %p\n",
			sys_getpid(), sys_gettid(), lock);
	int c;
	sigset_t sigset = block_signals();
	if ((c = atomic_cmpxchg(&lock->val, 0, 1)) != 0) {
		do {
			if (c == 2 || atomic_cmpxchg(&lock->val, 1, 2) != 0)
				futex_wait(&lock->val, 2);
		} while ((c = atomic_cmpxchg(&lock->val, 0, 2)) != 0);
	}
	TRACE(MUTEX, "thread %d:%d gained lock %p\n",
			sys_getpid(), sys_gettid(), lock);
	return sigset;
}
コード例 #24
0
ファイル: secrets.c プロジェクト: srimalik/samba
/**
 * Use a TDB to store an incrementing random seed.
 *
 * Initialised to the current pid, the very first time Samba starts,
 * and incremented by one each time it is needed.
 *
 * @note Not called by systems with a working /dev/urandom.
 */
static void get_rand_seed(void *userdata, int *new_seed)
{
	*new_seed = sys_getpid();
	if (db_ctx) {
		dbwrap_trans_change_int32_atomic(db_ctx, "INFO/random_seed",
						 new_seed, 1);
	}
}
コード例 #25
0
void
pmain(void)
{
	volatile int checker = 30; /* This variable checks for some common
				      stack errors. */
	pid_t p;
	int i, status;

	app_printf("About to start a new process...\n");

	p = sys_fork();
	if (p == 0) {
		// Check that the kernel correctly copied the parent's stack.
		check(checker, 30, "new child");
		checker = 30 + sys_getpid();

		// Yield several times to help test Exercise 3
		app_printf("Child process %d!\n", sys_getpid());
		for (i = 0; i < 20; i++)
			sys_yield();

		// Check that no one else corrupted our stack.
		check(checker, 30 + sys_getpid(), "end child");
		sys_exit(1000);

	} else if (p > 0) {
		// Check that the child didn't corrupt our stack.
		check(checker, 30, "main parent");

		app_printf("Main process %d!\n", sys_getpid());
		do {
			status = sys_wait(p);
		} while (status == WAIT_TRYAGAIN);
		app_printf("Child %d exited with status %d!\n", p, status);
		check(status, 1000, "sys_wait for child");

		// Check again that the child didn't corrupt our stack.
		check(checker, 30, "end parent");
		sys_exit(0);

	} else {
		app_printf("Error!\n");
		sys_exit(1);
	}
}
コード例 #26
0
ファイル: pidfile.c プロジェクト: WiseMan787/ralink_sdk
/* create a pid file in the pid directory. open it and leave it locked */
void pidfile_create(const char *program_name)
{
	int     fd;
	char    buf[20];
	char    *short_configfile;
	pstring name;
	pstring pidFile;
	pid_t pid;

	/* Add a suffix to the program name if this is a process with a
	 * none default configuration file name. */
	if (strcmp( CONFIGFILE, dyn_CONFIGFILE) == 0) {
		strncpy( name, program_name, sizeof( name)-1);
	} else {
		short_configfile = strrchr( dyn_CONFIGFILE, '/');
		if (short_configfile == NULL) {
			/* conf file in current directory */
			short_configfile = dyn_CONFIGFILE;
		} else {
			/* full/relative path provided */
			short_configfile++;
		}
		slprintf( name, sizeof( name)-1, "%s-%s", program_name,
			  short_configfile );
	}

	slprintf(pidFile, sizeof(pidFile)-1, "%s/%s.pid", lp_piddir(), name);

	pid = pidfile_pid(name);
	if (pid != 0) {
		DEBUG(0,("ERROR: %s is already running. File %s exists and process id %d is running.\n", 
			 name, pidFile, (int)pid));
		exit(1);
	}

	fd = sys_open(pidFile, O_NONBLOCK | O_CREAT | O_WRONLY | O_EXCL, 0644);
	if (fd == -1) {
		DEBUG(0,("ERROR: can't open %s: Error was %s\n", pidFile, 
			 strerror(errno)));
		exit(1);
	}

	if (fcntl_lock(fd,SMB_F_SETLK,0,1,F_WRLCK)==False) {
		DEBUG(0,("ERROR: %s : fcntl lock of file %s failed. Error was %s\n",  
              name, pidFile, strerror(errno)));
		exit(1);
	}

	memset(buf, 0, sizeof(buf));
	slprintf(buf, sizeof(buf) - 1, "%u\n", (unsigned int) sys_getpid());
	if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf)) {
		DEBUG(0,("ERROR: can't write to file %s: %s\n", 
			 pidFile, strerror(errno)));
		exit(1);
	}
	/* Leave pid file open & locked for the duration... */
}
コード例 #27
0
int mutex_trylock(mutex_t* mtx) {
	if(unlikely(!mtx))
		return E_ERR;

	if(mtx->owner != sys_getpid()) {
		if(spinlock_trylock(&mtx->lock) == E_ERR)
			return E_ERR;

		mtx->owner = sys_getpid();
		mtx->recursion = 0;
	} else if(mtx->kind == MTX_KIND_ERRORCHECK)
		return E_ERR;

	if(mtx->kind == MTX_KIND_RECURSIVE)
		mtx->recursion += 1;

	return E_OK;
}
コード例 #28
0
static BOOL irix_oplocks_available(void)
{
	int fd;
	int pfd[2];
	pstring tmpname;

	set_effective_capability(KERNEL_OPLOCK_CAPABILITY);

	slprintf(tmpname,sizeof(tmpname)-1, "%s/koplock.%d", lp_lockdir(),
		 (int)sys_getpid());

	if(pipe(pfd) != 0) {
		DEBUG(0,("check_kernel_oplocks: Unable to create pipe. Error "
			 "was %s\n",
			 strerror(errno) ));
		return False;
	}

	if((fd = sys_open(tmpname, O_RDWR|O_CREAT|O_EXCL|O_TRUNC, 0600)) < 0) {
		DEBUG(0,("check_kernel_oplocks: Unable to open temp test file "
			 "%s. Error was %s\n",
			 tmpname, strerror(errno) ));
		unlink( tmpname );
		close(pfd[0]);
		close(pfd[1]);
		return False;
	}

	unlink(tmpname);

	if(sys_fcntl_long(fd, F_OPLKREG, pfd[1]) == -1) {
		DEBUG(0,("check_kernel_oplocks: Kernel oplocks are not "
			 "available on this machine. Disabling kernel oplock "
			 "support.\n" ));
		close(pfd[0]);
		close(pfd[1]);
		close(fd);
		return False;
	}

	if(sys_fcntl_long(fd, F_OPLKACK, OP_REVOKE) < 0 ) {
		DEBUG(0,("check_kernel_oplocks: Error when removing kernel "
			 "oplock. Error was %s. Disabling kernel oplock "
			 "support.\n", strerror(errno) ));
		close(pfd[0]);
		close(pfd[1]);
		close(fd);
		return False;
	}

	close(pfd[0]);
	close(pfd[1]);
	close(fd);

	return True;
}
コード例 #29
0
ファイル: debug.c プロジェクト: jophxy/samba
BOOL dbghdr( int level, const char *file, const char *func, int line )
{
  /* Ensure we don't lose any real errno value. */
  int old_errno = errno;

  if( format_pos ) {
    /* This is a fudge.  If there is stuff sitting in the format_bufr, then
     * the *right* thing to do is to call
     *   format_debug_text( "\n" );
     * to write the remainder, and then proceed with the new header.
     * Unfortunately, there are several places in the code at which
     * the DEBUG() macro is used to build partial lines.  That in mind,
     * we'll work under the assumption that an incomplete line indicates
     * that a new header is *not* desired.
     */
    return( True );
  }

#ifdef WITH_SYSLOG
  /* Set syslog_level. */
  syslog_level = level;
#endif

  /* Don't print a header if we're logging to stdout. */
  if( stdout_logging )
    return( True );

  /* Print the header if timestamps are turned on.  If parameters are
   * not yet loaded, then default to timestamps on.
   */
  if( lp_timestamp_logs() || !(lp_loaded()) ) {
    char header_str[200];

	header_str[0] = '\0';

	if( lp_debug_pid())
	  slprintf(header_str,sizeof(header_str)-1,", pid=%u",(unsigned int)sys_getpid());

	if( lp_debug_uid()) {
      size_t hs_len = strlen(header_str);
	  slprintf(header_str + hs_len,
               sizeof(header_str) - 1 - hs_len,
			   ", effective(%u, %u), real(%u, %u)",
               (unsigned int)geteuid(), (unsigned int)getegid(),
			   (unsigned int)getuid(), (unsigned int)getgid()); 
	}
  
    /* Print it all out at once to prevent split syslog output. */
    (void)Debug1( "[%s, %d%s] %s:%s(%d)\n",
                  timestring(lp_debug_hires_timestamp()), level,
				  header_str, file, func, line );
  }

  errno = old_errno;
  return( True );
}
コード例 #30
0
ファイル: locking.c プロジェクト: livebox/livebox2
static NTSTATUS do_lock(files_struct *fsp,connection_struct *conn, uint16 lock_pid,
		 SMB_BIG_UINT count,SMB_BIG_UINT offset,enum brl_type lock_type)
{
	NTSTATUS status;

	if (!lp_locking(SNUM(conn)))
		return NT_STATUS_OK;

	/* NOTE! 0 byte long ranges ARE allowed and should be stored  */


	DEBUG(10,("do_lock: lock type %s start=%.0f len=%.0f requested for file %s\n",
		  lock_type_name(lock_type), (double)offset, (double)count, fsp->fsp_name ));

	if (OPEN_FSP(fsp) && fsp->can_lock && (fsp->conn == conn)) {
		status = brl_lock(fsp->dev, fsp->inode, fsp->fnum,
				  lock_pid, sys_getpid(), conn->cnum,
				  offset, count,
				  lock_type);

		if (NT_STATUS_IS_OK(status) && lp_posix_locking(SNUM(conn))) {

			/*
			 * Try and get a POSIX lock on this range.
			 * Note that this is ok if it is a read lock
			 * overlapping on a different fd. JRA.
			 */

			if (!set_posix_lock(fsp, offset, count, lock_type)) {
				status = NT_STATUS_LOCK_NOT_GRANTED;
				/*
				 * We failed to map - we must now remove the brl
				 * lock entry.
				 */
				(void)brl_unlock(fsp->dev, fsp->inode, fsp->fnum,
								lock_pid, sys_getpid(), conn->cnum,
								offset, count, False);
			}
		}
	}

	return status;
}