Example #1
0
int run_wiviz_main(int argc, char **argv)
{
	pid_t pid;

	pid = fork();
	switch (pid) {
	case -1:
		perror("fork failed");
		exit(1);
		break;
	case 0:
		if (pidof("wiviz") > 0)
			killall("wiviz", SIGUSR1);
		else {
			char *hopseq = nvram_safe_get("hopseq");
			FILE *fp = fopen("/tmp/wiviz2-cfg", "wb");
			if (nvram_match("hopseq", "0"))
				fprintf(fp, "channelsel=hop&");
			else if (strstr(hopseq, ","))
				fprintf(fp, "channelsel=hop&");
			else
				fprintf(fp, "channelsel=%s&", hopseq);
			fprintf(fp, "hopdwell=%s&hopseq=%s\n",
				nvram_safe_get("hopdwell"), hopseq);
			fclose(fp);
			eval("wiviz", ">/dev/null", "</dev/null", "2>&1", "&");
		}
		exit(0);
		break;
	default:
		_exit(0);
		break;
	}
}
Example #2
0
File: aoss.c Project: ebichu/dd-wrt
int aoss_status(void)
{
	if (pidof("aoss") > 0) {
		return 1;
	}
	return 0;
}
Example #3
0
/*
 *	Pidof functionality.
 */
