ReactOS  0.4.14-dev-358-gbef841c
spool.c File Reference
#include "syshdrs.h"
#include "spool.h"
#include "util.h"
Include dependency graph for spool.c:

Go to the source code of this file.

Functions

void CloseControlConnection (const FTPCIPtr)
 
void TruncBatchLog (void)
 
int MkSpoolDir (char *sdir, size_t size)
 
void SpoolName (const char *const sdir, char *sp, size_t size, int flag, int serial, time_t when)
 
int HaveSpool (void)
 
int CanSpool (void)
 
int SpoolX (const char *const op, const char *const rfile, const char *const rdir, const char *const lfile, const char *const ldir, const char *const host, const char *const ip, const unsigned int port, const char *const user, const char *const passclear, int xtype, int recursive, int delete, int passive, const char *const precmd, const char *const perfilecmd, const char *const postcmd, time_t when)
 
static int PWrite (int sfd, const char *const buf0, size_t size)
 
void Jobs (void)
 
void RunBatch (int Xstruct, const FTPCIPtr cip)
 
void RunBatchIfNeeded (const FTPCIPtr cip)
 

Variables

int gSpoolSerial = 0
 
int gUnprocessedJobs = 0
 
int gJobs = 0
 
int gHaveSpool = -1
 
FTPLibraryInfo gLib
 
char gOurDirectoryPath []
 
char gOurInstallationPath []
 

Function Documentation

◆ CanSpool()

int CanSpool ( void  )

Definition at line 145 of file spool.c.

146 {
147  char sdir[256];
148 
149  if (gOurDirectoryPath[0] == '\0') {
150  return (-1);
151  }
152  if (MkSpoolDir(sdir, sizeof(sdir)) < 0)
153  return (-1);
154  return (0);
155 } /* CanSpool */
int MkSpoolDir(char *sdir, size_t size)
Definition: spool.c:56
char gOurDirectoryPath[]
Definition: util.c:17

Referenced by SpoolCheck().

◆ CloseControlConnection()

void CloseControlConnection ( const  FTPCIPtr)

Definition at line 197 of file ftp.c.

198 {
199  /* This will close each file, if it was open. */
200 #ifdef NO_SIGNALS
201  SClose(cip->ctrlSocketR, 3);
202  cip->ctrlSocketR = kClosedFileDescriptor;
203  cip->ctrlSocketW = kClosedFileDescriptor;
204  DisposeSReadlineInfo(&cip->ctrlSrl);
205 #else /* NO_SIGNALS */
206  if (cip->ctrlTimeout > 0)
207  (void) alarm(cip->ctrlTimeout);
208  CloseFile(&cip->cin);
209  CloseFile(&cip->cout);
210  cip->ctrlSocketR = kClosedFileDescriptor;
211  cip->ctrlSocketW = kClosedFileDescriptor;
212  if (cip->ctrlTimeout > 0)
213  (void) alarm(0);
214 #endif /* NO_SIGNALS */
215  cip->connected = 0;
216  cip->loggedIn = 0;
217 } /* CloseControlConnection */
void DisposeSReadlineInfo(SReadlineInfo *)
Definition: SReadline.c:57
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
int SClose(int sfd, int tlen)
Definition: SClose.c:9
#define kClosedFileDescriptor
Definition: util.h:47
void CloseFile(FILE **f)
Definition: util.c:327

Referenced by FTPCloseHost(), FTPShutdownHost(), HangupOnServer(), and RunBatch().

◆ HaveSpool()

int HaveSpool ( void  )

Definition at line 107 of file spool.c.

