Home | History | Annotate | Line # | Download | only in kernel
      1  1.1  pgoyette /*	$NetBSD: h_ps_strings1.c,v 1.1 2011/03/05 18:14:33 pgoyette Exp $	*/
      2  1.1  pgoyette /*-
      3  1.1  pgoyette  * Copyright (c) 2011 The NetBSD Foundation, Inc.
      4  1.1  pgoyette  * All rights reserved.
      5  1.1  pgoyette  *
      6  1.1  pgoyette  * This code is derived from software contributed to The NetBSD Foundation
      7  1.1  pgoyette  * by Joerg Sonnenberger.
      8  1.1  pgoyette  *
      9  1.1  pgoyette  * Redistribution and use in source and binary forms, with or without
     10  1.1  pgoyette  * modification, are permitted provided that the following conditions
     11  1.1  pgoyette  * are met:
     12  1.1  pgoyette  *
     13  1.1  pgoyette  * 1. Redistributions of source code must retain the above copyright
     14  1.1  pgoyette  *    notice, this list of conditions and the following disclaimer.
     15  1.1  pgoyette  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  pgoyette  *    notice, this list of conditions and the following disclaimer in
     17  1.1  pgoyette  *    the documentation and/or other materials provided with the
     18  1.1  pgoyette  *    distribution.
     19  1.1  pgoyette  *
     20  1.1  pgoyette  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     21  1.1  pgoyette  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     22  1.1  pgoyette  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     23  1.1  pgoyette  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
     24  1.1  pgoyette  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.1  pgoyette  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
     26  1.1  pgoyette  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     27  1.1  pgoyette  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     28  1.1  pgoyette  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     29  1.1  pgoyette  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     30  1.1  pgoyette  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  1.1  pgoyette  * SUCH DAMAGE.
     32  1.1  pgoyette  */
     33  1.1  pgoyette 
     34  1.1  pgoyette #include <sys/types.h>
     35  1.1  pgoyette #include <sys/exec.h>
     36  1.1  pgoyette #include <stdlib.h>
     37  1.1  pgoyette #include <unistd.h>
     38  1.1  pgoyette 
     39  1.1  pgoyette extern struct ps_strings *__ps_strings;
     40  1.1  pgoyette 
     41  1.1  pgoyette int
     42  1.1  pgoyette main(int argc, char **argv, char **environ)
     43  1.1  pgoyette {
     44  1.1  pgoyette 	int ret = 0;
     45  1.1  pgoyette 	int nenv;
     46  1.1  pgoyette 
     47  1.1  pgoyette 	if (__ps_strings->ps_nargvstr != argc) {
     48  1.1  pgoyette 		static const char nargv_err[] = "Wrong argc in ps_strings";
     49  1.1  pgoyette 		write(STDOUT_FILENO, nargv_err, sizeof(nargv_err));
     50  1.1  pgoyette 		ret = 1;
     51  1.1  pgoyette 	}
     52  1.1  pgoyette 
     53  1.1  pgoyette 	if (__ps_strings->ps_argvstr != argv) {
     54  1.1  pgoyette 		static const char argv_err[] = "Wrong argv in ps_strings";
     55  1.1  pgoyette 		write(STDOUT_FILENO, argv_err, sizeof(argv_err));
     56  1.1  pgoyette 		ret = 1;
     57  1.1  pgoyette 	}
     58  1.1  pgoyette 
     59  1.1  pgoyette 	if (__ps_strings->ps_envstr != environ) {
     60  1.1  pgoyette 		static const char env_err[] = "Wrong env in ps_strings";
     61  1.1  pgoyette 		write(STDOUT_FILENO, env_err, sizeof(env_err));
     62  1.1  pgoyette 		ret = 1;
     63  1.1  pgoyette 	}
     64  1.1  pgoyette 	nenv = 0;
     65  1.1  pgoyette 	while (environ[nenv])
     66  1.1  pgoyette 		++nenv;
     67  1.1  pgoyette 	if (__ps_strings->ps_nenvstr != nenv) {
     68  1.1  pgoyette 		static const char nenv_err[] = "Wrong nenv in ps_strings";
     69  1.1  pgoyette 		write(STDOUT_FILENO, nenv_err, sizeof(nenv_err));
     70  1.1  pgoyette 		ret = 1;
     71  1.1  pgoyette 	}
     72  1.1  pgoyette 
     73  1.1  pgoyette 	return ret;
     74  1.1  pgoyette }
     75