コード例 #1
0
ファイル: xkcdrandom.c プロジェクト: lt/xkcdrandom
static int __init mod_init(void)
{
	int errno = 0;
	struct device *device = NULL;

	errno = alloc_chrdev_region(&device_num, 0, 1, DEVICE_NAME);
	if (errno < 0) {
		printk(KERN_WARNING "alloc_chrdev_region failed (%d)", errno);
		return errno;
	}

	device_class = class_create(THIS_MODULE, DEVICE_NAME);
	if (IS_ERR(device_class)) {
		errno = PTR_ERR(device_class);
		printk(KERN_WARNING "class_create failed (%d)", errno);
		goto fail;
	}
	device_class->dev_uevent = device_uevent;

	device_cdev = kzalloc(sizeof(struct cdev), GFP_KERNEL);
	if (device_cdev == NULL) {
		printk(KERN_WARNING "kzalloc failed");
		errno = -ENOMEM;
		goto fail;
	}

	cdev_init(device_cdev, &fops);
	device_cdev->owner = THIS_MODULE;

	errno = cdev_add(device_cdev, device_num, 1);
	if (errno) {
		printk(KERN_WARNING "cdev_add failed (%d)", errno);
		goto fail;
	}

	device = device_create(device_class, NULL, device_num, NULL, DEVICE_NAME);
	if (IS_ERR(device)) {
		errno = PTR_ERR(device);
		printk(KERN_WARNING "device_create failed (%d)", errno);
		cdev_del(device_cdev);
		goto fail;
	}

	return 0;

fail:
	mod_cleanup();
	return errno;
}
コード例 #2
0
ファイル: env.c プロジェクト: funtoo/vzctl
/** Stop CT.
 *
 * @param h		CT handler.
 * @param veid		CT ID.
 * @param param		CT parameters.
 * @param stop_mode	stop mode, one of (M_REBOOT M_HALT M_KILL).
 * @param skip		flag to skip run action script (SKIP_ACTION_SCRIPT)
 * @param action	modules list, used to call cleanup() callback.
 * @return		0 on success.
 */
int vps_stop(vps_handler *h, envid_t veid, vps_param *param, int stop_mode,
             skipFlags skip, struct mod_action *action)
{
    int ret;
    char buf[64];
    vps_res *res = &param->res;

    if (check_var(res->fs.root, "VE_ROOT is not set"))
        return VZ_VE_ROOT_NOTSET;
    if (!vps_is_run(h, veid)) {
        logger(-1, 0, "Unable to stop: container is not running");
        return 0;
    }
    if (!(skip & SKIP_ACTION_SCRIPT)) {
        snprintf(buf, sizeof(buf), VPS_CONF_DIR "%d.%s", veid,
                 STOP_PREFIX);
        if (stat_file(buf)) {
            if (vps_exec_script(h, veid, res->fs.root, NULL, NULL,
                                buf, NULL, 0))
            {
                return VZ_ACTIONSCRIPT_ERROR;
            }
        }
    }
    /* get CT IP addresses for cleanup */
    get_vps_ip(h, veid, &param->del_res.net.ip);
    if ((ret = env_stop(h, veid, res->fs.root, stop_mode)))
        goto end;
    mod_cleanup(h, veid, action, param);
    /* Cleanup CT IPs */
    run_net_script(veid, DEL, &param->del_res.net.ip,
                   STATE_STOPPING, param->res.net.skip_arpdetect);
    ret = vps_umount(h, veid, res->fs.root, skip);

end:
    free_str_param(&param->del_res.net.ip);
    return ret;
}
コード例 #3
0
ファイル: xkcdrandom.c プロジェクト: lt/xkcdrandom
static void __exit mod_exit(void)
{
	mod_cleanup();
	return;
}