int affix_pidof(char *name, int flags, pid_t pid)
{
	PROC	*p;
	PIDQ	*q;
	int	i,oind;
	pid_t	opid[PIDOF_OMITSZ], spid = 0;
	char	*basec = NULL;

	for (oind = PIDOF_OMITSZ-1; oind > 0; oind--)
		opid[oind] = 0;

	if (flags&PIDOF_SCRIPTS)
		scripts_too++;

	if (flags&PIDOF_OMIT) {
		opid[oind] = pid;
		oind++;
	}
	if (flags&PIDOF_POMIT) {
		opid[oind] = getppid();
		oind++;
	}
	if (flags&PIDOF_BASENAME) {
		char	*ch;

		basec = strdup(name);
		name = basename(basec);
		if ((ch = strchr(name, ' '))) {
			*ch = '\0';
		}
	}
	/* Print out process-ID's one by one. */
	readproc();
	if ((q = pidof(name)) == NULL)
		goto exit;
	while ((p = get_next_from_pid_q(q))) {
		if (flags & PIDOF_OMIT) {
			for (i = 0; i < oind; i++) {
				if (opid[i] == p->pid)
					break;
			}
			/*
			 *	On a match, continue with
			 *	the for loop above.
			 */
			if (i < oind)
				continue;
		}
		if (flags & PIDOF_SINGLE) {
			if (spid)
				continue;
			else
				spid = p->pid;
		}
	}
exit:
	free(basec);
	freeproc();
	return spid;
}
Example #4
0
void stop_rstats(void)
{
	if (pidof("rstats") > 0) {
		dd_syslog(LOG_INFO,
			  "rstats : rstats daemon successfully stopped\n");
		killall("rstats", SIGTERM);
	}
}
Example #5
0
void start_igmp_proxy(void)
{
	int ret = 0;
	pid_t pid;
	char name[80], *next, *svbuf;
	char *argv[] = { "igmprt", "/tmp/igmpproxy.conf", NULL };

	int ifcount = 0;

	FILE *fp = fopen("/tmp/igmpproxy.conf", "wb");

	if (nvram_match("dtag_vlan8", "1") && nvram_match("wan_vdsl", "1")) {
		fprintf(fp, "quickleave\nphyint %s upstream  ratelimit 0  threshold 1\n", nvram_safe_get("tvnicfrom"));
		fprintf(fp, "phyint %s disabled\n", get_wan_face());
	} else {
		fprintf(fp, "quickleave\nphyint %s upstream  ratelimit 0  threshold 1\n", get_wan_face());
	}
	if (nvram_match("block_multicast", "0")) {
		fprintf(fp, "phyint %s downstream  ratelimit 0  threshold 1\n", nvram_safe_get("lan_ifname"));
		ifcount++;
	} else {
		fprintf(fp, "phyint %s disabled\n" "phyint %s:0 disabled\n", nvram_safe_get("lan_ifname"), nvram_safe_get("lan_ifname"));
	}
	char ifnames[256];

	getIfLists(ifnames, 256);
	foreach(name, ifnames, next) {
		if (strcmp(get_wan_face(), name)
		    && strcmp(nvram_safe_get("lan_ifname"), name)
		    && strcmp(nvram_safe_get("tvnicfrom"), name)) {
			if (nvram_nmatch("0", "%s_bridged", name)
			    && nvram_nmatch("1", "%s_multicast", name)) {
				fprintf(fp, "phyint %s downstream  ratelimit 0  threshold 1\n", name);
				ifcount++;
			} else
				fprintf(fp, "phyint %s disabled\n", name);
		}
	}
	fprintf(fp, "phyint lo disabled\n");
	fclose(fp);
	if (nvram_match("wan_proto", "disabled"))	// todo: add upstream 
		// config
	{
		// ret = _evalpid (igmp_proxybr_argv, NULL, 0, &pid);
		return;
	} else {
		if (ifcount) {
			if (pidof("igmprt") < 1)
				ret = _evalpid(argv, NULL, 0, &pid);
			dd_syslog(LOG_INFO, "igmprt : multicast daemon successfully started\n");
		}
	}

	cprintf("done\n");
	return;
}
Example #6
0
void reset_nocat( void )
{
    if( pidof( "splashd" ) > 0 )
    {
        syslog( LOG_INFO,
			"splashd : Reseting splashd firewall rules\n" );
        killall( "splashd", SIGUSR1);
    }
    return;
}
Example #7
0
int stop_process(char *name, char *desc)
{
	if (!desc)
		desc = name;
	if (pidof(name) > 0) {
		dd_syslog(LOG_INFO,
			  "%s : %s successfully stopped\n", name, desc);
		killall(name, SIGTERM);
		int deadcounter = 20;
		while (pidof(name) > 0 && deadcounter--) {
			usleep(100*1000);
		}
		if (pidof(name) > 0) {
			dd_syslog(LOG_INFO,
				  "%s : %s hanging, send SIGKILL\n", name,
				  desc);
			killall(name, SIGKILL);
		}
		return 1;
	}
	return 0;
}
Example #8
0
void start_gen_radius_cert(void)
{
	if (nvram_match("cert_running", "1") && pidof("openssl") > 0)
		return;		//already running
	prep();
	gen_cert("/jffs/etc/freeradius/certs/server.cnf", TYPE_SERVER, nvram_safe_get("radius_common"), nvram_safe_get("radius_passphrase"));
	gen_cert("/jffs/etc/freeradius/certs/ca.cnf", TYPE_CA, nvram_safe_get("radius_common"), nvram_safe_get("radius_passphrase"));
	nvram_set("cert_running", "1");
	//this takes a long time (depending from the cpu speed)
	system("cd /jffs/etc/freeradius/certs && ./bootstrap");
	sysprintf("sed \"s/private_key_password = whatever/private_key_password = %s/g\" /etc/freeradius/eap.conf > /jffs/etc/freeradius/eap.conf", nvram_safe_get("radius_passphrase"));
	nvram_set("cert_running", "0");
}
Example #9
0
void stop_siproxd(void)
{
	unsigned int i;

	i = 0;
	syslog(LOG_INFO,"Siproxd - killing daemon\n");
	if ((i = pidof (siproxd_process)) > 3) {
		killall_tk(siproxd_process);
			if (f_exists(siproxdpid)) {
			unlink(siproxdpid);
			}
	}
}
Example #10
0
void stop_nocat( void )
{
    if( pidof( "splashd" ) > 0 )
    {
	syslog( LOG_INFO,
			"splashd : Captive Portal Splash daemon successfully stopped\n" );
	killall_tk( "splashd");
	eval( "/usr/libexec/nocat/uninitialize.fw" );
	system( "rm /tmp/nocat.leases\n");
	system( "rm /tmp/start_splashd.sh\n");
	system( "rm /tmp/nocat.log\n");
	
    }
    return;
}
Example #11
0
/* start the command */
pid_t start_cmd(char *cmd, char *cmdpath, char **argv) {
    int status = 0;
    int cmdpid = 0;
    pid_t pid = 0;

    syslog(LOG_NOTICE, "starting %s", cmdpath);

    if ((pid = fork()) == 0) {
        if (execv(cmdpath, argv) == -1) {
            syslog(LOG_ERR, "execv failure: %s:%d", __func__, __LINE__);
            exit(EXIT_FAILURE);
        }
    } else if (pid == -1) {
        syslog(LOG_ERR, "fork failure: %s:%d", __func__, __LINE__);
        return -1;
    } else {
        if (waitpid(pid, &status, 0) == -1) {
            syslog(LOG_ERR, "waitpid failure: %s:%d", __func__, __LINE__);
            return -1;
        }

        if (WIFSIGNALED(status)) {
            syslog(LOG_ERR, "%s killed with signal %d", cmd, WTERMSIG(status));
            return -1;
        }

        if (!WIFEXITED(status)) {
            syslog(LOG_ERR, "waitpid returned %d", status);
            return -1;
        }

        if ((cmdpid = pidof(cmd)) == -1) {
            syslog(LOG_ERR, "%s is not running", cmd);
        } else {
            syslog(LOG_NOTICE, "%s started", cmd);
        }

        return cmdpid;
    }

    /* never reached */
    return -1;
}
Example #12
0
int dhcpc_renew_main(int argc, char **argv)
{
	int pid;

	_dprintf("%s: begin\n", __FUNCTION__);

	if (!using_dhcpc()) return 1;

	if ((pid = pidof("udhcpc")) > 1) {
		kill(pid, SIGUSR1);
		f_write(renewing, NULL, 0, 0, 0);
	}
	else {
		stop_dhcpc();
		start_dhcpc();
	}
	
	_dprintf("%s: end\n", __FUNCTION__);	
	return 0;
}
Example #13
0
/*
 *	Pidof functionality.
 */
