Beispiel #1
0
static void lock_callback(int mode, int type, const char* file, int line)
{
  if (mode & 0x01 /* CRYPTO_LOCK from openssl/crypto.h */ )
    getlock(type)->lock();
  else
    getlock(type)->unlock();
}
Beispiel #2
0
int main(void) {
    int fd;

    /* set up a file to lock */
    fd = open("testlockfile", O_RDWR | O_CREAT, 0666);
    if (fd < 0) {
        perror("open");
        return 1;
    }

    printf("getting read lock\n");
    getlock(fd, F_RDLCK);
    printf("got read lock\n");

    waitforuser("\npress <return> to continue:");
    
    printf("releasing lock\n");
    getlock(fd, F_UNLCK);

    printf("getting write lock\n");
    getlock(fd, F_WRLCK);
    printf("got write lock\n");

    waitforuser("\npress <return> to exit:");

    /* locks are released when the file is closed */

    return 0;
}
Beispiel #3
0
/** Evaluate a lock.
 * Evaluate lock ltype on thing for player.
 * \param player dbref attempting to pass the lock.
 * \param thing object containing the lock.
 * \param ltype type of lock to check.
 * \retval 1 player passes the lock.
 * \retval 0 player does not pass the lock.
 */
int
eval_lock(dbref player, dbref thing, lock_type ltype)
{
  boolexp b = getlock(thing, ltype);
  log_activity(LA_LOCK, thing, unparse_boolexp(player, b, UB_DBREF));
  if(Pass_Lock(player, thing) && IS_passlock_type(ltype))
    return 1;
  return eval_boolexp(player, getlock(thing, ltype), thing, NULL);
}
Beispiel #4
0
/** Check to see if an object has a good zone lock set.
 * If it doesn't have a lock at all, set one of '=Zone'.
 * \param player The object responsible for having the lock checked.
 * \param zone the object whose lock needs to be checked.
 * \param noisy if 1, notify player of automatic locking
 */
void
check_zone_lock(dbref player, dbref zone, int noisy)
{
  boolexp key = getlock(zone, Zone_Lock);
  if (key == TRUE_BOOLEXP) {
    add_lock(GOD, zone, Zone_Lock, parse_boolexp(zone, "=me", Zone_Lock), -1);
    if (noisy)
      notify_format(player,
                    T
                    ("Unlocked zone %s - automatically zone-locking to itself"),
                    unparse_object(player, zone));
  } else if (eval_lock(Location(player), zone, Zone_Lock)) {
    /* Does #0 and #2 pass it? If so, probably trivial elock */
    if (eval_lock(PLAYER_START, zone, Zone_Lock) &&
        eval_lock(MASTER_ROOM, zone, Zone_Lock)) {
      if (noisy)
        notify_format(player,
                      T("Zone %s really should have a more secure zone-lock."),
                      unparse_object(player, zone));
    } else                      /* Probably inexact zone lock */
      notify_format(player,
                    T
                    ("Warning: Zone %s may have loose zone lock. Lock zones to =player, not player"),
                    unparse_object(player, zone));
  }
}
Beispiel #5
0
/** Evaluate a lock.
 * Evaluate lock ltype on thing for player, passing dbrefs for %0/%1.
 * \param player dbref attempting to pass the lock.
 * \param thing object containing the lock.
 * \param ltype type of lock to check.
 * \retval 1 player passes the lock.
 * \retval 0 player does not pass the lock.
 */
int
eval_lock_with(dbref player, dbref thing, lock_type ltype, dbref env0,
	       dbref env1)
{
  char *myenv[10] = { NULL };
  char e0[SBUF_LEN], e1[SBUF_LEN], *ep;
  char *preserves[10];
  int result;

  if (env0 != NOTHING) {
    ep = e0;
    safe_dbref(env0, e0, &ep);
    *ep = '\0';
    myenv[0] = e0;
  }

  if (env1 != NOTHING) {
    ep = e1;
    safe_dbref(env1, e1, &ep);
    *ep = '\0';
    myenv[1] = e1;
  }

  save_global_env("eval_lock_save", preserves);
  restore_global_env("eval_lock", myenv);

  boolexp b = getlock(thing, ltype);
  log_activity(LA_LOCK, thing, unparse_boolexp(player, b, UB_DBREF));
  result = eval_boolexp(player, b, thing, NULL);
  restore_global_env("eval_lock_save", preserves);
  return result;
}
Beispiel #6
0
/** Unlock a lock (user interface).
 * \verbatim
 * This implements @unlock.
 * \endverbatim
 * \param player the enactor.
 * \param name name of object to unlock.
 * \param type type of lock to unlock.
 */