108 {
109 #if defined(WIN32) || defined(_WINDOWS)
110  char ncftpbatch[260];
111 
112  if (gHaveSpool < 0) {
113  gHaveSpool = 0;
114  if (gOurInstallationPath[0] != '\0') {
115  OurInstallationPath(ncftpbatch, sizeof(ncftpbatch), "ncftpbatch.exe");
116  gHaveSpool = (_access(ncftpbatch, F_OK) == 0) ? 1 : 0;
117  }
118  }
119 #elif defined(BINDIR)
120  char ncftpbatch[256];
121 
122  if (gHaveSpool < 0) {
123  STRNCPY(ncftpbatch, BINDIR);
124  STRNCAT(ncftpbatch, "/");
125  STRNCAT(ncftpbatch, "ncftpbatch");
126  gHaveSpool = (access(ncftpbatch, X_OK) == 0) ? 1 : 0;
127  }
128 #else /* BINDIR */
129  if (gHaveSpool < 0) {
130  if (geteuid() == 0) {
131  gHaveSpool = (access("/usr/bin/ncftpbatch", X_OK) == 0) ? 1 : 0;
132  } else {
133  gHaveSpool = (system("ncftpbatch -X") == 0) ? 1 : 0;
134  }
135  }
136 #endif /* BINDIR */
137 
138  return (gHaveSpool);
139 } /* HaveSpool */
int gHaveSpool
Definition: spool.c:21
char gOurInstallationPath[]
Definition: util.c:18
#define STRNCPY(dst, src, n)
Definition: rdesktop.h:168
#define F_OK
Definition: util.h:52
int __cdecl system(_In_opt_z_ const char *_Command)
#define X_OK
Definition: io.h:169
#define STRNCAT(d, s)
Definition: Strn.h:48
_Check_return_ _CRTIMP int __cdecl _access(_In_z_ const char *_Filename, _In_ int _AccessMode)
EXPORT uid_t geteuid()
Definition: uid.c:37
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
char * OurInstallationPath(char *const dst, const size_t siz, const char *const fname)
Definition: util.c:494

Referenced by SpoolCheck().

◆ Jobs()

void Jobs ( void  )

Definition at line 318 of file spool.c.

319 {
320 #if defined(WIN32) || defined(_WINDOWS)
321  assert(0); // Not supported
322 #else
323  char *argv[8];
324  pid_t pid;
325 #ifdef BINDIR
326  char ncftpbatch[256];
327 
328  STRNCPY(ncftpbatch, BINDIR);
329  STRNCAT(ncftpbatch, "/");
330  STRNCAT(ncftpbatch, "ncftpbatch");
331 #endif /* BINDIR */
332 
333  pid = fork();
334  if (pid < 0) {
335  perror("fork");
336  } else if (pid == 0) {
337  argv[0] = (char *) "ncftpbatch";
338  argv[1] = (char *) "-l";
339  argv[2] = NULL;
340 
341 #ifdef BINDIR
342  (void) execv(ncftpbatch, argv);
343  (void) fprintf(stderr, "Could not run %s. Is it in installed as %s?\n", argv[0], ncftpbatch);
344 #else /* BINDIR */
345  (void) execvp(argv[0], argv);
346  (void) fprintf(stderr, "Could not run %s. Is it in your $PATH?\n", argv[0]);
347 #endif /* BINDIR */
348  perror(argv[0]);
349  exit(1);
350  } else {
351 #ifdef HAVE_WAITPID
352  (void) waitpid(pid, NULL, 0);
353 #else
354  (void) wait(NULL);
355 #endif
356  }
357 #endif
358 } /* Jobs */
_In_ ULONG_PTR _In_ ULONG _Out_ ULONG_PTR * pid
Definition: winddi.h:3835
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define STRNCPY(dst, src, n)
Definition: rdesktop.h:168
#define assert(x)
Definition: debug.h:53
DWORD pid_t
Definition: types.h:91
#define argv
Definition: mplay32.c:18
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
smooth NULL
Definition: ftsmooth.c:416
#define STRNCAT(d, s)
Definition: Strn.h:48
_CRTIMP intptr_t __cdecl execvp(_In_z_ const char *_Filename, _In_z_ char *const _ArgList[])
FILE * stderr
_CRTIMP intptr_t __cdecl execv(_In_z_ const char *_Filename, _In_z_ char *const _ArgList[])
void exit(int exitcode)
Definition: _exit.c:33

Referenced by JobsCmd().

◆ MkSpoolDir()

int MkSpoolDir ( char sdir,
size_t  size 
)

Definition at line 56 of file spool.c.

