diff options
author | H. Peter Anvin <hpa@zytor.com> | 2008-03-26 16:25:35 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2008-03-26 16:25:35 -0700 |
commit | 9eddd22a7b53b1d02fbae0d987df8af122924248 (patch) | |
tree | 882f5152880b0b1aa2d7a0619d30065acc69fb16 /gpxe/src/core/monojob.c | |
parent | bbb8f15936b851e6a0ef6f7bb2c95197bff35994 (diff) | |
download | syslinux-9eddd22a7b53b1d02fbae0d987df8af122924248.tar.gz |
Add gPXE into the source tree; build unified imagesyslinux-3.70-pre7
Diffstat (limited to 'gpxe/src/core/monojob.c')
-rw-r--r-- | gpxe/src/core/monojob.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/gpxe/src/core/monojob.c b/gpxe/src/core/monojob.c new file mode 100644 index 00000000..ea9bc834 --- /dev/null +++ b/gpxe/src/core/monojob.c @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <string.h> +#include <stdio.h> +#include <errno.h> +#include <gpxe/process.h> +#include <console.h> +#include <gpxe/keys.h> +#include <gpxe/job.h> +#include <gpxe/monojob.h> + +/** @file + * + * Single foreground job + * + */ + +static int monojob_rc; + +static void monojob_done ( struct job_interface *job __unused, int rc ) { + monojob_rc = rc; +} + +/** Single foreground job operations */ +static struct job_interface_operations monojob_operations = { + .done = monojob_done, + .kill = ignore_job_kill, + .progress = ignore_job_progress, +}; + +/** Single foreground job */ +struct job_interface monojob = { + .intf = { + .dest = &null_job.intf, + .refcnt = NULL, + }, + .op = &monojob_operations, +}; + +/** + * Wait for single foreground job to complete + * + * @v string Job description to display + * @ret rc Job final status code + */ +int monojob_wait ( const char *string ) { + int key; + int rc; + + printf ( "%s... ", string ); + monojob_rc = -EINPROGRESS; + while ( monojob_rc == -EINPROGRESS ) { + step(); + if ( iskey() ) { + key = getchar(); + switch ( key ) { + case CTRL_C: + job_kill ( &monojob ); + rc = -ECANCELED; + goto done; + default: + break; + } + } + } + rc = monojob_rc; + +done: + if ( rc ) { + printf ( "%s\n", strerror ( rc ) ); + } else { + printf ( "ok\n" ); + } + return rc; +} |