int main(int argc, char *argv[])
{
	PIDQ_HEAD	*q;
	PROC		*p;
	pid_t		spid;
	int		first = 1;

	/* Print out process-ID's one by one. */
	readproc();
	if ((q = pidof(argv[1])) != NULL) {
		spid = 0;
		while ((p = get_next_from_pid_q(q))) {
			if (!first)
				printf(" ");
			printf("%d", p->pid);
			first = 0;
		}
	}
	printf("\n");
	closelog();
	return(first ? 1 : 0);	
}
Example #14
0
int main(int argc, char **argv)
{
	/* these vars are reused several times */
	int rc, opt, i, c;
	char *context, *root_path;

	/* files that need context checks */
	char *fc[MAX_CHECK];
	char *cterm = ttyname(0);
	int nfc = 0;
	struct stat m;

	/* processes that need context checks */
	char *pc[MAX_CHECK];
	int npc = 0;

	/* booleans */
	char **bools;
	int nbool;

	int verbose = 0;
	int show_bools = 0;

	/* policy */
	const char *pol_name, *root_dir;
	char *pol_path;


	while (1) {
		opt = getopt(argc, argv, "vb");
		if (opt == -1)
			break;
		switch (opt) {
		case 'v':
			verbose = 1;
			break;
		case 'b':
			show_bools = 1;
			break;
		default:
			/* invalid option */
			printf("\nUsage: %s [OPTION]\n\n", basename(argv[0]));
			printf("  -v  Verbose check of process and file contexts.\n");
			printf("  -b  Display current state of booleans.\n");
			printf("\nWithout options, show SELinux status.\n");
			return -1;
		}
	}
	printf_tab("SELinux status:");
	rc = is_selinux_enabled();

	switch (rc) {
	case 1:
		printf("enabled\n");
		break;
	case 0:
		printf("disabled\n");
		return 0;
		break;
	default:
		printf("unknown (%s)\n", strerror(errno));
		return 0;
		break;
	}

	printf_tab("SELinuxfs mount:");
	if (selinux_mnt != NULL) {
		printf("%s\n", selinux_mnt);
	} else {
		printf("not mounted\n\n");
		printf("Please mount selinuxfs for proper results.\n");
		return -1;
	}

	printf_tab("SELinux root directory:");
	root_dir = selinux_path();
	if (root_dir == NULL) {
		printf("error (%s)\n", strerror(errno));
		return -1;
	}
	/* The path has a trailing '/' so duplicate to edit */
	root_path = strdup(root_dir);
	if (!root_path) {
		printf("malloc error (%s)\n", strerror(errno));
		return -1;
	}
	/* actually blank the '/' */
	root_path[strlen(root_path) - 1] = '\0';
	printf("%s\n", root_path);
	free(root_path);

	/* Dump all the path information */
	printf_tab("Loaded policy name:");
	pol_path = strdup(selinux_policy_root());
	if (pol_path) {
		pol_name = basename(pol_path);
		puts(pol_name);
		free(pol_path);
	} else {
		printf("error (%s)\n", strerror(errno));
	}

	printf_tab("Current mode:");
	rc = security_getenforce();
	switch (rc) {
	case 1:
		printf("enforcing\n");
		break;
	case 0:
		printf("permissive\n");
		break;
	default:
		printf("unknown (%s)\n", strerror(errno));
		break;
	}

	printf_tab("Mode from config file:");
	if (selinux_getenforcemode(&rc) == 0) {
		switch (rc) {
		case 1:
			printf("enforcing\n");
			break;
		case 0:
			printf("permissive\n");
			break;
		case -1:
			printf("disabled\n");
			break;
		}
	} else {
		printf("error (%s)\n", strerror(errno));
	}

	printf_tab("Policy MLS status:");
	rc = is_selinux_mls_enabled();
	switch (rc) {
		case 0:
			printf("disabled\n");
			break;
		case 1:
			printf("enabled\n");
			break;
		default:
			printf("error (%s)\n", strerror(errno));
			break;
	}

	printf_tab("Policy deny_unknown status:");
	rc = security_deny_unknown();
	switch (rc) {
		case 0:
			printf("allowed\n");
			break;
		case 1:
			printf("denied\n");
			break;
		default:
			printf("error (%s)\n", strerror(errno));
			break;
	}

	rc = security_policyvers();
	printf_tab("Max kernel policy version:");
	if (rc < 0)
		printf("unknown (%s)\n", strerror(errno));
	else
		printf("%d\n", rc);


	if (show_bools) {
		/* show booleans */
		if (security_get_boolean_names(&bools, &nbool) >= 0) {
			printf("\nPolicy booleans:\n");

			for (i = 0; i < nbool; i++) {
				if (strlen(bools[i]) + 1 > COL)
					COL = strlen(bools[i]) + 1;
			}
			for (i = 0; i < nbool; i++) {
				printf_tab(bools[i]);

				rc = security_get_boolean_active(bools[i]);
				switch (rc) {
				case 1:
					printf("on");
					break;
				case 0:
					printf("off");
					break;
				default:
					printf("unknown (%s)", strerror(errno));
					break;
				}
				c = security_get_boolean_pending(bools[i]);
				if (c != rc)
					switch (c) {
					case 1:
						printf(" (activate pending)");
						break;
					case 0:
						printf(" (inactivate pending)");
						break;
					default:
						printf(" (pending error: %s)",
						       strerror(errno));
						break;
					}
				printf("\n");

				/* free up the booleans */
				free(bools[i]);
			}
			free(bools);
		}
	}
	/* only show contexts if -v is given */
	if (!verbose)
		return 0;

	load_checks(pc, &npc, fc, &nfc);

	printf("\nProcess contexts:\n");

	printf_tab("Current context:");
	if (getcon(&context) >= 0) {
		printf("%s\n", context);
		freecon(context);
	} else
		printf("unknown (%s)\n", strerror(errno));

	printf_tab("Init context:");
	if (getpidcon(1, &context) >= 0) {
		printf("%s\n", context);
		freecon(context);
	} else
		printf("unknown (%s)\n", strerror(errno));

	for (i = 0; i < npc; i++) {
		rc = pidof(pc[i]);
		if (rc > 0) {
			if (getpidcon(rc, &context) < 0)
				continue;

			printf_tab(pc[i]);
			printf("%s\n", context);
			freecon(context);
		}
	}

	printf("\nFile contexts:\n");

	/* controlling term */
	printf_tab("Controlling terminal:");
	if (lgetfilecon(cterm, &context) >= 0) {
		printf("%s\n", context);
		freecon(context);
	} else {
		printf("unknown (%s)\n", strerror(errno));
	}

	for (i = 0; i < nfc; i++) {
		if (lgetfilecon(fc[i], &context) >= 0) {
			printf_tab(fc[i]);

			/* check if this is a symlink */
			if (lstat(fc[i], &m)) {
				printf
				    ("%s (could not check link status (%s)!)\n",
				     context, strerror(errno));
				freecon(context);
				continue;
			}
			if (S_ISLNK(m.st_mode)) {
				/* print link target context */
				printf("%s -> ", context);
				freecon(context);

				if (getfilecon(fc[i], &context) >= 0) {
					printf("%s\n", context);
					freecon(context);
				} else {
					printf("unknown (%s)\n",
					       strerror(errno));
				}
			} else {
				printf("%s\n", context);
				freecon(context);
			}
		}
	}

	return 0;
}
Example #15
0
int ej_show_sysinfo(int eid, webs_t wp, int argc, char_t ** argv)
{
	char *type;
	char result[2048];
	int retval = 0;
	struct sysinfo sys;
	char *tmp;

	strcpy(result,"None");

	if (ejArgs(argc, argv, "%s", &type) < 1) {
		websError(wp, 400, "Insufficient args\n");
		return retval;
	}

	if (type) {
		if (strcmp(type,"cpu.model") == 0) {
			char *buffer = read_whole_file("/proc/cpuinfo");

			if (buffer) {
				tmp = strstr(buffer, "system type");
				if (tmp)
					sscanf(tmp, "system type  :  %[^\n]", result);
				free(buffer);
			}

		} else if(strcmp(type,"cpu.freq") == 0) {
			tmp = nvram_get("clkfreq");
			if (tmp)
				sscanf(tmp,"%[^,]s", result);

		} else if(strcmp(type,"memory.total") == 0) {
			sysinfo(&sys);
			sprintf(result,"%.2f",(sys.totalram/(float)MBYTES));
		} else if(strcmp(type,"memory.free") == 0) {
			sysinfo(&sys);
			sprintf(result,"%.2f",(sys.freeram/(float)MBYTES));
		} else if(strcmp(type,"memory.buffer") == 0) {
			sysinfo(&sys);
			sprintf(result,"%.2f",(sys.bufferram/(float)MBYTES));
		} else if(strcmp(type,"memory.swap.total") == 0) {
			sysinfo(&sys);
			sprintf(result,"%.2f",(sys.totalswap/(float)MBYTES));
		} else if(strcmp(type,"memory.swap.used") == 0) {
			sysinfo(&sys);
			sprintf(result,"%.2f",((sys.totalswap - sys.freeswap) / (float)MBYTES));
		} else if(strcmp(type,"cpu.load.1") == 0) {
			sysinfo(&sys);
			sprintf(result,"%.2f",(sys.loads[0] / (float)(1<<SI_LOAD_SHIFT)));
		} else if(strcmp(type,"cpu.load.5") == 0) {
			sysinfo(&sys);
			sprintf(result,"%.2f",(sys.loads[1] / (float)(1<<SI_LOAD_SHIFT)));
		} else if(strcmp(type,"cpu.load.15") == 0) {
			sysinfo(&sys);
			sprintf(result,"%.2f",(sys.loads[2] / (float)(1<<SI_LOAD_SHIFT)));
		} else if(strcmp(type,"nvram.total") == 0) {
			sprintf(result,"%d",NVRAM_SPACE);
		} else if(strcmp(type,"nvram.used") == 0) {
			char *buf;
			int size = 0;

			buf = malloc(NVRAM_SPACE);
			if (buf) {
				nvram_getall(buf, NVRAM_SPACE);
				tmp = buf;
				while (*tmp) tmp += strlen(tmp) +1;

				size = sizeof(struct nvram_header) + (int) tmp - (int) buf;
				free(buf);
			}
			sprintf(result,"%d",size);

		} else if(strcmp(type,"jffs.usage") == 0) {
			struct statvfs fiData;

			char *mount_info = read_whole_file("/proc/mounts");

			if ((mount_info) && (strstr(mount_info, "/jffs")) && (statvfs("/jffs",&fiData) == 0 )) {
				sprintf(result,"%.2f / %.2f MB",((fiData.f_blocks-fiData.f_bfree) * fiData.f_frsize / (float)MBYTES) ,(fiData.f_blocks * fiData.f_frsize / (float)MBYTES));
			} else {
				strcpy(result,"<i>Unmounted</i>");
			}

			if (mount_info) free(mount_info);

		} else if(strncmp(type,"temperature",11) == 0) {
			unsigned int temperature;
			int radio=0;

                        sscanf(type,"temperature.%d", &radio);
			temperature = get_phy_temperature(radio);
			if (temperature == 0)
				strcpy(result,"<i>disabled</i>");
			else
				sprintf(result,"%u&deg;C", temperature);

		} else if(strcmp(type,"conn.total") == 0) {
			FILE* fp;

			fp = fopen ("/proc/sys/net/ipv4/netfilter/ip_conntrack_count", "r");
			if (fp) {
				if (fgets(result, sizeof(result), fp) != NULL) {
					fclose(fp);
				}
			}
		} else if(strcmp(type,"conn.active") == 0) {
			char buf[256];
			FILE* fp;
			unsigned int established = 0;

			fp = fopen("/proc/net/nf_conntrack", "r");
			if (fp) {
				while (fgets(buf, sizeof(buf), fp) != NULL) {
				if (strstr(buf,"ESTABLISHED") || ((strstr(buf,"udp")) && (strstr(buf,"ASSURED"))))
					established++;
				}
				fclose(fp);
			}
			sprintf(result,"%u",established);

		} else if(strcmp(type,"conn.max") == 0) {
			FILE* fp;

			fp = fopen ("/proc/sys/net/ipv4/netfilter/ip_conntrack_max", "r");
			if (fp) {
				if (fgets(result, sizeof(result), fp) != NULL) {
					fclose(fp);
				}
			}
		} else if(strncmp(type,"conn.wifi",9) == 0) {
			int count, radio;
			char command[10];

			sscanf(type,"conn.wifi.%d.%9s", &radio, command);

			if (strcmp(command,"autho") == 0) {
				count = get_wifi_clients(radio,SI_WL_QUERY_AUTHO);
			} else if (strcmp(command,"authe") == 0) {
				count = get_wifi_clients(radio,SI_WL_QUERY_AUTHE);
			} else if (strcmp(command,"assoc") == 0) {
				count = get_wifi_clients(radio,SI_WL_QUERY_ASSOC);
			} else {
				count = 0;
			}
			if (count == -1)
				strcpy(result,"<i>off</i>");
			else
				sprintf(result,"%d",count);

		} else if(strcmp(type,"driver_version") == 0 ) {
			system("/usr/sbin/wl ver >/tmp/output.txt");

			char *buffer = read_whole_file("/tmp/output.txt");

			if (buffer) {
				if (tmp = strstr(buffer, "\n"))
					strncpy(result, tmp+1, sizeof result);
				else
					strncpy(result, buffer, sizeof result);

				free(buffer);
				unlink("/tmp/output.txt");
			}

		} else if(strncmp(type,"pid",3) ==0 ) {
			char service[32];
			sscanf(type, "pid.%31s", service);

			if (strlen(service))
				sprintf(result, "%d", pidof(service));

		} else if(strncmp(type,"vpnstatus",9) == 0 ) {
			int num = 0;
			char service[10], buf[256];

			sscanf(type,"vpnstatus.%9[^.].%d", service, &num);

			if ( strlen(service) && (num > 0) )
			{
				// Trigger OpenVPN to update the status file
				snprintf(buf, sizeof(buf), "vpn%s%d", service, num);
				killall(buf, SIGUSR2);

				// Give it a chance to update the file
				sleep(1);

				// Read the status file and repeat it verbatim to the caller
				sprintf(buf,"/etc/openvpn/%s%d/status", service, num);
				char *buffer = read_whole_file(buf);
				if (buffer)
				{
					strncpy(result, buffer, sizeof(result));
					free(buffer);
				}
			}

		} else {
			strcpy(result,"Not implemented");
		}

	}

	retval += websWrite(wp, result);
	return retval;
}
Example #16
0
/*
 *	Pidof functionality.
 */
