I have this C code that runs smartctl command and takes its output:#include <iostream>#include <cstdio>#include <cstdlib>using namespace std;int main(){    cout << Hello !  << endl;    FILE *fp;    char path[1035];    /* Open the command for reading. */    fp = popen(smartctl -A /dev/sda, r);    if (fp == NULL) {        printf(Failed to run command\n );        exit(1);    }    /* Read the output a line at a time - output it. */    while (fgets(path, sizeof(path), fp) != NULL) {        printf(%s, path);    }    /* close */    pclose(fp);    return 0;}The machine is openSUSE 13.2. My problem is it requires root privilege, but I don't want to switch to root.What I tried and did not work:Added CAP_SYS_ADMIN capability to the program executable.Added CAP_DAC_OVERRIDE to the smartctl executable (as suggested here) and I also added it to the program executable.I used setcap 'cap_dac_override=+ep' cpptest to add the capability (also for the CAP_SYS_Admin) but when I use getcap I get only one of them, not both. (Can you help me in this ?)I changed the permission of /dev/sda to 755, 777, 766 and changed ownership of the device to my group using chown root:users /dev/sda.I wrote a program that performs some network operations using sockets and it required root privilege but I added CAP_NET_ADMIN and it worked. I just don't know why capabilities does not work.This is really important issue. Any help is really appreciated.Please note: I provided a C code but this is an issue with Linux not a programming problem.
How to run smartctl as root without switching to root?
root;c;not root user;privileges;capabilities
According to this discussion CAP_SYS_RAWIO capability needs to be applied to smartctl executable.