# #
#############################################################################*/
+#include <linux/limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/resource.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
return EXIT_SUCCESS;
}
+static int stat_self(struct stat* st) {
+ char path[PATH_MAX];
+ int r;
+
+ // Find path to ourselves
+ r = readlink("/proc/self/exe", path, sizeof(path));
+ if (r < 0) {
+ fprintf(stderr, "readlink() failed: %m\n");
+ return 1;
+ }
+
+ // stat()
+ r = stat(path, st);
+ if (r < 0) {
+ fprintf(stderr, "stat() on %s failed: %m\n", path);
+ return 1;
+ }
+
+ return 0;
+}
+
+/*
+ Returns who owns this binary
+*/
+static int stat_ownership(int argc, char* argv[]) {
+ struct stat st;
+ int r;
+
+ // Stat ourselves
+ r = stat_self(&st);
+ if (r)
+ return r;
+
+ // Print result
+ printf("uid=%d gid=%d\n", st.st_uid, st.st_gid);
+
+ return 0;
+}
+
int main(int argc, char* argv[]) {
if (argc < 2) {
fprintf(stderr, "No command given\n");
else if (strcmp(command, "sleep") == 0)
callback = _sleep;
+ // Stat ownership
+ else if (strcmp(command, "stat-ownership") == 0)
+ callback = stat_ownership;
+
// Exit if no callback has been set
if (!callback) {
fprintf(stderr, "Unknown command: %s\n", command);