home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / managers / git-4.3 / git-4 / git-4.3.7 / src / system.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-08  |  3.5 KB  |  158 lines

  1. /* system.c -- the code needed in order to start child processes. */
  2.  
  3. /* Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
  4.  
  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 2, or (at your option)
  8.    any later version.
  9.  
  10.    This program is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.    GNU General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this program; if not, write to the Free Software
  17.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. /* Written by Tudor Hulubei and Andrei Pitis.  */
  20.  
  21.  
  22. #ifdef HAVE_CONFIG_H
  23. #include <config.h>
  24. #endif
  25.  
  26. #include <stdio.h>
  27.  
  28. #ifdef HAVE_STDLIB_H
  29. #include <stdlib.h>
  30. #else /* !HAVE_STDLIB_H */
  31. #include "ansi_stdlib.h"
  32. #endif /* !HAVE_STDLIB_H */
  33.  
  34. #include <sys/types.h>
  35. #include <fcntl.h>
  36.  
  37. #ifdef HAVE_UNISTD_H
  38. #include <unistd.h>
  39. #endif /* HAVE_UNISTD_H */
  40.  
  41. #include <errno.h>
  42.  
  43. /* Not all systems declare ERRNO in errno.h... and some systems #define it! */
  44. #if !defined (errno)
  45. extern int errno;
  46. #endif /* !errno */
  47.  
  48. #include "xmalloc.h"
  49. #include "xio.h"
  50. #include "tty.h"
  51. #include "xtimer.h"
  52. #include "signals.h"
  53. #include "inputline.h"
  54. #include "system.h"
  55. #include "misc.h"
  56.  
  57.  
  58. char *stdout_log_name = NULL;
  59. char *stderr_log_name = NULL;
  60.  
  61. extern int signals_status;
  62. extern char *screen;
  63.  
  64. /* This should be read from the configuration file here, in system.c.
  65.    We will be able to do so when the hooks package will be ready.  */
  66. extern char *TempDirectory;
  67.  
  68.  
  69. char il_read_char __P((char *, char *, int));
  70.  
  71.  
  72. int
  73. start(cmd, hide)
  74.     char *cmd;
  75.     int hide;
  76. {
  77.     int child_exit_code;
  78.     FILE *stdout_log, *stderr_log;
  79.  
  80.     if (hide)
  81.     {
  82.         close(1);
  83.         close(2);
  84.         stdout_log = fopen(stdout_log_name, "w");
  85.         stderr_log = fopen(stderr_log_name, "w");
  86.         
  87.         xtimer(XT_OFF);
  88.         restore_signals();
  89.         signals_dfl();
  90.         child_exit_code = system(cmd);
  91.         signals(signals_status);
  92.         ignore_signals();
  93.  
  94.         fclose(stderr_log);
  95.         fclose(stdout_log);
  96.         open(tty_name, O_RDWR);
  97.         open(tty_name, O_RDWR);
  98.     }
  99.     else
  100.     {
  101.         tty_set_mode(TTY_CANONIC);
  102.         tty_put_screen(screen);
  103.  
  104.         xtimer(XT_OFF);
  105.         restore_signals();
  106.         signals_dfl();
  107.         child_exit_code = system(cmd);
  108.         signals(signals_status);
  109.         ignore_signals();
  110.  
  111.         xwrite(1, "\n\n", 2);
  112.         tty_set_mode(TTY_NONCANONIC);
  113.     }
  114.  
  115.     return child_exit_code;
  116. }
  117.  
  118.  
  119. void
  120. removelog()
  121. {
  122.     if (stdout_log_name) unlink(stdout_log_name);
  123.     if (stderr_log_name) unlink(stderr_log_name);
  124. }
  125.  
  126.  
  127. void
  128. display_errors(command)
  129.     char *command;
  130. {
  131.     FILE *stderr_log = fopen(stderr_log_name, "r");
  132.  
  133.     if (stderr_log == NULL)
  134.     {
  135.         size_t buf_len = 32 + strlen(stderr_log_name);
  136.         char *buf      = xmalloc(buf_len);
  137.  
  138.         sprintf(buf, "%s: cannot open log file %s", command, stderr_log_name);
  139.  
  140.         il_read_char(buf, NULL, IL_MOVE | IL_BEEP | IL_SAVE | IL_ERROR);
  141.         xfree(buf);
  142.     }
  143.     else
  144.     {
  145.         char *buf = xmalloc(2048 + 1);
  146.  
  147.         xtimer(XT_ON);
  148.  
  149.         while (fgets(buf, 2048 + 1, stderr_log))
  150.             if (il_read_char(buf, NULL, IL_MOVE | IL_ERROR) == 0)
  151.                 break;
  152.  
  153.         xfree(buf);
  154.     }
  155.  
  156.     fclose(stderr_log);
  157. }
  158.