1 /*- 2 * Copyright (c) 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)instr.c 5.2 (Berkeley) 02/28/91"; 10 #endif /* not lint */ 11 12 #include <sys/types.h> 13 #include <sys/wait.h> 14 #include <sys/errno.h> 15 #include <sys/stat.h> 16 #include <unistd.h> 17 #include <stdio.h> 18 #include <stdlib.h> 19 #include <string.h> 20 #include "pathnames.h" 21 22 instructions() 23 { 24 extern int errno; 25 struct stat sb; 26 union wait pstat; 27 pid_t pid; 28 char *pager, *path; 29 30 if (stat(_PATH_INSTR, &sb)) { 31 (void)fprintf(stderr, "cribbage: %s: %s.\n", _PATH_INSTR, 32 strerror(errno)); 33 exit(1); 34 } 35 switch(pid = vfork()) { 36 case -1: 37 (void)fprintf(stderr, "cribbage: %s.\n", strerror(errno)); 38 exit(1); 39 case 0: 40 if (!(path = getenv("PAGER"))) 41 path = _PATH_MORE; 42 if (pager = rindex(path, '/')) 43 ++pager; 44 pager = path; 45 execlp(path, pager, _PATH_INSTR, (char *)NULL); 46 (void)fprintf(stderr, "cribbage: %s.\n", strerror(errno)); 47 _exit(1); 48 default: 49 do { 50 pid = waitpid(pid, (int *)&pstat, 0); 51 } while (pid == -1 && errno == EINTR); 52 if (pid == -1 || pstat.w_status) 53 exit(1); 54 } 55 } 56