Did some stuff
[matches/swarm.git] / src / options.h
1 /**
2  * @file options.h
3  * @purpose Defines struct that is basically a container for global variables
4  *      Also contains definitions for functions that initialise the struct
5  *      Contains a few other clobal definitions
6  * @author Sam Moore ([email protected])
7  */
8
9 #ifndef _OPTIONS_H
10 #define _OPTIONS_H
11
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <stdbool.h>
15 #include <sys/select.h>
16
17 // One off commands are written to this file and then read back through a freopen of stdin
18 #define COMMAND_FILE ".swarm.command"
19
20 #define SHELL_EXIT_COMMAND "exit\n"
21 #define SHELL_OUTPUT_FINISHED "\a\a\a" // No one ever uses bell characters... right?
22 #define SHELL_OUTPUT_FINISHED_LENGTH 3 // WARNING: Make sure this is consistent with the above!
23
24 /**
25  * @struct Options
26  * @purpose Container for "options" (ie: arguments) to the program, as well as other global variables
27  */
28 typedef struct
29 {
30         char * program; // program name
31         char * name; // name of machine the program is running on
32                      // Is populated by gethostname(2) but may be changed on remote instances
33         char * shell; // The shell to start; default "bash"
34         char * master_addr; // Name of master swarm. If this swarm *is* the master, it is NULL.
35         char * logfile; // Name of file to be opened after option parsing for logging messages and errors
36         char * outfile; // Name of file to be opened after option parsing for stdout
37         int verbosity; // Level at which to print log messages (see log.h)
38         int port; // Port for remote instance to connect to master on; has no effect if ssh tunneling is used
39         char * prepend; // Command to prepend to every other command //TODO: Not fully implemented
40         char * append; // Command to append to every other command  //TODO: Not fully implemented
41         int nCPU; // Number of local shells to spawn; defaults to the number of cores/CPU on the machine
42         bool daemon; // indicates whether this instance is a daemon or not
43         bool daemon_wrapper; // indicates whether this instance is a daemon wrapper
44         bool interactive; // indicates whether this instance is interactive
45         bool encrypt; // indicates whether ssh tunnels will be used when absorbing remote instances
46                         // NOTE: This cannot be set by the user
47                         // It will automatically be set to true when #ABSORB# is used, and false when #ABSORB UNSECURE# is used.
48
49 } Options;
50
51
52 extern Options options; // single global variable
53
54 extern void options_setup(int argc, char ** argv, Options * o); // fill options with default values, call ParseArguments
55 extern void options_parse_args(int argc, char ** argv, Options * o); // parse arguments and change option values
56
57 extern char * strdup(); //HACK: For some reason I couldn't use stdlib's strdup and wrote my own.
58
59 extern void sigchld_respond(int s, char * name, int id); // I don't know why this is here, but it is
60
61
62 #endif //_OPTIONS_H
63
64

UCC git Repository :: git.ucc.asn.au