From: simtc@hp_mgs1.mentorg.com (Sim Thiam Chye)
Subject: RPC client TIMEOUT
Date: Tue, 17 Nov 1992 03:04:46 GMT
Reply-To: thiam-chye_sim@mentorg.com
Organization: Mentor Graphics Corporation
Keywords: rpc
Followup-To: 

I am re-posting my question, but this time with a trim down source as requested
by Brian Fritzgerald. 

Problem: The client did not receive an signal from the server that it has
finished it's request. This problem occurs only when the server is running
on a HP710 (OS HP-UX 9.0). The same source runs as desired on the Sun machine.

Since this is my first attempt to write a useful C program, please excuse the
programming "style".

############## alarm.x ################
/* The file alarm.x */

struct body {
        char    user[256];
        char    msg[1024];
};


program ALARMPROG {
        version ALARMVERS {
                void SEND_ALARM(body) = 1;
        } = 1;
} = 0x30000055;

############### END ####################

############ send_alarm.c ##############

#include <stdio.h>
#include <pwd.h>
#include <string.h>
#include <sys/types.h>
#include <rpc/rpc.h>
#include "alarm.h"
#define maxlen 256

void usage();
void call_server();

main(argc, argv)
int argc; char *argv[];
{
	CLIENT *cl;
	int i, uid;
	int j = 0;
	int start = 0;
	int idx = 0;
	int nodeidx = 0;
	int nodenum = 0;
	char group[32];
	char alias[32];
	char string[256];
	char tbuf[256];
    char *server, *s, *m, *msg;
	char *node[50];
	char *alarmrc;
	char ch;
	struct passwd *pass;
	struct body *x;
	FILE *fp1; 

	if (argc < 3) /* If not enough arguments */
	  	usage(); 

    uid=getuid();
    pass=getpwuid(uid);
    x = (body *)malloc(sizeof(body));
    alarmrc = (char *)malloc(strlen(pass->pw_dir) + 9);
    strcpy(alarmrc, pass->pw_dir); 
    strcat(alarmrc, "/.alarmrc");
    strcpy(x->user, pass->pw_name); 
    
    for (i=1; i<argc; i++)
    {
    	if (*argv[i] == '-')
		{
    		switch(ch = argv[i][1])
    		{
			case 'n':
				if ( i == (argc-1))
				{
    				usage(); 
				}
    			j = strlen(argv[i]);
    			if ( j != 2 )     /* Check for extra characters */
					break;
				if (idx == 0)
    			{ start = i+1;
    			    idx = start;
				}
    			for ( idx; idx < argc; idx++)
    			{
					if (*argv[idx] == '-')
					{	i = idx-1;
						break;
					}
    			  	node[nodeidx] = argv[idx];
    			  	nodeidx++;
    			}
    			nodenum = nodeidx; 
    			call_server(start, &nodenum, node, argv, x);
    			break;
    		default:
				if (i == (argc-1))
					usage(); 
				else
					break;
    		}
			exit(0);
		}
		else
		{
			if (i == (argc-1))
				usage();
		}
    }
}   /* End of main() */

/***************** usage() ******************/
void usage()
{
	(void) printf("usage: send_alarm <message> [-n <nodes>] [-a] [-g grp1 grp2]\n");
	exit(1);
}

/***************** call_server() ******************/
void call_server(start, nodenum, node, message, x)
int start;
int *nodenum;
char *node[];
char **message;
struct body *x;
{
CLIENT *cl;
int i, idx;
char *server;

	idx = start - 1;
	strcpy(x->msg, " ");
	for (i=1; i<idx; i++)
	{
		strcat(x->msg, message[i]);
		strcat(x->msg, " ");
	}

	for (i=0; i<*nodenum; i++)
	{
		server = node[i];
		cl = clnt_create(server, ALARMPROG, ALARMVERS, "tcp");
		if (cl == NULL) {
			clnt_pcreateerror(server); 
			printf("alarm not send to %s\n",server);
		}
		else
		{
			send_alarm_1(x, cl); 
			clnt_destroy(cl);
		}
	} 
	exit(0);
}
################ END ##########################

#################### alarm_server.c #####################
#include <stdio.h>
#include <string.h>
#include <rpc/rpc.h>
#include "alarm.h"

typedef char *string;
char sys_cmd[2048];

void *send_alarm_1(list)
body *list;
{
	char buf1[2048] ;
	char *token;
	int i;
	int j = 60;

 	strcpy(sys_cmd,"xalarm -geom +0+0 -nc -time +0 \"");
	strcat(buf1, list->msg); 
	strcat(buf1, "\"");
	strcat(sys_cmd, buf1);
	system(sys_cmd);
}
################ END ###########################

-- 
*************************************************************************
*    _/_/_/_/  _/_/_/_/_/  _/_/_/_/    Sim Thiam Chye                   *
*   _/            _/      _/           Mentor Graphics (S) Pte Ltd      *
*  _/_/_/_/      _/      _/            Phone: 8709-265                  *
*       _/      _/      _/             Email: simtc@em-sg01.mentorg.com *
*_/_/_/_/      _/      _/_/_/_/                                         *
*************************************************************************