57 {
58  struct stat st;
59  *sdir = '\0';
60 
61  /* Don't create in root directory. */
62  if (gOurDirectoryPath[0] != '\0') {
64  if ((stat(sdir, &st) < 0) && (MkDirs(sdir, 00700) < 0)) {
65  perror(sdir);
66  return (-1);
67  } else {
68  return (0);
69  }
70  }
71  return (-1);
72 } /* MkSpoolDir */
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define kSpoolDir
Definition: spool.h:8
char * OurDirectoryPath(char *const dst, const size_t siz, const char *const fname)
Definition: util.c:486
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
GLsizeiptr size
Definition: glext.h:5919
char gOurDirectoryPath[]
Definition: util.c:17
int MkDirs(const char *const, int mode1)
Definition: util.c:785
Definition: stat.h:55
_CRTIMP int __cdecl stat(const char *_Filename, struct stat *_Stat)
Definition: stat.h:345

Referenced by CanSpool(), and SpoolX().

◆ PWrite()

static int PWrite ( int  sfd,
const char *const  buf0,
size_t  size 
)
static

Definition at line 284 of file spool.c.

285 {
286  int nleft;
287  const char *buf = buf0;
288  int nwrote;
289 
290  nleft = (int) size;
291  for (;;) {
292  nwrote = (int) write(sfd, buf, nleft);
293  if (nwrote < 0) {
294  if (errno != EINTR) {
295  nwrote = (int) size - nleft;
296  if (nwrote == 0)
297  nwrote = -1;
298  return (nwrote);
299  } else {
300  errno = 0;
301  nwrote = 0;
302  /* Try again. */
303  }
304  }
305  nleft -= nwrote;
306  if (nleft <= 0)
307  break;
308  buf += nwrote;
309  }
310  nwrote = (int) size - nleft;
311  return (nwrote);
312 } /* PWrite */
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define EINTR
Definition: acclib.h:80
int errno
#define write
Definition: acwin.h:97
GLsizeiptr size
Definition: glext.h:5919
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by RunBatch().

◆ RunBatch()

void RunBatch ( int  Xstruct,
const FTPCIPtr  cip 
)

Definition at line 364 of file spool.c.

