Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

monojob.c 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 <ipxe/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. struct job_progress progress;
  52. int key;
  53. int rc;
  54. unsigned long last_progress;
  55. unsigned long elapsed;
  56. unsigned int percentage;
  57. int shown_percentage = 0;
  58. printf ( "%s...", string );
  59. monojob_rc = -EINPROGRESS;
  60. last_progress = currticks();
  61. while ( monojob_rc == -EINPROGRESS ) {
  62. step();
  63. if ( iskey() ) {
  64. key = getchar();
  65. switch ( key ) {
  66. case CTRL_C:
  67. monojob_close ( &monojob, -ECANCELED );
  68. break;
  69. default:
  70. break;
  71. }
  72. }
  73. elapsed = ( currticks() - last_progress );
  74. if ( elapsed >= TICKS_PER_SEC ) {
  75. if ( shown_percentage )
  76. printf ( "\b\b\b\b \b\b\b\b" );
  77. job_progress ( &monojob, &progress );
  78. if ( progress.total ) {
  79. percentage = ( ( 100 * progress.completed ) /
  80. progress.total );
  81. printf ( "%3d%%", percentage );
  82. shown_percentage = 1;
  83. } else {
  84. printf ( "." );
  85. shown_percentage = 0;
  86. }
  87. last_progress = currticks();
  88. }
  89. }
  90. rc = monojob_rc;
  91. if ( shown_percentage )
  92. printf ( "\b\b\b\b \b\b\b\b" );
  93. if ( rc ) {
  94. printf ( " %s\n", strerror ( rc ) );
  95. } else {
  96. printf ( " ok\n" );
  97. }
  98. return rc;
  99. }