* Return code: 0 is true, anything else is error/not supported
*
* Test for machine features
+ * -o report a number of online cpus
* -s report pagesize
* -w report bits per long
*/
#include <sys/quota.h>
#include <sys/resource.h>
#include <signal.h>
+#include <unistd.h>
#ifdef HAVE_XFS_XQM_H
#include <xfs/xqm.h>
fprintf(stderr, "Usage: feature [-v] -<q|u|g|p|U|G|P> <filesystem>\n");
fprintf(stderr, " feature [-v] -c <file>\n");
fprintf(stderr, " feature [-v] -t <file>\n");
- fprintf(stderr, " feature -s | -w\n");
+ fprintf(stderr, " feature -o | -s | -w\n");
exit(1);
}
int uflag = 0;
int Uflag = 0;
int wflag = 0;
+ int oflag = 0;
char *fs = NULL;
- while ((c = getopt(argc, argv, "ctgGpPqsuUvw")) != EOF) {
+ while ((c = getopt(argc, argv, "ctgGopPqsuUvw")) != EOF) {
switch (c) {
case 'c':
cflag++;
case 'G':
Gflag++;
break;
+ case 'o':
+ oflag++;
+ break;
case 'p':
pflag++;
break;
if (optind != argc-1) /* need a device */
usage();
fs = argv[argc-1];
- } else if (wflag || sflag) {
+ } else if (wflag || sflag || oflag) {
if (optind != argc)
usage();
} else
#endif
exit(0);
}
+ if (oflag) {
+ long ncpus = -1;
+
+#if defined(_SC_NPROCESSORS_ONLN)
+ ncpus = sysconf(_SC_NPROCESSORS_ONLN);
+#elif defined(_SC_NPROC_ONLN)
+ ncpus = sysconf(_SC_NPROC_ONLN);
+#endif
+ if (ncpus == -1)
+ ncpus = 1;
+
+ printf("%ld\n", ncpus);
+
+ exit(0);
+ }
fprintf(stderr, "feature: dunno what you're after.\n");
return(1);