Well, the main thing you need to do is get the current working directory in your C script, and then you can either write some C code to combine the result with argv[0] to create the full path to the file and pass that to your python script as command line argument when you call it. Alternatively, you could pass both argv[0] and the result of getcwd() as parameters to your Python script, which is what I did below:
requestAudit.c
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, const char* argv[]) {
char* cwd = getcwd(NULL, 0);
char* command = "python audit.py ";
char* combine;
// I added 2 because 1 for the null terminator and 1 for the space
// between cwd and argv[0]
size_t len = strlen(command) + strlen(cwd) + strlen(argv[0]) + 2;
combine = malloc(sizeof(*combine)*len);
strncpy(combine, command, strlen(command) + 1);
strncat(combine, cwd, strlen(cwd) + 1);
strncat(combine, " ", 2);
strncat(combine, argv[0], strlen(argv[0]) + 1);
return system(combine);
}
audit.py
import sys
if __name__ == "__main__":
full_path = sys.argv[1] + sys.argv[2][1:]
print(full_path)
This is just one way to do it, I'm sure there are other, probably better, ways to do this.
os.getcwd()from the python scriptos.getcwd()may or may not be the path where the binary is located, that will depend on how it's been designed. At any rate you can useos.getppid()to get the PID of the process that invoked the script, I'm not sure how you get the process image path from the PID though, maybe this helps.