home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / unix / programm / 5305 < prev    next >
Encoding:
Text File  |  1992-11-17  |  4.6 KB  |  212 lines

  1. Newsgroups: comp.unix.programmer
  2. Path: sparky!uunet!news.mentorg.com!hp_mgs1!simtc
  3. From: simtc@hp_mgs1.mentorg.com (Sim Thiam Chye)
  4. Subject: RPC client TIMEOUT
  5. Message-ID: <1992Nov17.030446.29591@news.mentorg.com>
  6. Sender: simtc@hp_mgs1 (Sim Thiam Chye)
  7. Date: Tue, 17 Nov 1992 03:04:46 GMT
  8. Reply-To: thiam-chye_sim@mentorg.com
  9. Nntp-Posting-Host: hp_mgs1.mentorg.com
  10. Organization: Mentor Graphics Corporation
  11. Keywords: rpc
  12. Followup-To: 
  13. Lines: 197
  14.  
  15. I am re-posting my question, but this time with a trim down source as requested
  16. by Brian Fritzgerald. 
  17.  
  18. Problem: The client did not receive an signal from the server that it has
  19. finished it's request. This problem occurs only when the server is running
  20. on a HP710 (OS HP-UX 9.0). The same source runs as desired on the Sun machine.
  21.  
  22. Since this is my first attempt to write a useful C program, please excuse the
  23. programming "style".
  24.  
  25. ############## alarm.x ################
  26. /* The file alarm.x */
  27.  
  28. struct body {
  29.         char    user[256];
  30.         char    msg[1024];
  31. };
  32.  
  33.  
  34. program ALARMPROG {
  35.         version ALARMVERS {
  36.                 void SEND_ALARM(body) = 1;
  37.         } = 1;
  38. } = 0x30000055;
  39.  
  40. ############### END ####################
  41.  
  42. ############ send_alarm.c ##############
  43.  
  44. #include <stdio.h>
  45. #include <pwd.h>
  46. #include <string.h>
  47. #include <sys/types.h>
  48. #include <rpc/rpc.h>
  49. #include "alarm.h"
  50. #define maxlen 256
  51.  
  52. void usage();
  53. void call_server();
  54.  
  55. main(argc, argv)
  56. int argc; char *argv[];
  57. {
  58.     CLIENT *cl;
  59.     int i, uid;
  60.     int j = 0;
  61.     int start = 0;
  62.     int idx = 0;
  63.     int nodeidx = 0;
  64.     int nodenum = 0;
  65.     char group[32];
  66.     char alias[32];
  67.     char string[256];
  68.     char tbuf[256];
  69.     char *server, *s, *m, *msg;
  70.     char *node[50];
  71.     char *alarmrc;
  72.     char ch;
  73.     struct passwd *pass;
  74.     struct body *x;
  75.     FILE *fp1; 
  76.  
  77.     if (argc < 3) /* If not enough arguments */
  78.           usage(); 
  79.  
  80.     uid=getuid();
  81.     pass=getpwuid(uid);
  82.     x = (body *)malloc(sizeof(body));
  83.     alarmrc = (char *)malloc(strlen(pass->pw_dir) + 9);
  84.     strcpy(alarmrc, pass->pw_dir); 
  85.     strcat(alarmrc, "/.alarmrc");
  86.     strcpy(x->user, pass->pw_name); 
  87.     
  88.     for (i=1; i<argc; i++)
  89.     {
  90.         if (*argv[i] == '-')
  91.         {
  92.             switch(ch = argv[i][1])
  93.             {
  94.             case 'n':
  95.                 if ( i == (argc-1))
  96.                 {
  97.                     usage(); 
  98.                 }
  99.                 j = strlen(argv[i]);
  100.                 if ( j != 2 )     /* Check for extra characters */
  101.                     break;
  102.                 if (idx == 0)
  103.                 { start = i+1;
  104.                     idx = start;
  105.                 }
  106.                 for ( idx; idx < argc; idx++)
  107.                 {
  108.                     if (*argv[idx] == '-')
  109.                     {    i = idx-1;
  110.                         break;
  111.                     }
  112.                       node[nodeidx] = argv[idx];
  113.                       nodeidx++;
  114.                 }
  115.                 nodenum = nodeidx; 
  116.                 call_server(start, &nodenum, node, argv, x);
  117.                 break;
  118.             default:
  119.                 if (i == (argc-1))
  120.                     usage(); 
  121.                 else
  122.                     break;
  123.             }
  124.             exit(0);
  125.         }
  126.         else
  127.         {
  128.             if (i == (argc-1))
  129.                 usage();
  130.         }
  131.     }
  132. }   /* End of main() */
  133.  
  134. /***************** usage() ******************/
  135. void usage()
  136. {
  137.     (void) printf("usage: send_alarm <message> [-n <nodes>] [-a] [-g grp1 grp2]\n");
  138.     exit(1);
  139. }
  140.  
  141. /***************** call_server() ******************/
  142. void call_server(start, nodenum, node, message, x)
  143. int start;
  144. int *nodenum;
  145. char *node[];
  146. char **message;
  147. struct body *x;
  148. {
  149. CLIENT *cl;
  150. int i, idx;
  151. char *server;
  152.  
  153.     idx = start - 1;
  154.     strcpy(x->msg, " ");
  155.     for (i=1; i<idx; i++)
  156.     {
  157.         strcat(x->msg, message[i]);
  158.         strcat(x->msg, " ");
  159.     }
  160.  
  161.     for (i=0; i<*nodenum; i++)
  162.     {
  163.         server = node[i];
  164.         cl = clnt_create(server, ALARMPROG, ALARMVERS, "tcp");
  165.         if (cl == NULL) {
  166.             clnt_pcreateerror(server); 
  167.             printf("alarm not send to %s\n",server);
  168.         }
  169.         else
  170.         {
  171.             send_alarm_1(x, cl); 
  172.             clnt_destroy(cl);
  173.         }
  174.     } 
  175.     exit(0);
  176. }
  177. ################ END ##########################
  178.  
  179. #################### alarm_server.c #####################
  180. #include <stdio.h>
  181. #include <string.h>
  182. #include <rpc/rpc.h>
  183. #include "alarm.h"
  184.  
  185. typedef char *string;
  186. char sys_cmd[2048];
  187.  
  188. void *send_alarm_1(list)
  189. body *list;
  190. {
  191.     char buf1[2048] ;
  192.     char *token;
  193.     int i;
  194.     int j = 60;
  195.  
  196.      strcpy(sys_cmd,"xalarm -geom +0+0 -nc -time +0 \"");
  197.     strcat(buf1, list->msg); 
  198.     strcat(buf1, "\"");
  199.     strcat(sys_cmd, buf1);
  200.     system(sys_cmd);
  201. }
  202. ################ END ###########################
  203.  
  204. -- 
  205. *************************************************************************
  206. *    _/_/_/_/  _/_/_/_/_/  _/_/_/_/    Sim Thiam Chye                   *
  207. *   _/            _/      _/           Mentor Graphics (S) Pte Ltd      *
  208. *  _/_/_/_/      _/      _/            Phone: 8709-265                  *
  209. *       _/      _/      _/             Email: simtc@em-sg01.mentorg.com *
  210. *_/_/_/_/      _/      _/_/_/_/                                         *
  211. *************************************************************************
  212.