Hello,
I’m trying to get the process name by calling devctl, but it fails and errno
returns a “Bad file descriptor”. I have no idea how to tell (other then the
return being -1) that the file descriptor returned from an open is valid.
Can anyone see a problem with the following code. I essentially took this
code from an example in a previous post on the subject.
Thanks,
Eric
int proc_fd, status;
// Structure used to get the process info
struct dinfo_s
{
procfs_debuginfo info;
char pathbuffer[_POSIX_PATH_MAX];
};
struct dinfo_s dinfo;
char buf[_POSIX_PATH_MAX + 1];
// Open up the proc namespace to find our process info
sprintf( buf, “%s/%d/as”, PROC_BASE, getpid() );
printf(“buf: %s\n”,buf);
if( (proc_fd = open(buf, O_RDONLY)) == -1 )
{
fprintf( stderr, “%s: Error opening path to %s.\n”, FunctionName, buf );
close(proc_fd);
return(-1);
}
memset(&dinfo, 0, sizeof(dinfo));
// Get the info from procmgr
status = devctl( proc_fd, DCMD_PROC_MAPDEBUG_BASE, &dinfo, sizeof(dinfo),
0 );
if( status != EOK )
{
fprintf( stderr, “%s: Error in devctl() call. %s\n”,
FunctionName,strerror(status) );
close(proc_fd);
return(-1);
}
close(proc_fd);