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 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 <errno.h>
  19. #include <gpxe/process.h>
  20. #include <console.h>
  21. #include <gpxe/keys.h>
  22. #include <gpxe/job.h>
  23. #include <gpxe/monojob.h>
  24. /** @file
  25. *
  26. * Single foreground job
  27. *
  28. */
  29. static int monojob_rc;
  30. static void monojob_done ( struct job_interface *job __unused, int rc ) {
  31. monojob_rc = rc;
  32. }
  33. /** Single foreground job operations */
  34. static struct job_interface_operations monojob_operations = {
  35. .done = monojob_done,
  36. .kill = ignore_job_kill,
  37. .progress = ignore_job_progress,
  38. };
  39. /** Single foreground job */
  40. struct job_interface monojob = {
  41. .intf = {
  42. .dest = &null_job.intf,
  43. .refcnt = NULL,
  44. },
  45. .op = &monojob_operations,
  46. };
  47. /**
  48. * Wait for single foreground job to complete
  49. *
  50. * @ret rc Job final status code
  51. */
  52. int monojob_wait ( void ) {
  53. int key;
  54. monojob_rc = -EINPROGRESS;
  55. while ( monojob_rc == -EINPROGRESS ) {
  56. step();
  57. if ( iskey() ) {
  58. key = getchar();
  59. switch ( key ) {
  60. case CTRL_C:
  61. job_kill ( &monojob );
  62. return -ECANCELED;
  63. break;
  64. default:
  65. break;
  66. }
  67. }
  68. }
  69. return monojob_rc;
  70. }