| 1 |
|
| 2 |
|
| 3 |
#include <p7_config.h> |
| 4 |
|
| 5 |
#ifdef HMMER_THREADS |
| 6 |
|
| 7 |
#include <stdio.h> |
| 8 |
#include <stdlib.h> |
| 9 |
#include <string.h> |
| 10 |
#include <signal.h> |
| 11 |
|
| 12 |
#ifndef HMMER_THREADS |
| 13 |
#error "Program requires pthreads be enabled." |
| 14 |
#endif |
| 15 |
|
| 16 |
#include "easel.h" |
| 17 |
#include "esl_getopts.h" |
| 18 |
|
| 19 |
#include "hmmer.h" |
| 20 |
#include "hmmpgmd.h" |
| 21 |
|
| 22 |
#define CONF_FILE "/etc/hmmpgmd.conf" |
| 23 |
|
| 24 |
static ESL_OPTIONS cmdlineOpts[] = { |
| 25 |
|
| 26 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 1 }, |
| 27 |
{ "--master", eslARG_NONE, NULL, NULL, NULL, NULL, NULL, "--worker", "run program as the master server", 12 }, |
| 28 |
{ "--worker", eslARG_STRING, NULL, NULL, NULL, NULL, NULL, "--master", "run program as a worker with server at <s>", 12 }, |
| 29 |
{ "--cport", eslARG_INT, "51371", NULL, "49151<n<65536",NULL, NULL, "--worker", "port to use for client/server communication", 12 }, |
| 30 |
{ "--wport", eslARG_INT, "51372", NULL, "49151<n<65536",NULL, NULL, NULL, "port to use for server/worker communication", 12 }, |
| 31 |
{ "--ccncts", eslARG_INT, "16", NULL, "n>0", NULL, NULL, "--worker", "maximum number of client side connections to accept", 12 }, |
| 32 |
{ "--wcncts", eslARG_INT, "32", NULL, "n>0", NULL, NULL, "--worker", "maximum number of worker side connections to accept", 12 }, |
| 33 |
{ "--pid", eslARG_OUTFILE, NULL, NULL, NULL, NULL, NULL, NULL, "file to write process id to", 12 }, |
| 34 |
{ "--seqdb", eslARG_INFILE, NULL, NULL, NULL, NULL, NULL, "--worker", "protein database to cache for searches", 12 }, |
| 35 |
{ "--hmmdb", eslARG_INFILE, NULL, NULL, NULL, NULL, NULL, "--worker", "hmm database to cache for searches", 12 }, |
| 36 |
{ "--cpu", eslARG_INT, p7_NCPU,"HMMER_NCPU","n>0", NULL, NULL, "--master", "number of parallel CPU workers to use for multithreads", 12 }, |
| 37 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 38 |
|
| 39 |
}; |
| 40 |
|
| 41 |
static char usage[] = "[options]"; |
| 42 |
static char banner[] = "search a query against a database"; |
| 43 |
|
| 44 |
|
| 45 |
typedef void sig_func(int); |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
sig_func * |
| 53 |
our_signal(int signo, sig_func *fn) |
| 54 |
{ |
| 55 |
struct sigaction act; |
| 56 |
struct sigaction oact; |
| 57 |
|
| 58 |
act.sa_handler = fn; |
| 59 |
sigemptyset(&act.sa_mask); |
| 60 |
act.sa_flags = 0; |
| 61 |
if (signo == SIGALRM) { |
| 62 |
#ifdef SA_INTERRUPT |
| 63 |
act.sa_flags |= SA_INTERRUPT; |
| 64 |
#endif |
| 65 |
} else { |
| 66 |
#ifdef SA_RESTART |
| 67 |
act.sa_flags |= SA_RESTART; |
| 68 |
#endif |
| 69 |
} |
| 70 |
if (sigaction(signo, &act, &oact) < 0) { |
| 71 |
return SIG_ERR; |
| 72 |
} |
| 73 |
|
| 74 |
return oact.sa_handler; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
static void |
| 81 |
write_pid(ESL_GETOPTS *go) |
| 82 |
{ |
| 83 |
char *pid_file = esl_opt_GetString(go, "--pid"); |
| 84 |
FILE *fp = fopen(pid_file, "w"); |
| 85 |
|
| 86 |
if (!fp) p7_Fail("Unable to open PID file %s for writing.", pid_file); |
| 87 |
fprintf(fp,"%ld\n", (long)getpid()); |
| 88 |
fclose(fp); |
| 89 |
} |
| 90 |
|
| 91 |
static int |
| 92 |
process_commandline(int argc, char **argv, ESL_GETOPTS **ret_go) |
| 93 |
{ |
| 94 |
ESL_GETOPTS *go = esl_getopts_Create(cmdlineOpts); |
| 95 |
int status; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
if (argc == 1) |
| 101 |
{ |
| 102 |
FILE *fp = NULL; |
| 103 |
|
| 104 |
if ((fp = fopen(CONF_FILE, "r")) == NULL) |
| 105 |
{ if (puts("Options --master or --worker must be specified.") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); goto FAILURE; } |
| 106 |
|
| 107 |
if ((status = esl_opt_ProcessConfigfile(go, CONF_FILE, fp) ) != eslOK) |
| 108 |
{ if (printf("Failed to parse configuration file %s: %s\n", CONF_FILE, go->errbuf) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); goto FAILURE; } |
| 109 |
fclose(fp); |
| 110 |
} |
| 111 |
else |
| 112 |
{ |
| 113 |
if (esl_opt_ProcessCmdline(go, argc, argv) != eslOK) |
| 114 |
{ if (printf("Failed to parse command line: %s\n", go->errbuf) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); goto FAILURE; } |
| 115 |
} |
| 116 |
|
| 117 |
if (esl_opt_VerifyConfig(go) != eslOK) { if (printf("Failed to parse command line: %s\n", go->errbuf) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); goto FAILURE; } |
| 118 |
|
| 119 |
|
| 120 |
if (esl_opt_GetBoolean(go, "-h") == TRUE) |
| 121 |
{ |
| 122 |
p7_banner(stdout, argv[0], banner); |
| 123 |
esl_usage(stdout, argv[0], usage); |
| 124 |
|
| 125 |
if (puts("\nBasic options:") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); |
| 126 |
esl_opt_DisplayHelp(stdout, go, 1, 2, 80); |
| 127 |
|
| 128 |
if (puts("\nOther expert options:") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); |
| 129 |
esl_opt_DisplayHelp(stdout, go, 12, 2, 80); |
| 130 |
exit(0); |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
if (esl_opt_ArgNumber(go) != 0) { if (puts("Incorrect number of command line arguments.") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); goto FAILURE; } |
| 135 |
|
| 136 |
if (esl_opt_IsUsed(go, "--master") && !(esl_opt_IsUsed(go, "--seqdb") || esl_opt_IsUsed(go, "--hmmdb"))) |
| 137 |
{ if (puts("At least one --seqdb or --hmmdb must be specified.") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); goto FAILURE; } |
| 138 |
|
| 139 |
*ret_go = go; |
| 140 |
return eslOK; |
| 141 |
|
| 142 |
FAILURE: |
| 143 |
esl_usage(stdout, argv[0], usage); |
| 144 |
puts("\nwhere most common options are:"); |
| 145 |
esl_opt_DisplayHelp(stdout, go, 1, 2, 80); |
| 146 |
printf("\nTo see more help on available options, do %s -h\n\n", argv[0]); |
| 147 |
esl_getopts_Destroy(go); |
| 148 |
exit(0); |
| 149 |
|
| 150 |
ERROR: |
| 151 |
if (go) esl_getopts_Destroy(go); |
| 152 |
exit(status); |
| 153 |
} |
| 154 |
|
| 155 |
int |
| 156 |
main(int argc, char **argv) |
| 157 |
{ |
| 158 |
ESL_GETOPTS *go = NULL; |
| 159 |
|
| 160 |
process_commandline(argc, argv, &go); |
| 161 |
|
| 162 |
|
| 163 |
our_signal(SIGPIPE, SIG_IGN); |
| 164 |
|
| 165 |
|
| 166 |
if (esl_opt_IsOn(go, "--pid")) write_pid(go); |
| 167 |
|
| 168 |
if (esl_opt_IsUsed(go, "--master")) master_process(go); |
| 169 |
else if (esl_opt_IsUsed(go, "--worker")) worker_process(go); |
| 170 |
else |
| 171 |
{ puts("Options --master or --worker must be specified."); } |
| 172 |
|
| 173 |
esl_getopts_Destroy(go); |
| 174 |
|
| 175 |
return eslOK; |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
#endif |
| 221 |
|