ucmd_browser.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* browser launcher: the real browser ships in the rootfs pack as
  2. * bin/browser.app (and can be overridden by /share/BROWSER or a FAT mount).
  3. * This tiny command keeps `browser` on PATH and in the WM's Web button. */
  4. #include "ucmd_lib.h"
  5. /* The sentinel is part of the array; do not size it to the number of
  6. * candidate strings or the loop reads past the end (that was a user #PF at
  7. * 0x40001000 in the first net-dev build). */
  8. static const char *const candidates[] = {
  9. "/share/BROWSER",
  10. "/share/BROWSER.ELF",
  11. /* The copy shipped in the command-pack rootfs. */
  12. "/ramfs/bin/browser.app",
  13. "/floppy1/BROWSER",
  14. "/floppy1/BROWSER.ELF",
  15. "/ide0p1/BROWSER",
  16. "/sata0p1/BROWSER",
  17. "/ide0/BROWSER",
  18. "/sata0/BROWSER",
  19. 0
  20. };
  21. void _start(const char *arg)
  22. {
  23. char cwd[64];
  24. char argbuf[64];
  25. unsigned int i, n = 0;
  26. while (arg && arg[n] && n + 1 < sizeof(argbuf)) {
  27. argbuf[n] = arg[n];
  28. n++;
  29. }
  30. argbuf[n] = '\0';
  31. if (u_getcwd(cwd, sizeof(cwd)) != 0 || !cwd[0]) {
  32. cwd[0] = '/';
  33. cwd[1] = '\0';
  34. }
  35. for (i = 0; i < sizeof(candidates) / sizeof(candidates[0]) &&
  36. candidates[i]; i++) {
  37. int pid = u_spawn(candidates[i], argbuf, 0, cwd);
  38. if (pid > 0) {
  39. u_puts("browser: started ");
  40. u_puts(candidates[i]);
  41. u_puts("\n");
  42. /* Stay in the foreground (and keep the app in this
  43. * terminal/WM session) until it exits. */
  44. while (u_alive((unsigned int)pid))
  45. u_sleep_ms(100);
  46. u_exit(0);
  47. }
  48. }
  49. u_puts("browser: BROWSER is not installed in the pack or on a disk\n");
  50. u_puts(" put browser.elf on the root floppy or /share\n");
  51. u_exit(1);
  52. }