亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? usbmgr.c

?? 一個基于armlinux的u盤管理精靈進程
?? C
字號:
/*======================================================================

    MMC Card Manager daemon

    usbmgr.c 1.183 2003/02/27 07:11:45

    The contents of this file are subject to the Mozilla Public
    License Version 1.1 (the "License"); you may not use this file
    except in compliance with the License. You may obtain a copy of
    the License at http://www.mozilla.org/MPL/

    Software distributed under the License is distributed on an "AS
    IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
    implied. See the License for the specific language governing
    rights and limitations under the License.

    The initial developer of the original code is David A. Hinds
    <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
    are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.

    Alternatively, the contents of this file may be used under the
    terms of the GNU General Public License version 2 (the "GPL"), in
    which case the provisions of the GPL are applicable instead of the
    above.  If you wish to allow the use of your version of this file
    only under the terms of the GPL and not to allow others to use
    your version of this file under the MPL, indicate your decision
    by deleting the provisions above and replace them with the notice
    and other provisions required by the GPL.  If you do not delete
    the provisions above, a recipient may use your version of this
    file under either the MPL or the GPL.
    
======================================================================*/

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <syslog.h>
#include <getopt.h>
#include <signal.h>
#include <stdarg.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <sys/file.h>


#define MAX_SOCKS 1
static int g_fd = -1;
static int sockets;
/*====================================================================*/

static int execute(char *msg, char *cmd)
{
    int ret;
    FILE *f;
    char line[256];

    syslog(LOG_INFO, "executing: '%s'", cmd);
    strcat(cmd, " 2>&1");
    f = popen(cmd, "r");
    while (fgets(line, 255, f)) {
	line[strlen(line)-1] = '\0';
	syslog(LOG_INFO, "+ %s", line);
    }
    ret = pclose(f);
    if (WIFEXITED(ret)) {
	if (WEXITSTATUS(ret))
	    syslog(LOG_INFO, "%s exited with status %d",
		   msg, WEXITSTATUS(ret));
	return WEXITSTATUS(ret);
    } else
	syslog(LOG_INFO, "%s exited on signal %d",
	       msg, WTERMSIG(ret));
    return -1;
}

/*====================================================================*/

/*====================================================================*/

static void fork_now(void)
{
    int ret;
    if ((ret = fork()) > 0)
	_exit(0);
    if (ret == -1)
	syslog(LOG_ERR, "forking: %m");
    if (setsid() < 0)
	syslog(LOG_ERR, "detaching from tty: %m");
}    

/*====================================================================*/

/* most recent signal */
static int caught_signal = 0;

static void catch_signal(int sig)
{
    caught_signal = sig;
    if (signal(sig, catch_signal) == SIG_ERR)
	syslog(LOG_INFO, "signal(%d): %m", sig);
}

static void handle_signal(void)
{
    int i;
    char umount[64] = "umount /mnt/sda";

    switch (caught_signal) {
    case SIGTERM:
    case SIGINT:
	execute("usbmgr terminated, umount file system", umount);
	exit(0);
	break;
    case SIGHUP:
	break;
#ifdef SIGPWR
    case SIGPWR:
	break;
#endif
    }
}

/*********************************************** 
 * BEGIN: routines for char device "usb_event" *
 ***********************************************/
static int major = 0;

/* find a device's major number from /proc/devices */
static int lookup_dev(char *name)
{
    FILE *f;
    int n;
    char s[32], t[32];

    f = fopen("/proc/devices", "r");
    if (f == NULL)
            return -errno;
    while (fgets(s, 32, f) != NULL) {
        if (sscanf(s, "%d %s", &n, t) == 2)
        if (strcmp(name, t) == 0)
            break;
    }
    fclose(f);
    if (strcmp(name, t) == 0)
        return n;
    else
        return -ENODEV;
}

/* make a device node with the dev_t(major<<8 | minor),
 * then open it and return the file descriptor. 
 */
