1
1
/* pred.c -- execute the expression tree.
2
Copyright (C) 1990, 91, 92, 93, 94, 2000, 2003 Free Software Foundation, Inc.
2
Copyright (C) 1990, 1991, 1992, 1993, 1994, 2000, 2003,
3
2004, 2005 Free Software Foundation, Inc.
4
5
This program is free software; you can redistribute it and/or modify
5
6
it under the terms of the GNU General Public License as published by
245
262
Return true if the file passes this predicate, false if not. */
267
* Returns true if THE_TIME is
268
* COMP_GT: after the specified time
269
* COMP_LT: before the specified time
270
* COMP_EQ: less than WINDOW seconds after the specified time.
273
pred_timewindow(time_t the_time, struct predicate const *pred_ptr, int window)
275
switch (pred_ptr->args.info.kind)
278
if (the_time > (time_t) pred_ptr->args.info.l_val)
282
if (the_time < (time_t) pred_ptr->args.info.l_val)
286
if ((the_time >= (time_t) pred_ptr->args.info.l_val)
287
&& (the_time < (time_t) pred_ptr->args.info.l_val + window))
248
296
pred_amin (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
250
switch (pred_ptr->args.info.kind)
253
if (stat_buf->st_atime > (time_t) pred_ptr->args.info.l_val)
257
if (stat_buf->st_atime < (time_t) pred_ptr->args.info.l_val)
261
if ((stat_buf->st_atime >= (time_t) pred_ptr->args.info.l_val)
262
&& (stat_buf->st_atime < (time_t) pred_ptr->args.info.l_val + 60))
299
return pred_timewindow(stat_buf->st_atime, pred_ptr, 60);
303
330
pred_atime (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
305
switch (pred_ptr->args.info.kind)
308
if (stat_buf->st_atime > (time_t) pred_ptr->args.info.l_val)
312
if (stat_buf->st_atime < (time_t) pred_ptr->args.info.l_val)
316
if ((stat_buf->st_atime >= (time_t) pred_ptr->args.info.l_val)
317
&& (stat_buf->st_atime < (time_t) pred_ptr->args.info.l_val
333
return pred_timewindow(stat_buf->st_atime, pred_ptr, DAYSECS);
326
337
pred_close (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
332
347
pred_cmin (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
334
switch (pred_ptr->args.info.kind)
337
if (stat_buf->st_ctime > (time_t) pred_ptr->args.info.l_val)
341
if (stat_buf->st_ctime < (time_t) pred_ptr->args.info.l_val)
345
if ((stat_buf->st_ctime >= (time_t) pred_ptr->args.info.l_val)
346
&& (stat_buf->st_ctime < (time_t) pred_ptr->args.info.l_val + 60))
350
return pred_timewindow(stat_buf->st_ctime, pred_ptr, 60);
354
354
pred_cnewer (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
356
358
if (stat_buf->st_ctime > pred_ptr->args.time)
383
379
pred_ctime (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
385
switch (pred_ptr->args.info.kind)
382
return pred_timewindow(stat_buf->st_ctime, pred_ptr, DAYSECS);
386
pred_delete (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
390
if (strcmp (state.rel_pathname, "."))
388
if (stat_buf->st_ctime > (time_t) pred_ptr->args.info.l_val)
392
if (stat_buf->st_ctime < (time_t) pred_ptr->args.info.l_val)
396
if ((stat_buf->st_ctime >= (time_t) pred_ptr->args.info.l_val)
397
&& (stat_buf->st_ctime < (time_t) pred_ptr->args.info.l_val
392
if (0 != remove (state.rel_pathname))
394
error (0, errno, "cannot delete %s", pathname);
406
408
pred_empty (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
408
413
if (S_ISDIR (stat_buf->st_mode))
452
new_impl_pred_exec (const char *pathname, struct stat *stat_buf,
453
struct predicate *pred_ptr,
454
const char *prefix, size_t pfxlen)
456
struct exec_val *execp = &pred_ptr->args.exec_vec;
457
size_t len = strlen(pathname);
463
/* Push the argument onto the current list.
464
* The command may or may not be run at this point,
465
* depending on the command line length limits.
467
bc_push_arg(&execp->ctl,
473
/* POSIX: If the primary expression is punctuated by a plus
474
* sign, the primary shall always evaluate as true
482
for (i=0; i<execp->num_args; ++i)
484
bc_do_insert(&execp->ctl,
486
execp->replace_vec[i],
487
strlen(execp->replace_vec[i]),
493
/* Actually invoke the command. */
494
return execp->ctl.exec_callback(&execp->ctl,
447
501
pred_exec (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
451
struct exec_val *execp; /* Pointer for efficiency. */
453
execp = &pred_ptr->args.exec_vec;
455
/* Replace "{}" with the real path in each affected arg. */
456
for (path_pos = 0; execp->paths[path_pos].offset >= 0; path_pos++)
458
register char *from, *to;
460
i = execp->paths[path_pos].offset;
462
xmalloc (strlen (execp->paths[path_pos].origarg) + 1
463
+ (strlen (pathname) - 2) * execp->paths[path_pos].count);
464
for (from = execp->paths[path_pos].origarg, to = execp->vec[i]; *from; )
465
if (from[0] == '{' && from[1] == '}')
467
to = stpcpy (to, pathname);
472
*to = *from; /* Copy null. */
475
i = launch (pred_ptr);
477
/* Free the temporary args. */
478
for (path_pos = 0; execp->paths[path_pos].offset >= 0; path_pos++)
479
free (execp->vec[execp->paths[path_pos].offset]);
503
return new_impl_pred_exec(pathname, stat_buf, pred_ptr, NULL, 0);
507
pred_execdir (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
509
const char *prefix = (state.rel_pathname[0] == '/') ? NULL : "./";
511
return new_impl_pred_exec (state.rel_pathname, stat_buf, pred_ptr,
512
prefix, (prefix ? 2 : 0));
485
516
pred_false (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
491
527
pred_fls (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
493
list_file (pathname, rel_pathname, stat_buf, start_time,
494
output_block_size, pred_ptr->args.stream);
529
list_file (pathname, state.rel_pathname, stat_buf, options.start_time,
530
options.output_block_size, pred_ptr->args.stream);
499
535
pred_fprint (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
501
fputs (pathname, pred_ptr->args.stream);
502
putc ('\n', pred_ptr->args.stream);
540
print_quoted(pred_ptr->args.printf_vec.stream,
541
pred_ptr->args.printf_vec.quote_opts,
542
pred_ptr->args.printf_vec.dest_is_tty,
507
549
pred_fprint0 (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
509
554
fputs (pathname, pred_ptr->args.stream);
510
555
putc (0, pred_ptr->args.stream);
515
564
pred_fprintf (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
517
566
FILE *fp = pred_ptr->args.printf_vec.stream;
567
const struct quoting_options *qopts = pred_ptr->args.printf_vec.quote_opts;
568
boolean ttyflag = pred_ptr->args.printf_vec.dest_is_tty;
518
569
struct segment *segment;
520
571
char hbuf[LONGEST_HUMAN_READABLE + 1];
548
604
switch (segment->kind)
550
606
case KIND_PLAIN: /* Plain text string (no % conversion). */
551
608
fwrite (segment->text, 1, segment->text_len, fp);
553
610
case KIND_STOP: /* Terminate argument and flush output. */
554
612
fwrite (segment->text, 1, segment->text_len, fp);
557
615
case 'a': /* atime in `ctime' format. */
616
/* UNTRUSTED, probably unexploitable */
558
617
fprintf (fp, segment->text, ctime_format (stat_buf->st_atime));
560
619
case 'b': /* size in 512-byte blocks */
620
/* UNTRUSTED, probably unexploitable */
561
621
fprintf (fp, segment->text,
562
622
human_readable ((uintmax_t) ST_NBLOCKS (*stat_buf),
563
hbuf, ST_NBLOCKSIZE, 512));
624
ST_NBLOCKSIZE, 512));
565
626
case 'c': /* ctime in `ctime' format */
627
/* UNTRUSTED, probably unexploitable */
566
628
fprintf (fp, segment->text, ctime_format (stat_buf->st_ctime));
568
630
case 'd': /* depth in search tree */
569
fprintf (fp, segment->text, curdepth);
571
case 'f': /* basename of path */
572
fprintf (fp, segment->text, base_name (pathname));
631
/* UNTRUSTED, probably unexploitable */
632
fprintf (fp, segment->text, state.curdepth);
634
case 'D': /* Device on which file exists (stat.st_dev) */
636
fprintf (fp, segment->text,
637
human_readable ((uintmax_t) stat_buf->st_dev, hbuf,
638
human_ceiling, 1, 1));
640
case 'f': /* base name of path */
642
print_quoted (fp, qopts, ttyflag, segment->text, base_name (pathname));
574
644
case 'F': /* filesystem type */
575
fprintf (fp, segment->text,
576
filesystem_type (pathname, rel_pathname, stat_buf));
646
print_quoted (fp, qopts, ttyflag, segment->text, filesystem_type (stat_buf));
578
648
case 'g': /* group name */
650
/* (well, the actual group is selected by the user but
651
* its name was selected by the system administrator)
589
663
/* else fallthru */
591
665
case 'G': /* GID number */
666
/* UNTRUSTED, probably unexploitable */
592
667
fprintf (fp, segment->text,
593
human_readable ((uintmax_t) stat_buf->st_gid, hbuf, 1, 1));
668
human_readable ((uintmax_t) stat_buf->st_gid, hbuf,
669
human_ceiling, 1, 1));
595
671
case 'h': /* leading directories part of path */
599
676
cp = strrchr (pathname, '/');
600
677
if (cp == NULL) /* No leading directories. */
604
fprintf (fp, segment->text, pathname);
679
/* If there is no slash in the pathname, we still
680
* print the string because it contains characters
681
* other than just '%s'. The %h expands to ".".
683
print_quoted (fp, qopts, ttyflag, segment->text, ".");
689
print_quoted (fp, qopts, ttyflag, segment->text, pathname);
608
694
case 'H': /* ARGV element file was found under */
610
char cc = pathname[path_length];
697
char cc = pathname[state.path_length];
612
pathname[path_length] = '\0';
699
pathname[state.path_length] = '\0';
613
700
fprintf (fp, segment->text, pathname);
614
pathname[path_length] = cc;
701
pathname[state.path_length] = cc;
617
704
case 'i': /* inode number */
705
/* UNTRUSTED, but not exploitable I think */
618
706
fprintf (fp, segment->text,
619
human_readable ((uintmax_t) stat_buf->st_ino, hbuf, 1, 1));
707
human_readable ((uintmax_t) stat_buf->st_ino, hbuf,
621
711
case 'k': /* size in 1K blocks */
712
/* UNTRUSTED, but not exploitable I think */
622
713
fprintf (fp, segment->text,
623
714
human_readable ((uintmax_t) ST_NBLOCKS (*stat_buf),
624
hbuf, ST_NBLOCKSIZE, 1024));
716
ST_NBLOCKSIZE, 1024));
626
718
case 'l': /* object of symlink */
629
722
char *linkname = 0;
631
724
if (S_ISLNK (stat_buf->st_mode))
633
linkname = get_link_name (pathname, rel_pathname);
726
linkname = get_link_name (pathname, state.rel_pathname);
634
727
if (linkname == 0)
728
state.exit_status = 1;
639
fprintf (fp, segment->text, linkname);
732
print_quoted (fp, qopts, ttyflag, segment->text, linkname);
643
fprintf (fp, segment->text, "");
736
print_quoted (fp, qopts, ttyflag, segment->text, "");
645
738
#endif /* S_ISLNK */
741
case 'M': /* mode as 10 chars (eg., "-rwxr-x--x" */
742
/* UNTRUSTED, probably unexploitable */
744
char modestring[16] ;
745
mode_string (stat_buf->st_mode, modestring);
746
modestring[10] = '\0';
747
fprintf (fp, segment->text, modestring);
647
751
case 'm': /* mode as octal number (perms only) */
752
/* UNTRUSTED, probably unexploitable */
649
754
/* Output the mode portably using the traditional numbers,
650
755
even if the host unwisely uses some other numbering
673
778
| (m & S_IXOTH ? 00001 : 0))));
676
782
case 'n': /* number of links */
783
/* UNTRUSTED, probably unexploitable */
677
784
fprintf (fp, segment->text,
678
785
human_readable ((uintmax_t) stat_buf->st_nlink,
681
790
case 'p': /* pathname */
682
fprintf (fp, segment->text, pathname);
792
print_quoted (fp, qopts, ttyflag, segment->text, pathname);
684
794
case 'P': /* pathname with ARGV element stripped */
796
if (state.curdepth > 0)
687
cp = pathname + path_length;
798
cp = pathname + state.path_length;
689
800
/* Move past the slash between the ARGV element
690
801
and the rest of the pathname. But if the ARGV element
697
fprintf (fp, segment->text, cp);
808
print_quoted (fp, qopts, ttyflag, segment->text, cp);
699
810
case 's': /* size in bytes */
811
/* UNTRUSTED, probably unexploitable */
700
812
fprintf (fp, segment->text,
701
813
human_readable ((uintmax_t) stat_buf->st_size,
814
hbuf, human_ceiling, 1, 1));
704
816
case 't': /* mtime in `ctime' format */
817
/* UNTRUSTED, probably unexploitable */
705
818
fprintf (fp, segment->text, ctime_format (stat_buf->st_mtime));
707
820
case 'u': /* user name */
822
/* (well, the actual user is selected by the user on systems
823
* where chown is not restricted, but the user name was
824
* selected by the system administrator)
709
827
struct passwd *p;
718
836
/* else fallthru */
720
839
case 'U': /* UID number */
840
/* UNTRUSTED, probably unexploitable */
721
841
fprintf (fp, segment->text,
722
human_readable ((uintmax_t) stat_buf->st_uid, hbuf, 1, 1));
842
human_readable ((uintmax_t) stat_buf->st_uid, hbuf,
843
human_ceiling, 1, 1));
846
/* type of filesystem entry like `ls -l`: (d,-,l,s,p,b,c,n) n=nonexistent(symlink) */
847
case 'Y': /* in case of symlink */
851
if (S_ISLNK (stat_buf->st_mode))
854
/* If we would normally follow links, do not do so.
855
* If we would normally not follow links, do so.
857
if ((following_links() ? lstat : stat)
858
(state.rel_pathname, &sbuf) != 0)
860
if ( errno == ENOENT ) {
861
fprintf (fp, segment->text, "N");
864
if ( errno == ELOOP ) {
865
fprintf (fp, segment->text, "L");
868
error (0, errno, "%s", pathname);
872
stat_buf->st_mode = sbuf.st_mode;
880
mode_t m = stat_buf->st_mode & S_IFMT;
882
fprintf (fp, segment->text,
883
( m == S_IFSOCK ? "s" :
890
m == S_IFDOOR ? "D" :
892
m == S_IFIFO ? "p" : "U" ) );
862
1051
pred_ls (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
864
list_file (pathname, rel_pathname, stat_buf, start_time,
865
output_block_size, stdout);
1055
list_file (pathname, state.rel_pathname, stat_buf, options.start_time,
1056
options.output_block_size, stdout);
870
1061
pred_mmin (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
872
switch (pred_ptr->args.info.kind)
875
if (stat_buf->st_mtime > (time_t) pred_ptr->args.info.l_val)
879
if (stat_buf->st_mtime < (time_t) pred_ptr->args.info.l_val)
883
if ((stat_buf->st_mtime >= (time_t) pred_ptr->args.info.l_val)
884
&& (stat_buf->st_mtime < (time_t) pred_ptr->args.info.l_val + 60))
1064
return pred_timewindow(stat_buf->st_mtime, pred_ptr, 60);
892
1068
pred_mtime (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
894
switch (pred_ptr->args.info.kind)
897
if (stat_buf->st_mtime > (time_t) pred_ptr->args.info.l_val)
901
if (stat_buf->st_mtime < (time_t) pred_ptr->args.info.l_val)
905
if ((stat_buf->st_mtime >= (time_t) pred_ptr->args.info.l_val)
906
&& (stat_buf->st_mtime < (time_t) pred_ptr->args.info.l_val
1071
return pred_timewindow(stat_buf->st_mtime, pred_ptr, DAYSECS);
981
1150
The exact format is not specified.
982
1151
This standard does not have requirements for locales other than POSIX
984
fprintf (stderr, _("< %s ... %s > ? "),
985
pred_ptr->args.exec_vec.vec[0], pathname);
1153
/* XXX: printing UNTRUSTED data here. */
1154
fprintf (stderr, _("< %s ... %s > ? "), program, arg);
986
1155
fflush (stderr);
988
return pred_exec (pathname, stat_buf, pred_ptr);
1160
pred_ok (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
1162
if (is_ok(pred_ptr->args.exec_vec.replace_vec[0], pathname))
1163
return new_impl_pred_exec (pathname, stat_buf, pred_ptr, NULL, 0);
1169
pred_okdir (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
1171
const char *prefix = (state.rel_pathname[0] == '/') ? NULL : "./";
1172
if (is_ok(pred_ptr->args.exec_vec.replace_vec[0], pathname))
1173
return new_impl_pred_exec (state.rel_pathname, stat_buf, pred_ptr,
1174
prefix, (prefix ? 2 : 0));
994
1180
pred_open (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
1003
1192
|| !(*pred_ptr->pred_left->pred_func) (pathname, stat_buf,
1004
1193
pred_ptr->pred_left))
1006
/* Check whether we need a stat here. */
1007
if (pred_ptr->need_stat)
1009
if (!have_stat && (*xstat) (rel_pathname, stat_buf) != 0)
1011
error (0, errno, "%s", pathname);
1195
if (get_info(pathname, state.rel_pathname, stat_buf, pred_ptr) != 0)
1017
1197
return ((*pred_ptr->pred_right->pred_func) (pathname, stat_buf,
1018
1198
pred_ptr->pred_right));
1025
1205
pred_path (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
1027
1208
if (fnmatch (pred_ptr->args.str, pathname, 0) == 0)
1029
1210
return (false);
1071
1261
pred_prune (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
1073
stop_at_current_level = true;
1074
return (do_dir_first); /* This is what SunOS find seems to do. */
1266
state.stop_at_current_level = true;
1267
return (options.do_dir_first); /* This is what SunOS find seems to do. */
1271
pred_quit (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
1277
/* Run any cleanups. This includes executing any command lines
1278
* we have partly built but not executed.
1282
/* Since -exec and friends don't leave child processes running in the
1283
* background, there is no need to wait for them here.
1285
exit(state.exit_status); /* 0 for success, etc. */
1078
1289
pred_regex (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
1080
1291
int len = strlen (pathname);
1081
1293
if (re_match (pred_ptr->args.regex, pathname, len, 0,
1082
1294
(struct re_registers *) NULL) == len)
1326
pred_samefile (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
1328
/* Potential optimisation: because of the loop protection, we always
1329
* know the device of the current directory, hence the device number
1330
* of the file we're currently considering. If -L is not in effect,
1331
* and the device number of the file we're looking for is not the
1332
* same as the device number of the current directory, this
1333
* predicate cannot return true. Hence there would be no need to
1334
* stat the file we're lookingn at.
1338
return stat_buf->st_ino == pred_ptr->args.fileid.ino
1339
&& stat_buf->st_dev == pred_ptr->args.fileid.dev;
1113
1343
pred_true (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
1119
1352
pred_type (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
1121
mode_t mode = stat_buf->st_mode;
1122
1355
mode_t type = pred_ptr->args.type;
1357
assert(state.have_type);
1358
assert(state.type != 0);
1362
if (state.have_stat)
1363
mode = stat_buf->st_mode;
1125
1368
/* POSIX system; check `mode' the slow way. */
1126
1369
if ((S_ISBLK (mode) && type == S_IFBLK)
1208
1438
pred_xtype (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
1440
struct stat sbuf; /* local copy, not stat_buf because we're using a different stat method */
1441
int (*ystat) (const char*, struct stat *p);
1213
ystat = xstat == lstat ? stat : lstat;
1214
if ((*ystat) (rel_pathname, &sbuf) != 0)
1443
/* If we would normally stat the link itself, stat the target instead.
1444
* If we would normally follow the link, stat the link itself instead.
1446
if (following_links())
1447
ystat = optionp_stat;
1449
ystat = optionl_stat;
1451
if ((*ystat) (state.rel_pathname, &sbuf) != 0)
1216
if (ystat == stat && errno == ENOENT)
1217
/* Mimic behavior of ls -lL. */
1218
return (pred_type (pathname, stat_buf, pred_ptr));
1219
error (0, errno, "%s", pathname);
1453
if (following_links() && errno == ENOENT)
1455
/* If we failed to follow the symlink,
1456
* fall back on looking at the symlink itself.
1458
/* Mimic behavior of ls -lL. */
1459
return (pred_type (pathname, stat_buf, pred_ptr));
1463
error (0, errno, "%s", pathname);
1464
state.exit_status = 1;
1468
/* Now that we have our stat() information, query it in the same
1469
* way that -type does.
1223
1471
return (pred_type (pathname, &sbuf, pred_ptr));
1241
1489
zero, and the exit arg (status high) is 0.
1242
1490
Otherwise return false, possibly printing an error message. */
1245
launch (struct predicate *pred_ptr)
1494
prep_child_for_exec (void)
1496
const char inputfile[] = "/dev/null";
1497
/* fprintf(stderr, "attaching stdin to /dev/null\n"); */
1500
if (open(inputfile, O_RDONLY) < 0)
1502
/* This is not entirely fatal, since
1503
* executing the child with a closed
1504
* stdin is almost as good as executing it
1505
* with its stdin attached to /dev/null.
1507
error (0, errno, "%s", inputfile);
1514
launch (const struct buildcmd_control *ctl,
1515
struct buildcmd_state *buildstate)
1248
1518
pid_t child_pid;
1249
struct exec_val *execp; /* Pointer for efficiency. */
1250
1519
static int first_time = 1;
1252
execp = &pred_ptr->args.exec_vec;
1520
const struct exec_val *execp = buildstate->usercontext;
1522
/* Null terminate the arg list. */
1523
bc_push_arg (ctl, buildstate, (char *) NULL, 0, NULL, 0, false);
1254
1525
/* Make sure output of command doesn't get mixed with find output. */
1255
1526
fflush (stdout);
1256
1527
fflush (stderr);
1258
1529
/* Make sure to listen for the kids. */
1259
1530
if (first_time)
1268
1539
if (child_pid == 0)
1270
1541
/* We be the child. */
1271
if (starting_desc < 0
1272
? chdir (starting_dir) != 0
1273
: fchdir (starting_desc) != 0)
1542
prep_child_for_exec();
1544
/* For -exec and -ok, change directory back to the starting directory.
1545
* for -execdir and -okdir, stay in the directory we are searching
1546
* (the latter is more secure).
1548
if (!execp->use_current_dir)
1275
error (0, errno, "%s", starting_dir);
1550
/* Even if DEBUG_STAT is set, don't announce our change of
1551
* directory, since we're not going to emit a subsequent
1552
* announcement of a call to stat() anyway, as we're about
1553
* to exec something.
1555
if (starting_desc < 0
1556
? chdir (starting_dir) != 0
1557
: fchdir (starting_desc) != 0)
1559
error (0, errno, "%s", starting_dir);
1278
execvp (execp->vec[0], execp->vec);
1279
error (0, errno, "%s", execp->vec[0]);
1564
execvp (buildstate->cmd_argv[0], buildstate->cmd_argv);
1565
error (0, errno, "%s", buildstate->cmd_argv[0]);
1284
while (waitpid (child_pid, &status, 0) == (pid_t) -1)
1287
error (0, errno, _("error waiting for %s"), execp->vec[0]);
1291
if (WIFSIGNALED (status))
1570
/* In parent; set up for next time. */
1571
bc_clear_args(ctl, buildstate);
1574
while (waitpid (child_pid, &wait_status, 0) == (pid_t) -1)
1578
error (0, errno, _("error waiting for %s"), buildstate->cmd_argv[0]);
1579
state.exit_status = 1;
1580
return 0; /* FAIL */
1584
if (WIFSIGNALED (wait_status))
1293
1586
error (0, 0, _("%s terminated by signal %d"),
1294
execp->vec[0], WTERMSIG (status));
1298
return (!WEXITSTATUS (status));
1587
buildstate->cmd_argv[0], WTERMSIG (wait_status));
1589
if (execp->multiple)
1591
/* -exec \; just returns false if the invoked command fails.
1592
* -exec {} + returns true if the invoked command fails, but
1593
* sets the program exit status.
1595
state.exit_status = 1;
1601
if (0 == WEXITSTATUS (wait_status))
1607
if (execp->multiple)
1609
/* -exec \; just returns false if the invoked command fails.
1610
* -exec {} + returns true if the invoked command fails, but
1611
* sets the program exit status.
1613
state.exit_status = 1;
1615
return 0; /* FAIL */
1301
1621
/* Return a static string formatting the time WHEN according to the
1302
1622
strftime format character KIND. */
1390
1712
INDENT is the number of levels to indent the left margin. */
1393
print_tree (node, indent)
1394
struct predicate *node;
1715
print_tree (FILE *fp, struct predicate *node, int indent)
1399
1719
if (node == NULL)
1401
1721
for (i = 0; i < indent; i++)
1403
printf ("pred = %s type = %s prec = %s addr = %x\n",
1723
fprintf (fp, "pred = %s type = %s prec = %s addr = %p\n",
1404
1724
find_pred_name (node->pred_func),
1405
1725
type_name (node->p_type), prec_name (node->p_prec), node);
1406
for (i = 0; i < indent; i++)
1408
printf (_("left:\n"));
1409
print_tree (node->pred_left, indent + 1);
1410
for (i = 0; i < indent; i++)
1412
printf (_("right:\n"));
1413
print_tree (node->pred_right, indent + 1);
1726
if (node->need_stat || node->need_type)
1730
for (i = 0; i < indent; i++)
1733
fprintf (fp, "Needs ");
1734
if (node->need_stat)
1736
fprintf (fp, "stat");
1739
if (node->need_type)
1741
fprintf (fp, "%stype", comma ? "," : "");
1746
for (i = 0; i < indent; i++)
1748
fprintf (fp, "left:\n");
1749
print_tree (fp, node->pred_left, indent + 1);
1750
for (i = 0; i < indent; i++)
1752
fprintf (fp, "right:\n");
1753
print_tree (fp, node->pred_right, indent + 1);
1416
1756
/* Copy STR into BUF and trim blanks from the end of BUF.
1446
1785
while (cur != NULL)
1448
printf ("%s ", blank_rtrim (find_pred_name (cur->pred_func), name));
1787
fprintf (fp, "%s ", blank_rtrim (find_pred_name (cur->pred_func), name));
1449
1788
cur = cur->pred_next;
1794
/* Print out the predicate list starting at NODE. */
1798
print_parenthesised(FILE *fp, struct predicate *node)
1804
if ( ( (node->pred_func == pred_or)
1805
|| (node->pred_func == pred_and) )
1806
&& node->pred_left == NULL)
1808
/* We print "<nothing> or X" as just "X"
1809
* We print "<nothing> and X" as just "X"
1811
print_parenthesised(fp, node->pred_right);
1815
if (node->pred_left || node->pred_right)
1819
fprintf(fp, "%s", " ( ");
1820
print_optlist(fp, node);
1822
fprintf(fp, "%s", " ) ");
1828
print_optlist (FILE *fp, struct predicate *p)
1834
print_parenthesised(fp, p->pred_left);
1837
p->need_stat ? "[stat called here] " : "",
1838
p->need_type ? "[type needed here] " : "",
1839
blank_rtrim (find_pred_name (p->pred_func), name));
1840
print_parenthesised(fp, p->pred_right);
1453
1844
#endif /* DEBUG */