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