예제 #1
0
/**
 * Called for each printer found in /etc/printcap.
 */
static void
handle_printer(struct printer *pp)
{
	struct device_entry *dev_entry;
	struct printer_entry *printer_entry;
	char dev_only[128];
	struct stat sb;

	if (pp->remote_host != NULL) {
		HRDBG("skipped %s -- remote", pp->printer);
		return;
	}

	if (strncmp(pp->lp, _PATH_DEV, strlen(_PATH_DEV)) != 0) {
		HRDBG("skipped %s [device %s] -- remote", pp->printer, pp->lp);
		return;
	}

	memset(dev_only, '\0', sizeof(dev_only));
	snprintf(dev_only, sizeof(dev_only), "%s", pp->lp + strlen(_PATH_DEV));

	HRDBG("printer %s has device %s", pp->printer, dev_only);

	if (stat(pp->lp, &sb) < 0) {
		if (errno == ENOENT) {
			HRDBG("skipped %s -- device %s missing",
			    pp->printer, pp->lp);
			return;
		}
	}

	if ((dev_entry = device_find_by_name(dev_only)) == NULL) {
		HRDBG("%s not in hrDeviceTable", pp->lp);
		return;
	}
	HRDBG("%s found in hrDeviceTable", pp->lp);
	dev_entry->type = &OIDX_hrDevicePrinter_c;

	dev_entry->flags |= HR_DEVICE_IMMUTABLE;

	/* Then check hrPrinterTable for this device */
	if ((printer_entry = printer_find_by_index(dev_entry->index)) == NULL &&
	    (printer_entry = printer_entry_create(dev_entry)) == NULL)
		return;

	printer_entry->flags |= HR_PRINTER_FOUND;
	printer_entry->status = get_printer_status(pp);
	memset(printer_entry->detectedErrorState, 0,
	    sizeof(printer_entry->detectedErrorState));
}
예제 #2
0
파일: console.c 프로젝트: daoweifan/wmdp
/**
 * This function will set a device as console device.
 * After set a device to console, all output of rt_kprintf will be
 * redirected to this new device.
 *
 * @param name the name of new console device
 *
 * @return the old console device handler
 */
device_t console_init(const char *name)
{
	device_t dev;

	/* find new console device */
	dev = device_find_by_name(name);
	if (dev != WM_NULL) {
		/* set new console device */
		_console_device = dev;
		_console_default = dev;
		device_open(_console_device, DEVICE_OFLAG_RDWR);
	}

	return dev;
}