365 {
366 #if defined(WIN32) || defined(_WINDOWS)
367  char ncftpbatch[260];
368  const char *prog;
369  int winExecResult;
370 
371  if (gOurInstallationPath[0] == '\0') {
372  (void) fprintf(stderr, "Cannot find path to %s. Please re-run Setup.\n", "ncftpbatch.exe");
373  return;
374  }
375  prog = ncftpbatch;
376  OurInstallationPath(ncftpbatch, sizeof(ncftpbatch), "ncftpbatch.exe");
377 
378  winExecResult = WinExec(prog, SW_SHOWNORMAL);
379  if (winExecResult <= 31) switch (winExecResult) {
380  case ERROR_BAD_FORMAT:
381  fprintf(stderr, "Could not run %s: %s\n", prog, "The .EXE file is invalid");
382  return;
384  fprintf(stderr, "Could not run %s: %s\n", prog, "The specified file was not found.");
385  return;
387  fprintf(stderr, "Could not run %s: %s\n", prog, "The specified path was not found.");
388  return;
389  default:
390  fprintf(stderr, "Could not run %s: Unknown error #%d.\n", prog, winExecResult);
391  return;
392  }
393 #else
394  int pfd[2];
395  char pfdstr[32];
396  char *argv[8];
397  pid_t pid = 0;
398 #ifdef BINDIR
399  char ncftpbatch[256];
400 
401  STRNCPY(ncftpbatch, BINDIR);
402  STRNCAT(ncftpbatch, "/");
403  STRNCAT(ncftpbatch, "ncftpbatch");
404 #endif /* BINDIR */
405 
406  if (Xstruct != 0) {
407  if (pipe(pfd) < 0) {
408  perror("pipe");
409  }
410 
411  (void) sprintf(pfdstr, "%d", pfd[0]);
412  pid = fork();
413  if (pid < 0) {
414  (void) close(pfd[0]);
415  (void) close(pfd[1]);
416  perror("fork");
417  } else if (pid == 0) {
418  (void) close(pfd[1]); /* Child closes write end. */
419  argv[0] = (char *) "ncftpbatch";
420 #ifdef DEBUG_NCFTPBATCH
421  argv[1] = (char *) "-SD";
422 #else
423  argv[1] = (char *) "-d";
424 #endif
425  argv[2] = (char *) "-|";
426  argv[3] = pfdstr;
427  argv[4] = NULL;
428 
429 #ifdef BINDIR
430  (void) execv(ncftpbatch, argv);
431  (void) fprintf(stderr, "Could not run %s. Is it in installed as %s?\n", argv[0], ncftpbatch);
432 #else /* BINDIR */
433  (void) execvp(argv[0], argv);
434  (void) fprintf(stderr, "Could not run %s. Is it in your $PATH?\n", argv[0]);
435 #endif /* BINDIR */
436  perror(argv[0]);
437  exit(1);
438  }
439  (void) close(pfd[0]); /* Parent closes read end. */
440  (void) PWrite(pfd[1], (const char *) cip->lip, sizeof(FTPLibraryInfo));
441  (void) PWrite(pfd[1], (const char *) cip, sizeof(FTPConnectionInfo));
442  (void) close(pfd[1]); /* Parent closes read end. */
443 
444  /* Close it now, or else this process would send
445  * the server a QUIT message. This will cause it
446  * to think it already has.
447  */
449  } else {
450  pid = fork();
451  if (pid < 0) {
452  perror("fork");
453  } else if (pid == 0) {
454  argv[0] = (char *) "ncftpbatch";
455  argv[1] = (char *) "-d";
456  argv[2] = NULL;
457 #ifdef BINDIR
458  (void) execv(ncftpbatch, argv);
459  (void) fprintf(stderr, "Could not run %s. Is it in installed as %s?\n", argv[0], ncftpbatch);
460 #else /* BINDIR */
461  (void) execvp(argv[0], argv);
462  (void) fprintf(stderr, "Could not run %s. Is it in your $PATH?\n", argv[0]);
463 #endif /* BINDIR */
464  perror(argv[0]);
465  exit(1);
466  }
467  }
468 
469  if (pid > 1) {
470 #ifdef HAVE_WAITPID
471  (void) waitpid(pid, NULL, 0);
472 #else
473  (void) wait(NULL);
474 #endif
475  }
476 #endif
477 } /* RunBatch */
#define ERROR_BAD_FORMAT
Definition: winerror.h:114
_In_ ULONG_PTR _In_ ULONG _Out_ ULONG_PTR * pid
Definition: winddi.h:3835
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
char * prog
Definition: isohybrid.c:47
char gOurInstallationPath[]
Definition: util.c:18
#define STRNCPY(dst, src, n)
Definition: rdesktop.h:168
DWORD pid_t
Definition: types.h:91
void CloseControlConnection(const FTPCIPtr)
Definition: ftp.c:197
UINT WINAPI DECLSPEC_HOTPATCH WinExec(LPCSTR lpCmdLine, UINT uCmdShow)
Definition: proc.c:4774
#define argv
Definition: mplay32.c:18
#define sprintf(buf, format,...)
Definition: sprintf.c:55
FTPLIPtr lip
Definition: ncftp.h:149
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
smooth NULL
Definition: ftsmooth.c:416
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
struct FTPConnectionInfo FTPConnectionInfo
#define STRNCAT(d, s)
Definition: Strn.h:48
_CRTIMP intptr_t __cdecl execvp(_In_z_ const char *_Filename, _In_z_ char *const _ArgList[])
static PIXELFORMATDESCRIPTOR pfd
Definition: ssstars.c:67
#define close
Definition: acwin.h:98
#define SW_SHOWNORMAL
Definition: winuser.h:764
char * OurInstallationPath(char *const dst, const size_t siz, const char *const fname)
Definition: util.c:494
static int PWrite(int sfd, const char *const buf0, size_t size)
Definition: spool.c:284
FILE * stderr
_CRTIMP intptr_t __cdecl execv(_In_z_ const char *_Filename, _In_z_ char *const _ArgList[])
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
void exit(int exitcode)
Definition: _exit.c:33
struct FTPLibraryInfo FTPLibraryInfo

