int toi_netlink_setup(struct user_helper_data *uhd) { /* In case userui didn't cleanup properly on us */ toi_netlink_close_complete(uhd); if (netlink_prepare(uhd) < 0) { printk(KERN_INFO "Netlink prepare failed.\n"); return 1; } if (toi_launch_userspace_program(uhd->program, uhd->netlink_id, UMH_WAIT_EXEC, uhd->debug) < 0) { printk(KERN_INFO "Launch userspace program failed.\n"); toi_netlink_close_complete(uhd); return 1; } /* Wait 2 seconds for the userspace process to make contact */ wait_for_completion_timeout(&uhd->wait_for_process, 2*HZ); if (uhd->pid == -1) { printk(KERN_INFO "%s: Failed to contact userspace process.\n", uhd->name); toi_netlink_close_complete(uhd); return 1; } return 0; }
static int netlink_prepare(struct user_helper_data *uhd) { struct netlink_kernel_cfg cfg = { .groups = 0, .input = toi_user_rcv_skb, }; uhd->next = uhd_list; uhd_list = uhd; uhd->sock_seq = 0x42c0ffee; uhd->nl = netlink_kernel_create(&init_net, uhd->netlink_id, &cfg); if (!uhd->nl) { printk(KERN_INFO "Failed to allocate netlink socket for %s.\n", uhd->name); return -ENOMEM; } toi_fill_skb_pool(uhd); return 0; } void toi_netlink_close(struct user_helper_data *uhd) { struct task_struct *t; toi_read_lock_tasklist(); t = find_task_by_pid_ns(uhd->pid, &init_pid_ns); if (t) t->flags &= ~PF_NOFREEZE; toi_read_unlock_tasklist(); toi_send_netlink_message(uhd, NETLINK_MSG_CLEANUP, NULL, 0); } EXPORT_SYMBOL_GPL(toi_netlink_close); int toi_netlink_setup(struct user_helper_data *uhd) { /* In case userui didn't cleanup properly on us */ toi_netlink_close_complete(uhd); if (netlink_prepare(uhd) < 0) { printk(KERN_INFO "Netlink prepare failed.\n"); return 1; } if (toi_launch_userspace_program(uhd->program, uhd->netlink_id, UMH_WAIT_EXEC, uhd->debug) < 0) { printk(KERN_INFO "Launch userspace program failed.\n"); toi_netlink_close_complete(uhd); return 1; } /* Wait 2 seconds for the userspace process to make contact */ wait_for_completion_timeout(&uhd->wait_for_process, 2*HZ); if (uhd->pid == -1) { printk(KERN_INFO "%s: Failed to contact userspace process.\n", uhd->name); toi_netlink_close_complete(uhd); return 1; } return 0; }