wohler@SPAM.ISTC.SRI.COM (Bill Wohler) (10/12/87)
i patched in ed moys mods to xinit that source your ~/.Xinit file. commands are placed in this file that you like to run whenever you bring up x. examples include uwm, xlock and xhost. the file is executed if possible, otherwise /bin/sh is used to run the commands. i also reduced the lint output from about 40 lines to one. i feel that these patches are useful enough to make it into the distribution... if so, i'll be glad to make the necessary changes to the man page. --bw ----- patches for clients/xinit/xinit.c ----- *** /tmp/,RCSt1a01554 Sun Oct 11 17:28:49 1987 --- xinit.c Sun Oct 11 17:25:31 1987 *************** *** 9,14 **** --- 9,19 ---- #include <stdio.h> #include <ctype.h> #include <signal.h> + #include <strings.h> + #include <pwd.h> + #include <sys/types.h> + #include <sys/file.h> + #include <sys/dir.h> #include <sys/time.h> /* unused but resource.h needs it */ #include <sys/resource.h> #include <sys/wait.h> *************** *** 39,48 **** sigCatch(sig) int sig; { ! signal(SIGQUIT, SIG_IGN); ! signal(SIGINT, SIG_IGN); Error("signal %d\n", sig); ! shutdown(serverpid, clientpid); exit(1); } --- 44,53 ---- sigCatch(sig) int sig; { ! (void)signal(SIGQUIT, SIG_IGN); ! (void)signal(SIGINT, SIG_IGN); Error("signal %d\n", sig); ! (void)shutdown(serverpid, clientpid); exit(1); } *************** *** 53,59 **** register char **sptr = server; register char **cptr = client; register char **ptr; ! int pid, i; program = *argv++; argc--; --- 58,64 ---- register char **sptr = server; register char **cptr = client; register char **ptr; ! int pid; program = *argv++; argc--; *************** *** 94,111 **** /* * Start the server and client. */ ! signal(SIGQUIT, sigCatch); ! signal(SIGINT, sigCatch); if ((serverpid = startServer(server)) > 0 && (clientpid = startClient(client)) > 0) { pid = -1; while (pid != clientpid && pid != serverpid) ! pid = wait(NULL); } ! signal(SIGQUIT, SIG_IGN); ! signal(SIGINT, SIG_IGN); ! shutdown(serverpid, clientpid); if (serverpid < 0 || clientpid < 0) exit(ERR_EXIT); --- 99,117 ---- /* * Start the server and client. */ ! (void)signal(SIGQUIT, sigCatch); ! (void)signal(SIGINT, sigCatch); if ((serverpid = startServer(server)) > 0 && (clientpid = startClient(client)) > 0) { + rc(); pid = -1; while (pid != clientpid && pid != serverpid) ! pid = wait((union wait *)NULL); } ! (void)signal(SIGQUIT, SIG_IGN); ! (void)signal(SIGINT, SIG_IGN); ! (void)shutdown(serverpid, clientpid); if (serverpid < 0 || clientpid < 0) exit(ERR_EXIT); *************** *** 124,131 **** int cycles; /* Wait cycle count */ char display[100]; /* Display name */ ! strcpy(display, "unix"); ! strcat(display, displayNum); for (cycles = 0; cycles < ncycles; cycles++) { if (xd = XOpenDisplay(display)) { return(TRUE); --- 130,137 ---- int cycles; /* Wait cycle count */ char display[100]; /* Display name */ ! (void)strcpy(display, "unix"); ! (void)strcat(display, displayNum); for (cycles = 0; cycles < ncycles; cycles++) { if (xd = XOpenDisplay(display)) { return(TRUE); *************** *** 150,163 **** static char *laststring; for (;;) { ! if ((pidfound = wait3(&status, WNOHANG, NULL)) == pid) break; if (timeout) { if (i == 0 && string != laststring) ! fprintf(stderr, "\nwaiting for %s ", string); else ! fprintf(stderr, ".", string); ! fflush(stderr); } if (timeout) sleep (1); --- 156,171 ---- static char *laststring; for (;;) { ! if ((pidfound = wait3(&status, WNOHANG, NULL)) ! == pid) break; if (timeout) { if (i == 0 && string != laststring) ! (void)fprintf(stderr, ! "\nwaiting for %s ", string); else ! (void)fprintf(stderr, ".", string); ! (void)fflush(stderr); } if (timeout) sleep (1); *************** *** 168,184 **** return( pid != pidfound ); } Error(fmt, x0,x1,x2,x3,x4,x5,x6,x7,x8,x9) char *fmt; { extern char *sys_errlist[]; ! fprintf(stderr, "%s: ", program); if (errno) ! fprintf(stderr, "%s: ", sys_errlist[ errno ]); ! fprintf(stderr, fmt, x0,x1,x2,x3,x4,x5,x6,x7,x8,x9); } Fatal(fmt, x0,x1,x2,x3,x4,x5,x6,x7,x8,x9) char *fmt; { --- 176,194 ---- return( pid != pidfound ); } + /* VARARGS1 */ Error(fmt, x0,x1,x2,x3,x4,x5,x6,x7,x8,x9) char *fmt; { extern char *sys_errlist[]; ! (void)fprintf(stderr, "%s: ", program); if (errno) ! (void)fprintf(stderr, "%s: ", sys_errlist[ errno ]); ! (void)fprintf(stderr, fmt, x0,x1,x2,x3,x4,x5,x6,x7,x8,x9); } + /* VARARGS1 */ Fatal(fmt, x0,x1,x2,x3,x4,x5,x6,x7,x8,x9) char *fmt; { *************** *** 194,207 **** serverpid = vfork(); switch(serverpid) { case 0: ! close(0); ! close(1); /* * prevent server from getting sighup from vhangup() * if client is xterm -L */ ! setpgrp(0,0); execvp(server[0], server); Fatal("Server \"%s\" died on startup\n", server[0]); --- 204,217 ---- serverpid = vfork(); switch(serverpid) { case 0: ! (void)close(0); ! (void)close(1); /* * prevent server from getting sighup from vhangup() * if client is xterm -L */ ! (void)setpgrp(0,0); execvp(server[0], server); Fatal("Server \"%s\" died on startup\n", server[0]); *************** *** 212,218 **** /* * don't nice server */ ! setpriority( PRIO_PROCESS, serverpid, -1 ); errno = 0; if (! processTimeout(serverpid, 0, "")) { --- 222,228 ---- /* * don't nice server */ ! (void)setpriority( PRIO_PROCESS, serverpid, -1 ); errno = 0; if (! processTimeout(serverpid, 0, "")) { *************** *** 227,233 **** if (waitforserver(serverpid) == 0) { Error("Can't connect to server\n"); ! shutdown(serverpid, -1); serverpid = -1; } break; --- 237,243 ---- if (waitforserver(serverpid) == 0) { Error("Can't connect to server\n"); ! (void)shutdown(serverpid, -1); serverpid = -1; } break; *************** *** 242,249 **** int clientpid; if ((clientpid = vfork()) == 0) { ! setreuid(-1, -1); ! setpgrp(0, getpid()); execvp(client[0], client); Fatal("Client \"%s\" died on startup\n", client[0]); } --- 252,259 ---- int clientpid; if ((clientpid = vfork()) == 0) { ! (void)setreuid(-1, -1); ! (void)setpgrp(0, getpid()); execvp(client[0], client); Fatal("Client \"%s\" died on startup\n", client[0]); } *************** *** 250,255 **** --- 260,292 ---- return (clientpid); } + rc() + { + struct passwd *pw; + int pid; + char file[MAXNAMLEN]; + + if (pw = getpwuid(getuid())) { + (void)strcpy(file, pw->pw_dir); + (void)strcat(file, "/.Xinit"); + if (access(file, X_OK|R_OK) == 0) { + /*sleep(10); */ + if ((pid = vfork()) == 0) { + (void)setgid(getgid()); + (void)setuid(getuid()); + execl(file, file, 0); + /* failed, so try sourcing through sh */ + if ((pid = open(file, 0)) >= 0) { + (void)dup2(pid, 0); + (void)close(pid); + execl("/bin/sh", "sh", 0); + } + exit(1); + } + } + } + } + shutdown(serverpid, clientpid) int serverpid, clientpid; { *************** *** 276,283 **** if (! processTimeout(serverpid, 10, "server to terminate")) return; ! fprintf(stderr, "timeout... send SIGKILL"); ! fflush(stderr); errno = 0; if (kill(serverpid, SIGKILL) < 0) { if (errno == ESRCH) --- 313,320 ---- if (! processTimeout(serverpid, 10, "server to terminate")) return; ! (void)fprintf(stderr, "timeout... send SIGKILL"); ! (void)fflush(stderr); errno = 0; if (kill(serverpid, SIGKILL) < 0) { if (errno == ESRCH)
wohler@milk1.istc.sri.com..istc.sri.com (Bill Wohler) (10/12/87)
the examples include xclock, not xlock. freudian slip there. hap et