#############################################################################*/
#include <linux/limits.h>
+#include <mntent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
return 0;
}
+static int check_mountpoint(int argc, char* argv[]) {
+ if (argc < 1) {
+ fprintf(stderr, "check-mountpoint requires an argument\n");
+ return EXIT_FAILURE;
+ }
+
+ const char* mp = argv[0];
+ int r = 1;
+
+ FILE* f = fopen("/proc/self/mounts", "r");
+ if (!f) {
+ fprintf(stderr, "Could not open /proc/self/mounts: %m\n");
+ return 1;
+ }
+
+ // Walk through all mountpoints
+ for (;;) {
+ struct mntent* entry = getmntent(f);
+ if (!entry)
+ break;
+
+ // Check for match
+ if (strcmp(entry->mnt_dir, mp) == 0) {
+ r = 0;
+ break;
+ }
+ }
+
+ fclose(f);
+
+ // Print something useful
+ if (r)
+ printf("%s is not a mountpoint\n", mp);
+ else
+ printf("%s is a mointpoint\n", mp);
+
+ return r;
+}
+
static int check_open_file_descriptors(int argc, char* argv[]) {
struct rlimit limits;
int r;
int (*callback)(int argc, char* argv[]) = NULL;
const char* command = argv[1];
- if (strcmp(command, "check-open-file-descriptors") == 0)
+ if (strcmp(command, "check-mountpoint") == 0)
+ callback = check_mountpoint;
+
+ else if (strcmp(command, "check-open-file-descriptors") == 0)
callback = check_open_file_descriptors;
// Echo