static unsigned int rb_batch = RB_BATCH_DEFAULT;
static int pipeline;
+static char *pipename;
static int text_output = 1;
return 0;
}
-static int do_stdin(void)
+static void do_pipe(int fd)
{
unsigned long long youngest;
- int fd, events, fdblock;
+ int events, fdblock;
last_allowed_time = -1ULL;
- fd = dup(STDIN_FILENO);
- if (fd == -1) {
- perror("dup stdin");
- return -1;
- }
-
fdblock = -1;
while ((events = read_events(fd, 0, &fdblock)) > 0) {
read_sequence++;
if (rb_sort_entries)
show_entries_rb(1);
+}
+
+static int do_fifo(void)
+{
+ int fd;
+
+ if (!strcmp(pipename, "-"))
+ fd = dup(STDIN_FILENO);
+ else
+ fd = open(pipename, O_RDONLY);
+
+ if (fd == -1) {
+ perror("dup stdin");
+ return -1;
+ }
+ do_pipe(fd);
close(fd);
return 0;
}
return 0;
}
+static int is_pipe(const char *str)
+{
+ struct stat st;
+
+ if (!strcmp(str, "-"))
+ return 1;
+ if (!stat(str, &st) && S_ISFIFO(st.st_mode))
+ return 1;
+
+ return 0;
+}
+
#define S_OPTS "a:A:b:D:d:f:F:hi:o:Oqstw:vV"
static char usage_str[] = "\n\n" \
"-i <file> | --input=<file>\n" \
act_mask_tmp = i;
break;
case 'i':
- if (!strcmp(optarg, "-") && !pipeline)
+ if (is_pipe(optarg) && !pipeline) {
pipeline = 1;
- else if (resize_devices(optarg) != 0)
+ pipename = strdup(optarg);
+ } else if (resize_devices(optarg) != 0)
return 1;
break;
case 'D':
}
while (optind < argc) {
- if (!strcmp(argv[optind], "-") && !pipeline)
+ if (is_pipe(argv[optind]) && !pipeline) {
pipeline = 1;
- else if (resize_devices(argv[optind]) != 0)
+ pipename = strdup(optarg);
+ } else if (resize_devices(argv[optind]) != 0)
return 1;
optind++;
}
}
if (pipeline)
- ret = do_stdin();
+ ret = do_fifo();
else
ret = do_file();