4 Copyright (C) 1991, 1992, 1993, 1995 Ian Lance Taylor
6 This file is part of the Taylor UUCP package.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 The author of the program may be contacted at ian@airs.com or
23 c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
36 /* Given a set of commands to execute for a remote system, create a
37 command file holding them. This creates a single command file
38 holding all the commands passed in. It returns a jobid. */
41 zsysdep_spool_commands (qsys, bgrade, ccmds, pascmds)
42 const struct uuconf_system *qsys;
45 const struct scmd *pascmds;
47 char abtempfile[sizeof "TMP1234567890"];
56 if (! UUCONF_GRADE_LEGAL (bgrade))
57 ulog (LOG_FATAL, "Bad grade %d", bgrade);
60 /* Write the commands into a temporary file and then rename it to
61 avoid a race with uucico reading the file. */
62 sprintf (abtempfile, "TMP%010lx", (unsigned long) getpid ());
63 ztemp = zsfind_file (abtempfile, qsys->uuconf_zname, bgrade);
67 e = esysdep_fopen (ztemp, FALSE, FALSE, TRUE);
74 for (i = 0, q = pascmds; i < ccmds; i++, q++)
79 fprintf (e, "S %s %s %s -%s %s 0%o %s\n", q->zfrom, q->zto,
80 q->zuser, q->zoptions, q->ztemp, q->imode,
81 q->znotify == NULL ? (const char *) "" : q->znotify);
84 fprintf (e, "R %s %s %s -%s\n", q->zfrom, q->zto, q->zuser,
88 fprintf (e, "X %s %s %s -%s\n", q->zfrom, q->zto, q->zuser,
92 fprintf (e, "E %s %s %s -%s %s 0%o %s 0 %s\n", q->zfrom, q->zto,
93 q->zuser, q->zoptions, q->ztemp, q->imode,
98 "zsysdep_spool_commands: Unrecognized type %d",
101 (void) remove (ztemp);
107 if (! fstdiosync (e, ztemp))
110 (void) remove (ztemp);
117 ulog (LOG_ERROR, "fclose: %s", strerror (errno));
118 (void) remove (ztemp);
123 /* The filename returned by zscmd_file is subject to some unlikely
124 race conditions, so keep trying the link until the destination
125 file does not already exist. Each call to zscmd_file should
126 return a file name which does not already exist, so we don't have
127 to do anything special before calling it again. */
130 z = zscmd_file (qsys, bgrade);
133 (void) remove (ztemp);
138 if (link (ztemp, z) >= 0)
143 ulog (LOG_ERROR, "link (%s, %s): %s", ztemp, z, strerror (errno));
144 (void) remove (ztemp);
153 (void) remove (ztemp);
156 zjobid = zsfile_to_jobid (qsys, z, bgrade);