void
do_unlock(dbref player, const char *name, lock_type type)
{
  dbref thing;
  char *sp;
  lock_type real_type;

  /* check for '@unlock <object>/<atr>'  */
  sp = strchr(name, '/');
  if (sp) {
    notify(player, "Use @atrlock.");
    return;
  }
  if ((thing = match_controlled(player, name)) != NOTHING) {
    if ((real_type = check_lock_type(player, thing, type)) != NULL) {
      if (getlock(thing, real_type) == TRUE_BOOLEXP) {
        if (!AreQuiet(player, thing))
          notify_format(player, T("%s(%s) - %s (already) unlocked."),
                        Name(thing), unparse_dbref(thing), real_type);
      } else if (delete_lock(player, thing, real_type)) {
        if (!AreQuiet(player, thing))
          notify_format(player, T("%s(%s) - %s unlocked."), Name(thing),
                        unparse_dbref(thing), real_type);
        if (!IsPlayer(thing)) {
          char lmbuf[1024];
          ModTime(thing) = mudtime;
          snprintf(lmbuf, 1023, "%s lock[#%d]", real_type, player);
          lmbuf[strlen(lmbuf)+1] = '\0';
          set_lmod(thing, lmbuf);
        }
      } else
        notify(player, T("Permission denied."));
    }
  }
}
Beispiel #7
0
static Whist*
readwhist(char *file, char *lock, Qid *qid)
{
	int lfd;
	Biobuf *b;
	Dir *d;
	Whist *wh;

	if((lfd=getlock(lock)) < 0)	// LOG?
		return nil;

	if(qid){
		if((d = wdirstat(file)) == nil){
			close(lfd);
			return nil;
		}
		*qid = d->qid;
		free(d);
	}

	if((b = wBopen(file, OREAD)) == nil){	//LOG?
		close(lfd);
		return nil;
	}

	wh = Brdwhist(b);

	Bterm(b);
	close(lfd);
	return wh;
}
Beispiel #8
0
//
// send statusbyte to microHam device
//
static void writeFlags()
{
    unsigned char seq[4];
    int ret;

    DEBUG("%10d:Sending FlagByte: %02x\n", TIME, statusbyte);
    getlock();
    seq[0] = 0x08;

    if (statusbyte & 0x80)
    {
        seq[0] = 0x09;
    }

    seq[1] = 0x80;
    seq[2] = 0x80;
    seq[3] = 0x80 | statusbyte;

    if ((ret = write(uh_device_fd, seq, 4)) < 4)
    {
        MYERROR("WriteFlags failed with %d\n", ret);

        if (ret < 0)
        {
            perror("WriteFlagsError:");
        }
    }

    freelock();
}
Beispiel #9
0
static int linopen(Aflinst *t)
{
	afprintv(t->rq->verbose, 4, "Locking database");
	if (getlock(t->rq->db) < 0)
		return -1;

	afprintv(t->rq->verbose, 4, "Opening database files");
	if (openfiles(t->rq->db, &(t->f)) < 0)
		return -1;

	afprintv(t->rq->verbose, 4, "Reading database information");
	if (afreadinfo(t->f.info, &(t->info)) < 0)
		return -1;

	afprintv(t->rq->verbose, 4, "Checking file sizes");
	if (getfsizes(t) < 0)
		return -1;

	if (!t->rq->nobuffer) {
		if (aflinbuf(t->f.upost, t->rq->memory) < 0)
			return -1;
	}

	return 0;
}
Beispiel #10
0
/** Unlock a lock (user interface).
 * \verbatim
 * This implements @unlock.
 * \endverbatim
 * \param player the enactor.
 * \param name name of object to unlock.
 * \param type type of lock to unlock.
 */
