]> Dogcows Code - chaz/tar/blob - src/system.c
Merge branch 'master' of ssh://git.sv.gnu.org/srv/git/tar
[chaz/tar] / src / system.c
1 /* System-dependent calls for tar.
2
3 Copyright (C) 2003, 2004, 2005, 2006, 2007,
4 2008, 2010 Free Software Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any later
9 version.
10
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14 Public License for more details.
15
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19
20 #include <system.h>
21
22 #include "common.h"
23 #include <priv-set.h>
24 #include <rmt.h>
25 #include <signal.h>
26
27 #if MSDOS
28
29 bool
30 sys_get_archive_stat (void)
31 {
32 return 0;
33 }
34
35 bool
36 sys_file_is_archive (struct tar_stat_info *p)
37 {
38 return false;
39 }
40
41 void
42 sys_save_archive_dev_ino (void)
43 {
44 }
45
46 void
47 sys_detect_dev_null_output (void)
48 {
49 static char const dev_null[] = "nul";
50
51 dev_null_output = (strcmp (archive_name_array[0], dev_null) == 0
52 || (! _isrmt (archive)));
53 }
54
55 void
56 sys_wait_for_child (pid_t child_pid, bool eof)
57 {
58 }
59
60 void
61 sys_spawn_shell (void)
62 {
63 spawnl (P_WAIT, getenv ("COMSPEC"), "-", 0);
64 }
65
66 /* stat() in djgpp's C library gives a constant number of 42 as the
67 uid and gid of a file. So, comparing an FTP'ed archive just after
68 unpack would fail on MSDOS. */
69
70 bool
71 sys_compare_uid (struct stat *a, struct stat *b)
72 {
73 return true;
74 }
75
76 bool
77 sys_compare_gid (struct stat *a, struct stat *b)
78 {
79 return true;
80 }
81
82 void
83 sys_compare_links (struct stat *link_data, struct stat *stat_data)
84 {
85 return true;
86 }
87
88 int
89 sys_truncate (int fd)
90 {
91 return write (fd, "", 0);
92 }
93
94 size_t
95 sys_write_archive_buffer (void)
96 {
97 return full_write (archive, record_start->buffer, record_size);
98 }
99
100 /* Set ARCHIVE for writing, then compressing an archive. */
101 void
102 sys_child_open_for_compress (void)
103 {
104 FATAL_ERROR ((0, 0, _("Cannot use compressed or remote archives")));
105 }
106
107 /* Set ARCHIVE for uncompressing, then reading an archive. */
108 void
109 sys_child_open_for_uncompress (void)
110 {
111 FATAL_ERROR ((0, 0, _("Cannot use compressed or remote archives")));
112 }
113
114 #else
115
116 extern union block *record_start; /* FIXME */
117
118 static struct stat archive_stat; /* stat block for archive file */
119
120 bool
121 sys_get_archive_stat (void)
122 {
123 return fstat (archive, &archive_stat) == 0;
124 }
125
126 bool
127 sys_file_is_archive (struct tar_stat_info *p)
128 {
129 return (ar_dev && p->stat.st_dev == ar_dev && p->stat.st_ino == ar_ino);
130 }
131
132 /* Save archive file inode and device numbers */
133 void
134 sys_save_archive_dev_ino (void)
135 {
136 if (!_isrmt (archive) && S_ISREG (archive_stat.st_mode))
137 {
138 ar_dev = archive_stat.st_dev;
139 ar_ino = archive_stat.st_ino;
140 }
141 else
142 ar_dev = 0;
143 }
144
145 /* Detect if outputting to "/dev/null". */
146 void
147 sys_detect_dev_null_output (void)
148 {
149 static char const dev_null[] = "/dev/null";
150 struct stat dev_null_stat;
151
152 dev_null_output = (strcmp (archive_name_array[0], dev_null) == 0
153 || (! _isrmt (archive)
154 && S_ISCHR (archive_stat.st_mode)
155 && stat (dev_null, &dev_null_stat) == 0
156 && archive_stat.st_dev == dev_null_stat.st_dev
157 && archive_stat.st_ino == dev_null_stat.st_ino));
158 }
159
160 void
161 sys_wait_for_child (pid_t child_pid, bool eof)
162 {
163 if (child_pid)
164 {
165 int wait_status;
166
167 while (waitpid (child_pid, &wait_status, 0) == -1)
168 if (errno != EINTR)
169 {
170 waitpid_error (use_compress_program_option);
171 break;
172 }
173
174 if (WIFSIGNALED (wait_status))
175 {
176 int sig = WTERMSIG (wait_status);
177 if (!(!eof && sig == SIGPIPE))
178 FATAL_ERROR ((0, 0, _("Child died with signal %d"), sig));
179 }
180 else if (WEXITSTATUS (wait_status) != 0)
181 FATAL_ERROR ((0, 0, _("Child returned status %d"),
182 WEXITSTATUS (wait_status)));
183 }
184 }
185
186 void
187 sys_spawn_shell (void)
188 {
189 pid_t child;
190 const char *shell = getenv ("SHELL");
191 if (! shell)
192 shell = "/bin/sh";
193 child = xfork ();
194 if (child == 0)
195 {
196 priv_set_restore_linkdir ();
197 execlp (shell, "-sh", "-i", (char *) 0);
198 exec_fatal (shell);
199 }
200 else
201 {
202 int wait_status;
203 while (waitpid (child, &wait_status, 0) == -1)
204 if (errno != EINTR)
205 {
206 waitpid_error (shell);
207 break;
208 }
209 }
210 }
211
212 bool
213 sys_compare_uid (struct stat *a, struct stat *b)
214 {
215 return a->st_uid == b->st_uid;
216 }
217
218 bool
219 sys_compare_gid (struct stat *a, struct stat *b)
220 {
221 return a->st_gid == b->st_gid;
222 }
223
224 bool
225 sys_compare_links (struct stat *link_data, struct stat *stat_data)
226 {
227 return stat_data->st_dev == link_data->st_dev
228 && stat_data->st_ino == link_data->st_ino;
229 }
230
231 int
232 sys_truncate (int fd)
233 {
234 off_t pos = lseek (fd, (off_t) 0, SEEK_CUR);
235 return pos < 0 ? -1 : ftruncate (fd, pos);
236 }
237
238 /* Return nonzero if NAME is the name of a regular file, or if the file
239 does not exist (so it would be created as a regular file). */
240 static int
241 is_regular_file (const char *name)
242 {
243 struct stat stbuf;
244
245 if (stat (name, &stbuf) == 0)
246 return S_ISREG (stbuf.st_mode);
247 else
248 return errno == ENOENT;
249 }
250
251 size_t
252 sys_write_archive_buffer (void)
253 {
254 return rmtwrite (archive, record_start->buffer, record_size);
255 }
256
257 #define PREAD 0 /* read file descriptor from pipe() */
258 #define PWRITE 1 /* write file descriptor from pipe() */
259
260 /* Duplicate file descriptor FROM into becoming INTO.
261 INTO is closed first and has to be the next available slot. */
262 static void
263 xdup2 (int from, int into)
264 {
265 if (from != into)
266 {
267 int status = close (into);
268
269 if (status != 0 && errno != EBADF)
270 {
271 int e = errno;
272 FATAL_ERROR ((0, e, _("Cannot close")));
273 }
274 status = dup (from);
275 if (status != into)
276 {
277 if (status < 0)
278 {
279 int e = errno;
280 FATAL_ERROR ((0, e, _("Cannot dup")));
281 }
282 abort ();
283 }
284 xclose (from);
285 }
286 }
287
288 static void wait_for_grandchild (pid_t pid) __attribute__ ((__noreturn__));
289
290 /* Propagate any failure of the grandchild back to the parent. */
291 static void
292 wait_for_grandchild (pid_t pid)
293 {
294 int wait_status;
295 int exit_code = 0;
296
297 while (waitpid (pid, &wait_status, 0) == -1)
298 if (errno != EINTR)
299 {
300 waitpid_error (use_compress_program_option);
301 break;
302 }
303
304 if (WIFSIGNALED (wait_status))
305 raise (WTERMSIG (wait_status));
306 else if (WEXITSTATUS (wait_status) != 0)
307 exit_code = WEXITSTATUS (wait_status);
308
309 exit (exit_code);
310 }
311
312 /* Set ARCHIVE for writing, then compressing an archive. */
313 pid_t
314 sys_child_open_for_compress (void)
315 {
316 int parent_pipe[2];
317 int child_pipe[2];
318 pid_t grandchild_pid;
319 pid_t child_pid;
320
321 xpipe (parent_pipe);
322 child_pid = xfork ();
323
324 if (child_pid > 0)
325 {
326 /* The parent tar is still here! Just clean up. */
327
328 archive = parent_pipe[PWRITE];
329 xclose (parent_pipe[PREAD]);
330 return child_pid;
331 }
332
333 /* The new born child tar is here! */
334
335 set_program_name (_("tar (child)"));
336 signal (SIGPIPE, SIG_DFL);
337
338 xdup2 (parent_pipe[PREAD], STDIN_FILENO);
339 xclose (parent_pipe[PWRITE]);
340
341 /* Check if we need a grandchild tar. This happens only if either:
342 a) the file is to be accessed by rmt: compressor doesn't know how;
343 b) the file is not a plain file. */
344
345 if (!_remdev (archive_name_array[0])
346 && is_regular_file (archive_name_array[0]))
347 {
348 if (backup_option)
349 maybe_backup_file (archive_name_array[0], 1);
350
351 /* We don't need a grandchild tar. Open the archive and launch the
352 compressor. */
353 if (strcmp (archive_name_array[0], "-"))
354 {
355 archive = creat (archive_name_array[0], MODE_RW);
356 if (archive < 0)
357 {
358 int saved_errno = errno;
359
360 if (backup_option)
361 undo_last_backup ();
362 errno = saved_errno;
363 open_fatal (archive_name_array[0]);
364 }
365 xdup2 (archive, STDOUT_FILENO);
366 }
367 priv_set_restore_linkdir ();
368 execlp (use_compress_program_option, use_compress_program_option, NULL);
369 exec_fatal (use_compress_program_option);
370 }
371
372 /* We do need a grandchild tar. */
373
374 xpipe (child_pipe);
375 grandchild_pid = xfork ();
376
377 if (grandchild_pid == 0)
378 {
379 /* The newborn grandchild tar is here! Launch the compressor. */
380
381 set_program_name (_("tar (grandchild)"));
382
383 xdup2 (child_pipe[PWRITE], STDOUT_FILENO);
384 xclose (child_pipe[PREAD]);
385 priv_set_restore_linkdir ();
386 execlp (use_compress_program_option, use_compress_program_option,
387 (char *) 0);
388 exec_fatal (use_compress_program_option);
389 }
390
391 /* The child tar is still here! */
392
393 /* Prepare for reblocking the data from the compressor into the archive. */
394
395 xdup2 (child_pipe[PREAD], STDIN_FILENO);
396 xclose (child_pipe[PWRITE]);
397
398 if (strcmp (archive_name_array[0], "-") == 0)
399 archive = STDOUT_FILENO;
400 else
401 {
402 archive = rmtcreat (archive_name_array[0], MODE_RW, rsh_command_option);
403 if (archive < 0)
404 open_fatal (archive_name_array[0]);
405 }
406
407 /* Let's read out of the stdin pipe and write an archive. */
408
409 while (1)
410 {
411 size_t status = 0;
412 char *cursor;
413 size_t length;
414
415 /* Assemble a record. */
416
417 for (length = 0, cursor = record_start->buffer;
418 length < record_size;
419 length += status, cursor += status)
420 {
421 size_t size = record_size - length;
422
423 status = safe_read (STDIN_FILENO, cursor, size);
424 if (status == SAFE_READ_ERROR)
425 read_fatal (use_compress_program_option);
426 if (status == 0)
427 break;
428 }
429
430 /* Copy the record. */
431
432 if (status == 0)
433 {
434 /* We hit the end of the file. Write last record at
435 full length, as the only role of the grandchild is
436 doing proper reblocking. */
437
438 if (length > 0)
439 {
440 memset (record_start->buffer + length, 0, record_size - length);
441 status = sys_write_archive_buffer ();
442 if (status != record_size)
443 archive_write_error (status);
444 }
445
446 /* There is nothing else to read, break out. */
447 break;
448 }
449
450 status = sys_write_archive_buffer ();
451 if (status != record_size)
452 archive_write_error (status);
453 }
454
455 wait_for_grandchild (grandchild_pid);
456 }
457
458 static void
459 run_decompress_program (void)
460 {
461 int i;
462 const char *p, *prog = NULL;
463
464 for (p = first_decompress_program (&i); p; p = next_decompress_program (&i))
465 {
466 if (prog)
467 {
468 WARNOPT (WARN_DECOMPRESS_PROGRAM,
469 (0, errno, _("cannot run %s"), prog));
470 WARNOPT (WARN_DECOMPRESS_PROGRAM,
471 (0, 0, _("trying %s"), p));
472 }
473 prog = p;
474 execlp (p, p, "-d", NULL);
475 }
476 if (!prog)
477 FATAL_ERROR ((0, 0, _("unable to run decompression program")));
478 exec_fatal (prog);
479 }
480
481 /* Set ARCHIVE for uncompressing, then reading an archive. */
482 pid_t
483 sys_child_open_for_uncompress (void)
484 {
485 int parent_pipe[2];
486 int child_pipe[2];
487 pid_t grandchild_pid;
488 pid_t child_pid;
489
490 xpipe (parent_pipe);
491 child_pid = xfork ();
492
493 if (child_pid > 0)
494 {
495 /* The parent tar is still here! Just clean up. */
496
497 archive = parent_pipe[PREAD];
498 xclose (parent_pipe[PWRITE]);
499 return child_pid;
500 }
501
502 /* The newborn child tar is here! */
503
504 set_program_name (_("tar (child)"));
505 signal (SIGPIPE, SIG_DFL);
506
507 xdup2 (parent_pipe[PWRITE], STDOUT_FILENO);
508 xclose (parent_pipe[PREAD]);
509
510 /* Check if we need a grandchild tar. This happens only if either:
511 a) we're reading stdin: to force unblocking;
512 b) the file is to be accessed by rmt: compressor doesn't know how;
513 c) the file is not a plain file. */
514
515 if (strcmp (archive_name_array[0], "-") != 0
516 && !_remdev (archive_name_array[0])
517 && is_regular_file (archive_name_array[0]))
518 {
519 /* We don't need a grandchild tar. Open the archive and lauch the
520 uncompressor. */
521
522 archive = open (archive_name_array[0], O_RDONLY | O_BINARY, MODE_RW);
523 if (archive < 0)
524 open_fatal (archive_name_array[0]);
525 xdup2 (archive, STDIN_FILENO);
526 priv_set_restore_linkdir ();
527 run_decompress_program ();
528 }
529
530 /* We do need a grandchild tar. */
531
532 xpipe (child_pipe);
533 grandchild_pid = xfork ();
534
535 if (grandchild_pid == 0)
536 {
537 /* The newborn grandchild tar is here! Launch the uncompressor. */
538
539 set_program_name (_("tar (grandchild)"));
540
541 xdup2 (child_pipe[PREAD], STDIN_FILENO);
542 xclose (child_pipe[PWRITE]);
543 priv_set_restore_linkdir ();
544 run_decompress_program ();
545 }
546
547 /* The child tar is still here! */
548
549 /* Prepare for unblocking the data from the archive into the
550 uncompressor. */
551
552 xdup2 (child_pipe[PWRITE], STDOUT_FILENO);
553 xclose (child_pipe[PREAD]);
554
555 if (strcmp (archive_name_array[0], "-") == 0)
556 archive = STDIN_FILENO;
557 else
558 archive = rmtopen (archive_name_array[0], O_RDONLY | O_BINARY,
559 MODE_RW, rsh_command_option);
560 if (archive < 0)
561 open_fatal (archive_name_array[0]);
562
563 /* Let's read the archive and pipe it into stdout. */
564
565 while (1)
566 {
567 char *cursor;
568 size_t maximum;
569 size_t count;
570 size_t status;
571
572 clear_read_error_count ();
573
574 error_loop:
575 status = rmtread (archive, record_start->buffer, record_size);
576 if (status == SAFE_READ_ERROR)
577 {
578 archive_read_error ();
579 goto error_loop;
580 }
581 if (status == 0)
582 break;
583 cursor = record_start->buffer;
584 maximum = status;
585 while (maximum)
586 {
587 count = maximum < BLOCKSIZE ? maximum : BLOCKSIZE;
588 if (full_write (STDOUT_FILENO, cursor, count) != count)
589 write_error (use_compress_program_option);
590 cursor += count;
591 maximum -= count;
592 }
593 }
594
595 xclose (STDOUT_FILENO);
596
597 wait_for_grandchild (grandchild_pid);
598 }
599
600 \f
601
602 static void
603 dec_to_env (char const *envar, uintmax_t num)
604 {
605 char buf[UINTMAX_STRSIZE_BOUND];
606 char *numstr;
607
608 numstr = STRINGIFY_BIGINT (num, buf);
609 if (setenv (envar, numstr, 1) != 0)
610 xalloc_die ();
611 }
612
613 static void
614 time_to_env (char const *envar, struct timespec t)
615 {
616 char buf[TIMESPEC_STRSIZE_BOUND];
617 if (setenv (envar, code_timespec (t, buf), 1) != 0)
618 xalloc_die ();
619 }
620
621 static void
622 oct_to_env (char const *envar, unsigned long num)
623 {
624 char buf[1+1+(sizeof(unsigned long)*CHAR_BIT+2)/3];
625
626 snprintf (buf, sizeof buf, "0%lo", num);
627 if (setenv (envar, buf, 1) != 0)
628 xalloc_die ();
629 }
630
631 static void
632 str_to_env (char const *envar, char const *str)
633 {
634 if (str)
635 {
636 if (setenv (envar, str, 1) != 0)
637 xalloc_die ();
638 }
639 else
640 unsetenv (envar);
641 }
642
643 static void
644 chr_to_env (char const *envar, char c)
645 {
646 char buf[2];
647 buf[0] = c;
648 buf[1] = 0;
649 if (setenv (envar, buf, 1) != 0)
650 xalloc_die ();
651 }
652
653 static void
654 stat_to_env (char *name, char type, struct tar_stat_info *st)
655 {
656 str_to_env ("TAR_VERSION", PACKAGE_VERSION);
657 str_to_env ("TAR_ARCHIVE", *archive_name_cursor);
658 dec_to_env ("TAR_VOLUME", archive_name_cursor - archive_name_array + 1);
659 dec_to_env ("TAR_BLOCKING_FACTOR", blocking_factor);
660 str_to_env ("TAR_FORMAT",
661 archive_format_string (current_format == DEFAULT_FORMAT ?
662 archive_format : current_format));
663 chr_to_env ("TAR_FILETYPE", type);
664 oct_to_env ("TAR_MODE", st->stat.st_mode);
665 str_to_env ("TAR_FILENAME", name);
666 str_to_env ("TAR_REALNAME", st->file_name);
667 str_to_env ("TAR_UNAME", st->uname);
668 str_to_env ("TAR_GNAME", st->gname);
669 time_to_env ("TAR_ATIME", st->atime);
670 time_to_env ("TAR_MTIME", st->mtime);
671 time_to_env ("TAR_CTIME", st->ctime);
672 dec_to_env ("TAR_SIZE", st->stat.st_size);
673 dec_to_env ("TAR_UID", st->stat.st_uid);
674 dec_to_env ("TAR_GID", st->stat.st_gid);
675
676 switch (type)
677 {
678 case 'b':
679 case 'c':
680 dec_to_env ("TAR_MINOR", minor (st->stat.st_rdev));
681 dec_to_env ("TAR_MAJOR", major (st->stat.st_rdev));
682 unsetenv ("TAR_LINKNAME");
683 break;
684
685 case 'l':
686 case 'h':
687 unsetenv ("TAR_MINOR");
688 unsetenv ("TAR_MAJOR");
689 str_to_env ("TAR_LINKNAME", st->link_name);
690 break;
691
692 default:
693 unsetenv ("TAR_MINOR");
694 unsetenv ("TAR_MAJOR");
695 unsetenv ("TAR_LINKNAME");
696 break;
697 }
698 }
699
700 static pid_t global_pid;
701 static RETSIGTYPE (*pipe_handler) (int sig);
702
703 int
704 sys_exec_command (char *file_name, int typechar, struct tar_stat_info *st)
705 {
706 int p[2];
707 char *argv[4];
708
709 xpipe (p);
710 pipe_handler = signal (SIGPIPE, SIG_IGN);
711 global_pid = xfork ();
712
713 if (global_pid != 0)
714 {
715 xclose (p[PREAD]);
716 return p[PWRITE];
717 }
718
719 /* Child */
720 xdup2 (p[PREAD], STDIN_FILENO);
721 xclose (p[PWRITE]);
722
723 stat_to_env (file_name, typechar, st);
724
725 argv[0] = "/bin/sh";
726 argv[1] = "-c";
727 argv[2] = to_command_option;
728 argv[3] = NULL;
729
730 priv_set_restore_linkdir ();
731 execv ("/bin/sh", argv);
732
733 exec_fatal (file_name);
734 }
735
736 void
737 sys_wait_command (void)
738 {
739 int status;
740
741 if (global_pid < 0)
742 return;
743
744 signal (SIGPIPE, pipe_handler);
745 while (waitpid (global_pid, &status, 0) == -1)
746 if (errno != EINTR)
747 {
748 global_pid = -1;
749 waitpid_error (to_command_option);
750 return;
751 }
752
753 if (WIFEXITED (status))
754 {
755 if (!ignore_command_error_option && WEXITSTATUS (status))
756 ERROR ((0, 0, _("%lu: Child returned status %d"),
757 (unsigned long) global_pid, WEXITSTATUS (status)));
758 }
759 else if (WIFSIGNALED (status))
760 {
761 WARN ((0, 0, _("%lu: Child terminated on signal %d"),
762 (unsigned long) global_pid, WTERMSIG (status)));
763 }
764 else
765 ERROR ((0, 0, _("%lu: Child terminated on unknown reason"),
766 (unsigned long) global_pid));
767
768 global_pid = -1;
769 }
770
771 int
772 sys_exec_info_script (const char **archive_name, int volume_number)
773 {
774 pid_t pid;
775 char *argv[4];
776 char uintbuf[UINTMAX_STRSIZE_BOUND];
777 int p[2];
778 static RETSIGTYPE (*saved_handler) (int sig);
779
780 xpipe (p);
781 saved_handler = signal (SIGPIPE, SIG_IGN);
782
783 pid = xfork ();
784
785 if (pid != 0)
786 {
787 /* Master */
788
789 int rc;
790 int status;
791 char *buf = NULL;
792 size_t size = 0;
793 FILE *fp;
794
795 xclose (p[PWRITE]);
796 fp = fdopen (p[PREAD], "r");
797 rc = getline (&buf, &size, fp);
798 fclose (fp);
799
800 if (rc > 0 && buf[rc-1] == '\n')
801 buf[--rc] = 0;
802
803 while (waitpid (pid, &status, 0) == -1)
804 if (errno != EINTR)
805 {
806 signal (SIGPIPE, saved_handler);
807 waitpid_error (info_script_option);
808 return -1;
809 }
810
811 signal (SIGPIPE, saved_handler);
812
813 if (WIFEXITED (status))
814 {
815 if (WEXITSTATUS (status) == 0 && rc > 0)
816 *archive_name = buf;
817 else
818 free (buf);
819 return WEXITSTATUS (status);
820 }
821
822 free (buf);
823 return -1;
824 }
825
826 /* Child */
827 setenv ("TAR_VERSION", PACKAGE_VERSION, 1);
828 setenv ("TAR_ARCHIVE", *archive_name, 1);
829 setenv ("TAR_VOLUME", STRINGIFY_BIGINT (volume_number, uintbuf), 1);
830 setenv ("TAR_BLOCKING_FACTOR",
831 STRINGIFY_BIGINT (blocking_factor, uintbuf), 1);
832 setenv ("TAR_SUBCOMMAND", subcommand_string (subcommand_option), 1);
833 setenv ("TAR_FORMAT",
834 archive_format_string (current_format == DEFAULT_FORMAT ?
835 archive_format : current_format), 1);
836 setenv ("TAR_FD", STRINGIFY_BIGINT (p[PWRITE], uintbuf), 1);
837
838 xclose (p[PREAD]);
839
840 argv[0] = "/bin/sh";
841 argv[1] = "-c";
842 argv[2] = (char *) info_script_option;
843 argv[3] = NULL;
844
845 priv_set_restore_linkdir ();
846 execv (argv[0], argv);
847
848 exec_fatal (info_script_option);
849 }
850
851 void
852 sys_exec_checkpoint_script (const char *script_name,
853 const char *archive_name,
854 int checkpoint_number)
855 {
856 pid_t pid;
857 char *argv[4];
858 char uintbuf[UINTMAX_STRSIZE_BOUND];
859
860 pid = xfork ();
861
862 if (pid != 0)
863 {
864 /* Master */
865
866 int status;
867
868 while (waitpid (pid, &status, 0) == -1)
869 if (errno != EINTR)
870 {
871 waitpid_error (script_name);
872 break;
873 }
874
875 return;
876 }
877
878 /* Child */
879 setenv ("TAR_VERSION", PACKAGE_VERSION, 1);
880 setenv ("TAR_ARCHIVE", archive_name, 1);
881 setenv ("TAR_CHECKPOINT", STRINGIFY_BIGINT (checkpoint_number, uintbuf), 1);
882 setenv ("TAR_BLOCKING_FACTOR",
883 STRINGIFY_BIGINT (blocking_factor, uintbuf), 1);
884 setenv ("TAR_SUBCOMMAND", subcommand_string (subcommand_option), 1);
885 setenv ("TAR_FORMAT",
886 archive_format_string (current_format == DEFAULT_FORMAT ?
887 archive_format : current_format), 1);
888 argv[0] = "/bin/sh";
889 argv[1] = "-c";
890 argv[2] = (char *) script_name;
891 argv[3] = NULL;
892
893 priv_set_restore_linkdir ();
894 execv (argv[0], argv);
895
896 exec_fatal (script_name);
897 }
898
899 #endif /* not MSDOS */
This page took 0.077493 seconds and 5 git commands to generate.