| 
 | 
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes | 
 
This is an automatic "excavation" of a thematic subset of
 See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software.  | 
top - metrics - downloadIndex: T f
    Length: 1277 (0x4fd)
    Types: TextFile
    Names: »flock.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
    └─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z« 
        └─⟦e5a54fb17⟧ 
            └─⟦this⟧ »pp-5.0/Uip/misc/flock.c« 
/* flock.c: lock a file and execute a command */
# ifndef lint
static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Uip/misc/RCS/flock.c,v 5.0 90/09/20 16:33:18 pp Exp Locker: pp $";
# endif
/*
 * $Header: /cs/research/pp/hubris/pp-beta/Uip/misc/RCS/flock.c,v 5.0 90/09/20 16:33:18 pp Exp Locker: pp $
 *
 * $Log:	flock.c,v $
 * Revision 5.0  90/09/20  16:33:18  pp
 * rcsforce : 5.0 public release
 * 
 */
#include "util.h"
#include <sys/wait.h>
main (argc, argv)
int	argc;
char	**argv;
{
	FILE	*fp;
	extern int errno;
	int	pid, cpid;
	union wait status;
	uip_init (argv[0]);
	if (argc < 3) {
		fprintf (stderr, "Usage: %s file commands...\n", argv[0]);
		exit (1);
	}
	if ((fp = flckopen (argv[1], "a")) == NULL) {
		fprintf (stderr, "%s: Can't open file %s: %s\n",
			 argv[0], argv[1], sys_errname (errno));
		exit (1);
	}
	if ((pid = tryfork () ) == NOTOK) {
		fprintf (stderr, "%s: can't fork: %s\n", argv[0],
			 sys_errname (errno));
		exit (1);
	}
	if (pid == 0) {
		fclose (fp);
		execv (argv[2], &argv[2]);
		_exit (1);
	}
	while ((cpid = wait( &status)) != pid && cpid != NOTOK)
		continue;
	if (cpid == NOTOK)	/* ??? */
		exit (1);
	if (WIFSIGNALED(status))
		exit (1);
	if (WIFEXITED(status))
		exit (status.w_retcode);
	exit (1);
}