diff options
Diffstat (limited to 'gnu/libexec/uucp/libunix/splcmd.c')
-rw-r--r-- | gnu/libexec/uucp/libunix/splcmd.c | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/gnu/libexec/uucp/libunix/splcmd.c b/gnu/libexec/uucp/libunix/splcmd.c index 9f6616a36dd0..774066119967 100644 --- a/gnu/libexec/uucp/libunix/splcmd.c +++ b/gnu/libexec/uucp/libunix/splcmd.c @@ -1,7 +1,7 @@ /* splcmd.c Spool a command. - Copyright (C) 1991, 1992 Ian Lance Taylor + Copyright (C) 1991, 1992, 1993 Ian Lance Taylor This file is part of the Taylor UUCP package. @@ -20,7 +20,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. The author of the program may be contacted at ian@airs.com or - c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254. + c/o Cygnus Support, Building 200, 1 Kendall Square, Cambridge, MA 02139. */ #include "uucp.h" @@ -44,10 +44,12 @@ zsysdep_spool_commands (qsys, bgrade, ccmds, pascmds) int ccmds; const struct scmd *pascmds; { - char *z; + char abtempfile[sizeof "TMP1234567890"]; + char *ztemp; FILE *e; int i; const struct scmd *q; + char *z; char *zjobid; #if DEBUG > 0 @@ -55,14 +57,17 @@ zsysdep_spool_commands (qsys, bgrade, ccmds, pascmds) ulog (LOG_FATAL, "Bad grade %d", bgrade); #endif - z = zscmd_file (qsys, bgrade); - if (z == NULL) + /* Write the commands into a temporary file and then rename it to + avoid a race with uucico reading the file. */ + sprintf (abtempfile, "TMP%010lx", (unsigned long) getpid ()); + ztemp = zsfind_file (abtempfile, qsys->uuconf_zname, bgrade); + if (ztemp == NULL) return NULL; - e = esysdep_fopen (z, FALSE, FALSE, TRUE); + e = esysdep_fopen (ztemp, FALSE, FALSE, TRUE); if (e == NULL) { - ubuffree (z); + ubuffree (ztemp); return NULL; } @@ -93,8 +98,8 @@ zsysdep_spool_commands (qsys, bgrade, ccmds, pascmds) "zsysdep_spool_commands: Unrecognized type %d", q->bcmd); (void) fclose (e); - (void) remove (z); - ubuffree (z); + (void) remove (ztemp); + ubuffree (ztemp); return NULL; } } @@ -102,11 +107,30 @@ zsysdep_spool_commands (qsys, bgrade, ccmds, pascmds) if (fclose (e) != 0) { ulog (LOG_ERROR, "fclose: %s", strerror (errno)); - (void) remove (z); + (void) remove (ztemp); + ubuffree (ztemp); + return NULL; + } + + z = zscmd_file (qsys, bgrade); + if (z == NULL) + { + (void) remove (ztemp); + ubuffree (ztemp); + return NULL; + } + + if (! fsysdep_move_file (ztemp, z, FALSE, FALSE, FALSE, + (const char *) NULL)) + { + (void) remove (ztemp); + ubuffree (ztemp); ubuffree (z); return NULL; } + ubuffree (ztemp); + zjobid = zsfile_to_jobid (qsys, z, bgrade); if (zjobid == NULL) (void) remove (z); |