Esempio n. 1
0
conerr_t
smfu_get_property(char *fmri, char *pgname, char *propname, char *value,
    size_t n)
{
	conerr_t err = ce_ok;
	scf_handle_t *scfhandle = handle_create();
	scf_service_t *service = scf_service_create(scfhandle);
	scf_instance_t *instance = scf_instance_create(scfhandle);
	scf_propertygroup_t *pg = scf_pg_create(scfhandle);
	scf_property_t *prop = scf_property_create(scfhandle);
	scf_iter_t *iter = scf_iter_create(scfhandle);
	scf_value_t *val = scf_value_create(scfhandle);

	if (scfhandle == NULL || service == NULL || instance == NULL ||
	    pg == NULL || prop == NULL || iter == NULL || val == NULL) {
		err = ce_nomem;
		goto out;
	}

	if (scf_handle_decode_fmri(scfhandle, fmri, NULL, service, instance,
	    NULL, NULL, 0) != SCF_SUCCESS) {
		rad_log(RL_ERROR, "couldn't decode '%s': %s\n", fmri,
		    scf_strerror(scf_error()));
		err = maperr(scf_error());
		goto out;
	}

	if (scf_instance_get_pg(instance, pgname, pg) != 0 ||
	    scf_pg_get_property(pg, propname, prop) != 0 ||
	    scf_iter_property_values(iter, prop) != 0) {
		rad_log(RL_ERROR, "couldn't get property: '%s/%s/%s': %s\n",
		    fmri, pgname, propname, scf_strerror(scf_error()));
		err = maperr(scf_error());
		goto out;
	}

	if (scf_iter_next_value(iter, val) > 0 &&
	    scf_value_get_as_string(val, value, n) == -1) {
		rad_log(RL_ERROR,
		    "couldn't get property value: '%s/%s/%s': %s\n", fmri,
		    pgname, propname, scf_strerror(scf_error()));
		err = maperr(scf_error());
		goto out;
	}
out:
	scf_value_destroy(val);
	scf_property_destroy(prop);
	scf_pg_destroy(pg);
	scf_iter_destroy(iter);
	scf_instance_destroy(instance);
	scf_service_destroy(service);
	scf_handle_destroy(scfhandle);

	return (err);
}
Esempio n. 2
0
/* decode semaphore error */
void
semerr(
i4 rv,
CS_SEMAPHORE *sp,
char *msg)
{
    MY_SCB *scb;
#ifdef EX_DEBUG
    EX_CONTEXT context;

    if (EXdeclare(ex_handler, &context) != OK) {
	/* some exception was raised */
	SIfprintf( stderr,"Error: unexpected exception in semerr()...");
	EXdelete();
	return;
    }
#endif

    CSget_scb( (CS_SCB **)&scb );
    SIfprintf(stderr, "%s %p returned %d (%s)\n", msg, sp, rv, maperr(rv) );
    SIfprintf(stderr, "\tPhilosopher %d, scb %p\n", scb->phil, scb );
    SIfprintf(stderr, "\t%p->cs_value %d\n", sp, sp->cs_value );
    SIfprintf(stderr, "\t%p->cs_count %d\n", sp, sp->cs_count );
    SIfprintf(stderr, "\t%p->cs_owner %x\n", sp, sp->cs_owner );
    SIfprintf(stderr, "\t%p->cs_list %p\n", sp, sp->cs_list );
    SIfprintf(stderr, "\t%p->cs_next %p\n", sp, sp->cs_next );

#ifdef EX_DEBUG
    EXdelete();
#endif
}
Esempio n. 3
0
static HANDLE audio_open(Pdev_t *pdev, int close)
{
	HANDLE ph,th,hp=pdev->DeviceOutputHandle;
	DWORD err;
	WAVEFORMATEX *wp = (WAVEFORMATEX*)(pdev+1);
	if(!load_audio())
	{
		logerr(0, "audio functions not supported");
		return(0);
	}
	if(hp && P_CP->ntpid==pdev->NtPid)
	{
		if(!close)
			return(hp);
		(*pwaveOutReset)(hp);
		(*pwaveOutClose)(hp);
	}
	else if(pdev->NtPid && (ph=OpenProcess(PROCESS_ALL_ACCESS,FALSE,(DWORD)pdev->NtPid)))
	{
		/* remotely close the wave device */
		if(th=CreateRemoteThread(ph,NULL,0,wave_close,(void*)hp,0,&err))
		{
			if(WaitForSingleObject(th,1000)!=WAIT_OBJECT_0)
				logerr(LOG_PROC+2, "WaitForSingleObject");
			closehandle(th,HT_THREAD);
		}
		else
			logerr(LOG_PROC+2, "CreateRemoteThread");
		closehandle(ph,HT_PROC);
	}
	pdev->NtPid = 0;
	if(err=(*pwaveOutOpen)((HWAVEOUT*)&hp,WAVE_MAPPER,wp,0,0,WAVE_ALLOWSYNC))
	{
		SetLastError(err);
		logerr(LOG_DEV+5, "waveOutOpen");
		errno = maperr(err);
		return 0;
	}
	pdev->opencount = 1;
	pdev->NtPid = P_CP->ntpid;
	pdev->DeviceOutputHandle = hp;
	return(hp);
}
Esempio n. 4
0
static int dsp_close(int fd, Pfd_t* fdp,int noclose)
{
	register Pdev_t *pdev = dev_ptr(fdp->devno);
	int r=0,err;

	if(P_CP->ntpid==pdev->NtPid && --pdev->opencount==0)
	{
		(*pwaveOutReset)(pdev->DeviceOutputHandle);
		if(err=(*pwaveOutClose)(pdev->DeviceOutputHandle))
		{
			SetLastError(err);
			logerr(LOG_DEV+5, "waveOutClose");
			errno = maperr(err);
			r = -1;
		}
		pdev->NtPid = 0;
	}
	if(pdev->count <= 0)
		free_dsp(pdev,noclose);
	else
		InterlockedDecrement(&pdev->count);
	return(r);
}
Esempio n. 5
0
/**
 * Parses a character map from file.
 * @param filename Name of the character map file
 * @param map 256-byte buffer where parsed map shall be stored
 * @return 0 if fail, 1 if OK
 */
