Handle select help options properly.
[adu.git] / select.c
1 /*
2 * Copyright (C) 2008 Andre Noll <maan@systemlinux.org>
3 *
4 * Licensed under the GPL v2. For licencing details see COPYING.
5 */
6
7 /** \file select.c The select mode of adu. */
8
9 #include <dirent.h> /* readdir() */
10 #include "adu.h"
11 #include "gcc-compat.h"
12 #include "cmdline.h"
13 #include "fd.h"
14 #include "string.h"
15 #include "error.h"
16 #include "portable_io.h"
17
18 /** Global dir count. */
19 static uint64_t num_dirs;
20 /** Global files count. */
21 static uint64_t num_files;
22 /** Global bytes count. */
23 static uint64_t num_bytes;
24
25 /** The decimal representation of an uint64_t never exceeds that size. */
26 #define FORMATED_VALUE_SIZE 25
27
28 /* these get filled in by the select command. */
29 static char count_unit_buf[4] = "( )", size_unit_buf[4] = "( )";
30
31 enum global_stats_flags {
32 GSF_PRINT_DIRNAME = 1,
33 GSF_PRINT_BYTES = 2,
34 GSF_PRINT_FILES = 4,
35 GSF_COMPUTE_SUMMARY = 8,
36 };
37
38 struct global_stats_info {
39 uint32_t count;
40 int ret;
41 int osl_errno;
42 enum global_stats_flags flags;
43 };
44
45 enum user_stats_flags {
46 USF_PRINT_DIRNAME = 1,
47 USF_PRINT_BYTES = 2,
48 USF_PRINT_FILES = 4,
49 USF_COMPUTE_SUMMARY = 8,
50 };
51
52 struct user_stats_info {
53 uint32_t count;
54 enum user_stats_flags flags;
55 int ret;
56 int osl_errno;
57 struct user_info *ui;
58 };
59
60 static const uint64_t size_unit_divisors[] = {
61 [size_unit_arg_b] = 1ULL,
62 [size_unit_arg_k] = 1024ULL,
63 [size_unit_arg_m] = 1024ULL * 1024ULL,
64 [size_unit_arg_g] = 1024ULL * 1024ULL * 1024ULL,
65 [size_unit_arg_t] = 1024ULL * 1024ULL * 1024ULL * 1024ULL,
66 };
67
68 static const uint64_t count_unit_divisors[] = {
69
70 [count_unit_arg_n] = 1ULL,
71 [count_unit_arg_k] = 1000ULL,
72 [count_unit_arg_m] = 1000ULL * 1000ULL,
73 [count_unit_arg_g] = 1000ULL * 1000ULL * 1000ULL,
74 [count_unit_arg_t] = 1000ULL * 1000ULL * 1000ULL * 1000ULL,
75 };
76
77 static const char size_unit_abbrevs[] = " BKMGT";
78 static const char count_unit_abbrevs[] = " kmgt";
79 static enum enum_size_unit format_size_value(enum enum_size_unit unit,
80 uint64_t value, int print_unit, char *result)
81 {
82 enum enum_size_unit u = unit;
83 char unit_buf[2] = "\0\0";
84
85 if (unit == size_unit_arg_h) /* human readable */
86 for (u = size_unit_arg_b; u < size_unit_arg_t &&
87 value > size_unit_divisors[u + 1]; u++)
88 ; /* nothing */
89 if (print_unit)
90 unit_buf[0] = size_unit_abbrevs[u];
91 sprintf(result, "%llu%s",
92 (long long unsigned)value / size_unit_divisors[u], unit_buf);
93 return u;
94 }
95
96 static enum enum_count_unit format_count_value(enum enum_count_unit unit,
97 uint64_t value, int print_unit, char *result)
98 {
99 enum enum_count_unit u = unit;
100 char unit_buf[2] = "\0\0";
101
102 if (unit == count_unit_arg_h) /* human readable */
103 for (u = count_unit_arg_n; u < count_unit_arg_t &&
104 value > count_unit_divisors[u + 1]; u++)
105 ; /* nothing */
106 if (print_unit)
107 unit_buf[0] = count_unit_abbrevs[u];
108 sprintf(result, "%llu%s",
109 (long long unsigned)value / count_unit_divisors[u], unit_buf);
110 return u;
111 }
112
113 static FILE *output_file;
114
115 __printf_1_2 static int output(const char const *fmt, ...)
116 {
117 va_list argp;
118 int ret;
119
120 va_start(argp, fmt);
121 ret = vfprintf(output_file, fmt, argp);
122 va_end(argp);
123 return ret < 0? -E_OUTPUT : 1;
124 }
125
126 static int get_dir_name_by_number(uint64_t *dirnum, char **name)
127 {
128 char *result = NULL, *tmp;
129 struct osl_row *row;
130 uint64_t val = *dirnum;
131 struct osl_object obj;
132 int ret;
133 char *pfx;
134
135 again:
136 obj.data = &val;
137 obj.size = sizeof(val);
138 ret = osl(osl_get_row(dir_table, DT_NUM, &obj, &row));
139 if (ret < 0)
140 goto out;
141 ret = osl(osl_get_object(dir_table, row, DT_PARENT_NUM, &obj));
142 if (ret < 0)
143 goto out;
144 val = *(uint64_t *)obj.data;
145 ret = osl(osl_get_object(dir_table, row, DT_NAME, &obj));
146 if (ret < 0)
147 goto out;
148 pfx = (select_conf.print_base_dir_given || val)? (char *)obj.data : ".";
149 tmp = make_message("%s/%s", pfx, result? result : "");
150 free(result);
151 result = tmp;
152 if (val)
153 goto again;
154 out:
155 if (ret < 0) {
156 free(result);
157 *name = NULL;
158 } else {
159 assert(result);
160 *name = result;
161 }
162 return ret;
163 }
164
165 static int get_dir_name_of_row(struct osl_row *dir_table_row, char **name)
166 {
167 struct osl_object obj;
168 int ret;
169
170 *name = NULL;
171 ret = osl(osl_get_object(dir_table, dir_table_row, DT_NUM, &obj));
172 if (ret < 0)
173 return ret;
174 return get_dir_name_by_number((uint64_t *)obj.data, name);
175 }
176
177 static int user_stats_loop_function(struct osl_row *row, void *data)
178 {
179 struct user_stats_info *usi = data;
180 struct osl_object obj;
181 int ret, summary = usi->flags & GSF_COMPUTE_SUMMARY;
182 char formated_value[FORMATED_VALUE_SIZE];
183
184 check_signals();
185 if (!usi->count && !summary) {
186 ret = -E_LOOP_COMPLETE;
187 goto err;
188 }
189 if (summary || (usi->count && (usi->flags & USF_PRINT_FILES))) {
190 uint64_t files;
191 ret = osl(osl_get_object(usi->ui->table, row, UT_FILES, &obj));
192 if (ret < 0)
193 goto err;
194 files = *(uint64_t *)obj.data;
195 if (usi->count && (usi->flags & USF_PRINT_FILES)) {
196 format_count_value(select_conf.count_unit_arg, files,
197 select_conf.count_unit_arg == count_unit_arg_h,
198 formated_value);
199 ret = output("\t%s%s", formated_value,
200 (usi->flags & (USF_PRINT_BYTES | USF_PRINT_DIRNAME))?
201 "\t" : "\n");
202 if (ret < 0)
203 goto err;
204 }
205 if (summary)
206 usi->ui->files += files;
207 }
208 if (summary || (usi->count && (usi->flags & USF_PRINT_BYTES))) {
209 uint64_t bytes;
210 ret = osl(osl_get_object(usi->ui->table, row, UT_BYTES, &obj));
211 if (ret < 0)
212 goto err;
213 bytes = *(uint64_t *)obj.data;
214 if (usi->count && (usi->flags & USF_PRINT_BYTES)) {
215 format_size_value(select_conf.size_unit_arg, bytes,
216 select_conf.size_unit_arg == size_unit_arg_h,
217 formated_value);
218 ret = output("%s%s%s",
219 (usi->flags & USF_PRINT_FILES)? "" : "\t",
220 formated_value,
221 usi->flags & USF_PRINT_DIRNAME? "\t" : "\n"
222 );
223 if (ret < 0)
224 goto err;
225 }
226 if (summary) {
227 usi->ui->bytes += bytes;
228 usi->ui->dirs++;
229 }
230
231 }
232 if (usi->count && (usi->flags & USF_PRINT_DIRNAME)) {
233 char *dirname;
234 ret = osl(osl_get_object(usi->ui->table, row, UT_DIR_NUM, &obj));
235 if (ret < 0)
236 goto err;
237 ret = get_dir_name_by_number((uint64_t *)obj.data, &dirname);
238 if (ret < 0)
239 goto err;
240 ret = output("%s%s\n",
241 (usi->flags & (USF_PRINT_BYTES | USF_PRINT_FILES))? "" : "\t",
242 dirname);
243 free(dirname);
244 if (ret < 0)
245 goto err;
246 }
247 if (usi->count > 0)
248 usi->count--;
249 return 1;
250 err:
251 usi->ret = ret;
252 usi->osl_errno = (ret == -E_OSL)? osl_errno : 0;
253 return -1;
254 }
255
256 static int global_stats_loop_function(struct osl_row *row, void *data)
257 {
258 struct global_stats_info *gsi = data;
259 struct osl_object obj;
260 char *dirname, formated_value[FORMATED_VALUE_SIZE];
261 int ret, summary = gsi->flags & GSF_COMPUTE_SUMMARY;
262
263 check_signals();
264 if (!gsi->count && !summary) {
265 ret = -E_LOOP_COMPLETE;
266 goto err;
267 }
268 if (summary || (gsi->count && (gsi->flags & GSF_PRINT_FILES))) {
269 uint64_t files;
270 ret = osl(osl_get_object(dir_table, row, DT_FILES, &obj));
271 if (ret < 0)
272 goto err;
273 files = *(uint64_t *)obj.data;
274 if (gsi->count && (gsi->flags & GSF_PRINT_FILES)) {
275 format_count_value(select_conf.count_unit_arg, files,
276 select_conf.count_unit_arg == count_unit_arg_h,
277 formated_value);
278 ret = output("\t%s%s", formated_value,
279 (gsi->flags & (GSF_PRINT_BYTES | GSF_PRINT_DIRNAME))?
280 "\t" : "\n");
281 if (ret < 0)
282 goto err;
283 }
284 if (summary)
285 num_files += files;
286 }
287 if (summary || (gsi->count && (gsi->flags & GSF_PRINT_BYTES))) {
288 uint64_t bytes;
289 ret = osl(osl_get_object(dir_table, row, DT_BYTES, &obj));
290 if (ret < 0)
291 goto err;
292 bytes = *(uint64_t *)obj.data;
293 if (gsi->count && (gsi->flags & GSF_PRINT_BYTES)) {
294 format_size_value(select_conf.size_unit_arg, bytes,
295 select_conf.size_unit_arg == size_unit_arg_h,
296 formated_value);
297 ret = output("%s%s%s",
298 (gsi->flags & GSF_PRINT_FILES)? "" : "\t",
299 formated_value,
300 (gsi->flags & GSF_PRINT_DIRNAME)? "\t" : "\n"
301 );
302 if (ret < 0)
303 goto err;
304 }
305 if (summary) {
306 num_bytes += bytes;
307 num_dirs++;
308 }
309 }
310 if (gsi->count && (gsi->flags & GSF_PRINT_DIRNAME)) {
311 ret = get_dir_name_of_row(row, &dirname);
312 if (ret < 0)
313 goto err;
314 ret = output("%s%s\n",
315 (gsi->flags & (GSF_PRINT_BYTES | GSF_PRINT_FILES))? "" : "\t",
316 dirname);
317 free(dirname);
318 if (ret < 0)
319 goto err;
320 }
321 if (gsi->count > 0)
322 gsi->count--;
323 return 1;
324 err:
325 gsi->ret = ret;
326 gsi->osl_errno = (ret == -E_OSL)? osl_errno : 0;
327 return -1;
328 }
329
330 static int check_loop_return(int ret, int loop_ret, int loop_osl_errno)
331 {
332 if (ret >= 0)
333 return ret;
334 assert(ret == -E_OSL);
335 if (osl_errno != E_OSL_LOOP)
336 /* error not caused by loop function returning negative. */
337 return ret;
338 assert(loop_ret < 0);
339 if (loop_ret == -E_LOOP_COMPLETE) /* no error */
340 return 1;
341 if (loop_ret == -E_OSL) { /* osl error in loop function */
342 assert(loop_osl_errno);
343 osl_errno = loop_osl_errno;
344 }
345 return loop_ret;
346 }
347
348 static int adu_loop_reverse(struct osl_table *t, unsigned col_num, void *private_data,
349 osl_rbtree_loop_func *func, int *loop_ret, int *loop_osl_errno)
350 {
351 int ret = osl(osl_rbtree_loop_reverse(t, col_num, private_data, func));
352 return check_loop_return(ret, *loop_ret, *loop_osl_errno);
353 }
354
355 static int print_global_summary(void)
356 {
357 char d[FORMATED_VALUE_SIZE], f[FORMATED_VALUE_SIZE],
358 s[FORMATED_VALUE_SIZE];
359 enum enum_count_unit ud, uf;
360 enum enum_size_unit us;
361 int ret;
362
363 if (select_conf.no_global_summary_given)
364 return 1;
365 ud = format_count_value(select_conf.count_unit_arg, num_dirs, 0, d);
366 uf = format_count_value(select_conf.count_unit_arg, num_files, 0, f);
367 us = format_size_value(select_conf.size_unit_arg, num_bytes, 0, s);
368
369 if (!select_conf.no_headers_given) {
370 ret = output("Global summary "
371 "(dirs(%c)/files(%c)/size(%c))\n",
372 count_unit_abbrevs[ud],
373 count_unit_abbrevs[uf],
374 size_unit_abbrevs[us]
375 );
376 if (ret < 0)
377 return ret;
378 }
379 return output("\t%s\t%s\t%s\n\n", d, f, s);
380 }
381
382 static int print_user_summary_line(struct user_info *ui, __a_unused void *data)
383 {
384 char formated_dir_count[FORMATED_VALUE_SIZE],
385 formated_file_count[FORMATED_VALUE_SIZE],
386 formated_bytes[FORMATED_VALUE_SIZE ];
387
388 format_count_value(select_conf.count_unit_arg, ui->dirs,
389 select_conf.count_unit_arg == count_unit_arg_h,
390 formated_dir_count);
391 format_count_value(select_conf.count_unit_arg, ui->files,
392 select_conf.count_unit_arg == count_unit_arg_h,
393 formated_file_count);
394 format_size_value(select_conf.size_unit_arg, ui->bytes,
395 select_conf.size_unit_arg == size_unit_arg_h,
396 formated_bytes);
397 return output("\t%s\t%u\t%s\t%s\t%s\n",
398 ui->pw_name? ui->pw_name : "?",
399 (unsigned)ui->uid,
400 formated_dir_count,
401 formated_file_count,
402 formated_bytes
403 );
404 }
405
406 static int name_comp(const void *a, const void *b)
407 {
408 char *x = ((struct user_info *)a)->pw_name;
409 char *y = ((struct user_info *)b)->pw_name;
410
411 if (!x)
412 return 1;
413 if (!y)
414 return -1;
415 return strcmp(x, y);
416 }
417
418 static int uid_comp(const void *a, const void *b)
419 {
420 return -NUM_COMPARE(((struct user_info *)a)->uid,
421 ((struct user_info *)b)->uid);
422 }
423
424 static int dir_count_comp(const void *a, const void *b)
425 {
426 return NUM_COMPARE(((struct user_info *)a)->dirs,
427 ((struct user_info *)b)->dirs);
428 }
429
430 static int file_count_comp(const void *a, const void *b)
431 {
432 return NUM_COMPARE(((struct user_info *)a)->files,
433 ((struct user_info *)b)->files);
434 }
435
436 static int size_comp(const void *a, const void *b)
437 {
438 return NUM_COMPARE(((struct user_info *)a)->bytes,
439 ((struct user_info *)b)->bytes);
440 }
441
442 /*
443 * The comparators for sorting the user summary.
444 *
445 * This is an array of pointers to functions taking two constant void *
446 * pointers and returning an int.
447 */
448 static int (*summary_comparators[])(const void *, const void *) = {
449 [user_summary_sort_arg_name] = name_comp,
450 [user_summary_sort_arg_uid] = uid_comp,
451 [user_summary_sort_arg_dir_count] = dir_count_comp,
452 [user_summary_sort_arg_file_count] = file_count_comp,
453 [user_summary_sort_arg_size] = size_comp,
454 };
455
456 static int print_user_summary(void)
457 {
458 if (select_conf.no_user_summary_given)
459 return 1;
460 if (!select_conf.no_headers_given) {
461 int ret = output("User summary "
462 "(pw_name/uid/dirs%s/files%s/size%s):\n",
463 count_unit_buf, count_unit_buf, size_unit_buf);
464 if (ret < 0)
465 return ret;
466 }
467 sort_hash_table(summary_comparators[select_conf.user_summary_sort_arg]);
468 return for_each_admissible_user(print_user_summary_line, NULL);
469 }
470
471 static int print_user_list(struct user_info *ui, __a_unused void *data)
472 {
473 int ret;
474 struct user_stats_info usi;
475 enum enum_user_list ula = select_conf.user_list_arg;
476 int print_size_list = (ula == user_list_arg_size
477 || ula == user_list_arg_both);
478
479 if (print_size_list) {
480 usi.count = select_conf.limit_arg;
481 usi.ui = ui;
482 usi.flags = USF_PRINT_DIRNAME | USF_PRINT_BYTES | USF_COMPUTE_SUMMARY;
483 if (!select_conf.no_headers_given) {
484 ret = output("%s (uid %u), by size%s:\n",
485 ui->pw_name? ui->pw_name : "?", (unsigned)ui->uid,
486 size_unit_buf);
487 if (ret < 0)
488 return ret;
489 }
490 ret = adu_loop_reverse(ui->table, UT_BYTES, &usi, user_stats_loop_function,
491 &usi.ret, &usi.osl_errno);
492 if (ret < 0)
493 return ret;
494 ret = output("\n");
495 if (ret < 0)
496 return ret;
497 }
498 if (ula == user_list_arg_file_count || ula == user_list_arg_both) {
499 if (!select_conf.no_headers_given) {
500 ret = output("%s (uid %u), by file count%s:\n",
501 ui->pw_name? ui->pw_name : "?", (unsigned)ui->uid,
502 count_unit_buf);
503 if (ret < 0)
504 return ret;
505 }
506 usi.count = select_conf.limit_arg,
507 usi.ui = ui;
508 usi.flags = USF_PRINT_DIRNAME | USF_PRINT_FILES;
509 ret = adu_loop_reverse(ui->table, UT_FILES, &usi, user_stats_loop_function,
510 &usi.ret, &usi.osl_errno);
511 if (ret < 0)
512 return ret;
513 ret = output("\n");
514 if (ret < 0)
515 return ret;
516 }
517 if (ula == user_list_arg_none && !select_conf.no_user_summary_given) {
518 usi.count = select_conf.limit_arg;
519 usi.ui = ui;
520 usi.flags = USF_COMPUTE_SUMMARY;
521 ret = adu_loop_reverse(ui->table, UT_FILES, &usi, user_stats_loop_function,
522 &usi.ret, &usi.osl_errno);
523 if (ret < 0)
524 return ret;
525 }
526 return 1;
527 }
528
529 static int print_user_lists(void)
530 {
531 return for_each_admissible_user(print_user_list, NULL);
532 }
533
534 static int print_global_lists(void)
535 {
536 struct global_stats_info gsi;
537 int ret;
538 enum enum_global_list gla = select_conf.global_list_arg;
539 int print_size_list = (gla == global_list_arg_size
540 || gla == global_list_arg_both);
541
542 if (print_size_list) {
543 gsi.count = select_conf.limit_arg;
544 gsi.flags = GSF_PRINT_DIRNAME | GSF_PRINT_BYTES | GSF_COMPUTE_SUMMARY;
545 if (!select_conf.no_headers_given) {
546 ret = output("By size%s:\n", size_unit_buf);
547 if (ret < 0)
548 return ret;
549 }
550 ret = adu_loop_reverse(dir_table, DT_BYTES, &gsi,
551 global_stats_loop_function, &gsi.ret, &gsi.osl_errno);
552 if (ret < 0)
553 return ret;
554 ret = output("\n");
555 if (ret < 0)
556 return ret;
557 }
558 if (gla == global_list_arg_file_count || gla == global_list_arg_both) {
559 gsi.count = select_conf.limit_arg;
560 gsi.flags = GSF_PRINT_DIRNAME | GSF_PRINT_FILES;
561 if (!print_size_list)
562 gsi.flags |= GSF_COMPUTE_SUMMARY;
563 if (!select_conf.no_headers_given) {
564 ret = output("By file count%s:\n", count_unit_buf);
565 if (ret < 0)
566 return ret;
567 }
568 ret = adu_loop_reverse(dir_table, DT_FILES, &gsi,
569 global_stats_loop_function, &gsi.ret, &gsi.osl_errno);
570 if (ret < 0)
571 return ret;
572 ret = output("\n");
573 if (ret < 0)
574 return ret;
575 }
576 if (gla == global_list_arg_none && !select_conf.no_global_summary_given) {
577 /* must compute summary */
578 gsi.count = select_conf.limit_arg;
579 gsi.flags = GSF_COMPUTE_SUMMARY;
580 ret = adu_loop_reverse(dir_table, DT_FILES, &gsi,
581 global_stats_loop_function, &gsi.ret, &gsi.osl_errno);
582 if (ret < 0)
583 return ret;
584 }
585 return 1;
586 }
587
588 static int print_statistics(void)
589 {
590 int ret;
591
592 ret = print_global_lists();
593 if (ret < 0)
594 return ret;
595 ret = print_global_summary();
596 if (ret < 0)
597 return ret;
598 ret = print_user_lists();
599 if (ret < 0)
600 return ret;
601 ret = print_user_summary();
602 if (ret < 0)
603 return ret;
604 return 1;
605 }
606
607 static int read_uid_file(struct uid_range *admissible_uids)
608 {
609 size_t size;
610 uint32_t n;
611 char *filename = get_uid_list_name(), *map;
612 int ret = mmap_full_file(filename, O_RDONLY, (void **)&map, &size, NULL);
613 unsigned bits;
614
615 if (ret < 0) {
616 INFO_LOG("failed to map %s\n", filename);
617 free(filename);
618 return ret;
619 }
620 num_uids = size / 4;
621 INFO_LOG("found %u uids in %s\n", (unsigned)num_uids, filename);
622 free(filename);
623 /*
624 * Compute number of hash table bits. The hash table size must be a
625 * power of two and larger than the number of uids.
626 */
627 bits = 2;
628 while (1 << bits < num_uids)
629 bits++;
630 create_hash_table(bits);
631 for (n = 0; n < num_uids; n++) {
632 uint32_t uid = read_u32(map + n * sizeof(uid));
633 ret = search_uid(uid, admissible_uids, OPEN_USER_TABLE, NULL);
634 if (ret < 0)
635 goto out;
636 }
637 out:
638 adu_munmap(map, size);
639 return ret;
640 }
641
642 int run_select_query(struct uid_range *admissible_uids)
643 {
644 int ret;
645
646 if (select_conf.output_given && strcmp(select_conf.output_arg, "-")) {
647 output_file = fopen(select_conf.output_arg, "w");
648 if (!output_file)
649 return -ERRNO_TO_ERROR(errno);
650 } else
651 output_file = stdout;
652
653 if (select_conf.count_unit_arg != count_unit_arg_h)
654 count_unit_buf[1] = count_unit_abbrevs[select_conf.count_unit_arg];
655 else
656 count_unit_buf[0] = '\0';
657 if (select_conf.size_unit_arg != size_unit_arg_h)
658 size_unit_buf[1] = size_unit_abbrevs[select_conf.size_unit_arg];
659 else
660 size_unit_buf[0] = '\0';
661
662 ret = open_dir_table(0);
663 if (ret < 0)
664 goto out;
665 check_signals();
666 ret = read_uid_file(admissible_uids);
667 if (ret < 0)
668 goto out;
669 check_signals();
670 ret = print_statistics();
671 out:
672 close_all_tables();
673 if (output_file != stdout)
674 fclose(output_file);
675 return ret;
676 }
677
678 /* return: < 0: error, >0: OK, == 0: help given */
679 int parse_select_options(char *string, struct select_cmdline_parser_params *params,
680 struct uid_range **admissible_uids)
681 {
682 int ret;
683 const char **line;
684
685 if (select_cmdline_parser_string_ext(string, &select_conf, "select",
686 params))
687 return -E_SYNTAX;
688 ret = parse_uid_arg(select_conf.uid_arg, admissible_uids);
689 if (ret < 0)
690 return ret;
691 if (!select_conf.help_given && !select_conf.detailed_help_given)
692 return 1;
693
694 line = select_conf.detailed_help_given?
695 select_args_info_detailed_help : select_args_info_help;
696 if (!output_file)
697 output_file = stdout;
698 for (; *line; line++) {
699 ret = output("%s\n", *line);
700 if (ret < 0)
701 return ret;
702 }
703 return 0;
704 }
705
706 int com_select(void)
707 {
708 struct uid_range *admissible_uids = NULL;
709
710 if (conf.select_options_given) {
711 int ret;
712 struct select_cmdline_parser_params params = {
713 .override = 1,
714 .initialize = 1,
715 .check_required = 1,
716 .check_ambiguity = 1,
717 .print_errors = 1
718 };
719 ret = parse_select_options(conf.select_options_arg, &params,
720 &admissible_uids);
721 if (ret <= 0) /* do not run query if help was given */
722 return ret;
723 }
724 return run_select_query(admissible_uids);
725 }