Package: xfrisk
Version: 1.2-2
Severity: wishlist
Tags: patch

Hi,
I wrote a small risk.c which is a launcher for frisk.
It is similar to the shell script provided with the package, but it
will clean up (kill the server and clients) after xfrisk is ended.
I used C instead of bash so I can be shure of the server pid when
killing it.

I think it could be a replacement for the current risk script.

The code is under the GPL, version 2 or later.

Cheers,
Alfredo

-- System Information:
Debian Release: 3.1
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: i386 (i686)
Kernel: Linux 2.6.8-2-k7
Locale: LANG=en_US, LC_CTYPE=en_US (charmap=ISO-8859-1)

Versions of packages xfrisk depends on:
ii  libc6                2.3.2.ds1-20        GNU C Library: Shared libraries an
ii  libice6              4.3.0.dfsg.1-12.0.1 Inter-Client Exchange library
ii  libsm6               4.3.0.dfsg.1-12.0.1 X Window System Session Management
ii  libx11-6             4.3.0.dfsg.1-12.0.1 X Window System protocol client li
ii  libxext6             4.3.0.dfsg.1-12.0.1 X Window System miscellaneous exte
ii  libxmu6              4.3.0.dfsg.1-12.0.1 X Window System miscellaneous util
ii  libxt6               4.3.0.dfsg.1-12.0.1 X Toolkit Intrinsics
ii  xaw3dg               1.5+E-8             Xaw3d widget set
ii  xlibs                4.3.0.dfsg.1-12     X Keyboard Extension (XKB) configu

-- no debconf information
/*
risk - a launcher for the frisk clients/server
Copyright (C) 2005 Alfredo Pironti

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>

#define N_CLIENTS 3

#define TRUE 1
#define FALSE 0

void clean_on_exit(pid_t server);

int main(void) {
	pid_t server_pid,xfrisk_pid;
	char server[] = "friskserver";
	char *clients[] = {"aiColson","aiConway","aiDummy"}; //if update here remember to update N_CLIENTS!!!
	char xfrisk[] = "xfrisk";
	char location[] = "localhost";

	int i;

	//set up the server
	switch ((server_pid=fork())) {
		case -1:
			perror("fork(server)");
			exit(1);
		case 0: //child. It will be the server
			printf("Starting the server.\n");
			execlp(server,server,location,(char *)NULL);
			perror("execlp(server)");
			exit(1);
		default:
			break;
	}
	
	for (i=0;i<N_CLIENTS;i++) {
		switch (fork()) {
			case -1:
				perror("fork(client)");
				break; //this is not fatal, we don't exit
			case 0: //child. It will be a client
				printf("Starting the %s client.\n",clients[i]);
				execlp(clients[i],clients[i],location,(char *)NULL);
				perror("execlp(client)");
				exit(1);
			default:
				break;
		}
	}

	//now spawn the xfrisk client and wait for it
	switch((xfrisk_pid=fork())) {
		case -1:
			perror("fork(xfrisk)");
			clean_on_exit(server_pid);
			exit(1);
		case 0://child. we spawn xfrisk client
			printf("Starting xfrisk.\n");
			execlp(xfrisk,xfrisk,location,(char *)NULL);
			perror("execlp(xfrisk)");
			exit(1);
		default:
			waitpid(xfrisk_pid,NULL,0);
			clean_on_exit(server_pid);
			printf("xfrisk ended. Quitting.\n");
			exit(0);
	}
}

void clean_on_exit(pid_t server) {
	printf("Killing the server.\n");
	kill(server,SIGTERM);
	waitpid(server,NULL,0);
}

Reply via email to