|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <errno.h> /* obligatory includes */</errno.h>
|
|
Toshihiro Shimizu |
890ddd |
#include <signal.h></signal.h>
|
|
Toshihiro Shimizu |
890ddd |
#include <stdio.h></stdio.h>
|
|
Toshihiro Shimizu |
890ddd |
#include <unistd.h></unistd.h>
|
|
Toshihiro Shimizu |
890ddd |
#include <sys types.h=""></sys>
|
|
Toshihiro Shimizu |
890ddd |
#include <sys socket.h=""></sys>
|
|
Toshihiro Shimizu |
890ddd |
#include <sys wait.h=""></sys>
|
|
Toshihiro Shimizu |
890ddd |
#include <netinet in.h=""></netinet>
|
|
Toshihiro Shimizu |
890ddd |
#include <netdb.h></netdb.h>
|
|
Toshihiro Shimizu |
890ddd |
#include "tcommon.h"
|
|
Toshihiro Shimizu |
890ddd |
#define MAXHOSTNAME 1024
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int call_socket(char *hostname, unsigned short portnum)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
struct sockaddr_in sa;
|
|
Toshihiro Shimizu |
890ddd |
struct hostent *hp;
|
|
Toshihiro Shimizu |
890ddd |
int s;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if ((hp = gethostbyname(hostname)) == NULL) /* do we know the host's */
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
errno = ECONNREFUSED; /* address? */
|
|
Toshihiro Shimizu |
890ddd |
return (-1); /* no */
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
memset(&sa, 0, sizeof(sa));
|
|
Toshihiro Shimizu |
890ddd |
memcpy((char *)&sa.sin_addr, hp->h_addr, hp->h_length); /* set address */
|
|
Toshihiro Shimizu |
890ddd |
sa.sin_family = hp->h_addrtype;
|
|
Toshihiro Shimizu |
890ddd |
sa.sin_port = htons((u_short)portnum);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if ((s = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0) /* get socket */
|
|
Toshihiro Shimizu |
890ddd |
return (-1);
|
|
Toshihiro Shimizu |
890ddd |
if (connect(s, (struct sockaddr *)&sa, sizeof sa) < 0) /* connect */
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
close(s);
|
|
Toshihiro Shimizu |
890ddd |
return (-1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return (s);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int main(int argc, char *argv[])
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
char myname[MAXHOSTNAME + 1];
|
|
Toshihiro Shimizu |
890ddd |
gethostname(myname, MAXHOSTNAME); /* who are we? */
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int s;
|
|
Toshihiro Shimizu |
890ddd |
int portNumber = 8002;
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::ifstream is("/tmp/.tfarmserverd.dat");
|
|
Toshihiro Shimizu |
890ddd |
is >> portNumber;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
// std::cout << "shutting down " << portNumber << std::endl;
|
|
Toshihiro Shimizu |
890ddd |
if ((s = call_socket(myname, portNumber)) < 0) {
|
|
Toshihiro Shimizu |
890ddd |
fprintf(stderr, "Unable to stop the tfarmserved daemon\n");
|
|
Toshihiro Shimizu |
890ddd |
exit(1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
write(s, "shutdown", strlen("shutdown") + 1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
close(s);
|
|
Toshihiro Shimizu |
890ddd |
exit(0);
|
|
Toshihiro Shimizu |
890ddd |
}
|