int open_dev(dev_t dev, int mode)
{
    /* here we provides some optional paths for the device node */
    static char *paths[] = {
        "/var/lib/usb", "/var/run", "/dev", "/tmp", NULL
	};
    static int nd = 0;
    char **p, fn[64];
    int fd;

    int o_mode = (mode & S_IWRITE) ? O_RDWR : O_RDONLY;
    /* look for a path we can make the node file */
    for (p = paths; *p; p++) {
        sprintf(fn, "%s/usb-node", *p);
        if (mknod(fn, mode, dev) == 0) {
            fd = open(fn, o_mode);
            if (fd < 0)
                fd = open(fn, O_NONBLOCK|o_mode);
            unlink(fn);
            if (fd >= 0)
                return fd;
            if (errno == ENODEV)
                break;
        }

    }
    return -1;
}

/* give it the minor(sock) number and access mode */
int open_sock(int sock, int mode)
{
	dev_t dev = (major<<8) + sock;
        return open_dev(dev, mode);
}

/* main routine for init "usb_event" device:
 * 1. lookup_dev()
 * 	find the major of the device from /proc/devices
 * 2. open_sock()
 * 	create a node with the major and minor(0)
 * 3. assign the fd to global variable g_fd
 */
static int init_sockets(void)
{
    int fd, i;

    major = lookup_dev("usb_event");
    if (major < 0) {
            if (major == -ENODEV)
                syslog(LOG_ERR, "no pcmcia driver in /proc/devices");
            else
                syslog(LOG_ERR, "could not open /proc/devices: %m");
            exit(EXIT_FAILURE);
    }
    for (fd = -1, i = 0; i < MAX_SOCKS; i++) {
        fd = open_sock(i, S_IFCHR|S_IREAD|S_IWRITE);
        if (fd < 0) break;
        g_fd = fd;
    }
    if ((fd < 0) && (errno != ENODEV) && (errno != ENOENT))
        syslog(LOG_ERR, "open_sock(socket %d) failed: %m", i);
    sockets = i;
    if (sockets == 0) {
        if (errno == ENODEV)
             syslog(LOG_ERR, "no sockets found!");
        else if (errno == EBUSY)
             syslog(LOG_ERR, "another cardmgr is already running?");
        return -1;
    } else
        syslog(LOG_INFO, "watching %d sockets", sockets);

    return 0;
}
/********************************************* 
 * END: routines for char device "usb_event" *
 *********************************************/

/*====================================================================*/
static char *pidfile = "/var/run/usbmgr.pid";

static void write_pid(void)
{
    FILE *f;
    f = fopen(pidfile, "w");
    if (f == NULL)
        syslog(LOG_WARNING, "could not open %s: %m", pidfile);
    else {
        fprintf(f, "%d\n", getpid());
        fclose(f);
    }
}

/* 
 * int main(int argc, char *argv[])
 *   1. init_sockets()
 * 	open "usb_event" device and store the file descriptor in g_fd.
 *   2. fork_now()
 * 	run as a daemon
 *   3. write_pid()
 * 	store its process id in /var/run/usbmgr.pid
 *   4. FD_ZERO(&fds) and FD_SET(g_fd, &fds)
 * 	init a fd_set structure for slelect, which monitors the g_fd.
 *   5. select()
 * 	monitoring g_fd for an event, sleep on g_fd when it is empty.
 *   6. read() and switch(event)
 * 	read an event and execute mount/umount.
 * one more thing, we use handle_signal to serve a system signal issued
 * when we sleep on g_fd.
 */
