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 separated 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 |
> |
default: |
1103 |
> |
usage(); |
1104 |
> |
break; |
1105 |
|
} |
1106 |
|
} |
1107 |
|
|
1108 |
+ |
/* Don't take any other arguments */ |
1109 |
+ |
if(argc>optind){ |
1110 |
+ |
usage(); |
1111 |
+ |
} |
1112 |
+ |
|
1113 |
|
if(sortby_ptr==NULL){ |
1114 |
|
sortby_ptr=cmp_cpu_used; |
1115 |
|
strlcpy(display_config.sortby, "CPU Used", SORTBYMAXNAME); |
1116 |
|
} |
1117 |
|
|
1118 |
< |
if(argc<(optind+2)){ |
1074 |
< |
printf("Usage is %s <-d lines> hostname port <machine list>\n", argv[0]); |
1075 |
< |
exit(1); |
1076 |
< |
} |
1077 |
< |
|
1078 |
< |
servername=argv[optind]; |
1079 |
< |
server_control_port=atoi(argv[optind+1]); |
1080 |
< |
|
1081 |
< |
control=create_tcp_connection(servername, server_control_port); |
1118 |
> |
control=create_tcp_connection(server_name, server_control_port); |
1119 |
|
if(control==NULL){ |
1120 |
|
errf("Failed to connect (%m)"); |
1121 |
|
exit(1); |
1122 |
|
} |
1123 |
|
|
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 |
– |
|
1124 |
|
if((tcp_comm(control, NULL, &response, "PROTOCOL 1.1"))!=0){ |
1125 |
|
errf("Incorrect version number (%s)", response); |
1126 |
|
exit(1); |
1153 |
|
exit(1); |
1154 |
|
} |
1155 |
|
|
1156 |
< |
data=create_tcp_connection(servername, server_data_port); |
1156 |
> |
data=create_tcp_connection(server_name, server_data_port); |
1157 |
|
if(data==NULL){ |
1158 |
< |
errf("Failed to connect to host %s on port %d (%m)",servername, server_data_port); |
1158 |
> |
errf("Failed to connect to host %s on port %d (%m)",server_name, server_data_port); |
1159 |
|
exit(1); |
1160 |
|
} |
1161 |
|
|