示例#1
0
void iwinfo_finish(void)
{
	int i;

	for (i = 0; i < ARRAY_SIZE(backends); i++)
		backends[i]->close();

	iwinfo_close();
}
void iwinfo_finish(void)
{
#ifdef USE_WL
	wl_close();
#endif
#ifdef USE_MADWIFI
	madwifi_close();
#endif
#ifdef USE_NL80211
	nl80211_close();
#endif
	wext_close();
	iwinfo_close();
}
/* Shutdown backends */
static int iwinfo_L__gc(lua_State *L)
{
#ifdef USE_WL
    wl_close();
#endif
#ifdef USE_MADWIFI
    madwifi_close();
#endif
#ifdef USE_NL80211
    nl80211_close();
#endif
    wext_close();
    iwinfo_close();
}
示例#4
0
文件: luci-bwc.c 项目: 8devices/luci
static int run_daemon(void)
{
	FILE *info;
	uint32_t rxb, txb, rxp, txp;
	uint32_t udp, tcp, other;
	uint16_t rate;
	uint8_t rssi, noise;
	float lf1, lf5, lf15;
	char line[1024];
	char ifname[16];
	int i;
	void *iw;
	struct sigaction sa;

	struct stat s;
	const char *ipc = stat("/proc/net/nf_conntrack", &s)
		? "/proc/net/ip_conntrack" : "/proc/net/nf_conntrack";

	switch (fork())
	{
		case -1:
			perror("fork()");
			return -1;

		case 0:
			if (chdir("/") < 0)
			{
				perror("chdir()");
				exit(1);
			}

			close(0);
			close(1);
			close(2);
			break;

		default:
			return 0;
	}

	/* setup USR1 signal handler to reset timer */
	sa.sa_handler = reset_countdown;
	sa.sa_flags   = SA_RESTART;
	sigemptyset(&sa.sa_mask);
	sigaction(SIGUSR1, &sa, NULL);

	/* write pid */
	if (writepid())
	{
		fprintf(stderr, "Failed to write pid file: %s\n", strerror(errno));
		return 1;
	}

	/* initialize iwinfo */
	iw = iwinfo_open();

	/* go */
	for (reset_countdown(0); countdown >= 0; countdown--)
	{
		/* alter progname for ps, top */
		memset(progname, 0, prognamelen);
		snprintf(progname, prognamelen, "luci-bwc %d", countdown);

		if ((info = fopen("/proc/net/dev", "r")) != NULL)
		{
			while (fgets(line, sizeof(line), info))
			{
				if (strchr(line, '|'))
					continue;

				if (sscanf(line, IF_SCAN_PATTERN, ifname, &rxb, &rxp, &txb, &txp))
				{
					if (strncmp(ifname, "lo", sizeof(ifname)))
						update_ifstat(ifname, rxb, rxp, txb, txp);
				}
			}

			fclose(info);
		}

		if (iw)
		{
			for (i = 0; i < 5; i++)
			{
#define iwinfo_checkif(pattern) \
				do {                                                      \
					snprintf(ifname, sizeof(ifname), pattern, i);         \
					if (iwinfo_update(iw, ifname, &rate, &rssi, &noise))  \
					{                                                     \
						update_radiostat(ifname, rate, rssi, noise);      \
						continue;                                         \
					}                                                     \
				} while(0)

				iwinfo_checkif("wlan%d");
				iwinfo_checkif("ath%d");
				iwinfo_checkif("wl%d");
			}
		}

		if ((info = fopen(ipc, "r")) != NULL)
		{
			udp   = 0;
			tcp   = 0;
			other = 0;

			while (fgets(line, sizeof(line), info))
			{
				if (strstr(line, "TIME_WAIT"))
					continue;

				if (sscanf(line, "%*s %*d %s", ifname) || sscanf(line, "%s %*d", ifname))
				{
					if (!strcmp(ifname, "tcp"))
						tcp++;
					else if (!strcmp(ifname, "udp"))
						udp++;
					else
						other++;
				}
			}

			update_cnstat(udp, tcp, other);

			fclose(info);
		}

		if ((info = fopen("/proc/loadavg", "r")) != NULL)
		{
			if (fscanf(info, LD_SCAN_PATTERN, &lf1, &lf5, &lf15))
			{
				update_ldstat((uint16_t)(lf1  * 100),
							  (uint16_t)(lf5  * 100),
							  (uint16_t)(lf15 * 100));
			}

			fclose(info);
		}

		sleep(STEP_TIME);
	}

	unlink(PID_PATH);

	if (iw)
		iwinfo_close(iw);

	return 0;
}