#include #include #define _GNU_SOURCE #include "ui-socket.h" #include #include #include #include #include #include #include #include int init_ui_socket(const char *filename) { char line[256]; FILE *fp; // Test if Zenity is installed (get version) fp = popen("zenity --version", "r"); if (fp == NULL) { perror("Pipe returned a error"); return 1; } else { while (fgets(line, sizeof(line), fp)) printf("%s", line); pclose(fp); return 0; } } /* * This function is called from the FUSE operations functions. Those are called * from separate threads. Therefore, there can be multiple threads that try to * ask for access at the same time, but we have to */ int ask_access(const char *filename, struct process_info pi) { FILE *fp; size_t command_len = 139 + sizeof(pid_t) * 8 + strlen(pi.name) + strlen(filename); char *command = (char *)malloc(command_len); snprintf(command, command_len, "zenity --question --title \"Allow Access?\" --text \"Allow process " "%s with PID %d to access %s\"", pi.name, pi.PID, filename); // Zenity Question Message Popup fp = popen(command, "r"); free(command); if (fp == NULL) { perror("Pipe returned a error"); return -1; } else { return WEXITSTATUS(pclose(fp)); } }