void
do_unlock(dbref player, const char *name, lock_type type)
{
  dbref thing;
  lock_type real_type;

  /* check for '@unlock <object>/<atr>'  */
  if (strchr(name, '/')) {
    do_atrlock(player, name, "off");
    return;
  }
  if ((thing = match_controlled(player, name)) != NOTHING) {
    if ((real_type = check_lock_type(player, thing, type)) != NULL) {
      if (getlock(thing, real_type) == TRUE_BOOLEXP) {
        if (!AreQuiet(player, thing))
          notify_format(player, T("%s(%s) - %s (already) unlocked."),
                        AName(thing, AN_SYS, NULL), unparse_dbref(thing),
                        real_type);
      } else if (delete_lock(player, thing, real_type)) {
        if (!AreQuiet(player, thing))
          notify_format(player, T("%s(%s) - %s unlocked."),
                        AName(thing, AN_SYS, NULL), unparse_dbref(thing),
                        real_type);
        if (!IsPlayer(thing))
          ModTime(thing) = mudtime;
      } else
        notify(player, T("Permission denied."));
    }
  }
}
Beispiel #11
0
static int lock_collection(void)
{
    CALL(getlock(ne_lockscope_exclusive, NE_DEPTH_INFINITE));
    /* change res to point to a normal resource for subsequent
     * {not_,}owner_modify tests */
    res = ne_concat(coll, "lockme.txt", NULL);
    return upload_foo("lockcoll/lockme.txt");
}
Beispiel #12
0
/** Evaluate a lock.
 * Evaluate lock ltype on thing for player.
 * \param player dbref attempting to pass the lock.
 * \param thing object containing the lock.
 * \param ltype type of lock to check.
 * \param pe_info the pe_info to use when evaluating softcode in the lock
 * \retval 1 player passes the lock.
 * \retval 0 player does not pass the lock.
 */
