/* pst3.c
*
* Third version to get process arg info; this time by using
* a combination of reading the /proc/<pid>/psinfo structures
* and reading the complete arg vector from kernel memory structures.
*
* Developed and tested under Solaris 5.8 (both 32 and 64 bit modes).
*
* NOTE: This program must be setuid-root (or run by root) to work!
*
* Written: 2005-04-28 R.W.Ingraham
*/
#define _KMEMUSER 1
#include <kvm.h>
#include <sys/param.h>
#include <sys/user.h>
#include <sys/time.h>
#include <sys/proc.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <procfs.h>
#include <fcntl.h>
#include <dirent.h>
#include <errno.h>
/*
* Constants
*/
#define PROC_DIR "/proc"
#define MAX_PATH 1024
/*
* Structures
*/
/*
* Globals
*/
static char * szProg;
static kvm_t * kd;
static struct proc * pProc;
static struct user * pUser;
static char ** myArgv;
/*
* Prototypes
*/
static int HandleFile (struct dirent *pDent);
static int HandlePsInfo (char *szPath, psinfo_t *pPsInfo);
static int GetArgVectors (pid_t pid);
static void ShowArgVectors (void);
static void ReleaseArgVectors();
/*----------------------------------------------------------------------------*/
int main (int argc, char **argv)
{
DIR *pDir;
struct dirent *pDent;
int retcode = 0;
/* Set our program name global */
if ((szProg = strrchr(argv[0], '/')) != NULL)
szProg++;
else
szProg = argv[0];
/* Make sure that our euid is root */
if (geteuid() != 0)
{
fprintf(stderr, "%s: This program can only be run by the root user!\n", szProg);
exit(1);
}
/* Get a handle to the running kernel image */
if ((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, argv[0])) == NULL)
{
fprintf(stderr, "%s: Failed to open kernel memory: %s\n", szProg, strerror(errno));
exit(2);
}
/* Open the /proc directory */
if ((pDir = opendir(PROC_DIR)) != NULL)
{
=1= |