Compare commits
No commits in common. "519f9d415fba66b58572cf39b4cf5e2596a29e9f" and "ec30d78d3cf08c93cd7eb439fa94d3e6bb7d1dc2" have entirely different histories.
519f9d415f
...
ec30d78d3c
3 changed files with 16 additions and 29 deletions
22
README.md
22
README.md
|
@ -7,19 +7,19 @@ machines and their disks associated.
|
|||
|
||||
## Why
|
||||
|
||||
`qemush` is **daemonless**: no bloaty long running process is needed for
|
||||
`qemush` is **daemonless** : no bloaty long running process is needed for
|
||||
`qemush` to work.
|
||||
|
||||
`qemush` is **lightweight**: it only consists in a shell script to
|
||||
`qemush` is **lightweight** : it only consists in a shell script to
|
||||
automate repeated tasks and force good practices.
|
||||
|
||||
`qemush` needs **few dependencies**: see section
|
||||
`qemush` needs **few dependencies** : see section
|
||||
[Dependencies](#dependencies) for details.
|
||||
|
||||
`qemush` is **hackable**: you can [write your own launching
|
||||
`qemush` is **hackable** : you can [write your own launching
|
||||
scripts](#writing-a-launching-script) to make it work as intended.
|
||||
|
||||
`qemush` is **easy to setup**: you can make it work in a few steps, see
|
||||
`qemush` is **easy to setup** : you can make it work in a few steps, see
|
||||
section [Installation instructions](#installation-instructions).
|
||||
|
||||
## Good practices?
|
||||
|
@ -49,7 +49,7 @@ need it
|
|||
- `screen` - for process supervision
|
||||
- `source-highlight` - for syntax highlighting when displaying launching
|
||||
scripts
|
||||
- any text editor - used for builtin function to edit launching scripts
|
||||
- any text editor - used for builting function to edit launching scripts
|
||||
|
||||
## Installation instructions
|
||||
|
||||
|
@ -57,7 +57,7 @@ scripts
|
|||
|
||||
`qemush` acts as Unix user `qemu` to manage virtual machines. You need to
|
||||
create a system user `qemu` that cannot login, with any home directory,
|
||||
in an Unix group of the same name. Example:
|
||||
in an Unix group of the same name. Example :
|
||||
|
||||
```sh
|
||||
# Example if the qemu user doesn't exist
|
||||
|
@ -72,7 +72,7 @@ For ease of use, you need to grant every user in the `qemu` group via
|
|||
### Add `qemush` in the `PATH`
|
||||
|
||||
Use your preferred way to add the `qemush` script to a folder of `PATH`.
|
||||
Recommended: copy the script in `/usr/local/bin` to make it effortlessly
|
||||
Recommended : copy the script in `/usr/local/bin` to make it effortlessly
|
||||
system wide.
|
||||
|
||||
### Extra: add `first-free-port` in `PATH`
|
||||
|
@ -92,7 +92,7 @@ The default text editor used by `qemush` is `nvim`, but it can be
|
|||
overriden by the `EDITOR` environment variable.
|
||||
|
||||
Run the following command to start editing a launching script by the name
|
||||
of your choice:
|
||||
of your choice :
|
||||
|
||||
```sh
|
||||
qemush edit "$name"
|
||||
|
@ -103,13 +103,13 @@ Example scripts are available in this repo's `qemu/bin` folder.
|
|||
### Launching a virtual machine
|
||||
|
||||
Virtual machines are identified by the name of their launching scripts.
|
||||
You can launch any machine with the following command:
|
||||
You can launch any machine with the following command :
|
||||
|
||||
```sh
|
||||
qemush start "$name"
|
||||
```
|
||||
|
||||
You can also list all available virtual machines by running this command:
|
||||
You can also list all available virtual machines by running this command :
|
||||
|
||||
```sh
|
||||
qemush ls
|
||||
|
|
|
@ -93,7 +93,7 @@ public_diskls() {
|
|||
public_edit() {
|
||||
local file="${bin}/${1}"
|
||||
"$EDITOR" "$file"
|
||||
[ -f "$file" ] && exec chmod u+x "$file"
|
||||
exec chmod u+x "$file"
|
||||
}
|
||||
|
||||
public_rm() {
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include <fcntl.h>
|
||||
#include <sysexits.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define MIN_TCP_PORT 1
|
||||
#define TCP_TABLE "/proc/net/tcp"
|
||||
|
@ -13,13 +12,6 @@
|
|||
#define LISTENING_HEX "0A"
|
||||
#define PORTS_BLOCKS_TO_ALLOW 4
|
||||
|
||||
/**
|
||||
* Print a nice error message
|
||||
*/
|
||||
static void print_error(char *name, const char *message) {
|
||||
fprintf(stderr, "%s: %s\n", name, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the listening TCP ports
|
||||
*/
|
||||
|
@ -89,25 +81,20 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
if (!is_valid_tcp_port(current_port)) {
|
||||
print_error(argv[0], "provide a valid TCP port number as first argument.");
|
||||
fprintf(stderr, "Provide a valid TCP port number as first argument.\n");
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
||||
// Open TCP table
|
||||
FILE *tcp_table_fptr = fopen(TCP_TABLE, "r");
|
||||
if (tcp_table_fptr == NULL) {
|
||||
print_error(argv[0], "error opening the TCP table.");
|
||||
return errno;
|
||||
fprintf(stderr, "Error opening the TCP table.\n");
|
||||
return EX_OSFILE;
|
||||
}
|
||||
|
||||
unsigned short *listening_ports = malloc(PORTS_BLOCKS_TO_ALLOW * sizeof(unsigned short));
|
||||
listening_ports = get_listening_ports(listening_ports, tcp_table_fptr);
|
||||
|
||||
if (fclose(tcp_table_fptr) != 0) {
|
||||
print_error(argv[0], "can't close the TCP table.");
|
||||
return errno;
|
||||
}
|
||||
|
||||
// Check if the current port is available, add
|
||||
while (!is_port_available(current_port, listening_ports)) {
|
||||
current_port++;
|
||||
|
@ -119,7 +106,7 @@ int main(int argc, char *argv[]) {
|
|||
printf("%d\n", current_port);
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
print_error(argv[0], "no more ports available; how did you fuck up that bad ???");
|
||||
fprintf(stderr, "No more ports available. How did you fuck up that bad ???\n");
|
||||
return EX_TEMPFAIL;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue