1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
/*
* Copyright (c) 2000-2001 Silicon Graphics, Inc.
* All Rights Reserved.
*
* 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.
*
* This program is distributed in the hope that it would 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 the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <time.h>
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
#include <assert.h>
#include <string.h>
#include <uuid/uuid.h>
#include "config.h"
#include "types.h"
#include "mlog.h"
#include "dlog.h"
#include "cldmgr.h"
#include "global.h"
#include "drive.h"
#define PREAMBLEMAX 3
#define QUERYMAX 1
#define CHOICEMAX 2
#define ACKMAX 3
#define POSTAMBLEMAX 3
#define DLOG_TIMEOUT 3600
bool_t
Media_prompt_change(drive_t *drivep)
{
fold_t fold;
char question[100];
char *preamblestr[PREAMBLEMAX];
size_t preamblecnt;
char *querystr[QUERYMAX];
size_t querycnt;
char *choicestr[CHOICEMAX];
size_t choicecnt;
char *ackstr[ACKMAX];
size_t ackcnt;
char *postamblestr[POSTAMBLEMAX];
size_t postamblecnt;
ix_t doix;
ix_t dontix;
ix_t responseix;
ix_t sigintix;
retry:
preamblecnt = 0;
fold_init(fold, _("change media dialog"), '=');
preamblestr[preamblecnt++ ] = "\n";
preamblestr[preamblecnt++] = fold;
preamblestr[preamblecnt++ ] = "\n\n";
assert(preamblecnt <= PREAMBLEMAX);
dlog_begin(preamblestr, preamblecnt);
/* query: ask if media changed or declined
*/
sprintf(question, _(
"please change media in "
"drive %u\n"),
(unsigned int)drivep->d_index);
querycnt = 0;
querystr[querycnt++] = question;
assert(querycnt <= QUERYMAX);
choicecnt = 0;
dontix = choicecnt;
choicestr[choicecnt++ ] = _("media change declined");
doix = choicecnt;
choicestr[choicecnt++ ] = _("media changed");
assert(choicecnt <= CHOICEMAX);
sigintix = IXMAX - 1;
responseix = dlog_multi_query(querystr,
querycnt,
choicestr,
choicecnt,
0, /* hilitestr */
IXMAX, /* hiliteix */
0, /* defaultstr */
doix, /* defaultix */
DLOG_TIMEOUT,
dontix, /* timeout ix */
sigintix, /* sigint ix */
dontix, /* sighup ix */
dontix); /* sigquit ix */
ackcnt = 0;
if (responseix == doix) {
ackstr[ackcnt++ ] = _("examining new media\n");
} else if (responseix == dontix) {
ackstr[ackcnt++ ] = _("media change aborted\n");
} else {
assert(responseix == sigintix);
ackstr[ackcnt++ ] = _("keyboard interrupt\n");
}
assert(ackcnt <= ACKMAX);
dlog_multi_ack(ackstr,
ackcnt);
postamblecnt = 0;
fold_init(fold, _("end dialog"), '-');
postamblestr[postamblecnt++ ] = "\n";
postamblestr[postamblecnt++] = fold;
postamblestr[postamblecnt++ ] = "\n\n";
assert(postamblecnt <= POSTAMBLEMAX);
dlog_end(postamblestr,
postamblecnt);
if (responseix == sigintix) {
if (cldmgr_stop_requested()) {
return BOOL_FALSE;
}
sleep(1); /* to allow main thread to begin dialog */
mlog(MLOG_NORMAL | MLOG_BARE,
""); /* to block until main thread dialog complete */
sleep(1); /* to allow main thread to request children die */
if (cldmgr_stop_requested()) {
return BOOL_FALSE;
}
mlog(MLOG_DEBUG,
"retrying media change dialog\n");
goto retry;
}
return responseix == doix;
}
|