Referenced by BGStartCmd(), and RunBatchIfNeeded().

◆ RunBatchIfNeeded()

void RunBatchIfNeeded ( const FTPCIPtr  cip)

Definition at line 482 of file spool.c.

483 {
484  if (gUnprocessedJobs > 0) {
485 #ifdef ncftp
486  Trace(0, "Running ncftp_batch for %d job%s.\n", gUnprocessedJobs, gUnprocessedJobs > 0 ? "s" : "");
487  gUnprocessedJobs = 0;
488  RunBatch(1, cip);
489 #else
490  gUnprocessedJobs = 0;
491  RunBatch(0, cip);
492 #endif
493  }
494 } /* RunBatchIfNeeded */
int gUnprocessedJobs
Definition: spool.c:19
void RunBatch(int Xstruct, const FTPCIPtr cip)
Definition: spool.c:364
#define Trace(x)
Definition: zutil.h:197

Referenced by CloseHost().

◆ SpoolName()

void SpoolName ( const char *const  sdir,
char sp,
size_t  size,
int  flag,
int  serial,
time_t  when 
)

Definition at line 78 of file spool.c.

79 {
80  char sname[64];
81  char dstr[32];
82  struct tm *ltp;
83 
84  if ((when == (time_t) 0) || (when == (time_t) -1))
85  (void) time(&when);
86  ltp = localtime(&when);
87  if (ltp == NULL) {
88  /* impossible */
89  (void) Strncpy(dstr, "19700101-000000", size);
90  } else {
91  (void) strftime(dstr, sizeof(dstr), "%Y%m%d-%H%M%S", ltp);
92  }
93  (void) Strncpy(sp, sdir, size);
94  (void) sprintf(sname, "/%c-%010u-%04x-%s",
95  flag,
96  (unsigned int) getpid(),
97  (serial % (16 * 16 * 16 * 16)),
98  dstr
99  );
100  (void) Strncat(sp, sname, size);
101 } /* SpoolName */
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
__u16 time
Definition: mkdosfs.c:366
#define sprintf(buf, format,...)
Definition: sprintf.c:55
char * Strncat(char *const, const char *const, const size_t)
Definition: Strncat.c:13
smooth NULL
Definition: ftsmooth.c:416
size_t CDECL strftime(char *str, size_t max, const char *format, const struct tm *mstm)
Definition: strftime.c:293
_CRTIMP int __cdecl getpid(void)
GLsizeiptr size
Definition: glext.h:5919
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean flag
Definition: glfuncs.h:52
Definition: time.h:76
_CRTIMP struct tm *__cdecl localtime(const time_t *_Time)
Definition: time.h:424
uint32_t serial
Definition: fsck.fat.h:64
__kernel_time_t time_t
Definition: linux.h:252
char * Strncpy(char *const, const char *const, const size_t)
Definition: Strncpy.c:11
static const WCHAR sp[]
Definition: suminfo.c:288

Referenced by SpoolX().

◆ SpoolX()

int SpoolX ( const char *const  op,
const char *const  rfile,
const char *const  rdir,
const char *const  lfile,
const char *const  ldir,
const char *const  host,
const char *const  ip,
const unsigned int  port,
const char *const  user,
const char *const  passclear,
int  xtype,
int  recursive,
int  delete,
int  passive,
const char *const  precmd,
const char *const  perfilecmd,
const char *const  postcmd,
time_t  when 
)

Definition at line 161 of file spool.c.

