Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

monojob.c 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #include <string.h>
  19. #include <stdio.h>
  20. #include <errno.h>
  21. #include <gpxe/process.h>
  22. #include <console.h>
  23. #include <gpxe/keys.h>
  24. #include <gpxe/job.h>
  25. #include <gpxe/monojob.h>
  26. #include <gpxe/timer.h>
  27. /** @file
  28. *
  29. * Single foreground job
  30. *
  31. */
  32. static int monojob_rc;
  33. static void monojob_done ( struct job_interface *job __unused, int rc ) {
  34. monojob_rc = rc;
  35. }
  36. /** Single foreground job operations */
  37. static struct job_interface_operations monojob_operations = {
  38. .done = monojob_done,
  39. .kill = ignore_job_kill,
  40. .progress = ignore_job_progress,
  41. };
  42. /** Single foreground job */
  43. struct job_interface monojob = {
  44. .intf = {
  45. .dest = &null_job.intf,
  46. .refcnt = NULL,
  47. },
  48. .op = &monojob_operations,
  49. };
  50. /**
  51. * Wait for single foreground job to complete
  52. *
  53. * @v string Job description to display
  54. * @ret rc Job final status code
  55. */
  56. int monojob_wait ( const char *string ) {
  57. int key;
  58. int rc;
  59. tick_t last_progress_dot;
  60. printf ( "%s.", string );
  61. monojob_rc = -EINPROGRESS;
  62. last_progress_dot = currticks();
  63. while ( monojob_rc == -EINPROGRESS ) {
  64. step();
  65. if ( iskey() ) {
  66. key = getchar();
  67. switch ( key ) {
  68. case CTRL_C:
  69. job_kill ( &monojob );
  70. rc = -ECANCELED;
  71. goto done;
  72. default:
  73. break;
  74. }
  75. }
  76. if ( ( currticks() - last_progress_dot ) > TICKS_PER_SEC ) {
  77. printf ( "." );
  78. last_progress_dot = currticks();
  79. }
  80. }
  81. rc = monojob_rc;
  82. done:
  83. if ( rc ) {
  84. printf ( " %s\n", strerror ( rc ) );
  85. } else {
  86. printf ( " ok\n" );
  87. }
  88. return rc;
  89. }