I am trying to get system UUID from C program, I tried the following:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SYS_UUID_PATH "/sys/class/dmi/id/product_uuid"
#define DBUS_MACHINE_ID "/var/lib/dbus/machine-id"
int main(int argc, char ** argv)
{
char buffer[100];
//FILE * fd = popen(DBUS_MACHINE_ID, "r");
FILE * fd = popen(SYS_UUID_PATH, "r");
if (fd== NULL)
{
printf("No file to open my guy \n");
return -1;
}
int len = fseek(fd, 0, SEEK_END);
printf("size: %d", len);
return 0;
}
: And running as root or as a user with sudo, I got the following output:
size: -1root@nabil-Inspiron:/tmp# sh: 1: /sys/class/dmi/id/product_uuid: Permission denied
What's the proper way to do it?