180 {
181  char sdir[256];
182  char pass[160];
183  char spathname[256];
184  char spathname2[256];
185  char ldir2[256];
186  FILE *fp;
187 #if defined(WIN32) || defined(_WINDOWS)
188 #else
189  mode_t um;
190 #endif
191 
192  if (MkSpoolDir(sdir, sizeof(sdir)) < 0)
193  return (-1);
194 
195  gSpoolSerial++;
196  SpoolName(sdir, spathname2, sizeof(spathname2), op[0], gSpoolSerial, when);
197  SpoolName(sdir, spathname, sizeof(spathname), 'z', gSpoolSerial, when);
198 #if defined(WIN32) || defined(_WINDOWS)
199  fp = fopen(spathname, FOPEN_WRITE_TEXT);
200 #else
201  um = umask(077);
202  fp = fopen(spathname, FOPEN_WRITE_TEXT);
203  (void) umask(um);
204 #endif
205  if (fp == NULL)
206  return (-1);
207 
208  if (fprintf(fp, "# This is a NcFTP spool file entry.\n# Run the \"ncftpbatch\" program to process the spool directory.\n#\n") < 0)
209  goto err;
210  if (fprintf(fp, "op=%s\n", op) < 0)
211  goto err;
212  if (fprintf(fp, "hostname=%s\n", host) < 0)
213  goto err;
214  if ((ip != NULL) && (ip[0] != '\0') && (fprintf(fp, "host-ip=%s\n", ip) < 0))
215  goto err;
216  if ((port > 0) && (port != (unsigned int) kDefaultFTPPort) && (fprintf(fp, "port=%u\n", port) < 0))
217  goto err;
218  if ((user != NULL) && (user[0] != '\0') && (strcmp(user, "anonymous") != 0) && (fprintf(fp, "user=%s\n", user) < 0))
219  goto err;
220  if ((strcmp(user, "anonymous") != 0) && (passclear != NULL) && (passclear[0] != '\0')) {
222  ToBase64(pass + kPasswordMagicLen, passclear, strlen(passclear), 1);
223  if (fprintf(fp, "pass=%s\n", pass) < 0)
224  goto err;
225  } else if ((strcmp(user, "anonymous") == 0) && (gLib.defaultAnonPassword[0] != '\0')) {
226  if (fprintf(fp, "anon-pass=%s\n", gLib.defaultAnonPassword) < 0)
227  goto err;
228  }
229  if (fprintf(fp, "xtype=%c\n", xtype) < 0)
230  goto err;
231  if ((recursive != 0) && (fprintf(fp, "recursive=%s\n", YESNO(recursive)) < 0))
232  goto err;
233  if ((delete != 0) && (fprintf(fp, "delete=%s\n", YESNO(delete)) < 0))
234  goto err;
235  if (fprintf(fp, "passive=%d\n", passive) < 0)
236  goto err;
237  if (fprintf(fp, "remote-dir=%s\n", rdir) < 0)
238  goto err;
239  if ((ldir == NULL) || (ldir[0] == '\0') || (strcmp(ldir, ".") == 0)) {
240  /* Use current process' working directory. */
241  FTPGetLocalCWD(ldir2, sizeof(ldir2));
242  if (fprintf(fp, "local-dir=%s\n", ldir2) < 0)
243  goto err;
244  } else {
245  if (fprintf(fp, "local-dir=%s\n", ldir) < 0)
246  goto err;
247  }
248  if (fprintf(fp, "remote-file=%s\n", rfile) < 0)
249  goto err;
250  if (fprintf(fp, "local-file=%s\n", lfile) < 0)
251  goto err;
252  if ((precmd != NULL) && (precmd[0] != '\0') && (fprintf(fp, "pre-command=%s\n", precmd) < 0))
253  goto err;
254  if ((perfilecmd != NULL) && (perfilecmd[0] != '\0') && (fprintf(fp, "per-file-command=%s\n", perfilecmd) < 0))
255  goto err;
256  if ((postcmd != NULL) && (postcmd[0] != '\0') && (fprintf(fp, "post-command=%s\n", postcmd) < 0))
257  goto err;
258 
259  if (fclose(fp) < 0)
260  goto err2;
261 
262  /* Move the spool file into its "live" name. */
263  if (rename(spathname, spathname2) < 0) {
264  perror("rename spoolfile failed");
265  goto err3;
266  }
268  return (0);
269 
270 err:
271  (void) fclose(fp);
272 err2:
273  perror("write to spool file failed");
274 err3:
275  (void) unlink(spathname);
276  return (-1);
277 }
int MkSpoolDir(char *sdir, size_t size)
Definition: spool.c:56
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define kDefaultFTPPort
Definition: ncftp.h:312
#define kPasswordMagic
Definition: util.h:47
void SpoolName(const char *const sdir, char *sp, size_t size, int flag, int serial, time_t when)
Definition: spool.c:78
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * host
Definition: whois.c:55
#define kPasswordMagicLen
Definition: util.h:48
#define unlink
Definition: syshdrs.h:54
#define FOPEN_WRITE_TEXT
Definition: syshdrs.h:83
int gUnprocessedJobs
Definition: spool.c:19
pass
Definition: typegen.h:24
int gSpoolSerial
Definition: spool.c:18
_Check_return_ int __cdecl rename(_In_z_ const char *_OldFilename, _In_z_ const char *_NewFilename)
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
smooth NULL
Definition: ftsmooth.c:416
void ToBase64(void *dst0, const void *src0, size_t n, int terminate)
Definition: util.c:83
#define YESNO(i)
Definition: util.h:28
Definition: dhcpd.h:61
char defaultAnonPassword[80]
Definition: ncftp.h:121
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
#define err(...)
__kernel_mode_t mode_t
Definition: linux.h:199
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
_CRTIMP int __cdecl umask(_In_ int _Mode)
UINT op
Definition: effect.c:223
USHORT port
Definition: uri.c:227
void user(int argc, const char *argv[])
Definition: cmds.c:1350
char * FTPGetLocalCWD(char *buf, size_t size)
Definition: util.c:29
FTPLibraryInfo gLib
Definition: main.c:36
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by SpoolGetCmd(), and SpoolPutCmd().