int main(int argc, char *argv[])
{
    int i, max_fd, ret;
    fd_set fds;
    unsigned int event = 0;
    char mount[128] = "mount -t vfat /dev/sda1 /mnt/sda";
    char umount[64] = "umount /mnt/sda";

    putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin");

    /* open the "usb_event" device */
    if (init_sockets() != 0)
	    exit(EXIT_FAILURE);

    /* daemonlize */
    fork_now();
    syslog(LOG_INFO, "usbmgr starting, version is 1.0");

    write_pid();
    if (signal(SIGHUP, catch_signal) == SIG_ERR)
	syslog(LOG_ERR, "signal(SIGHUP): %m");
    if (signal(SIGTERM, catch_signal) == SIG_ERR)
	syslog(LOG_ERR, "signal(SIGTERM): %m");
    if (signal(SIGINT, catch_signal) == SIG_ERR)
	syslog(LOG_ERR, "signal(SIGINT): %m");
#ifdef SIGPWR
    if (signal(SIGPWR, catch_signal) == SIG_ERR)
	syslog(LOG_ERR, "signal(SIGPWR): %m");
#endif

    if ( g_fd == -1 ) {
	syslog(LOG_ERR, "open(): %m");
	exit(EXIT_FAILURE);
    }
    max_fd = g_fd;
    for (;;) {
	FD_ZERO(&fds);
	FD_SET(g_fd, &fds);

	/* wait for an event on the devcie */
	while ((ret = select(max_fd+1, &fds, NULL, NULL, NULL)) < 0) {
	    if (errno == EINTR) {
		handle_signal();
	    } else {
		syslog(LOG_ERR, "select(): %m");
		exit(EXIT_FAILURE);
	    }
	}

	if (!FD_ISSET(g_fd, &fds))
	    continue;
	ret = read(g_fd, &event, 4);
	if ((ret == -1) && (errno != EAGAIN))
	    syslog(LOG_INFO, "read(%d): %m\n", i);
	/* deal with the event returned */
	switch (event) {
		case 0:
			execute("removed!", umount);
			break;	
		case 1:
			execute("inserted!", mount);
			break;
	}

    } /* repeat */
    return 0;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲一区影音先锋| 成人美女视频在线看| 国产成人精品一区二区三区四区| 成人av在线一区二区| 欧美成人综合网站| 亚洲一区二区三区美女| 成人爽a毛片一区二区免费| 91精品久久久久久久91蜜桃 | 亚洲一区欧美一区| 国产jizzjizz一区二区| 欧美一区二区三区婷婷月色| 国产精品麻豆网站| 狠狠v欧美v日韩v亚洲ⅴ| 欧美精品一卡两卡| 亚洲一区二区三区精品在线| 91啪九色porn原创视频在线观看| 久久久亚洲精品石原莉奈| 视频在线观看国产精品| 欧美在线观看一区| 亚洲品质自拍视频| av中文一区二区三区| 久久久综合精品| 午夜精品免费在线| 欧美日韩国产123区| 亚洲国产另类av| 在线精品国精品国产尤物884a| 中文字幕一区二区三区四区不卡| 国产精品2024| 久久精品一区二区三区不卡牛牛| 韩国毛片一区二区三区| 久久久亚洲精品一区二区三区| 精品一区二区在线免费观看| 日韩欧美另类在线| 另类成人小视频在线| 日韩欧美一区电影| 久久99精品久久久| 久久久99精品免费观看不卡| 国产成人在线观看免费网站| 久久精品人人做人人综合| 国产91精品在线观看| 国产亚洲综合在线| 99久久99久久精品免费看蜜桃| 国产精品美女一区二区| 91天堂素人约啪| 亚洲香肠在线观看| 欧美一区二区女人| 国产呦萝稀缺另类资源| 国产精品美女久久久久久久久| av午夜一区麻豆| 亚洲午夜av在线| 欧美成人精品3d动漫h| 粉嫩av亚洲一区二区图片| 自拍偷拍国产精品| 欧美日韩一二区| 美女视频一区二区三区| 国产精品三级久久久久三级| 一道本成人在线| 免费日韩伦理电影| 欧美激情中文不卡| 欧美日韩视频在线一区二区| 免费视频最近日韩| 国产精品第一页第二页第三页| 91久久国产最好的精华液| 免费欧美日韩国产三级电影| 国产欧美日韩在线| 欧美视频第二页| 国产乱理伦片在线观看夜一区 | 久久久美女艺术照精彩视频福利播放| 国产激情一区二区三区桃花岛亚洲| 中文字幕亚洲精品在线观看 | 久久亚洲影视婷婷| 99精品在线免费| 蜜桃一区二区三区在线观看| 自拍偷拍欧美精品| 精品日韩成人av| 欧美熟乱第一页| 成人动漫中文字幕| 免费国产亚洲视频| 亚洲精品国产一区二区精华液| 日韩欧美一级精品久久| 91麻豆精品一区二区三区| 裸体歌舞表演一区二区| 亚洲精品成人在线| 久久久综合视频| 91精品国产黑色紧身裤美女| 99久久精品免费看国产免费软件| 免费一级片91| 亚洲小说欧美激情另类| 中文字幕一区二区在线观看| 精品日韩欧美一区二区| 精品视频一区三区九区| 99视频在线精品| 国产麻豆9l精品三级站| 日韩激情一二三区| 亚洲一区二区欧美激情| 国产精品久久久久9999吃药| 26uuu精品一区二区| 欧美一区二区免费观在线| 欧洲av一区二区嗯嗯嗯啊| 9人人澡人人爽人人精品| 国产在线视频一区二区三区| 蜜桃久久久久久| 欧美aaaaaa午夜精品| 亚洲成年人网站在线观看| 亚洲精品成人天堂一二三| 国产精品第五页| 国产精品毛片a∨一区二区三区| 久久日一线二线三线suv| 欧美一区二区三区啪啪| 欧美剧情片在线观看| 欧美体内she精视频| 欧美性猛交xxxx黑人交| 欧美色成人综合| 欧美日韩情趣电影| 欧美日韩精品欧美日韩精品一| 色妹子一区二区| 日本丶国产丶欧美色综合| 91国偷自产一区二区三区观看 | 日韩精品中午字幕| 6080yy午夜一二三区久久| 欧美日韩中文国产| 欧美精三区欧美精三区| 欧美一区二区三区人| 欧美成人福利视频| 久久久久亚洲综合| 日本一区二区视频在线| 国产精品不卡一区| 最新国产精品久久精品| 一二三区精品福利视频| 亚洲国产成人av网| 另类小说综合欧美亚洲| 国产成人av一区二区| 99国产精品久久久久| 欧美性猛交xxxx乱大交退制版| 在线成人免费观看| 精品剧情在线观看| 国产精品区一区二区三区| 一区二区成人在线| 免费成人在线视频观看| 国产91精品露脸国语对白| 91视频xxxx| 在线电影一区二区三区| 久久久久久97三级| 亚洲欧美区自拍先锋| 日韩av网站在线观看| 国产91露脸合集magnet| 欧美色精品在线视频| 久久婷婷成人综合色| ...xxx性欧美| 久久99精品国产麻豆婷婷| 91视频国产观看| 久久一二三国产| 亚洲va欧美va人人爽| 国内国产精品久久| 欧洲精品一区二区三区在线观看| 日韩欧美国产一二三区| 中文字幕一区二区三区不卡| 美女在线观看视频一区二区| 91天堂素人约啪| 久久夜色精品一区| 天天影视涩香欲综合网| 成人激情开心网| 日韩精品一区二区三区视频在线观看| 中文字幕一区二区三区精华液| 美女mm1313爽爽久久久蜜臀| 在线免费观看日韩欧美| 亚洲国产成人私人影院tom| 日韩电影在线免费观看| av网站免费线看精品| 精品国产sm最大网站| 亚洲一区av在线| 不卡一区二区三区四区| 精品国产百合女同互慰| 天天色天天操综合| 色婷婷精品大在线视频| 中文字幕制服丝袜成人av| 麻豆91精品视频| 欧美日韩高清一区二区不卡| 亚洲欧美日韩中文字幕一区二区三区| 国产伦精品一区二区三区免费迷| 337p亚洲精品色噜噜噜| 亚洲国产精品久久艾草纯爱| 一本大道久久a久久精二百| 国产精品伦一区二区三级视频| 丰满放荡岳乱妇91ww| 欧美xxxx在线观看| 久久精品理论片| 欧美肥妇毛茸茸| 日韩av一区二区在线影视| 欧美日韩一区二区三区在线 | 欧美群妇大交群中文字幕| 一区二区三区美女| 成人美女视频在线观看18| 中日韩av电影| 成人av综合在线| 中文字幕人成不卡一区| 91网址在线看| 亚洲影视资源网| 欧美撒尿777hd撒尿| 日韩精品久久理论片|