963 |
|
signal(SIGWINCH, sig_winch_handler); |
964 |
|
} |
965 |
|
|
966 |
+ |
void usage() { |
967 |
+ |
printf("Usage: idar [-o order] [-s server] [-p port] [-l list] [-h]\n\n"); |
968 |
+ |
printf(" -o Sets the initial sort order. Accepted arguments are one of:\n"); |
969 |
+ |
printf(" cpu load mem swap net disk\n"); |
970 |
+ |
printf(" -s Specifies the i-scream server to connect to.\n"); |
971 |
+ |
printf(" default: %s\n", DEF_SERVER_NAME); |
972 |
+ |
printf(" -p Specifies the i-scream server port.\n"); |
973 |
+ |
printf(" default: %d\n", DEF_SERVER_PORT); |
974 |
+ |
printf(" -l Sets the list of hosts to monitor in a semi-colon seperated list.\n"); |
975 |
+ |
printf(" -h Displays this help information.\n"); |
976 |
+ |
printf("\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT); |
977 |
+ |
exit(1); |
978 |
+ |
} |
979 |
+ |
|
980 |
|
int main(int argc, char **argv){ |
981 |
|
WINDOW *window; |
982 |
|
fd_set infds; |
988 |
|
char *machine_list=NULL; |
989 |
|
char *response=NULL; |
990 |
|
|
991 |
< |
char *servername; |
991 |
> |
char *server_name; |
992 |
|
int server_control_port; |
993 |
|
int server_data_port; |
994 |
|
|
1052 |
|
|
1053 |
|
signal(SIGWINCH, sig_winch_handler); |
1054 |
|
|
1055 |
< |
while((cmdopt=getopt(argc, argv, "s:")) != -1){ |
1055 |
> |
server_name=DEF_SERVER_NAME; |
1056 |
> |
server_control_port=DEF_SERVER_PORT; |
1057 |
> |
|
1058 |
> |
while((cmdopt=getopt(argc, argv, "o:s:p:l:h")) != -1){ |
1059 |
|
switch(cmdopt){ |
1060 |
< |
case 's': |
1060 |
> |
case 'o': |
1061 |
|
if(!strcmp(optarg, "cpu")){ |
1062 |
|
sortby_ptr=cmp_cpu_used; |
1063 |
|
strlcpy(display_config.sortby, CPU_USED, SORTBYMAXNAME); |
1071 |
|
strlcpy(display_config.sortby, MEM, SORTBYMAXNAME); |
1072 |
|
} |
1073 |
|
if(!strcmp(optarg, "swap")){ |
1074 |
< |
sortby_ptr=cmp_swap_used_pecent; |
1075 |
< |
strlcpy(display_config.sortby, SWAP, SORTBYMAXNAME); |
1076 |
< |
} |
1074 |
> |
sortby_ptr=cmp_swap_used_pecent; |
1075 |
> |
strlcpy(display_config.sortby, SWAP, SORTBYMAXNAME); |
1076 |
> |
} |
1077 |
> |
if(!strcmp(optarg, "net")){ |
1078 |
> |
sortby_ptr=cmp_network_io_total; |
1079 |
> |
strlcpy(display_config.sortby, NETIO, SORTBYMAXNAME); |
1080 |
> |
} |
1081 |
> |
if(!strcmp(optarg, "disk")){ |
1082 |
> |
sortby_ptr=cmp_disk_io_total; |
1083 |
> |
strlcpy(display_config.sortby, DISKIO, SORTBYMAXNAME); |
1084 |
> |
} |
1085 |
|
if(sortby_ptr==NULL){ |
1086 |
< |
errf("Invalid sort type"); |
1087 |
< |
exit(1); |
1086 |
> |
errf("Invalid order given."); |
1087 |
> |
usage(); |
1088 |
|
} |
1089 |
< |
break; |
1089 |
> |
break; |
1090 |
> |
case 's': |
1091 |
> |
server_name=optarg; |
1092 |
> |
break; |
1093 |
> |
case 'p': |
1094 |
> |
server_control_port=atoi(optarg); |
1095 |
> |
break; |
1096 |
> |
case 'l': |
1097 |
> |
/* We've been passed a machine list */ |
1098 |
> |
/* list currently needs to be ; seperated */ |
1099 |
> |
machine_list=strdup(optarg); |
1100 |
> |
break; |
1101 |
> |
case 'h': |
1102 |
> |
usage(); |
1103 |
> |
break; |
1104 |
|
} |
1105 |
|
} |
1106 |
|
|
1107 |
+ |
/* Don't take any other arguments */ |
1108 |
+ |
if(argc>optind){ |
1109 |
+ |
usage(); |
1110 |
+ |
} |
1111 |
+ |
|
1112 |
|
if(sortby_ptr==NULL){ |
1113 |
|
sortby_ptr=cmp_cpu_used; |
1114 |
|
strlcpy(display_config.sortby, "CPU Used", SORTBYMAXNAME); |
1115 |
|
} |
1116 |
|
|
1117 |
< |
servername=DEF_SERVER_NAME; |
1074 |
< |
server_control_port=DEF_SERVER_PORT; |
1075 |
< |
|
1076 |
< |
if(argc>=(optind+2)){ |
1077 |
< |
servername=argv[optind]; |
1078 |
< |
server_control_port=atoi(argv[optind+1]); |
1079 |
< |
} |
1080 |
< |
|
1081 |
< |
control=create_tcp_connection(servername, server_control_port); |
1117 |
> |
control=create_tcp_connection(server_name, server_control_port); |
1118 |
|
if(control==NULL){ |
1119 |
|
errf("Failed to connect (%m)"); |
1120 |
|
exit(1); |
1121 |
|
} |
1122 |
|
|
1087 |
– |
if(argc==4){ |
1088 |
– |
/* We've been passed a machine list */ |
1089 |
– |
/* list currently needs to be ; seperated */ |
1090 |
– |
machine_list=strdup(argv[3]); |
1091 |
– |
} |
1092 |
– |
|
1123 |
|
if((tcp_comm(control, NULL, &response, "PROTOCOL 1.1"))!=0){ |
1124 |
|
errf("Incorrect version number (%s)", response); |
1125 |
|
exit(1); |
1152 |
|
exit(1); |
1153 |
|
} |
1154 |
|
|
1155 |
< |
data=create_tcp_connection(servername, server_data_port); |
1155 |
> |
data=create_tcp_connection(server_name, server_data_port); |
1156 |
|
if(data==NULL){ |
1157 |
< |
errf("Failed to connect to host %s on port %d (%m)",servername, server_data_port); |
1157 |
> |
errf("Failed to connect to host %s on port %d (%m)",server_name, server_data_port); |
1158 |
|
exit(1); |
1159 |
|
} |
1160 |
|
|