int
eval_lock_with(dbref player, dbref thing, lock_type ltype, NEW_PE_INFO *pe_info)
{
  boolexp b = getlock(thing, ltype);
  /* Prevent overwriting a static buffer in unparse_boolexp() */
  if (!unparsing_boolexp)
    log_activity(LA_LOCK, thing, unparse_boolexp(player, b, UB_DBREF));
  return eval_boolexp(player, b, thing, pe_info);
}
Beispiel #13
0
//
// Write a control string to the microHam device
//
static void writeControl(unsigned char *data, int len)
{
    int i, ret;
    unsigned char seq[8];

    DEBUG("%10d:WriteControl:", TIME);

    for (i = 0; i < len; i++) { DEBUG(" %02x", data[i]); }

    DEBUG(".\n");
    // Control data is in the second frame of a sequence,
    // So send a no-op first. Include statusbyte in first frame.
    // First and last byte of the control message is NOT marked "valid"
    getlock();

    for (i = 0; i < len; i++)
    {
        // encode statusbyte in first frame
        seq[0] = 0x08;
        seq[1] = 0x80;
        seq[2] = 0x80;
        seq[3] = 0x80 | statusbyte;
        seq[4] = 0x48; // marked valid
        seq[5] = 0x80;
        seq[6] = 0x80;
        seq[7] = 0x80 | data[i];

        if (statusbyte & 0x80)
        {
            seq[0] |= 1;
        }

        if (i == 0 || i == len - 1)
        {
            seq[4] = 0x40; // un-mark valid
        }

        if (data[i] & 0x80)
        {
            seq[4] |= 0x01;
        }

        if ((ret = write(uh_device_fd, seq, 8)) < 8)
        {
            MYERROR("WriteControl failed, ret=%d\n", ret);

            if (ret < 0)
            {
                perror("WriteControlError:");
            }
        }
    }

    freelock();
}
Beispiel #14
0
kern_obj * spawn_process(const uchar * cd, ulong csz, ulong dsz, ulong bsz, kern_obj * par, uchar priv, uchar priority)
{
	ulong i, pbase, ssz, absz, pgs;
	kern_obj * proc = alloc_kobj();
	
	ssz = csz + dsz;
	absz = bsz;

	if (csz % 0x1000 != 0) csz = csz - (csz % 0x1000) + 0x1000;
	if (dsz % 0x1000 != 0) dsz = dsz - (dsz % 0x1000) + 0x1000;
	if (bsz % 0x1000 != 0) bsz = bsz - (bsz % 0x1000) + 0x1000;

	proc->type = KOBJ_PROCESS;
	proc->u.proc.parent = par;
	proc->u.proc.priv = priv;
	proc->u.proc.priority = priority;
	
	proc->u.proc.code_data_ws = alloc_ws();
	
	pgs = csz / 0x1000 + dsz / 0x1000 + bsz / 0x1000;
	pbase = alloc_pages(pgs + 0x200, PHYS_PAGES);
	if (pbase == 0) {
		free_kobj(proc);
		return NULL;
	}

	add_pgs_to_ws(proc->u.proc.code_data_ws, USPACE_BOT, pbase, csz + dsz + bsz + 0x200000, 7);

	for (i = 0; i < ssz + absz; i++) {
		if (i % 0x1000 == 0) {
			ATQ(KPT0_0_LOC) = (pbase + i) | 3;
			INVLPG(KSPACE_LOC);
		}
		if (i < ssz) ATB(KSPACE_LOC + i % 0x1000) = cd[i];
		else ATB(KSPACE_LOC + i % 0x1000) = 0;
	}

	if (spawn_thread(proc, (int (*)())USPACE_BOT) == NULL) {
		free_kobj(proc);
		free_pages(pbase, pgs, PHYS_PAGES);
		return NULL;
	}

	getlock(&procthrd_lock, 0);
	if (head_process == NULL) {
		proc->u.proc.next = proc;
		head_process = proc;
	} else {
		proc->u.proc.next = head_process->u.proc.next;
		head_process->u.proc.next = proc;
	}
	unlock(&procthrd_lock, 0);
	
	return proc;
}
Beispiel #15
0
static void
addtolist(char *dev)
{
	int	lckfd, fd;
	FILE	*fp, *nfp;
	char	newfile[MAXPATHLEN];
	char	buf[MAXPATHLEN];
	int	len;
	boolean_t	found = B_FALSE;

	/* update file of devices configured to get console msgs. */

	lckfd = getlock();

	/* Open new file */
	(void) snprintf(newfile, sizeof (newfile), "%s%d",
	    CONSCONFIG, (int)getpid());
	if (((fd = creat(newfile, 0644)) < 0) ||
	    ((nfp = fdopen(fd, "w")) == NULL)) {
		(void) close(lckfd);
		(void) unlink(CONSADMLOCK);
		die(gettext("could not create new %s file"), CONSCONFIG);
	}

	/* Add header to new file */
	(void) fprintf(nfp, "%s", conshdr);

	/* Check that the file doesn't already exist */
	if ((fp = fopen(CONSCONFIG, "r")) != NULL) {
		while (fgets(buf, MAXPATHLEN, fp) != NULL) {
			if (buf[0] == COMMENT || buf[0] == NEWLINE ||
			    buf[0] == SPACE || buf[0] == TAB)
				continue;
			len = strlen(buf);
			buf[len - 1] = NULL; /* Clear carriage return */
			if (pathcmp(dev, buf) == 0) {
				/* they match so use name passed in. */
				(void) fprintf(nfp, "%s\n", dev);
				found = B_TRUE;
			} else
				(void) fprintf(nfp, "%s\n", buf);
		}
	}
	/* User specified persistent settings */
	if (found == B_FALSE)
		(void) fprintf(nfp, "%s\n", dev);

	(void) fclose(fp);
	(void) fclose(nfp);
	(void) rename(newfile, CONSCONFIG);
	(void) close(lckfd);
	(void) unlink(CONSADMLOCK);
}
Beispiel #16
0
//
// Send bytes to the WinKeyer within microHam device
//
static void writeWkey(unsigned char *bytes, int len)
{
    unsigned char seq[12];
    int i, ret;
    DEBUG("%10d:Send WinKey data: ", TIME);

    for (i = 0; i < len; i++) { DEBUG(" %02x", (int) bytes[i]); }

    DEBUG(".\n");
    // Winkey data is in the third frame of a sequence,
    // So send two no-ops first. Include statusbyte in first frame
    getlock();

    for (i = 0; i < len; i++)
    {
        seq[ 0] = 0x08;
        seq[ 1] = 0x80;
        seq[ 2] = 0x80;
        seq[ 3] = 0X80 | statusbyte;
        seq[ 4] = 0x40;
        seq[ 5] = 0x80;
        seq[ 6] = 0x80;
        seq[ 7] = 0x80;
        seq[ 8] = 0x48;
        seq[ 9] = 0x80;
        seq[10] = 0x80;
        seq[11] = 0x80 | bytes[i];

        if (statusbyte & 0x80)
        {
            seq[ 0] |= 0x01;
        }

        if (bytes[i]   & 0x80)
        {
            seq[ 8] |= 0x01;
        }

        if ((ret = write(uh_device_fd, seq, 12)) < 12)
        {
            MYERROR("WriteWINKEY failed with %d\n", ret);

            if (ret < 0)
            {
                perror("WriteWinkeyError:");
            }
        }
    }

    freelock();
}
Beispiel #17
0
void *
nlm4_lock_msg_4_svc(nlm4_lockargs *arg, struct svc_req *rqstp)
{
	static nlm4_res result;

	if (debug_level)
		log_from_addr("nlm4_lock_msg", rqstp);

	result.cookie = arg->cookie;
	result.stat.stat = getlock(arg, rqstp, LOCK_MON | LOCK_ASYNC | LOCK_V4);
	transmit4_result(NLM4_LOCK_RES, &result, svc_getcaller(rqstp->rq_xprt));

	return NULL;
}
Beispiel #18
0
/*
 * Purposes:	Establish a lock
 * Returns:	granted, denied or blocked
 * Notes:	*** grace period support missing
 */