int charmap_parse(const char *filename, unsigned char *map)
{
    int lineno;
    FILE *fp;
    char line[1024];
    /* Attempt to open the file */
    fp = fopen(filename, "rt");
    if (fp == NULL) {
        return 0;
    }
    /* Reset line counter */
    lineno = 0;
    /* Read mappings */
    while (fgets(line, 1023, fp) != NULL) {
        unsigned char key;
        unsigned char hkey;
        unsigned char value;
        int i;
        /* Increase line number */
        lineno++;
        /* Comment? */
        if (line[0] == '#')
            continue;
        /* Reset line index */
        i = 0;
        /* Read key */
        if (get_key(line, &i, &key) == 0) {
            maperr(filename, lineno, "key expected");
            continue;
        }
        /* Check if this is a range definition */
        if (line[i] == '-') {
            /* Eat - */
            i++;
            /* Read high key */
            if (get_key(line, &i, &hkey) == 0) {
                maperr(filename, lineno, "high limit key expected");
                continue;
            }
            /* Make sure hkey larger or equal to key */
            if (hkey < key) {
                maperr(filename, lineno, "invalid range");
                continue;
            }
        }
        else {
            hkey = key;
        }
        /* Eat whitespace */
        eat_ws(line, &i);
        /* Verify = */
        if (line[i] != '=') {
            maperr(filename, lineno, "`=' expected");
            continue;
        }
        /* Eat = */
        i++;
        /* Eat whitespace */
        eat_ws(line, &i);
        /* Make sure we've not hit end of string */
        if ((line[i] == '\0') || (line[i] == '\n')) {
            maperr(filename, lineno, "value expected");
            return 0;
        }
        /* Read value */
        value = get_value(&line[i]);
        /* Store mapping(s) */
        for (; key <= hkey; key++) {
            map[key] = value++;
        }
    }
    /* Close the file */
    fclose(fp);
    /* Success */
    return 1;
}
Esempio n. 6
0
conerr_t
smfu_set_property(char *fmri, char *pgname, char *propname, char *value)
{
	conerr_t err = ce_ok;
	scf_handle_t *scfhandle = handle_create();
	scf_service_t *service = scf_service_create(scfhandle);
	scf_instance_t *instance = scf_instance_create(scfhandle);
	scf_propertygroup_t *pg = scf_pg_create(scfhandle);
	scf_property_t *prop = scf_property_create(scfhandle);
	scf_value_t *val = scf_value_create(scfhandle);
	scf_transaction_t *tx = scf_transaction_create(scfhandle);
	scf_transaction_entry_t *ent = scf_entry_create(scfhandle);
	scf_type_t type;

	if (scfhandle == NULL || service == NULL || instance == NULL ||
	    pg == NULL || prop == NULL || tx == NULL || ent == NULL ||
	    val == NULL) {
		err = ce_nomem;
		goto out;
	}

	if (scf_handle_decode_fmri(scfhandle, fmri, NULL, service, instance,
	    NULL, NULL, 0) != SCF_SUCCESS) {
		rad_log(RL_ERROR, "couldn't decode '%s': %s\n", fmri,
		    scf_strerror(scf_error()));
		err = maperr(scf_error());
		goto out;
	}

	if (scf_instance_get_pg(instance, pgname, pg) != 0 ||
	    scf_pg_get_property(pg, propname, prop) != 0 ||
	    scf_property_type(prop, &type) != 0) {
		rad_log(RL_ERROR, "couldn't get property: '%s/%s/%s': %s\n",
		    fmri, pgname, propname, scf_strerror(scf_error()));
		err = maperr(scf_error());
		goto out;
	}

top:
	if (scf_transaction_start(tx, pg) == -1 ||
	    scf_transaction_property_change(tx, ent, propname, type) != 0 ||
	    scf_value_set_from_string(val, type, value) != 0 ||
	    scf_entry_add_value(ent, val) != 0) {
		rad_log(RL_ERROR, "couldn't set property: '%s/%s/%s': %s\n",
		    fmri, pgname, propname, scf_strerror(scf_error()));
		err = maperr(scf_error());
		goto out;
	}

	switch (scf_transaction_commit(tx)) {
	/* success */
	case 1:
		if (smf_refresh_instance(fmri) != 0) {
			err = maperr(scf_error());
			goto out;
		}
		break;
	/* retry */
	case 0:
		if (scf_pg_update(pg) != 0) {
			err = maperr(scf_error());
			goto out;
		}
		scf_transaction_reset(tx);
		goto top;
	default:
		err = maperr(scf_error());
		goto out;
	}
out:
	scf_entry_destroy(ent);
	scf_transaction_destroy(tx);
	scf_value_destroy(val);
	scf_property_destroy(prop);
	scf_pg_destroy(pg);
	scf_instance_destroy(instance);
	scf_service_destroy(service);
	scf_handle_destroy(scfhandle);

	return (err);
}