@@ -349,6 +349,7 @@ int main(int argc, char **argv) {
349
349
size_t ipset_reduce_factor = 120 ;
350
350
size_t ipset_reduce_min_accepted = 16384 ;
351
351
int ret = 0 , quiet = 0 ;
352
+ int inputs = 0 ;
352
353
353
354
ipset * root = NULL , * ips = NULL , * first = NULL , * second = NULL ;
354
355
int i , mode = MODE_COMBINE , header = 0 , read_second = 0 ;
@@ -565,9 +566,8 @@ int main(int argc, char **argv) {
565
566
}
566
567
else {
567
568
if (!strcmp (argv [i ], "-" )) {
568
- ips = ipset_load (NULL );
569
-
570
- if (!ips ) {
569
+ inputs ++ ;
570
+ if (!(ips = ipset_load (NULL ))) {
571
571
fprintf (stderr , "%s: Cannot load ipset from stdin\n" , PROG );
572
572
exit (1 );
573
573
}
@@ -585,6 +585,8 @@ int main(int argc, char **argv) {
585
585
}
586
586
}
587
587
else if (argv [i ][0 ] == '@' ) {
588
+ inputs ++ ;
589
+
588
590
/* Handle @filename as a file list or directory */
589
591
const char * listname = argv [i ] + 1 ; /* Skip the @ character */
590
592
struct stat st ;
@@ -629,11 +631,10 @@ int main(int argc, char **argv) {
629
631
fprintf (stderr , "%s: Loading file %s from directory %s\n" , PROG , entry -> d_name , listname );
630
632
631
633
/* Load the file as an independent ipset */
632
- ips = ipset_load (filepath );
633
- if (!ips ) {
634
+ if (!(ips = ipset_load (filepath ))) {
634
635
fprintf (stderr , "%s: Cannot load file %s from directory %s\n" ,
635
636
PROG , filepath , listname );
636
- continue ;
637
+ exit ( 1 ) ;
637
638
}
638
639
639
640
files_loaded = 1 ;
@@ -700,11 +701,10 @@ int main(int argc, char **argv) {
700
701
fprintf (stderr , "%s: Loading file %s from list (line %d)\n" , PROG , s , lineid );
701
702
702
703
/* Load the file as an independent ipset */
703
- ips = ipset_load (s );
704
- if (!ips ) {
704
+ if (!(ips = ipset_load (s ))) {
705
705
fprintf (stderr , "%s: Cannot load file %s from list %s (line %d)\n" ,
706
706
PROG , s , listname , lineid );
707
- continue ;
707
+ exit ( 1 ) ;
708
708
}
709
709
710
710
files_loaded = 1 ;
@@ -736,11 +736,10 @@ int main(int argc, char **argv) {
736
736
}
737
737
}
738
738
else {
739
- ips = ipset_load (argv [i ]);
740
-
741
- if (!ips ) {
739
+ inputs ++ ;
740
+ if (!(ips = ipset_load (argv [i ]))) {
742
741
fprintf (stderr , "%s: Cannot load ipset: %s\n" , PROG , argv [i ]);
743
- continue ; /* Continue with other arguments instead of exiting */
742
+ exit ( 1 );
744
743
}
745
744
746
745
if (read_second ) {
@@ -760,21 +759,21 @@ int main(int argc, char **argv) {
760
759
761
760
/*
762
761
* if no ipset was given on the command line
763
- * assume stdin, but only if no other filenames were specified
762
+ * assume stdin, regardless of whether other options were specified
764
763
*/
765
764
766
- if (!root && argc <= 1 ) {
765
+ if (!inputs ) {
767
766
if (unlikely (debug ))
768
- fprintf (stderr , "%s: No inputs provided, reading from stdin\n" , PROG );
769
-
770
- first = root = ipset_load (NULL );
771
- if (!root ) {
772
- fprintf (stderr , "%s: No ipsets to merge.\n" , PROG );
767
+ fprintf (stderr , "%s: No input files provided, reading from stdin\n" , PROG );
768
+
769
+ if (!(first = root = ipset_load (NULL ))) {
770
+ fprintf (stderr , "%s: Cannot load ipset from stdin\n" , PROG );
773
771
exit (1 );
774
772
}
775
773
}
776
- else if (!root ) {
777
- /* We had parameters but still ended up with no valid ipsets */
774
+
775
+ if (!root ) {
776
+ // impossible situation since we fail if no ipset is loaded
778
777
fprintf (stderr , "%s: No valid ipsets to merge from the provided inputs.\n" , PROG );
779
778
exit (1 );
780
779
}
0 commit comments