PROXY  WHOIS  RQUOTE  TEXTS  SOFT  FOREX  BBOARD
 Music  Philosophy  Code  Literature  Russian

= ROOT|Technical|Code_Examples|C|nagios-plugins-1.4.10|plugins-root|pst3.c =

page 1 of 3



/*	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=

= PAGE 1 = NEXT > |2|3

UP TO ROOT | UP TO DIR

Google
 


E-mail Facebook Google Digg del.icio.us BlinkList Fark Furl Ma.gnolia Netscape NewsVine Reddit Slashdot Spurl StumbleUpon Technorati YahooMyWeb LiveJournal Blogmarks TwitThis Live News2.ru BobrDobr.ru Memori.ru MoeMesto.ru

0.0743139 wallclock secs ( 0.01 usr + 0.00 sys = 0.01 CPU)