home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / linux / 17389 < prev    next >
Encoding:
Text File  |  1992-11-20  |  10.6 KB  |  404 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!arumble
  3. From: arumble@extro.ucc.su.OZ.AU (Anthony Rumble)
  4. Subject: Re: Seyon, PATCH FOR SEYON1.0
  5. Message-ID: <arumble.722312451@extro.ucc.su.OZ.AU>
  6. Sender: news@ucc.su.OZ.AU
  7. Nntp-Posting-Host: extro.ucc.su.oz.au
  8. Organization: Sydney University Computing Service, Sydney, NSW, Australia
  9. References: <1992Nov20.161114.20044@cs.tulane.edu>
  10. Date: Sat, 21 Nov 1992 02:20:51 GMT
  11. Lines: 391
  12.  
  13. kranz@cs.tulane.edu (Barry Kranz) writes:
  14.  
  15. >Although I have been able to compile the X app Seyon, everytime I
  16. >execute it I get a "killed by signal 11" error, has anyone gotten
  17. >this to work?
  18.  
  19. >Any help would be greatly appreciated!
  20.  
  21. Yes.. While fixing the LOCKFILE stuff, I found a MAJOR
  22. bug/nasty.. He should be rapped over the knuckles
  23. for this one..
  24.  
  25. Basically, he did something like 
  26. lckf[40] = LOCKFILE;  (LOCKFILE being "/usr/spool/uucp/LCK.."
  27.  
  28. Which is illegal.
  29.  
  30. Here is a patch that fixes that bug and implementes CORRECT
  31. lock files...
  32.  
  33. -------- Cut here -------
  34.  
  35. diff +show-c-function +new-file seyon/Makefile seyon-1.0//Makefile
  36. *** seyon/Makefile    Sat Nov 21 04:15:21 1992
  37. --- seyon-1.0//Makefile    Mon Nov 16 04:44:29 1992
  38. *************** DEFS         = -DHELPFILE=$(HELPFILE)
  39. *** 43,49 ****
  40.   LIBS        = -lXaw -lXmu -lXt -lX11
  41.   OBJS        = Seyon.o SeTerm.o xcsubs.o SePort.o \
  42.                   xcscrpt.o SeMain.o SeWin.o SeSubs.o SeHelp.o SeSet.o \
  43. !               SeDial.o SeTrans.o SeMisc.o lockfile.o
  44.   .c.o:;    $(CC) $(CFLAGS) -c $<
  45.   
  46.   all:: seyon-cmd seyon
  47. --- 43,49 ----
  48.   LIBS        = -lXaw -lXmu -lXt -lX11
  49.   OBJS        = Seyon.o SeTerm.o xcsubs.o SePort.o \
  50.                   xcscrpt.o SeMain.o SeWin.o SeSubs.o SeHelp.o SeSet.o \
  51. !               SeDial.o SeTrans.o SeMisc.o
  52.   .c.o:;    $(CC) $(CFLAGS) -c $<
  53.   
  54.   all:: seyon-cmd seyon
  55. diff +show-c-function +new-file seyon/SePort.c seyon-1.0//SePort.c
  56. *** seyon/SePort.c    Sat Nov 21 14:27:18 1992
  57. --- seyon-1.0//SePort.c    Mon Nov 16 10:14:41 1992
  58. ***************
  59. *** 27,33 ****
  60.   
  61.   #include "seyon.h"
  62.   #include "SeDecl.h"
  63. - #include "lockfile.h"
  64.   
  65.   /*
  66.       The dial() routine uses these two defines.
  67. --- 27,32 ----
  68. *************** send_slowly(s)
  69. *** 427,449 ****
  70.       Simple, eh?
  71.   */
  72.   
  73.   
  74.   lock_tty()
  75.   {
  76. !     char lckf[40];
  77. !     int tmp;    
  78.       char *modemname;
  79.   
  80. !     strcpy(lckf, LOCKFILE);
  81.       modemname = strrchr(port, '/');
  82.       strcat(lckf, (modemname ? (modemname+1) : port));
  83. !     tmp = makelock(lckf);
  84.   
  85. !     if (tmp)
  86. !     return 0;
  87.   }
  88.   
  89.   unlock_tty()
  90.   {
  91. !     rmlocks();
  92.   }
  93. --- 426,500 ----
  94.       Simple, eh?
  95.   */
  96.   
  97. + char lckf[40] = LOCKFILE;
  98. + char ltmp[40] = LTMPFILE;
  99.   
  100.   lock_tty()
  101.   {
  102. !     int pid, lckpid, lfd;
  103. !     char pidstr[20];
  104. !     char lckpidstr[20];
  105.       char *modemname;
  106. +     extern int errno;
  107.   
  108. !     /*
  109. !      * Get our PID, and initialize the filename strings.
  110. !      */
  111. !     pid = getpid();
  112. !     sprintf(pidstr, "%d", pid);
  113.       modemname = strrchr(port, '/');
  114.       strcat(lckf, (modemname ? (modemname+1) : port));
  115. !     strcat(ltmp, pidstr);
  116.   
  117. !     /*
  118. !      * Create the LTMP.<pid> file and scribble our PID in it.
  119. !      */
  120. !     unlink(ltmp);
  121. !     if ((lfd = creat(ltmp, 0444)) == -1) {
  122. !     fprintf(stderr, "Can't creat(2) LTMP file in %s\r\n", LTMPFILE);
  123. !     return -1;
  124. !     }
  125. !     sprintf(pidstr, "%10d\n", pid);
  126. !     write(lfd, pidstr, 11);
  127. !     close(lfd);
  128. !     /*
  129. !      * Attempt to link directly - if it works, we're done.
  130. !      */
  131. !   relink:
  132. !     if (link(ltmp, lckf) == 0) {
  133. !     unlink(ltmp);
  134. !         return 0;
  135. !     }
  136. !     /*
  137. !      * Oh, bother, there's a LCK..* file already; we must
  138. !      * now expend effort to learn if it's stale or not.
  139. !      */
  140. !     if ((lfd = open(lckf, O_RDONLY)) != -1) {
  141. !     if (read(lfd, lckpidstr, 11) == 11) {
  142. !         lckpid = atol(lckpidstr);
  143. !         if (kill(lckpid, 0) == 0) {
  144. !         fprintf(stderr, "%s locked by process %d.\r\n", port, lckpid);
  145. !         unlink(ltmp);
  146. !         return -1;
  147. !         }
  148. !     }
  149. !     }
  150. !     /*
  151. !      * The LCK..* file was stale.  Remove and retry.
  152. !      */
  153. !     if (unlink(lckf)) {
  154. !     fprintf(stderr, "Can't unlink(2) stale LCK?\r\n");
  155. !     unlink(ltmp);
  156. !     return -1;
  157. !     }
  158. !     goto relink;
  159. !     /*NOTREACHED*/
  160.   }
  161.   
  162.   unlock_tty()
  163.   {
  164. !     unlink(lckf);
  165.   }
  166. diff +show-c-function +new-file seyon/lockfile.c seyon-1.0//lockfile.c
  167. *** seyon/lockfile.c    Sat Nov 21 04:10:59 1992
  168. --- seyon-1.0//lockfile.c
  169. ***************
  170. *** 1,182 ****
  171. - /*************************************************************************
  172. - General UUCP Lock file Code (For NIXMAIL)
  173. - --------------------------------------------------------------------------
  174. - Copyright (c) 1992 Anthony Rumble
  175. - --------------------------------------------------------------------------
  176. - RCS Info
  177. - $Header: /home/smilie/emsi/RCS/lockfile.c,v 1.7 1992/10/18 07:57:51 smilie Exp $
  178. - $Log: lockfile.c,v $
  179. -  * Revision 1.7  1992/10/18  07:57:51  smilie
  180. -  * added rmlock
  181. -  *
  182. -  * Revision 1.6  1992/10/16  08:58:01  smilie
  183. -  * updated for nixmail
  184. -  *
  185. -  * Revision 1.5  1992/10/10  05:58:36  smilie
  186. -  * took out atexit
  187. -  *
  188. -  * Revision 1.4  1992/10/09  13:36:46  smilie
  189. -  * fixed some warnings
  190. -  *
  191. -  * Revision 1.3  1992/10/09  13:05:45  smilie
  192. -  * fixed a bug with the kill return
  193. -  *
  194. -  * Revision 1.2  1992/10/09  12:56:02  smilie
  195. -  * fixed an debug message up
  196. -  *
  197. -  * Revision 1.1  1992/10/09  09:57:26  smilie
  198. -  * Initial revision
  199. -  *
  200. - *************************************************************************/
  201. - /* Feature test switches */
  202. - #define _POSIX_SOURCE 1
  203. - #define _LOCKFILE_C
  204. - /* System Headers */
  205. - #include <stdio.h>
  206. - #include <stdlib.h>
  207. - #include <sys/types.h>
  208. - #include <unistd.h>
  209. - #include <signal.h>
  210. - #include <string.h>
  211. - /* Local Headers */
  212. - #include "lockfile.h"
  213. - /* Macros */
  214. - /* File scope variables */
  215. - static char lockfile_rcsid[] = "$Id: lockfile.c,v 1.7 1992/10/18 07:57:51 smilie Exp $";
  216. - #define RCSID lockfile_rcsid
  217. - /* External variables */
  218. - char lock[256];        /* Store the current lockfile */
  219. - /* External Functions */
  220. - /* Structures and unions */
  221. - /* Functions */
  222. - /************************************************************************
  223. -                 RMLOCKS
  224. - -------------------------------------------------------------------------
  225. -              Remove the current UUCP locks
  226. - *************************************************************************/
  227. - void rmlocks(void)
  228. - {
  229. - (void)unlink(lock);
  230. - }
  231. - /************************************************************************
  232. -                 RMLOCK
  233. - -------------------------------------------------------------------------
  234. - *************************************************************************/
  235. - void rmlock(char *s)
  236. - {
  237. - (void)unlink(s);
  238. - }
  239. - /************************************************************************
  240. -                 READLOCK
  241. - -------------------------------------------------------------------------
  242. - Read the PID from a lockfile, return -1 if there is no
  243. - valid lockfile
  244. - *************************************************************************/
  245. - pid_t readlock(char *name)
  246. - {
  247. - pid_t pid;
  248. - FILE *fh;
  249. - /**/
  250. - if ((fh = fopen(name, "rb")) == NULL)            /* Open the lockfile */
  251. -     {
  252. -     #ifdef DEBUG
  253. -     fprintf(stderr, "readlock: %s : %s\n", name, strerror(errno));
  254. -     #endif
  255. -     return -1;                    /* No lockfile exists */
  256. -     }
  257. - (void)fread(&pid, sizeof(pid), 1, fh);            /* Read in PID */
  258. - (void)fclose(fh);
  259. - return pid;
  260. - }
  261. - /************************************************************************
  262. -                 CHECKLOCK
  263. - -------------------------------------------------------------------------
  264. - Check the current lock, return TRUE if a valid lock exists
  265. - return FALSE if there is no valid lock
  266. - Pass the full path and filename of the lockfile to name
  267. - *************************************************************************/
  268. - int checklock(char *name)
  269. - {
  270. - pid_t pid;                /* PID Variable */
  271. - /**/
  272. - pid = readlock(name);            /* Read in PID */
  273. - if (pid == -1)                
  274. -     {
  275. -     #ifdef DEBUG
  276. -     (void)fprintf(stderr, "checklock: no valid lockfile exists\n");
  277. -     #endif
  278. -     return FALSE;
  279. -     }
  280. - if (kill(pid, 0) == -1)        /* See if the PID actually exists */
  281. -     {
  282. -     if (errno == ESRCH)
  283. -         {
  284. -         #ifdef DEBUG
  285. -         (void)fprintf(stderr, "checklock: PID '%u' does not exist, removing lockfile\n", pid);
  286. -         #endif
  287. -         (void)unlink(name);    /* Remove lock file as there is no such PID */
  288. -         return FALSE;
  289. -         }
  290. -     (void)fprintf(stderr, "checklock: Unknown KILL return '%u'\n", errno);
  291. -     return FALSE;
  292. -     }
  293. -     
  294. - return TRUE;                /* A valid lockfile was found */
  295. - }
  296. - /************************************************************************
  297. -                 MAKELOCK
  298. - -------------------------------------------------------------------------
  299. -      Will creat the lockfile 'name' if there is not a valid lockfile
  300. -                 under this name.
  301. - *************************************************************************/
  302. - int makelock(char *name)
  303. - {
  304. - FILE *fh;
  305. - pid_t pid;
  306. - /**/
  307. - if (checklock(name))
  308. -     {
  309. -     (void)fprintf(stderr, "makelock: Error, Valid lock file exists\n");
  310. -     return FALSE;
  311. -     }
  312. - pid = getpid();                        /* Get current PID */
  313. - if ((fh = fopen(name, "wb")) == NULL)
  314. -     {
  315. -     (void)fprintf(stderr, "Error creating lockfile '%s'\n", name);
  316. -     return FALSE;
  317. -     }
  318. - (void)fwrite(&pid, sizeof(pid), 1, fh);            /* Write PID */
  319. - (void)fclose(fh);
  320. - #ifdef DEBUG
  321. - (void)fprintf(stderr, "makelock: lock made\n");
  322. - #endif
  323. - (void)strcpy(lock, name);                /* set global lock file */
  324. - return TRUE;
  325. - }
  326. --- 0 ----
  327. diff +show-c-function +new-file seyon/lockfile.h seyon-1.0//lockfile.h
  328. *** seyon/lockfile.h    Sat Nov 21 04:10:03 1992
  329. --- seyon-1.0//lockfile.h
  330. ***************
  331. *** 1,36 ****
  332. - /*************************************************************************
  333. - GENERAL Lockfile header file
  334. - --------------------------------------------------------------------------
  335. - Copyright (c) 1992 Anthony Rumble
  336. - --------------------------------------------------------------------------
  337. - RCS Info
  338. - $Header: /home/smilie/emsi/RCS/lockfile.h,v 1.1 1992/10/09 13:19:00 smilie Exp $
  339. - $Log: lockfile.h,v $
  340. -  * Revision 1.1  1992/10/09  13:19:00  smilie
  341. -  * Initial revision
  342. -  *
  343. - $Id: lockfile.h,v 1.1 1992/10/09 13:19:00 smilie Exp $
  344. - *************************************************************************/
  345. - #ifndef _LOCKFILE_H
  346. - #define _LOCKFILE_H
  347. - #include <sys/types.h>
  348. - extern char lock[256];            /* lock file name */
  349. - extern void rmlocks(void);        /* remove lock file */
  350. - extern pid_t readlock(char *);        /* read a lock file */
  351. - extern int checklock(char *);        /* check a lock file */
  352. - extern int makelock(char *);        /* make a lock file */
  353. - #ifndef TRUE
  354. - #define TRUE 1
  355. - #define FALSE 0
  356. - #endif
  357. - #endif
  358. --- 0 ----
  359. Common subdirectories: seyon/xcomm_docs and seyon-1.0//xcomm_docs
  360. -- 
  361. Anthony Rumble
  362. aka SmilieZ
  363. "Anything is possible.. If there is enuf money in it"
  364.