int main_pidof(int argc, char **argv)
{
	PIDQ_HEAD	*q;
	PROC		*p;
	pid_t		opid[PIDOF_OMITSZ], spid;
	int		f;
	int		first = 1;
	int		i, oind, opt, flags = 0;
	int		chroot_check = 0;
	struct stat	st;
	char		tmp[512];

	for (oind = PIDOF_OMITSZ-1; oind > 0; oind--)
		opid[oind] = 0;
	opterr = 0;

	while ((opt = getopt(argc,argv,"hco:sx")) != EOF) switch (opt) {
		case '?':
			nsyslog(LOG_ERR,"invalid options on command line!\n");
			closelog();
			exit(1);
		case 'c':
			if (geteuid() == 0) chroot_check = 1;
			break;
		case 'o':
			if (oind >= PIDOF_OMITSZ -1) {
				nsyslog(LOG_ERR,"omit pid buffer size %d "
					"exceeded!\n", PIDOF_OMITSZ);
				closelog();
				exit(1);
			}
			if (strcmp("%PPID",optarg) == 0)
				opid[oind] = getppid();
			else if ((opid[oind] = atoi(optarg)) < 1) {
				nsyslog(LOG_ERR,
					"illegal omit pid value (%s)!\n",
					optarg);
				closelog();
				exit(1);
			}
			oind++;
			flags |= PIDOF_OMIT;
			break;
		case 's':
			flags |= PIDOF_SINGLE;
			break;
		case 'x':
			scripts_too++;
			break;
		default:
			/* Nothing */
			break;
	}
	argc -= optind;
	argv += optind;

	/* Check if we are in a chroot */
	if (chroot_check) {
		snprintf(tmp, 512, "/proc/%d/root", getpid());
		if (stat(tmp, &st) < 0) {
			nsyslog(LOG_ERR, "stat failed for %s!\n", tmp);
			closelog();
			exit(1);
		}
	}

	/* Print out process-ID's one by one. */
	readproc(DO_STAT);
	for(f = 0; f < argc; f++) {
		if ((q = pidof(argv[f])) != NULL) {
			spid = 0;
			while ((p = get_next_from_pid_q(q))) {
				if (flags & PIDOF_OMIT) {
					for (i = 0; i < oind; i++)
						if (opid[i] == p->pid)
							break;
					/*
					 *	On a match, continue with
					 *	the for loop above.
					 */
					if (i < oind)
						continue;
				}
				if (flags & PIDOF_SINGLE) {
					if (spid)
						continue;
					else
						spid = 1;
				}
				if (chroot_check) {
					struct stat st2;
					snprintf(tmp, 512, "/proc/%d/root",
						 p->pid);
					if (stat(tmp, &st2) < 0 ||
					    st.st_dev != st2.st_dev ||
					    st.st_ino != st2.st_ino) {
						continue;
					}
				}
				if (!first)
					printf(" ");
				printf("%d", p->pid);
				first = 0;
			}
		}
	}
	if (!first)
		printf("\n");
	closelog();
	return(first ? 1 : 0);
}