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.3KB

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