◆ TruncBatchLog()

void TruncBatchLog ( void  )

Definition at line 30 of file spool.c.

31 {
32  char f[256];
33  struct stat st;
34  time_t t;
35  int fd;
36 
37  if (gOurDirectoryPath[0] != '\0') {
38  time(&t);
39  t -= 86400;
40  (void) OurDirectoryPath(f, sizeof(f), kSpoolLog);
41  if ((stat(f, &st) == 0) && (st.st_mtime < t)) {
42  /* Truncate old log file.
43  * Do not remove it, since a process
44  * could still conceivably be going.
45  */
46  fd = open(f, O_WRONLY|O_TRUNC, 00600);
47  if (fd >= 0)
48  close(fd);
49  }
50  }
51 } /* TruncBatchLog */
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define open
Definition: acwin.h:95
GLdouble GLdouble t
Definition: gl.h:2047
char * OurDirectoryPath(char *const dst, const size_t siz, const char *const fname)
Definition: util.c:486
static int fd
Definition: io.c:51
__u16 time
Definition: mkdosfs.c:366
#define kSpoolLog
Definition: spool.h:12
#define O_WRONLY
Definition: acwin.h:111
GLfloat f
Definition: glext.h:7540
char gOurDirectoryPath[]
Definition: util.c:17
Definition: stat.h:55
#define O_TRUNC
Definition: acwin.h:112
#define close
Definition: acwin.h:98
_CRTIMP int __cdecl stat(const char *_Filename, struct stat *_Stat)
Definition: stat.h:345
__kernel_time_t time_t
Definition: linux.h:252

Referenced by PreInit().

Variable Documentation

◆ gHaveSpool

int gHaveSpool = -1

Definition at line 21 of file spool.c.

Referenced by HaveSpool().

◆ gJobs

int gJobs = 0

Definition at line 20 of file spool.c.

◆ gLib

Definition at line 36 of file main.c.

Referenced by SpoolX().

◆ gOurDirectoryPath

char gOurDirectoryPath[]

Definition at line 17 of file util.c.

Referenced by CanSpool(), MkSpoolDir(), and TruncBatchLog().

◆ gOurInstallationPath

char gOurInstallationPath[]

Definition at line 18 of file util.c.

Referenced by HaveSpool(), InitOurDirectory(), OurInstallationPath(), and RunBatch().

◆ gSpoolSerial

int gSpoolSerial = 0

Definition at line 18 of file spool.c.

Referenced by SpoolX().

◆ gUnprocessedJobs

int gUnprocessedJobs = 0

Definition at line 19 of file spool.c.

Referenced by InitConnectionInfo(), RunBatchIfNeeded(), and SpoolX().