mirror of https://github.com/akuker/RASCSI.git
Issue 319, detach all devices on SIGKILL/SIGTERM (#328)
* Removed size validation for MOs * rasctl -D detaches all devices * Detach all devices on Ctrl-C (KILL signal) * Added comment * Also detach all devices on SIGTERM
This commit is contained in:
parent
2cc9efc1a0
commit
84f40c7fe9
20
doc/rasctl.1
20
doc/rasctl.1
|
@ -8,26 +8,27 @@ rasctl \- Sends management commands to the rascsi process
|
|||
\fB\-m\fR |
|
||||
\fB\-s\fR |
|
||||
\fB\-v\fR |
|
||||
\fB\-D\fR |
|
||||
\fB\-I\fR |
|
||||
\fB\-L\fR |
|
||||
\fB\-O\fR |
|
||||
\fB\-T\fR |
|
||||
\fB\-V\fR |
|
||||
[\fB\-C\fR \fIFILENAME:FILESIZE\fR]
|
||||
[\fB\-E\fR \fIFILENAME\fR]
|
||||
[\fB\-F\fR \fIIMAGE_FOLDER\fR]
|
||||
[\fB\-C\fR \fIFILENAME:FILESIZE\fR]
|
||||
[\fB\-x\fR \fICURRENT_NAME:NEW_NAME\fR]
|
||||
[\fB\-R\fR \fICURRENT_NAME:NEW_NAME\fR]
|
||||
[\fB\-g\fR \fILOG_LEVEL\fR]
|
||||
[\fB\-h\fR \fIHOST\fR]
|
||||
[\fB\-p\fR \fIPORT\fR]
|
||||
[\fB\-r\fR \fIRESERVED_IDS\fR]
|
||||
[\fB\-i\fR \fIID\fR
|
||||
[\fB\-c\fR \fICMD\fR]
|
||||
[\fB\-f\fR \fIFILE|PARAM\fR]
|
||||
[\fB\-g\fR \fILOG_LEVEL\fR]
|
||||
[\fB\-h\fR \fIHOST\fR]
|
||||
[\fB\-i\fR \fIID\fR
|
||||
[\fB\-n\fR \fINAME\fR]
|
||||
[\fB\-p\fR \fIPORT\fR]
|
||||
[\fB\-r\fR \fIRESERVED_IDS\fR]
|
||||
[\fB\-t\fR \fITYPE\fR]
|
||||
[\fB\-u\fR \fIUNIT\fR]
|
||||
[\fB\-x\fR \fICURRENT_NAME:NEW_NAME\fR]
|
||||
.SH DESCRIPTION
|
||||
.B rasctl
|
||||
Sends commands to the rascsi process to make configuration adjustments at runtime or to check the status of the devices.
|
||||
|
@ -43,6 +44,9 @@ Note: The command and type arguments are case insensitive. Only the first letter
|
|||
.BR \-C\fI " "\fIFILENAME:FILESIZE
|
||||
Create an image file in the default image folder with the specified name and size in bytes.
|
||||
.TP
|
||||
.BR \-D\fI
|
||||
Detach all devices.
|
||||
.TP
|
||||
.BR \-E\fI " " \fIFILENAME
|
||||
Display information on an image file.
|
||||
.TP
|
||||
|
@ -94,7 +98,7 @@ Display the rascsi server version.
|
|||
.BR \-V\fI " " \fI
|
||||
Display the rasctl version.
|
||||
.TP
|
||||
.BR \-D\fI " "\fIFILENAME
|
||||
.BR \-d\fI " "\fIFILENAME
|
||||
Delete an image file in the default image folder.
|
||||
.TP
|
||||
.BR \-x\fI " "\fICURRENT_NAME:NEW_NAME
|
||||
|
|
|
@ -6,11 +6,11 @@ NAME
|
|||
rasctl - Sends management commands to the rascsi process
|
||||
|
||||
SYNOPSIS
|
||||
rasctl -e | -l | -m | -s | -v | -I | -L | -O | -T | -V | [-E FILENAME]
|
||||
[-F IMAGE_FOLDER] [-C FILENAME:FILESIZE] [-x CURRENT_NAME:NEW_NAME] [-R
|
||||
CURRENT_NAME:NEW_NAME] [-g LOG_LEVEL] [-h HOST] [-p PORT] [-r RE‐
|
||||
SERVED_IDS] [-i ID [-c CMD] [-f FILE|PARAM] [-n NAME] [-t TYPE] [-u
|
||||
UNIT]
|
||||
rasctl -e | -l | -m | -s | -v | -D | -I | -L | -O | -T | -V | [-C FILE‐
|
||||
NAME:FILESIZE] [-E FILENAME] [-F IMAGE_FOLDER] [-R CUR‐
|
||||
RENT_NAME:NEW_NAME] [-c CMD] [-f FILE|PARAM] [-g LOG_LEVEL] [-h HOST]
|
||||
[-i ID [-n NAME] [-p PORT] [-r RESERVED_IDS] [-t TYPE] [-u UNIT] [-x
|
||||
CURRENT_NAME:NEW_NAME]
|
||||
|
||||
DESCRIPTION
|
||||
rasctl Sends commands to the rascsi process to make configuration ad‐
|
||||
|
@ -28,6 +28,8 @@ OPTIONS
|
|||
Create an image file in the default image folder with the speci‐
|
||||
fied name and size in bytes.
|
||||
|
||||
-D Detach all devices.
|
||||
|
||||
-E FILENAME
|
||||
Display information on an image file.
|
||||
|
||||
|
@ -75,7 +77,7 @@ OPTIONS
|
|||
|
||||
-V Display the rasctl version.
|
||||
|
||||
-D FILENAME
|
||||
-d FILENAME
|
||||
Delete an image file in the default image folder.
|
||||
|
||||
-x CURRENT_NAME:NEW_NAME
|
||||
|
|
|
@ -63,12 +63,8 @@ void SCSIMO::Open(const Filepath& path)
|
|||
SetBlockCount(size >> GetSectorSizeShiftCount());
|
||||
}
|
||||
|
||||
// File size must be a multiple of the sector size
|
||||
if (size % GetSectorSizeInBytes()) {
|
||||
stringstream error;
|
||||
error << "File size must be a multiple of " << GetSectorSizeInBytes() << " bytes but is " << size << " bytes";
|
||||
throw io_exception(error.str());
|
||||
}
|
||||
// Effective size must be a multiple of the sector size
|
||||
size = (size / GetSectorSizeInBytes()) * GetSectorSizeInBytes();
|
||||
|
||||
SetReadOnly(false);
|
||||
SetProtectable(true);
|
||||
|
|
|
@ -1771,6 +1771,13 @@ static void *MonThread(void *param)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void TerminationHandler(int signum)
|
||||
{
|
||||
DetachAll();
|
||||
|
||||
exit(signum);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Main processing
|
||||
|
@ -1833,6 +1840,14 @@ int main(int argc, char* argv[])
|
|||
return EPERM;
|
||||
}
|
||||
|
||||
// Signal handler to detach all devices on a KILL or TERM signal
|
||||
struct sigaction termination_handler;
|
||||
termination_handler.sa_handler = TerminationHandler;
|
||||
sigemptyset(&termination_handler.sa_mask);
|
||||
termination_handler.sa_flags = 0;
|
||||
sigaction(SIGINT, &termination_handler, NULL);
|
||||
sigaction(SIGTERM, &termination_handler, NULL);
|
||||
|
||||
// Reset
|
||||
Reset();
|
||||
|
||||
|
|
|
@ -98,8 +98,8 @@ int main(int argc, char* argv[])
|
|||
cerr << "version " << rascsi_get_version_string() << " (" << __DATE__ << ", " << __TIME__ << ")" << endl;
|
||||
cerr << "Usage: " << argv[0] << " -i ID [-u UNIT] [-c CMD] [-C FILE] [-t TYPE] [-b BLOCK_SIZE] [-n NAME] [-f FILE|PARAM] ";
|
||||
cerr << "[-F IMAGE_FOLDER] [-L LOG_LEVEL] [-h HOST] [-p PORT] [-r RESERVED_IDS] ";
|
||||
cerr << "[-C FILENAME:FILESIZE] [-w FILENAME] [-R CURRENT_NAME:NEW_NAME] [-x CURRENT_NAME:NEW_NAME] ";
|
||||
cerr << "[-e] [-E FILENAME] [-I] [-l] [-L] [-m] [-O] [-s] [-v] [-V] [-y]" << endl;
|
||||
cerr << "[-C FILENAME:FILESIZE] [-d FILENAME] [-w FILENAME] [-R CURRENT_NAME:NEW_NAME] [-x CURRENT_NAME:NEW_NAME] ";
|
||||
cerr << "[-e] [-E FILENAME] [-D] [-I] [-l] [-L] [-m] [-O] [-s] [-v] [-V] [-y]" << endl;
|
||||
cerr << " where ID := {0-7}" << endl;
|
||||
cerr << " UNIT := {0-31}, default is 0" << endl;
|
||||
cerr << " CMD := {attach|detach|insert|eject|protect|unprotect|show}" << endl;
|
||||
|
@ -135,7 +135,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
opterr = 1;
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "elmsvINOTVa:b:c:f:h:i:n:p:r:t:u:x:C:D:E:F:L:R:")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "elmsvDINOTVa:b:c:d:f:h:i:n:p:r:t:u:x:C:E:F:L:R:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'i': {
|
||||
int id;
|
||||
|
@ -179,6 +179,15 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
break;
|
||||
|
||||
case 'D':
|
||||
command.set_operation(DETACH_ALL);
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
command.set_operation(DELETE_IMAGE);
|
||||
image_params = optarg;
|
||||
break;
|
||||
|
||||
case 'E':
|
||||
command.set_operation(IMAGE_FILE_INFO);
|
||||
filename = optarg;
|
||||
|
@ -301,11 +310,6 @@ int main(int argc, char* argv[])
|
|||
case 'T':
|
||||
command.set_operation(DEVICE_TYPES_INFO);
|
||||
break;
|
||||
|
||||
case 'D':
|
||||
command.set_operation(DELETE_IMAGE);
|
||||
image_params = optarg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue