Why return NULL for u_envp in struct user

Why return NULL for u_envp in struct user

Post by HongJin Ch » Fri, 06 Mar 1998 04:00:00



Quote:>65568,,

Newsgroups: comp.unix.programmer
Followup-To: comp.unix.solaris

Subject: Why return NULL for u_envp in struct user
Keywords: struct user

 Hi Everyone!!

 I writing kernel programm for solaris 2.x. But, I have a problem in following code.

 I don't know why return NULL in "User->u_envp".

 thanks in advance!!

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include <dirent.h>
#include <nlist.h>
#include <kvm.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/proc.h>
#include <sys/procfs.h>
#ifndef _KMEMUSER
#define _KMEMUSER
#endif
#include <sys/user.h>

struct nlist nlst[] = { {"nproc"}, {0}};

int main()
{
        DIR             *dirStream;
        struct dirent   *d;
        user_t          *User;
        prpsinfo_t      *PsInfo;
        proc_t          *p;
        kvm_t   *kd;
        char            **env;
        int     unit, i = 0, nproc = 80;

        p = (proc_t *)malloc(sizeof(proc_t) * nproc);
        PsInfo = (prpsinfo_t *)malloc(sizeof(prpsinfo_t) * nproc);
        User = (user_t *)malloc(sizeof(user_t) * nproc);

        if(chdir("/proc") == -1) {
                printf("Chdir Error ... \n");
                return -1;
        }

        if((dirStream = opendir(".")) == NULL) {
                printf("opendir Error ... \n");
                return -1;
        }

        while((d = readdir(dirStream)) != NULL) {
                if(*(d->d_name) == '.') continue;

                if((unit = open(d->d_name, O_RDONLY)) == -1) {
                        printf("Open Error ... \n");
                        continue;
                }

                if((ioctl(unit, PIOCGETPR, p) == -1) ||
                   (ioctl(unit, PIOCPSINFO, PsInfo) == -1) ||
                   (ioctl(unit, PIOCGETU, User) == -1)) {
                        printf("ioctl Error ... \n");
                        continue;
               }

                 env = User->u_envp;

                 if(envp == NULL)
                         printf("Why return NULL??? \n");

==> On this point, env and User->u_envp return NULL.

        Would you teach me why return NULL??

#>printf("OpenFile : %s, Class Name : %s, FileName : %s, PsArg : %s \n", User->u_comm, PsInfo->pr_clname, PsInfo->pr_fname, User->u_psargs);
#>
#>                close(unit); p++; PsInfo++; User++;
#>        }
#>
#>        closedir(dirStream);
#>        return 0;
#>}

Thanks a lot!!