mconsole_kern.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. /*
  2. * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org)
  3. * Copyright (C) 2001 - 2003 Jeff Dike (jdike@addtoit.com)
  4. * Licensed under the GPL
  5. */
  6. #include "linux/kernel.h"
  7. #include "linux/slab.h"
  8. #include "linux/init.h"
  9. #include "linux/notifier.h"
  10. #include "linux/reboot.h"
  11. #include "linux/utsname.h"
  12. #include "linux/ctype.h"
  13. #include "linux/interrupt.h"
  14. #include "linux/sysrq.h"
  15. #include "linux/workqueue.h"
  16. #include "linux/module.h"
  17. #include "linux/file.h"
  18. #include "linux/fs.h"
  19. #include "linux/namei.h"
  20. #include "linux/proc_fs.h"
  21. #include "linux/syscalls.h"
  22. #include "linux/console.h"
  23. #include "asm/irq.h"
  24. #include "asm/uaccess.h"
  25. #include "user_util.h"
  26. #include "kern_util.h"
  27. #include "kern.h"
  28. #include "mconsole.h"
  29. #include "mconsole_kern.h"
  30. #include "irq_user.h"
  31. #include "init.h"
  32. #include "os.h"
  33. #include "umid.h"
  34. #include "irq_kern.h"
  35. #include "choose-mode.h"
  36. static int do_unlink_socket(struct notifier_block *notifier,
  37. unsigned long what, void *data)
  38. {
  39. return(mconsole_unlink_socket());
  40. }
  41. static struct notifier_block reboot_notifier = {
  42. .notifier_call = do_unlink_socket,
  43. .priority = 0,
  44. };
  45. /* Safe without explicit locking for now. Tasklets provide their own
  46. * locking, and the interrupt handler is safe because it can't interrupt
  47. * itself and it can only happen on CPU 0.
  48. */
  49. static LIST_HEAD(mc_requests);
  50. static void mc_work_proc(void *unused)
  51. {
  52. struct mconsole_entry *req;
  53. unsigned long flags;
  54. while(!list_empty(&mc_requests)){
  55. local_save_flags(flags);
  56. req = list_entry(mc_requests.next, struct mconsole_entry,
  57. list);
  58. list_del(&req->list);
  59. local_irq_restore(flags);
  60. req->request.cmd->handler(&req->request);
  61. kfree(req);
  62. }
  63. }
  64. static DECLARE_WORK(mconsole_work, mc_work_proc, NULL);
  65. static irqreturn_t mconsole_interrupt(int irq, void *dev_id,
  66. struct pt_regs *regs)
  67. {
  68. /* long to avoid size mismatch warnings from gcc */
  69. long fd;
  70. struct mconsole_entry *new;
  71. struct mc_request req;
  72. fd = (long) dev_id;
  73. while (mconsole_get_request(fd, &req)){
  74. if(req.cmd->context == MCONSOLE_INTR)
  75. (*req.cmd->handler)(&req);
  76. else {
  77. new = kmalloc(sizeof(*new), GFP_ATOMIC);
  78. if(new == NULL)
  79. mconsole_reply(&req, "Out of memory", 1, 0);
  80. else {
  81. new->request = req;
  82. list_add(&new->list, &mc_requests);
  83. }
  84. }
  85. }
  86. if(!list_empty(&mc_requests))
  87. schedule_work(&mconsole_work);
  88. reactivate_fd(fd, MCONSOLE_IRQ);
  89. return(IRQ_HANDLED);
  90. }
  91. void mconsole_version(struct mc_request *req)
  92. {
  93. char version[256];
  94. sprintf(version, "%s %s %s %s %s", system_utsname.sysname,
  95. system_utsname.nodename, system_utsname.release,
  96. system_utsname.version, system_utsname.machine);
  97. mconsole_reply(req, version, 0, 0);
  98. }
  99. void mconsole_log(struct mc_request *req)
  100. {
  101. int len;
  102. char *ptr = req->request.data;
  103. ptr += strlen("log ");
  104. len = req->len - (ptr - req->request.data);
  105. printk("%.*s", len, ptr);
  106. mconsole_reply(req, "", 0, 0);
  107. }
  108. /* This is a more convoluted version of mconsole_proc, which has some stability
  109. * problems; however, we need it fixed, because it is expected that UML users
  110. * mount HPPFS instead of procfs on /proc. And we want mconsole_proc to still
  111. * show the real procfs content, not the ones from hppfs.*/
  112. #if 0
  113. void mconsole_proc(struct mc_request *req)
  114. {
  115. struct nameidata nd;
  116. struct file_system_type *proc;
  117. struct super_block *super;
  118. struct file *file;
  119. int n, err;
  120. char *ptr = req->request.data, *buf;
  121. ptr += strlen("proc");
  122. while(isspace(*ptr)) ptr++;
  123. proc = get_fs_type("proc");
  124. if(proc == NULL){
  125. mconsole_reply(req, "procfs not registered", 1, 0);
  126. goto out;
  127. }
  128. super = (*proc->get_sb)(proc, 0, NULL, NULL);
  129. put_filesystem(proc);
  130. if(super == NULL){
  131. mconsole_reply(req, "Failed to get procfs superblock", 1, 0);
  132. goto out;
  133. }
  134. up_write(&super->s_umount);
  135. nd.dentry = super->s_root;
  136. nd.mnt = NULL;
  137. nd.flags = O_RDONLY + 1;
  138. nd.last_type = LAST_ROOT;
  139. /* START: it was experienced that the stability problems are closed
  140. * if commenting out these two calls + the below read cycle. To
  141. * make UML crash again, it was enough to readd either one.*/
  142. err = link_path_walk(ptr, &nd);
  143. if(err){
  144. mconsole_reply(req, "Failed to look up file", 1, 0);
  145. goto out_kill;
  146. }
  147. file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
  148. if(IS_ERR(file)){
  149. mconsole_reply(req, "Failed to open file", 1, 0);
  150. goto out_kill;
  151. }
  152. /*END*/
  153. buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  154. if(buf == NULL){
  155. mconsole_reply(req, "Failed to allocate buffer", 1, 0);
  156. goto out_fput;
  157. }
  158. if((file->f_op != NULL) && (file->f_op->read != NULL)){
  159. do {
  160. n = (*file->f_op->read)(file, buf, PAGE_SIZE - 1,
  161. &file->f_pos);
  162. if(n >= 0){
  163. buf[n] = '\0';
  164. mconsole_reply(req, buf, 0, (n > 0));
  165. }
  166. else {
  167. mconsole_reply(req, "Read of file failed",
  168. 1, 0);
  169. goto out_free;
  170. }
  171. } while(n > 0);
  172. }
  173. else mconsole_reply(req, "", 0, 0);
  174. out_free:
  175. kfree(buf);
  176. out_fput:
  177. fput(file);
  178. out_kill:
  179. deactivate_super(super);
  180. out: ;
  181. }
  182. #endif
  183. void mconsole_proc(struct mc_request *req)
  184. {
  185. char path[64];
  186. char *buf;
  187. int len;
  188. int fd;
  189. int first_chunk = 1;
  190. char *ptr = req->request.data;
  191. ptr += strlen("proc");
  192. while(isspace(*ptr)) ptr++;
  193. snprintf(path, sizeof(path), "/proc/%s", ptr);
  194. fd = sys_open(path, 0, 0);
  195. if (fd < 0) {
  196. mconsole_reply(req, "Failed to open file", 1, 0);
  197. printk("open %s: %d\n",path,fd);
  198. goto out;
  199. }
  200. buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  201. if(buf == NULL){
  202. mconsole_reply(req, "Failed to allocate buffer", 1, 0);
  203. goto out_close;
  204. }
  205. for (;;) {
  206. len = sys_read(fd, buf, PAGE_SIZE-1);
  207. if (len < 0) {
  208. mconsole_reply(req, "Read of file failed", 1, 0);
  209. goto out_free;
  210. }
  211. /*Begin the file content on his own line.*/
  212. if (first_chunk) {
  213. mconsole_reply(req, "\n", 0, 1);
  214. first_chunk = 0;
  215. }
  216. if (len == PAGE_SIZE-1) {
  217. buf[len] = '\0';
  218. mconsole_reply(req, buf, 0, 1);
  219. } else {
  220. buf[len] = '\0';
  221. mconsole_reply(req, buf, 0, 0);
  222. break;
  223. }
  224. }
  225. out_free:
  226. kfree(buf);
  227. out_close:
  228. sys_close(fd);
  229. out:
  230. /* nothing */;
  231. }
  232. #define UML_MCONSOLE_HELPTEXT \
  233. "Commands: \n\
  234. version - Get kernel version \n\
  235. help - Print this message \n\
  236. halt - Halt UML \n\
  237. reboot - Reboot UML \n\
  238. config <dev>=<config> - Add a new device to UML; \n\
  239. same syntax as command line \n\
  240. config <dev> - Query the configuration of a device \n\
  241. remove <dev> - Remove a device from UML \n\
  242. sysrq <letter> - Performs the SysRq action controlled by the letter \n\
  243. cad - invoke the Ctl-Alt-Del handler \n\
  244. stop - pause the UML; it will do nothing until it receives a 'go' \n\
  245. go - continue the UML after a 'stop' \n\
  246. log <string> - make UML enter <string> into the kernel log\n\
  247. proc <file> - returns the contents of the UML's /proc/<file>\n\
  248. stack <pid> - returns the stack of the specified pid\n\
  249. "
  250. void mconsole_help(struct mc_request *req)
  251. {
  252. mconsole_reply(req, UML_MCONSOLE_HELPTEXT, 0, 0);
  253. }
  254. void mconsole_halt(struct mc_request *req)
  255. {
  256. mconsole_reply(req, "", 0, 0);
  257. machine_halt();
  258. }
  259. void mconsole_reboot(struct mc_request *req)
  260. {
  261. mconsole_reply(req, "", 0, 0);
  262. machine_restart(NULL);
  263. }
  264. extern void ctrl_alt_del(void);
  265. void mconsole_cad(struct mc_request *req)
  266. {
  267. mconsole_reply(req, "", 0, 0);
  268. ctrl_alt_del();
  269. }
  270. void mconsole_go(struct mc_request *req)
  271. {
  272. mconsole_reply(req, "Not stopped", 1, 0);
  273. }
  274. void mconsole_stop(struct mc_request *req)
  275. {
  276. deactivate_fd(req->originating_fd, MCONSOLE_IRQ);
  277. os_set_fd_block(req->originating_fd, 1);
  278. mconsole_reply(req, "", 0, 0);
  279. while(mconsole_get_request(req->originating_fd, req)){
  280. if(req->cmd->handler == mconsole_go) break;
  281. (*req->cmd->handler)(req);
  282. }
  283. os_set_fd_block(req->originating_fd, 0);
  284. reactivate_fd(req->originating_fd, MCONSOLE_IRQ);
  285. mconsole_reply(req, "", 0, 0);
  286. }
  287. /* This list is populated by __initcall routines. */
  288. LIST_HEAD(mconsole_devices);
  289. void mconsole_register_dev(struct mc_device *new)
  290. {
  291. list_add(&new->list, &mconsole_devices);
  292. }
  293. static struct mc_device *mconsole_find_dev(char *name)
  294. {
  295. struct list_head *ele;
  296. struct mc_device *dev;
  297. list_for_each(ele, &mconsole_devices){
  298. dev = list_entry(ele, struct mc_device, list);
  299. if(!strncmp(name, dev->name, strlen(dev->name)))
  300. return(dev);
  301. }
  302. return(NULL);
  303. }
  304. #define CONFIG_BUF_SIZE 64
  305. static void mconsole_get_config(int (*get_config)(char *, char *, int,
  306. char **),
  307. struct mc_request *req, char *name)
  308. {
  309. char default_buf[CONFIG_BUF_SIZE], *error, *buf;
  310. int n, size;
  311. if(get_config == NULL){
  312. mconsole_reply(req, "No get_config routine defined", 1, 0);
  313. return;
  314. }
  315. error = NULL;
  316. size = sizeof(default_buf)/sizeof(default_buf[0]);
  317. buf = default_buf;
  318. while(1){
  319. n = (*get_config)(name, buf, size, &error);
  320. if(error != NULL){
  321. mconsole_reply(req, error, 1, 0);
  322. goto out;
  323. }
  324. if(n <= size){
  325. mconsole_reply(req, buf, 0, 0);
  326. goto out;
  327. }
  328. if(buf != default_buf)
  329. kfree(buf);
  330. size = n;
  331. buf = kmalloc(size, GFP_KERNEL);
  332. if(buf == NULL){
  333. mconsole_reply(req, "Failed to allocate buffer", 1, 0);
  334. return;
  335. }
  336. }
  337. out:
  338. if(buf != default_buf)
  339. kfree(buf);
  340. }
  341. void mconsole_config(struct mc_request *req)
  342. {
  343. struct mc_device *dev;
  344. char *ptr = req->request.data, *name;
  345. int err;
  346. ptr += strlen("config");
  347. while(isspace(*ptr)) ptr++;
  348. dev = mconsole_find_dev(ptr);
  349. if(dev == NULL){
  350. mconsole_reply(req, "Bad configuration option", 1, 0);
  351. return;
  352. }
  353. name = &ptr[strlen(dev->name)];
  354. ptr = name;
  355. while((*ptr != '=') && (*ptr != '\0'))
  356. ptr++;
  357. if(*ptr == '='){
  358. err = (*dev->config)(name);
  359. mconsole_reply(req, "", err, 0);
  360. }
  361. else mconsole_get_config(dev->get_config, req, name);
  362. }
  363. void mconsole_remove(struct mc_request *req)
  364. {
  365. struct mc_device *dev;
  366. char *ptr = req->request.data, *err_msg = "";
  367. char error[256];
  368. int err, start, end, n;
  369. ptr += strlen("remove");
  370. while(isspace(*ptr)) ptr++;
  371. dev = mconsole_find_dev(ptr);
  372. if(dev == NULL){
  373. mconsole_reply(req, "Bad remove option", 1, 0);
  374. return;
  375. }
  376. ptr = &ptr[strlen(dev->name)];
  377. err = 1;
  378. n = (*dev->id)(&ptr, &start, &end);
  379. if(n < 0){
  380. err_msg = "Couldn't parse device number";
  381. goto out;
  382. }
  383. else if((n < start) || (n > end)){
  384. sprintf(error, "Invalid device number - must be between "
  385. "%d and %d", start, end);
  386. err_msg = error;
  387. goto out;
  388. }
  389. err = (*dev->remove)(n);
  390. switch(err){
  391. case -ENODEV:
  392. err_msg = "Device doesn't exist";
  393. break;
  394. case -EBUSY:
  395. err_msg = "Device is currently open";
  396. break;
  397. default:
  398. break;
  399. }
  400. out:
  401. mconsole_reply(req, err_msg, err, 0);
  402. }
  403. static DEFINE_SPINLOCK(console_lock);
  404. static LIST_HEAD(clients);
  405. static char console_buf[MCONSOLE_MAX_DATA];
  406. static int console_index = 0;
  407. static void console_write(struct console *console, const char *string,
  408. unsigned len)
  409. {
  410. struct list_head *ele;
  411. int n;
  412. if(list_empty(&clients))
  413. return;
  414. while(1){
  415. n = min(len, ARRAY_SIZE(console_buf) - console_index);
  416. strncpy(&console_buf[console_index], string, n);
  417. console_index += n;
  418. string += n;
  419. len -= n;
  420. if(len == 0)
  421. return;
  422. list_for_each(ele, &clients){
  423. struct mconsole_entry *entry;
  424. entry = list_entry(ele, struct mconsole_entry, list);
  425. mconsole_reply_len(&entry->request, console_buf,
  426. console_index, 0, 1);
  427. }
  428. console_index = 0;
  429. }
  430. }
  431. static struct console mc_console = { .name = "mc",
  432. .write = console_write,
  433. .flags = CON_ENABLED,
  434. .index = -1 };
  435. static int mc_add_console(void)
  436. {
  437. register_console(&mc_console);
  438. return 0;
  439. }
  440. late_initcall(mc_add_console);
  441. static void with_console(struct mc_request *req, void (*proc)(void *),
  442. void *arg)
  443. {
  444. struct mconsole_entry entry;
  445. unsigned long flags;
  446. INIT_LIST_HEAD(&entry.list);
  447. entry.request = *req;
  448. list_add(&entry.list, &clients);
  449. spin_lock_irqsave(&console_lock, flags);
  450. (*proc)(arg);
  451. mconsole_reply_len(req, console_buf, console_index, 0, 0);
  452. console_index = 0;
  453. spin_unlock_irqrestore(&console_lock, flags);
  454. list_del(&entry.list);
  455. }
  456. #ifdef CONFIG_MAGIC_SYSRQ
  457. static void sysrq_proc(void *arg)
  458. {
  459. char *op = arg;
  460. handle_sysrq(*op, &current->thread.regs, NULL);
  461. }
  462. void mconsole_sysrq(struct mc_request *req)
  463. {
  464. char *ptr = req->request.data;
  465. ptr += strlen("sysrq");
  466. while(isspace(*ptr)) ptr++;
  467. /* With 'b', the system will shut down without a chance to reply,
  468. * so in this case, we reply first.
  469. */
  470. if(*ptr == 'b')
  471. mconsole_reply(req, "", 0, 0);
  472. with_console(req, sysrq_proc, ptr);
  473. }
  474. #else
  475. void mconsole_sysrq(struct mc_request *req)
  476. {
  477. mconsole_reply(req, "Sysrq not compiled in", 1, 0);
  478. }
  479. #endif
  480. static void stack_proc(void *arg)
  481. {
  482. struct task_struct *from = current, *to = arg;
  483. to->thread.saved_task = from;
  484. switch_to(from, to, from);
  485. }
  486. /* Mconsole stack trace
  487. * Added by Allan Graves, Jeff Dike
  488. * Dumps a stacks registers to the linux console.
  489. * Usage stack <pid>.
  490. */
  491. void do_stack(struct mc_request *req)
  492. {
  493. char *ptr = req->request.data;
  494. int pid_requested= -1;
  495. struct task_struct *from = NULL;
  496. struct task_struct *to = NULL;
  497. /* Would be nice:
  498. * 1) Send showregs output to mconsole.
  499. * 2) Add a way to stack dump all pids.
  500. */
  501. ptr += strlen("stack");
  502. while(isspace(*ptr)) ptr++;
  503. /* Should really check for multiple pids or reject bad args here */
  504. /* What do the arguments in mconsole_reply mean? */
  505. if(sscanf(ptr, "%d", &pid_requested) == 0){
  506. mconsole_reply(req, "Please specify a pid", 1, 0);
  507. return;
  508. }
  509. from = current;
  510. to = find_task_by_pid(pid_requested);
  511. if((to == NULL) || (pid_requested == 0)) {
  512. mconsole_reply(req, "Couldn't find that pid", 1, 0);
  513. return;
  514. }
  515. with_console(req, stack_proc, to);
  516. }
  517. void mconsole_stack(struct mc_request *req)
  518. {
  519. /* This command doesn't work in TT mode, so let's check and then
  520. * get out of here
  521. */
  522. CHOOSE_MODE(mconsole_reply(req, "Sorry, this doesn't work in TT mode",
  523. 1, 0),
  524. do_stack(req));
  525. }
  526. /* Changed by mconsole_setup, which is __setup, and called before SMP is
  527. * active.
  528. */
  529. static char *notify_socket = NULL;
  530. static int mconsole_init(void)
  531. {
  532. /* long to avoid size mismatch warnings from gcc */
  533. long sock;
  534. int err;
  535. char file[256];
  536. if(umid_file_name("mconsole", file, sizeof(file))) return(-1);
  537. snprintf(mconsole_socket_name, sizeof(file), "%s", file);
  538. sock = os_create_unix_socket(file, sizeof(file), 1);
  539. if (sock < 0){
  540. printk("Failed to initialize management console\n");
  541. return(1);
  542. }
  543. register_reboot_notifier(&reboot_notifier);
  544. err = um_request_irq(MCONSOLE_IRQ, sock, IRQ_READ, mconsole_interrupt,
  545. SA_INTERRUPT | SA_SHIRQ | SA_SAMPLE_RANDOM,
  546. "mconsole", (void *)sock);
  547. if (err){
  548. printk("Failed to get IRQ for management console\n");
  549. return(1);
  550. }
  551. if(notify_socket != NULL){
  552. notify_socket = kstrdup(notify_socket, GFP_KERNEL);
  553. if(notify_socket != NULL)
  554. mconsole_notify(notify_socket, MCONSOLE_SOCKET,
  555. mconsole_socket_name,
  556. strlen(mconsole_socket_name) + 1);
  557. else printk(KERN_ERR "mconsole_setup failed to strdup "
  558. "string\n");
  559. }
  560. printk("mconsole (version %d) initialized on %s\n",
  561. MCONSOLE_VERSION, mconsole_socket_name);
  562. return(0);
  563. }
  564. __initcall(mconsole_init);
  565. static int write_proc_mconsole(struct file *file, const char __user *buffer,
  566. unsigned long count, void *data)
  567. {
  568. char *buf;
  569. buf = kmalloc(count + 1, GFP_KERNEL);
  570. if(buf == NULL)
  571. return(-ENOMEM);
  572. if(copy_from_user(buf, buffer, count)){
  573. count = -EFAULT;
  574. goto out;
  575. }
  576. buf[count] = '\0';
  577. mconsole_notify(notify_socket, MCONSOLE_USER_NOTIFY, buf, count);
  578. out:
  579. kfree(buf);
  580. return(count);
  581. }
  582. static int create_proc_mconsole(void)
  583. {
  584. struct proc_dir_entry *ent;
  585. if(notify_socket == NULL) return(0);
  586. ent = create_proc_entry("mconsole", S_IFREG | 0200, NULL);
  587. if(ent == NULL){
  588. printk(KERN_INFO "create_proc_mconsole : create_proc_entry failed\n");
  589. return(0);
  590. }
  591. ent->read_proc = NULL;
  592. ent->write_proc = write_proc_mconsole;
  593. return(0);
  594. }
  595. static DEFINE_SPINLOCK(notify_spinlock);
  596. void lock_notify(void)
  597. {
  598. spin_lock(&notify_spinlock);
  599. }
  600. void unlock_notify(void)
  601. {
  602. spin_unlock(&notify_spinlock);
  603. }
  604. __initcall(create_proc_mconsole);
  605. #define NOTIFY "=notify:"
  606. static int mconsole_setup(char *str)
  607. {
  608. if(!strncmp(str, NOTIFY, strlen(NOTIFY))){
  609. str += strlen(NOTIFY);
  610. notify_socket = str;
  611. }
  612. else printk(KERN_ERR "mconsole_setup : Unknown option - '%s'\n", str);
  613. return(1);
  614. }
  615. __setup("mconsole", mconsole_setup);
  616. __uml_help(mconsole_setup,
  617. "mconsole=notify:<socket>\n"
  618. " Requests that the mconsole driver send a message to the named Unix\n"
  619. " socket containing the name of the mconsole socket. This also serves\n"
  620. " to notify outside processes when UML has booted far enough to respond\n"
  621. " to mconsole requests.\n\n"
  622. );
  623. static int notify_panic(struct notifier_block *self, unsigned long unused1,
  624. void *ptr)
  625. {
  626. char *message = ptr;
  627. if(notify_socket == NULL) return(0);
  628. mconsole_notify(notify_socket, MCONSOLE_PANIC, message,
  629. strlen(message) + 1);
  630. return(0);
  631. }
  632. static struct notifier_block panic_exit_notifier = {
  633. .notifier_call = notify_panic,
  634. .next = NULL,
  635. .priority = 1
  636. };
  637. static int add_notifier(void)
  638. {
  639. notifier_chain_register(&panic_notifier_list, &panic_exit_notifier);
  640. return(0);
  641. }
  642. __initcall(add_notifier);
  643. char *mconsole_notify_socket(void)
  644. {
  645. return(notify_socket);
  646. }
  647. EXPORT_SYMBOL(mconsole_notify_socket);