You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

monojob.c 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. FILE_LICENCE ( GPL2_OR_LATER );
  19. #include <string.h>
  20. #include <stdio.h>
  21. #include <errno.h>
  22. #include <ipxe/process.h>
  23. #include <console.h>
  24. #include <ipxe/keys.h>
  25. #include <ipxe/job.h>
  26. #include <ipxe/monojob.h>
  27. #include <ipxe/timer.h>
  28. /** @file
  29. *
  30. * Single foreground job
  31. *
  32. */
  33. static int monojob_rc;
  34. static void monojob_close ( struct interface *intf, int rc ) {
  35. monojob_rc = rc;
  36. intf_restart ( intf, rc );
  37. }
  38. static struct interface_operation monojob_intf_op[] = {
  39. INTF_OP ( intf_close, struct interface *, monojob_close ),
  40. };
  41. static struct interface_descriptor monojob_intf_desc =
  42. INTF_DESC_PURE ( monojob_intf_op );
  43. struct interface monojob = INTF_INIT ( monojob_intf_desc );
  44. /**
  45. * Wait for single foreground job to complete
  46. *
  47. * @v string Job description to display
  48. * @ret rc Job final status code
  49. */
  50. int monojob_wait ( const char *string ) {
  51. int key;
  52. int rc;
  53. unsigned long last_progress_dot;
  54. unsigned long elapsed;
  55. printf ( "%s.", string );
  56. monojob_rc = -EINPROGRESS;
  57. last_progress_dot = currticks();
  58. while ( monojob_rc == -EINPROGRESS ) {
  59. step();
  60. if ( iskey() ) {
  61. key = getchar();
  62. switch ( key ) {
  63. case CTRL_C:
  64. monojob_close ( &monojob, -ECANCELED );
  65. break;
  66. default:
  67. break;
  68. }
  69. }
  70. elapsed = ( currticks() - last_progress_dot );
  71. if ( elapsed >= TICKS_PER_SEC ) {
  72. printf ( "." );
  73. last_progress_dot = currticks();
  74. }
  75. }
  76. rc = monojob_rc;
  77. if ( rc ) {
  78. printf ( " %s\n", strerror ( rc ) );
  79. } else {
  80. printf ( " ok\n" );
  81. }
  82. return rc;
  83. }