| die letzten Änderungen * Seitenstruktur * Stichwortsuche :


logo_puschin.jpg

Startseite

Knowledge base



Kontakt

Impressum

Knowledge base - C

Knowledge base

9 Benutzer online Druckversion




zurück



C
debug.c

#include <stdio.h>
#include <pwd.h>
#include <grp.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/utsname.h>

char    * user(), * gruppe();

void    main(argc, argv, env)
int     argc;
char    * argv[], * env[];
{
struct  utsname name;

char    * dir,
        * ctime(),
        * getcwd();

char    tmp[256];

time_t  zeit;

long    ulimit();

int     exit_code = 0,
        dk,
        cnt;

FILE    * fp;

        dk = open("/dev/null", O_RDONLY);
        close(dk);

        sprintf(tmp, "/tmp/debug%d", getpid());
        if ((fp = fopen(tmp, "w")) != NULL)
                {
                fprintf(fp, "Moerder - Debug - Trace V2.0\n");
                fprintf(fp, "(c) by Helmut Kuepker\n");
                fprintf(fp, "--------------------------------\n\n\n\n");

                fprintf(fp, "Kommando-Zeilen-Analyse\n");
                fprintf(fp, "-----------------------\n\n");
                fprintf(fp, "argc = %d\n\n", argc);

                cnt = 0;
                while (* argv)
                        fprintf(fp, "argv[%d] = \"%s\"\n", cnt++, * argv++);

                fprintf(fp, "\n\nEnvironment-Analyse\n");
                fprintf(fp, "-------------------\n\n");

                cnt = 0;
                while (* env)
                        fprintf(fp, "env[%d] = \"%s\"\n", cnt++, * env++);

                fprintf(fp, "\n\nUser-Daten-Analyse\n");
                fprintf(fp, "------------------\n\n");
                cnt = getuid();
                fprintf(fp, "getuid() = %d (%s)\n", cnt, user(cnt));
                cnt = geteuid();
                fprintf(fp, "geteuid() = %d (%s)\n", cnt, user(cnt));
                cnt = getgid();
                fprintf(fp, "getgid() = %d (%s)\n", cnt, gruppe(cnt));
                cnt = getegid();
                fprintf(fp, "getegid() = %d (%s)\n", cnt, gruppe(cnt));

                fprintf(fp, "\n\nFile-Daten\n");
                fprintf(fp, "----------\n");
                dir = getcwd(NULL, 128);
                fprintf(fp, "pwd() = \'%s\'\n", dir);
                free(dir);
                fprintf(fp, "Next file-filedescriptor = %d\n", dk);
                fprintf(fp, "ulimit(UL_GFILLIM) = %ld Blocks\n",
                                ulimit(1, 0L));

                fprintf(fp, "\n\nMemory-Daten\n");
                fprintf(fp, "------------\n");
                fprintf(fp, "ulimit(UL_GMEMLIM) = %ld Bytes\n",
                                ulimit(3, 0L));

                fprintf(fp, "\n\ntty-Daten\n");
                fprintf(fp, "---------\n");
                fprintf(fp, "isatty(stdin) = %d\n", isatty(0));
                fprintf(fp, "isatty(stdout) = %d\n", isatty(1));
                fprintf(fp, "isatty(stderr) = %d\n", isatty(2));

                fprintf(fp, "\n\nZeit-Daten\n");
                fprintf(fp,     "----------\n");
                time(&zeit);
                fprintf(fp, "ctime(%ld) = %s", zeit, ctime(&zeit));

                fprintf(fp, "\n\nUTS-Daten\n");
                fprintf(fp, "---------\n");
                uname(&name);
                fprintf(fp, "Systemname = \'%s\'\n", name.sysname);
                fprintf(fp, "Nodename   = \'%s\'\n", name.nodename);
                fprintf(fp, "Release    = \'%s\'\n", name.release);
                fprintf(fp, "Version    = \'%s\'\n", name.version);
                fprintf(fp, "Machine    = \'%s\'\n", name.machine);

                fprintf(fp, "\n\nSonstige Daten\n");
                fprintf(fp, "--------------\n\n");
                fprintf(fp, "nice() = %d\n", nice(0) + 20);
                fprintf(fp, "getpid() = %d\n", getpid());
                fprintf(fp, "getppid() = %d\n", getppid());
                fprintf(fp, "getpgrp() = %d\n\n", getpgrp());
                fprintf(fp, "gethostid() = %d\n", gethostid());
                gethostname(tmp, 255);
                fprintf(fp, "gethostname() = %s\n", tmp);
                getdomainname(tmp, 255);
                fprintf(fp, "getdomainname() = %s\n", tmp);

                fprintf(fp, "\n\nStandard-Eingabe\n");
                fprintf(fp, "----------------\n\n");
                while ((cnt = fgetc(stdin)) != EOF)
                        fputc(cnt, fp);
                fprintf(fp, "\n=====\n");

                fclose(fp);
                }
        else
                exit_code = errno;
        exit(exit_code);
}
char    * user(x)
int     x;
{
struct  passwd  * p, * getpwuid();
static  char    name[10];

        if ((p = getpwuid(x)) != NULL)
                strcpy(name, p -> pw_name);
        else
                strcpy(name, "unbekannt");
        return(name);
}
char    * gruppe(x)
int     x;
{
struct  group   * g, * getgrgid();
static  char    name[10];

        if ((g = getgrgid(x)) != NULL)
                strcpy(name, g -> gr_name);
        else
                strcpy(name, "unbekannt");
        return(name);
}


zurück



Knowledge base wurde zuletzt bearbeitet am 12.07.13 durch Frank

www.puschin.de
login

<body bgcolor='#FFFFFF' link='#000000' vlink='#000000' alink='#000000' text='#000000'><font face='Verdana' size='2'><strong>www.puschin.de</strong><br>Die Webseite http://www.puschin.de bietet eine interessante Webseite zu vielen Themen aus dem Bereich Linux und Windows. Man findet hier Tipps und Tricks zu cms php apache postfix openxchange tomcat windows linux firewall <br><br><font face='Verdana' size='2'><li><a href='cms.php?print=&aktion=thema_anzeigen&menue_id=191'>Startseite</a><font face='Verdana' size='2'><li><a href='cms.php?print=&aktion=thema_anzeigen&menue_id=63'>Knowledge base</a><font face='Verdana' size='2'><li><a href='cms.php?print=&aktion=thema_anzeigen&menue_id=57'>Kontakt</a><font face='Verdana' size='2'><li><a href='cms.php?print=&aktion=thema_anzeigen&menue_id=9'>Impressum</a></body>