nlm4_res *
nlm4_lock_4_svc(nlm4_lockargs *arg, struct svc_req *rqstp)
{
	static nlm4_res result;

	if (debug_level)
		log_from_addr("nlm4_lock", rqstp);

	/* copy cookie from arg to result.  See comment in nlm_test_4() */
	result.cookie = arg->cookie;

	result.stat.stat = getlock(arg, rqstp, LOCK_MON | LOCK_V4);
	return &result;
}
Beispiel #19
0
static int lock_collection(void)
{
    struct ne_lock dummy;
    char *tmp,*tmp2;
    
    CALL(getlock(ne_lockscope_exclusive, NE_DEPTH_INFINITE));
    
    PRECOND(gotlock);

    memcpy(&dummy, &reslock, sizeof(reslock));
    dummy.token = NULL;
    dummy.uri.path = collZ;
    dummy.owner = ne_strdup("litmus: owner lock");
    dummy.depth = NE_DEPTH_INFINITE;
    dummy.type = ne_locktype_write;
    dummy.scope = ne_lockscope_exclusive;
    
    ONNREQ2("LOCK on second collection for further tests", 
	    ne_lock(i_session, &dummy));
    gotlock = ne_lock_copy(&dummy);
    ne_lockstore_add(store, gotlock);

    /* Testing creation of directories under a collection */ 
    ONV(ne_mkcol(i_session, collX),
        ("MKCOL %s: %s", collX, ne_get_error(i_session)));
    ONV(ne_mkcol(i_session, collY),
        ("MKCOL %s: %s", collY, ne_get_error(i_session)));

    upload_foo("lockcoll/collX/temp");
    tmp = ne_concat(collY,"copy-temp",NULL);	
    ONV(ne_copy(i_session, 0, NE_DEPTH_INFINITE, res3,tmp),
	("collection COPY `%s' to `%s': %s", res2, tmp,
	 ne_get_error(i_session)));
    free(tmp);
    
    tmp2=ne_concat(collZ,"testing",NULL);
    ONV(ne_copy(i_session, 0, NE_DEPTH_INFINITE, res3,tmp2),
	("collection COPY `%s' to `%s': %s", res2, tmp2,
	 ne_get_error(i_session)));

    ne_free(res3);	
    res3 = ne_concat(i_path,"not-existing",NULL);

 
    /* change res to point to a normal resource for subsequent
     * {not_,}owner_modify tests */
    res = ne_concat(coll, "lockme.txt", NULL);
    return upload_foo("lockcoll/lockme.txt");
}
Beispiel #20
0
void *preenche2B (void *p2B)
{
	int l,c;
	for (l=0;l<LB;l++)
		for (c=0;c<CB;c++)
			while(getlock(&lk));
			if(B[l][c]==0)
			{
				B[l][c]=2;
				printf("P2B= B[%d][%d]=%d\n",l,c,B[l][c]);
				unlock(&lk);
				delay(100);
			}
	return NULL;
}
Beispiel #21
0
void *preenche1A (void *p1A)
{
	int l,c;
	for(l=0;l<LA;l++)
		for(c=0;c<CA;c++)
			while (getlock(&lk));
			if (A[l][c]==0)
			{
				A[l][c]=1;
				printf("P1A= A[%d][%d]=%d\n",l,c,A[l][c]);
				unlock(&lk);
				delay(10);
			}
			
	return NULL;
}
Beispiel #22
0
void *preenche2A (void *p2A)
{
	int l,c;
	for(l=0;l<LA;l++)
		for(c=0;c<CA;c++)
			while(getlock(&lk)); // falta ponto-e-virgula!!!
			if(A[l][c]==0)
			{
				A[l][c]=2;
				printf("P2A= A[%d][%d]=%d\n",l,c,A[l][c]);
				unlock(&lk);
				delay(10);
			}
			else;
			
	return NULL;
}
Beispiel #23
0
void *multiplica2 (void *m2)
{
	int c,i,m,n;
	c=CB;
	for(m=0;m<LA;m++)
		for(n=0;n<CB;n++)
			for(i=0;i<c;i++)
				while(getlock(&lk));
				if(C[m][n]==0)
				{
					C[m][n]+=((A[m][i])*(B[i][n]));
					printf("M2= C[%d][%d]=%d\n",m,n,C[m][n]);
					unlock(&lk);
					delay(10);
				}
	return NULL;
}
Beispiel #24
0
kern_obj * spawn_thread(kern_obj * proc, int (*func)())
{
	ulong fl, pg;
	kern_obj * thrd = alloc_kobj();

	thrd->type = KOBJ_THREAD;
	thrd->u.thrd.proc = proc;
	
	thrd->u.thrd.sub = alloc_kobj();
	thrd->u.thrd.sub->type = KOBJ_THREAD_SUB;
	thrd->u.thrd.sub->u.thrd2.stack_ws = alloc_ws();

	pg = alloc_pages(2, PHYS_PAGES);
	if (pg == 0) {
		free_kobj(thrd->u.thrd.sub);
		free_kobj(thrd);
		return 0;
	}

	add_pgs_to_ws(thrd->u.thrd.sub->u.thrd2.stack_ws, USPACE_TOP - 0x2000, pg, 0x2000, 7);
	thrd->u.thrd.sub->u.thrd2.rsp = USPACE_TOP - 0x50;
	
	ATQ(KPT0_0_LOC) = (pg + 0x1000) | 3;
	INVLPG(KSPACE_LOC);	

	ATQ(KSPACE_LOC + 0xFB0) = (ulong)func;
	ATQ(KSPACE_LOC + 0xFB8) = USER_CS | 3;
	GET_FLAGS(fl);
	ATQ(KSPACE_LOC + 0xFC0) = fl;
	ATQ(KSPACE_LOC + 0xFC8) = USPACE_TOP - 0x1000;
	ATQ(KSPACE_LOC + 0xFD0) = USER_DS | 3;

	getlock(&procthrd_lock, 1);
	if (head_thread == NULL) {
		thrd->u.thrd.next = thrd;
		head_thread = thrd;
	} else {
		thrd->u.thrd.next = head_thread->u.thrd.next;
		head_thread->u.thrd.next = thrd;
	}
	unlock(&procthrd_lock, 1);

	return thrd;
}
Beispiel #25
0
/* lock on unmapped url should return 201 */
static int unmapped_lock(void)
{
    if (gotlock) {
        ne_lock_destroy(gotlock);
        gotlock = NULL;
    }
    ne_free(res);

    res = ne_concat(i_path, "unmapped_url", NULL);

    ONV(getlock(ne_lockscope_exclusive, NE_DEPTH_ZERO),
        ("LOCK on %s via %s: %s",
         coll, res, ne_get_error(i_session)));

    if (STATUS(201)) 
	t_warning("LOCK on unmapped url returned %d not 201 (RFC4918:S7.3)", GETSTATUS);

    return OK;
}
Beispiel #26
0
//
// Send radio bytes to microHam device
//
static void writeRadio(unsigned char *bytes, int len)
{
    unsigned char seq[4];
    int i, ret;

    DEBUG("%10d:Send radio data: ", TIME);

    for (i = 0; i < len; i++) { DEBUG(" %02x", (int) bytes[i]); }

    DEBUG(".\n");

    getlock();

    for (i = 0; i < len; i++)
    {
        seq[0] = 0x28;
        seq[1] = 0x80 | bytes[i];
        seq[2] = 0x80;
        seq[3] = 0X80 | statusbyte;

        if (statusbyte & 0x80)
        {
            seq[0] |= 0x01;
        }

        if (bytes[i]   & 0x80)
        {
            seq[0] |= 0x04;
        }

        if ((ret = write(uh_device_fd, seq, 4)) < 4)
        {
            MYERROR("WriteRadio failed with %d\n", ret);

            if (ret < 0)
            {
                perror("WriteRadioError:");
            }
        }
    }

    freelock();
}
Beispiel #27
0
HS_DBREF CHSInterface::GetLock(int objnum, HS_LOCKTYPE lock)
{
#ifdef PENNMUSH                 // No change in code between versions
    boolexp boolExp = getlock(objnum, Use_Lock);

    if (boolExp == TRUE_BOOLEXP)
    {
        return NOTHING;
    }
    else
    {
        return strtodbref(unparse_boolexp(objnum, boolExp, UB_DBREF));
    }
#endif

#if defined(TM3) || defined(MUX)
    char *value;
    BOOLEXP *key;
    int aowner, aflags;
    dbref lockobj;

#ifdef TM3
    int alen;
    value = atr_get((dbref) objnum, A_LUSE, &aowner, &aflags, &alen);
#else
    value = atr_get((dbref) objnum, A_LUSE, &aowner, &aflags);
#endif
    key = parse_boolexp((dbref) objnum, value, 1);
    free_lbuf(value);
    if (key == TRUE_BOOLEXP)
    {
        free_boolexp(key);
        return NOTHING;
    }
    else
    {
        lockobj = key->thing;
        free_boolexp(key);
        return lockobj;
    }
#endif
}
Beispiel #28
0
static void
setfallback(char *argv[])
{
	pid_t	pid;
	FILE	*fp;
	char	*cmd = CONSADMD;
	int	lckfd, fd;

	lckfd = getlock();

	/*
	 * kill off any existing daemon
	 * remove /etc/consadm.pid
	 */
	removefallback();

	/* kick off a daemon */
	if ((pid = fork()) == (pid_t)0) {
		/* always fallback to /dev/console */
		argv[0] = cmd;
		argv[1] = NULL;
		(void) close(0);
		(void) close(1);
		(void) close(2);
		(void) close(lckfd);
		if ((fd = open(MSGLOG, O_RDWR)) < 0)
			die(gettext("cannot open %s"), MSGLOG);
		(void) dup2(fd, 1);
		(void) dup2(fd, 2);
		(void) execv(cmd, argv);
		exit(E_SUCCESS);
	} else if (pid == -1)
		die(gettext("%s not started"), CONSADMD);

	if ((fp = fopen(SETCONSOLEPID, "w")) == NULL)
		die(gettext("cannot open %s"), SETCONSOLEPID);
	/* write daemon pid to file */
	(void) fprintf(fp, "%d\n", (int)pid);
	(void) fclose(fp);
	(void) close(lckfd);
	(void) unlink(CONSADMLOCK);
}
Beispiel #29
0
int main()
{
    int fd1, fd2;
    pid_t pid;

    fd1 = open(LOCKFILE, O_RDWR | O_CREAT, LOCKMODE);
    if (fd1 < 0)
    {
        printf("can't open %s.\n", LOCKFILE);
        exit(1);
    }

    printf("parent pid: %d.\n", getpid());
    getlock(fd1);
    getlock2(fd1);
    if ((pid = fork()) < 0)
    {   
        printf("fork error.\n");
        exit(1);
    }   
    else if (pid == 0)
    {   
        printf("child pid: %d.\n", getpid());
        fd2 = open(LOCKFILE, O_RDWR | O_CREAT, LOCKMODE);
        if (fd2 < 0)
        {
            printf("can't open %s.\n", LOCKFILE);
            exit(1);
        }
        testlock(fd1);
        getlock2(fd2);
        getlock2(fd1);
    }   
    else
    {   
        while(1)
            sleep(10);
    }   

    return 0;
}
Beispiel #30
0
/*
 * Purposes:	Establish a lock
 * Returns:	granted, denied or blocked
 * Notes:	*** grace period support missing
 */
nlm_res *
nlm_lock_1_svc(nlm_lockargs *arg, struct svc_req *rqstp)
{
	static nlm_res result;
	struct nlm4_lockargs arg4;
	nlmtonlm4(&arg->alock, &arg4.alock);
	arg4.cookie = arg->cookie;
	arg4.block = arg->block;
	arg4.exclusive = arg->exclusive;
	arg4.reclaim = arg->reclaim;
	arg4.state = arg->state;

	if (debug_level)
		log_from_addr("nlm_lock", rqstp);

	/* copy cookie from arg to result.  See comment in nlm_test_1() */
	result.cookie = arg->cookie;

	result.stat.stat = getlock(&arg4, rqstp, LOCK_MON);
	return &result;
}