• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PERROR函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中PERROR函数的典型用法代码示例。如果您正苦于以下问题:C++ PERROR函数的具体用法?C++ PERROR怎么用?C++ PERROR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了PERROR函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: me8254_io_reset_subdevice

int me8254_io_reset_subdevice(struct me_subdevice* subdevice, struct file* filep, int flags)
{
	me8254_subdevice_t* instance;
	uint8_t clk_src;

	instance = (me8254_subdevice_t *) subdevice;

	PDEBUG("executed.\n");

	if (flags)
	{
		PERROR("Invalid flags specified. Must be ME_IO_RESET_SUBDEVICE_NO_FLAGS.\n");
		return ME_ERRNO_INVALID_FLAGS;
	}

	ME_SUBDEVICE_ENTER;
		ME_SUBDEVICE_LOCK;
			ME_SPIN_LOCK(instance->ctrl_reg_lock);
				if (instance->ctr_idx == 0)
					me_writeb(instance->base.dev, ME8254_CTRL_SC0 | ME8254_CTRL_LM | ME8254_CTRL_M0 | ME8254_CTRL_BIN, instance->ctrl_reg);
				else if (instance->ctr_idx == 1)
					me_writeb(instance->base.dev, ME8254_CTRL_SC1 | ME8254_CTRL_LM | ME8254_CTRL_M0 | ME8254_CTRL_BIN, instance->ctrl_reg);
				else
					me_writeb(instance->base.dev, ME8254_CTRL_SC2 | ME8254_CTRL_LM | ME8254_CTRL_M0 | ME8254_CTRL_BIN, instance->ctrl_reg);
			ME_SPIN_UNLOCK(instance->ctrl_reg_lock);

			me_writeb(instance->base.dev, 0x00, instance->val_reg);
			me_writeb(instance->base.dev, 0x00, instance->val_reg);
			ME_SPIN_LOCK(instance->clk_src_reg_lock);
/** @todo Instead of ID  features flags should be used.
*/
				switch (instance->device_id)
				{
					case PCI_DEVICE_ID_MEILHAUS_ME1400:
					case PCI_DEVICE_ID_MEILHAUS_ME140A:
					case PCI_DEVICE_ID_MEILHAUS_ME140B:
					case PCI_DEVICE_ID_MEILHAUS_ME14E0:
					case PCI_DEVICE_ID_MEILHAUS_ME14EA:
					case PCI_DEVICE_ID_MEILHAUS_ME14EB:
						me_readb(instance->base.dev, &clk_src, instance->clk_src_reg);
						if (instance->me8254_idx == 0)
						{
							if (instance->ctr_idx == 0)
								clk_src &= ~(ME1400AB_8254_A_0_CLK_SRC_10MHZ | ME1400AB_8254_A_0_CLK_SRC_QUARZ);
							else if (instance->ctr_idx == 1)
								clk_src &= ~(ME1400AB_8254_A_1_CLK_SRC_PREV);
							else
								clk_src &= ~(ME1400AB_8254_A_2_CLK_SRC_PREV);
						}
						else
						{
							if (instance->ctr_idx == 0)
								clk_src &= ~(ME1400AB_8254_B_0_CLK_SRC_10MHZ | ME1400AB_8254_B_0_CLK_SRC_QUARZ);
							else if (instance->ctr_idx == 1)
								clk_src &= ~(ME1400AB_8254_B_1_CLK_SRC_PREV);
							else
								clk_src &= ~(ME1400AB_8254_B_2_CLK_SRC_PREV);
						}
						me_writeb(instance->base.dev, clk_src, instance->clk_src_reg);
						break;

					case PCI_DEVICE_ID_MEILHAUS_ME140C:
					case PCI_DEVICE_ID_MEILHAUS_ME140D:
						me_readb(instance->base.dev, &clk_src, instance->clk_src_reg);
						switch (instance->me8254_idx)
						{
							case 0:
							case 2:
							case 4:
							case 6:
							case 8:
								if (instance->ctr_idx == 0)
									clk_src &= ~(ME1400CD_8254_ACE_0_CLK_SRC_MASK);
								else if (instance->ctr_idx == 1)
									clk_src &= ~(ME1400CD_8254_ACE_1_CLK_SRC_MASK);
								else
									clk_src &= ~(ME1400CD_8254_ACE_2_CLK_SRC_MASK);
								break;

							default:
								if (instance->ctr_idx == 0)
									clk_src &= ~(ME1400CD_8254_BD_0_CLK_SRC_MASK);
								else if (instance->ctr_idx == 1)
									clk_src &= ~(ME1400CD_8254_BD_1_CLK_SRC_MASK);
								else
									clk_src &= ~(ME1400CD_8254_BD_2_CLK_SRC_MASK);
								break;
						}
						me_writeb(instance->base.dev, clk_src, instance->clk_src_reg);
						break;

					default:
						// No clock source register available.
						break;
				}
			ME_SPIN_UNLOCK(instance->clk_src_reg_lock);
		ME_SUBDEVICE_UNLOCK;
	ME_SUBDEVICE_EXIT;

	return ME_ERRNO_SUCCESS;
//.........这里部分代码省略.........
开发者ID:imrehg,项目名称:meids,代码行数:101,代码来源:me8254.c


示例2: _m_get_media_info

int32_t
_m_get_media_info(rmedia_handle_t *handle, void *ip)
{
	smmedium_prop_t *medinfo = ip;
	struct dk_minfo media_info;
	struct dk_geom	dkgeom;
	int32_t ret_val;
	enum dkio_state state = DKIO_NONE;

	if (handle == NULL) {
		DPRINTF("Null Handle\n");
		errno = EINVAL;
		return (-1);
	}
	if (handle->sm_signature != (int32_t)LIBSMEDIA_SIGNATURE) {
		DPRINTF2(
		    "Signature expected=0x%x, found=0x%x\n",
		    LIBSMEDIA_SIGNATURE, handle->sm_signature);
		errno = EINVAL;
		return (-1);
	}
	if (handle->sm_fd < 0) {
		DPRINTF("Invalid file handle.\n");
		errno = EINVAL;
		return (-1);
	}
	if (ioctl(handle->sm_fd, DKIOCSTATE, &state) < 0) {
		PERROR("DKIOCSTATE failed");
		return (-1);
	}
	if (state != DKIO_INSERTED) {
		DPRINTF("No media.\n");
		medinfo->sm_media_type = SM_NOT_PRESENT;
		medinfo->sm_version = SMMEDIA_PROP_V_1;
		return (0);
	}

	(void) memset((void *) medinfo, 0, sizeof (smmedium_prop_t));

	ret_val = ioctl(handle->sm_fd, DKIOCGMEDIAINFO, &media_info);
	if (ret_val < 0) {
		DPRINTF("DKIOCGMEDIAINFO ioctl failed");
		return (ret_val);
	}

	medinfo->sm_media_type = media_info.dki_media_type;
	medinfo->sm_blocksize = media_info.dki_lbsize;
	medinfo->sm_capacity = media_info.dki_capacity;

	/* Is it a removable magnetic disk? */
	if (medinfo->sm_media_type == DK_FIXED_DISK) {
		int32_t removable = 0;

		ret_val = ioctl(handle->sm_fd, DKIOCREMOVABLE, &removable);
		if (ret_val < 0) {
			DPRINTF("DKIOCREMOVABLE ioctl failed");
			return (ret_val);
		}
		if (removable) {
			medinfo->sm_media_type = SM_PCMCIA_ATA;
		}
	}
	ret_val = ioctl(handle->sm_fd, DKIOCGGEOM, &dkgeom);
	if (ret_val < 0) {
#ifdef sparc
		DPRINTF("DKIOCGGEOM ioctl failed");
		return (ret_val);
#else /* !sparc */
		/*
		 * Try getting Physical geometry on x86.
		 */
		ret_val = ioctl(handle->sm_fd, DKIOCG_PHYGEOM, &dkgeom);
		if (ret_val < 0) {
			DPRINTF("DKIOCG_PHYGEOM ioctl failed");
			return (ret_val);
		}
#endif /* sparc */
	}

	medinfo->sm_pcyl = dkgeom.dkg_pcyl;
	medinfo->sm_nhead = dkgeom.dkg_nhead;
	medinfo->sm_nsect = dkgeom.dkg_nsect;

	return (0);
}
开发者ID:kele,项目名称:illumos-fsd,代码行数:85,代码来源:a_generic.c


示例3: findIface

UInteger32
findIface(Octet * ifaceName, UInteger8 * communicationTechnology,
          Octet * uuid, NetPath * netPath)
{
#if defined(linux)

    /* depends on linux specific ioctls (see 'netdevice' man page) */
    int i, flags;
    struct ifconf data;
    struct ifreq device[IFCONF_LENGTH];

    data.ifc_len = sizeof(device);
    data.ifc_req = device;

    memset(data.ifc_buf, 0, data.ifc_len);

    flags = IFF_UP | IFF_RUNNING | IFF_MULTICAST;

    /* look for an interface if none specified */
    if (ifaceName[0] != '\0') {
        i = 0;
        memcpy(device[i].ifr_name, ifaceName, IFACE_NAME_LENGTH);

        if (ioctl(netPath->eventSock, SIOCGIFHWADDR, &device[i]) < 0)
            DBGV("failed to get hardware address\n");
        else if ((*communicationTechnology = lookupCommunicationTechnology(device[i].ifr_hwaddr.sa_family)) == PTP_DEFAULT)
            DBGV("unsupported communication technology (%d)\n", *communicationTechnology);
        else
            memcpy(uuid, device[i].ifr_hwaddr.sa_data, PTP_UUID_LENGTH);
    } else {
        /* no iface specified */
        /* get list of network interfaces */
        if (ioctl(netPath->eventSock, SIOCGIFCONF, &data) < 0) {
            PERROR("failed query network interfaces");
            return 0;
        }
        if (data.ifc_len >= sizeof(device))
            DBG("device list may exceed allocated space\n");

        /* search through interfaces */
        for (i = 0; i < data.ifc_len / sizeof(device[0]); ++i) {
            DBGV("%d %s %s\n", i, device[i].ifr_name, inet_ntoa(((struct sockaddr_in *)&device[i].ifr_addr)->sin_addr));

            if (ioctl(netPath->eventSock, SIOCGIFFLAGS, &device[i]) < 0)
                DBGV("failed to get device flags\n");
            else if ((device[i].ifr_flags & flags) != flags)
                DBGV("does not meet requirements (%08x, %08x)\n", device[i].ifr_flags, flags);
            else if (ioctl(netPath->eventSock, SIOCGIFHWADDR, &device[i]) < 0)
                DBGV("failed to get hardware address\n");
            else if ((*communicationTechnology = lookupCommunicationTechnology(device[i].ifr_hwaddr.sa_family)) == PTP_DEFAULT)
                DBGV("unsupported communication technology (%d)\n", *communicationTechnology);
            else {
                DBGV("found interface (%s)\n", device[i].ifr_name);

                memcpy(uuid, device[i].ifr_hwaddr.sa_data, PTP_UUID_LENGTH);
                memcpy(ifaceName, device[i].ifr_name, IFACE_NAME_LENGTH);

                break;
            }
        }
    }

    if (ifaceName[0] == '\0') {
        ERROR("failed to find a usable interface\n");
        return 0;
    }
    if (ioctl(netPath->eventSock, SIOCGIFADDR, &device[i]) < 0) {
        PERROR("failed to get ip address");
        return 0;
    }
    return ((struct sockaddr_in *)&device[i].ifr_addr)->sin_addr.s_addr;

#elif defined(BSD_INTERFACE_FUNCTIONS)

    struct ifaddrs *if_list, *ifv4, *ifh;

    if (getifaddrs(&if_list) < 0) {
        PERROR("getifaddrs() failed");
        return FALSE;
    }
    /* find an IPv4, multicast, UP interface, right name(if supplied) */
    for (ifv4 = if_list; ifv4 != NULL; ifv4 = ifv4->ifa_next) {
        if ((ifv4->ifa_flags & IFF_UP) == 0)
            continue;
        if ((ifv4->ifa_flags & IFF_RUNNING) == 0)
            continue;
        if ((ifv4->ifa_flags & IFF_LOOPBACK))
            continue;
        if ((ifv4->ifa_flags & IFF_MULTICAST) == 0)
            continue;
        if (ifv4->ifa_addr->sa_family != AF_INET)	/* must have IPv4
								 * address */
            continue;

        if (ifaceName[0] && strncmp(ifv4->ifa_name, ifaceName, IF_NAMESIZE) != 0)
            continue;

        break;
    }

//.........这里部分代码省略.........
开发者ID:peterliu2,项目名称:tivaWare,代码行数:101,代码来源:net.c


示例4: video_init

int video_init(int window_w,
               int window_h,
               int fullscreen,
               int vsync,
               const char* scaler_name,
               int scale_factor) {
    state.w = window_w;
    state.h = window_h;
    state.fs = fullscreen;
    state.vsync = vsync;
    state.fade = 1.0f;
    state.target = NULL;
    state.target_move_x = 0;
    state.target_move_y = 0;

    // Load scaler (if any)
    memset(state.scaler_name, 0, sizeof(state.scaler_name));
    strncpy(state.scaler_name, scaler_name, sizeof(state.scaler_name)-1);
    if(video_load_scaler(scaler_name, scale_factor)) {
        DEBUG("Scaler \"%s\" plugin not found; using Nearest neighbour scaling.", scaler_name);
        state.scale_factor = 1;
    } else {
        DEBUG("Scaler \"%s\" loaded w/ factor %d", scaler_name, scale_factor);
        state.scale_factor = scale_factor;
    }

    // Clear palettes
    state.cur_palette = malloc(sizeof(screen_palette));
    state.base_palette = malloc(sizeof(palette));
    memset(state.cur_palette, 0, sizeof(screen_palette));
    state.cur_palette->version = 1;

    // Form title string
    char title[32];
    sprintf(title, "OpenOMF v%d.%d.%d", V_MAJOR, V_MINOR, V_PATCH);

    // Open window
    state.window = SDL_CreateWindow(
        title,
        SDL_WINDOWPOS_CENTERED,
        SDL_WINDOWPOS_CENTERED,
        window_w,
        window_h,
        SDL_WINDOW_SHOWN);
    if(state.window == NULL) {
        PERROR("Could not create window: %s", SDL_GetError());
        return 1;
    }

    // Set fullscreen if needed
    if(state.fs) {
        if(SDL_SetWindowFullscreen(state.window, SDL_WINDOW_FULLSCREEN) != 0) {
            PERROR("Could not set fullscreen mode!");
        } else {
            DEBUG("Fullscreen enabled!");
        }
    } else {
        SDL_SetWindowFullscreen(state.window, 0);
    }

    // Form flags
    int renderer_flags = SDL_RENDERER_ACCELERATED;
    if(state.vsync) {
        renderer_flags |= SDL_RENDERER_PRESENTVSYNC;
    }

    // Create renderer
    state.renderer = SDL_CreateRenderer(
        state.window,
        -1,
        renderer_flags);
    if(state.renderer == NULL) {
        PERROR("Could not create renderer: %s", SDL_GetError());
        return 1;
    }

    // Default resolution for renderer. This will them get scaled up to screen size.
    SDL_RenderSetLogicalSize(state.renderer,
                             NATIVE_W * state.scale_factor,
                             NATIVE_H * state.scale_factor);

    // Disable screensaver :/
    SDL_DisableScreenSaver();

    // Set rendertargets
    reset_targets();

    // Init texture cache
    tcache_init(state.renderer, state.scale_factor, &state.scaler);

    // Init hardware renderer
    state.cur_renderer = VIDEO_RENDERER_HW;
    video_hw_init(&state);

    // Get renderer data
    SDL_RendererInfo rinfo;
    SDL_GetRendererInfo(state.renderer, &rinfo);

    // Show some info
    INFO("Video Init OK");
//.........这里部分代码省略.........
开发者ID:acasaccia,项目名称:openomf,代码行数:101,代码来源:video.c


示例5: drct_rmw_write_complete_handler

static void drct_rmw_write_complete_handler(spd_dev_t *dev)
{
  int retval = 0;
  unsigned long flags = 0;
  u32 sector;
  int wsize;
  PTRACE();

  PINFO("<spd%c>complete time=%dms errcode=%d",
	dev->id+'a', jiffies_to_msecs(dev->ticks), dev->errcode);

  if(dev->cache){
    spd_cache_clr_dirty(dev->cache);
  }

  if(unlikely(dev->errcode < 0)){
    retval = dev->errcode;
    goto ABORT;
  }

  if(dev->bdev->rmw_count == 0){
    spin_lock_irqsave(&dev->bdev->rq_lock, flags);
    bdev_end_request(dev, 0);
    spin_unlock_irqrestore(&dev->bdev->rq_lock, flags);

    dev->complete_handler = NULL;
    spd_io_unlock(dev);

    return;
  }

  sector = dev->bdev->rmw_sector;
  wsize  = spd_get_wsize(dev, sector);
  if(unlikely(wsize < 0)){
    PERROR("<spd%c>spd_get_wsize() failed sector=%08x", dev->id+'a', sector);
    retval = -EINVAL;
    goto ABORT;
  }
  sector = align_sector(sector, wsize, spd_get_sector_offset(dev, sector));

  if(sector == dev->bdev->rmw_sector && dev->bdev->rmw_count >= wsize){
    dev->cache->sector   = sector;
    dev->cache->n_sector = wsize;
    retval = drct_make_rmw_sg(dev);
    if(unlikely(retval < 0)){
      PERROR("<spd%c>drct_make_rmw_sg() failed(%d)", dev->id+'a', retval);
      goto ABORT;
    }

    dev->complete_handler = drct_rmw_write_complete_handler;
    retval = spd_write_sector(dev, sector, wsize, dev->sg);
    if(unlikely(retval < 0)){
      PERROR("<spd%c>spd_write_sector() failed(%d)", dev->id+'a', retval);
      goto ABORT;
    }

    dev->cache->sector = (u32)-1;
    spd_cache_clr_dirty(dev->cache);

    return;
  }

  dev->cache->sector   = sector;
  dev->cache->n_sector = wsize;

  dev->complete_handler = drct_rmw_read_complete_handler;
  spd_cache_prepare(dev, SPD_DIR_READ);
  retval = spd_read_sector(dev,
                           dev->cache->sector,
                           dev->cache->n_sector,
                           dev->cache->sg);
  if(unlikely(retval < 0)){
    PERROR("<spd%c>spd_read_sector() failed(%d)", dev->id+'a', retval);
    goto ABORT;
  }

  return;

ABORT:
  PINFO("<spd%c>ABORT at %s", dev->id+'a', __FUNCTION__);
  if(dev->cache){
    dev->cache->sector = (u32)-1;
    spd_cache_clr_dirty(dev->cache);
  }

  spin_lock_irqsave(&dev->bdev->rq_lock, flags);
  bdev_end_request(dev, retval);
  spin_unlock_irqrestore(&dev->bdev->rq_lock, flags);

  dev->complete_handler = NULL;
  spd_io_unlock(dev);
}
开发者ID:kierank,项目名称:p2card,代码行数:92,代码来源:spd_drct.c


示例6: main

int main(int argc, char *argv[])
{
	struct sockaddr_in sin, sout, from;
	struct ifreq ifr;
	int fd, s, port, PORT, l;
	unsigned int soutlen, fromlen;
	char c, *p, *ip;
	char buf[1500];
	fd_set fdset;
	
	

	int MODE = 0, TUNMODE = IFF_TUN, DEBUG = 0;

	while ((c = getopt(argc, argv, "s:c:ehd")) != -1) {
		switch (c) {
		case 'h':
			usage();
		case 'd':
			DEBUG++;
			break;
		case 's':
			MODE = 1;
			PORT = atoi(optarg);
			break;
		case 'c':
			MODE = 2;
			p = (char*)memchr(optarg,':',16);
			if (!p) ERROR("invalid argument : [%s]\n",optarg);
			*p = 0;
			ip = optarg;
			port = atoi(p+1);
			PORT = 0;
			break;
		case 'e':
			TUNMODE = IFF_TAP;
			break;
		default:
			usage();
		}
	}
	if (MODE == 0) usage();

/*
	if ( (fd = open("/dev/net/tun",O_RDWR)) < 0) PERROR("open");

	memset(&ifr, 0, sizeof(ifr));
	ifr.ifr_flags = TUNMODE;
	strncpy(ifr.ifr_name, "toto%d", IFNAMSIZ);
	if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) PERROR("ioctl");

	printf("Allocated interface %s. Configure and use it\n", ifr.ifr_name);
*/
	
	/*
	s = socket(AF_INET, SOCK_DGRAM, 0);
  bzero(&sin, sizeof(sin));
	sin.sin_family = AF_INET;
	sin.sin_addr.s_addr = INADDR_ANY; // or  htonl(INADDR_ANY); TODO ?!
	sin.sin_port = htons(PORT);
	if ( bind(s,(struct sockaddr *)&sin, sizeof(sin)) < 0) PERROR("bind");
	*/

	printf("PORT=%d \n", PORT);

	// struct sockaddr_in sin;
	s = socket(AF_INET, SOCK_DGRAM, 0);
	if (s < 0) error(1, 1, "Opening socket");
	//length = sizeof(server);
	bzero(&sin, sizeof(sin));
	sin.sin_family=AF_INET;
	sin.sin_addr.s_addr=INADDR_ANY;
	sin.sin_port=htons(PORT); 
	// if (bind(sock,(struct sockaddr *)&server,length)<0)
	printf("Doing the bind\n");
	if (bind(s,(struct sockaddr *)&sin, sizeof(sin))<0) error(1, 1, "binding");
	printf("Doing the bind - DONE\n");
	// fromlen = sizeof(struct sockaddr_in);

	printf("After bind in line %d\n", __LINE__);

	fromlen = sizeof(from);

	if (MODE == 1) {
		printf("Will wait for the passwor packet now...%d\n", __LINE__);
		while(1) {
			printf("Trying to receive password...%d\n", __LINE__);
			l = recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr *)&from, &fromlen);
			printf("Read password packet len=%d in line %d\n", l, __LINE__);
			if (l < 0) PERROR("recvfrom");
			if (strncmp(MAGIC_WORD, buf, sizeof(MAGIC_WORD)) == 0)
				break;
			printf("Bad magic word from %s:%i\n", 
			       inet_ntoa(from.sin_addr), ntohs(from.sin_port));
		} 
		printf("Got correct password in line %d\n", __LINE__);
		printf("Sending reply line %d\n", __LINE__);
		l = sendto(s, MAGIC_WORD, sizeof(MAGIC_WORD), 0, (struct sockaddr *)&from, fromlen);
		printf("Sent reply line %d\n", __LINE__);
		if (l < 0) PERROR("sendto");
//.........这里部分代码省略.........
开发者ID:antinet,项目名称:antinet,代码行数:101,代码来源:tunproxy.c


示例7: main

int __cdecl main(int argc, char *argv[])
{
	enum {
		CMD_NONE = 0,
		CMD_USER,
		CMD_ATTACH,
		CMD_DETACH,
	} cmd = CMD_NONE;
	int ret;

	if (argc == 3 && strcasecmp(argv[1], "user") == 0) {
		cmd = CMD_USER;
	} else if (argc == 3 && strcasecmp(argv[1], "attach") == 0) {
		cmd = CMD_ATTACH;
	} else if (argc == 3 && strcasecmp(argv[1], "detach") == 0) {
		cmd = CMD_DETACH;
	} else {
		fprintf(stderr, "Usage: " APP_NAME " user <remote link ID>\n");
		fprintf(stderr,
			"       " APP_NAME " attach <kernel port ID>\n");
		fprintf(stderr,
			"       " APP_NAME " detach <kernel port ID>\n");
		exit(1);
	}

	if (cmd == CMD_USER) {
		SMBSIM_SERIAL *host;
		CSFNET *net;
		CSFNET_PARAMS net_params;

		ret = smbsim_serial_create(&host);
		if (ret) {
			PERROR("smbsim_serial_create", ret);
			exit(2);
		}

		memset(&net_params, 0, sizeof(net_params));
		net_params.server_host = "127.0.0.1";
		net_params.server_port = 5000;
		net_params.local_link_id = smbsim_serial_get_link_id(host);
		net_params.remote_link_id = (UINT16) strtoul(argv[2], 0, 0);
		net_params.bus_type = CSF_BUS_TYPE_SMBUS;

		ret = csfnet_create(&net_params, &net);
		if (ret) {
			PERROR("csfnet_create", ret);
			smbsim_serial_delete(host);
			exit(3);
		}

		printf("Press enter key to terminate...");
		getchar();

		csfnet_delete(net);
		smbsim_serial_delete(host);
	} else {
		XPCF_UDEV *udev;
		int port_id;

		ret = xpcf_udev_open(DEV_NAME, &udev);
		if (ret) {
			PERROR("xpcf_udev_open", ret);
			exit(4);
		}

		port_id = strtoul(argv[2], 0, 0);
		if (cmd == CMD_ATTACH) {
			ret = xpcf_udev_ioctl(udev,
					      IOCTL_SMBSIM_SERIAL_ATTACH_DEV,
					      &port_id, sizeof(port_id), NULL);
			if (ret) {
				PERROR("ioctl(IOCTL_SMBSIM_SERIAL_ATTACH_DEV)",
				       ret);
				xpcf_udev_close(udev);
				exit(5);
			}
		} else {
			ret = xpcf_udev_ioctl(udev,
					      IOCTL_SMBSIM_SERIAL_DETACH_DEV,
					      &port_id, sizeof(port_id), NULL);
			if (ret) {
				PERROR("ioctl(IOCTL_SMBSIM_SERIAL_DETACH_DEV)",
				       ret);
				xpcf_udev_close(udev);
				exit(6);
			}
		}

		xpcf_udev_close(udev);
	}
	return 0;
}
开发者ID:hiro-sakamoto,项目名称:csf,代码行数:92,代码来源:app.c


示例8: handle_one_cmd

/*
 * Return < 0 on error, 0 if OK, 1 on hangup.
 */
static
int handle_one_cmd(struct run_as_worker *worker)
{
	int ret = 0;
	struct run_as_data data;
	ssize_t readlen, writelen;
	struct run_as_ret sendret;
	run_as_fct cmd;
	uid_t prev_euid;

	/* Read data */
	readlen = lttcomm_recv_unix_sock(worker->sockpair[1], &data,
			sizeof(data));
	if (readlen == 0) {
		/* hang up */
		ret = 1;
		goto end;
	}
	if (readlen < sizeof(data)) {
		PERROR("lttcomm_recv_unix_sock error");
		ret = -1;
		goto end;
	}

	cmd = run_as_enum_to_fct(data.cmd);
	if (!cmd) {
		ret = -1;
		goto end;
	}

	prev_euid = getuid();
	if (data.gid != getegid()) {
		ret = setegid(data.gid);
		if (ret < 0) {
			PERROR("setegid");
			goto write_return;
		}
	}
	if (data.uid != prev_euid) {
		ret = seteuid(data.uid);
		if (ret < 0) {
			PERROR("seteuid");
			goto write_return;
		}
	}
	/*
	 * Also set umask to 0 for mkdir executable bit.
	 */
	umask(0);
	ret = (*cmd)(&data);

write_return:
	sendret.ret = ret;
	sendret._errno = errno;
	/* send back return value */
	writelen = lttcomm_send_unix_sock(worker->sockpair[1], &sendret,
			sizeof(sendret));
	if (writelen < sizeof(sendret)) {
		PERROR("lttcomm_send_unix_sock error");
		ret = -1;
		goto end;
	}
	ret = do_send_fd(worker, data.cmd, ret);
	if (ret) {
		PERROR("do_send_fd error");
		ret = -1;
		goto end;
	}
	if (seteuid(prev_euid) < 0) {
		PERROR("seteuid");
		ret = -1;
		goto end;
	}
	ret = 0;
end:
	return ret;
}
开发者ID:frdeso,项目名称:lttng-tools,代码行数:80,代码来源:runas.c


示例9: run_as_create_worker

LTTNG_HIDDEN
int run_as_create_worker(char *procname)
{
	pid_t pid;
	int i, ret = 0;
	ssize_t readlen;
	struct run_as_ret recvret;
	struct run_as_worker *worker;

	pthread_mutex_lock(&worker_lock);
	assert(!global_worker);
	if (!use_clone()) {
		/*
		 * Don't initialize a worker, all run_as tasks will be performed
		 * in the current process.
		 */
		ret = 0;
		goto end;
	}
	worker = zmalloc(sizeof(*worker));
	if (!worker) {
		ret = -ENOMEM;
		goto end;
	}
	worker->procname = procname;
	/* Create unix socket. */
	if (lttcomm_create_anon_unix_socketpair(worker->sockpair) < 0) {
		ret = -1;
		goto error_sock;
	}
	/* Fork worker. */
	pid = fork();
	if (pid < 0) {
		PERROR("fork");
		ret = -1;
		goto error_fork;
	} else if (pid == 0) {
		/* Child */

		reset_sighandler();

		set_worker_sighandlers();

		/* The child has no use for this lock. */
		pthread_mutex_unlock(&worker_lock);
		/* Just close, no shutdown. */
		if (close(worker->sockpair[0])) {
			PERROR("close");
			exit(EXIT_FAILURE);
		}
		worker->sockpair[0] = -1;
		ret = run_as_worker(worker);
		if (lttcomm_close_unix_sock(worker->sockpair[1])) {
			PERROR("close");
			ret = -1;
		}
		worker->sockpair[1] = -1;
		LOG(ret ? PRINT_ERR : PRINT_DBG, "run_as worker exiting (ret = %d)", ret);
		exit(ret ? EXIT_FAILURE : EXIT_SUCCESS);
	} else {
		/* Parent */

		/* Just close, no shutdown. */
		if (close(worker->sockpair[1])) {
			PERROR("close");
			ret = -1;
			goto error_fork;
		}
		worker->sockpair[1] = -1;
		worker->pid = pid;
		/* Wait for worker to become ready. */
		readlen = lttcomm_recv_unix_sock(worker->sockpair[0],
				&recvret, sizeof(recvret));
		if (readlen < sizeof(recvret)) {
			ERR("readlen: %zd", readlen);
			PERROR("Error reading response from run_as at creation");
			ret = -1;
			goto error_fork;
		}
		global_worker = worker;
	}
end:
	pthread_mutex_unlock(&worker_lock);
	return ret;

	/* Error handling. */
error_fork:
	for (i = 0; i < 2; i++) {
		if (worker->sockpair[i] < 0) {
			continue;
		}
		if (lttcomm_close_unix_sock(worker->sockpair[i])) {
			PERROR("close");
		}
		worker->sockpair[i] = -1;
	}
error_sock:
	free(worker);
	pthread_mutex_unlock(&worker_lock);
	return ret;
//.........这里部分代码省略.........
开发者ID:frdeso,项目名称:lttng-tools,代码行数:101,代码来源:runas.c


示例10: PERROR

/* epoint sends a message to a join
 *
 */
void JoinPBX::message_epoint(unsigned int epoint_id, int message_type, union parameter *param)
{
	class Join *cl;
	struct join_relation *relation, *reltemp;
	int num;
	int new_state;
	struct lcr_msg *message;
//	int size, writesize, oldpointer;
	char *number, *numbers;

	if (!epoint_id) {
		PERROR("software error, epoint == NULL\n");
		return;
	}

//	if (options.deb & DEBUG_JOIN) {
//		PDEBUG(DEBUG_JOIN, "message %d received from ep%d.\n", message, epoint->ep_serial);
//		joinpbx_debug(join,"Join::message_epoint");
//	}
	if (options.deb & DEBUG_JOIN) {
		if (message_type) {
			cl = join_first;
			while(cl) {
				if (cl->j_type == JOIN_TYPE_PBX)
					joinpbx_debug((class JoinPBX *)cl, "Join::message_epoint{all joins before processing}");
				cl = cl->next;
			}
		}
	}

	/* check relation */
	relation = j_relation;
	while(relation) {
		if (relation->epoint_id == epoint_id)
			break;
		relation = relation->next;
	}
	if (!relation) {
		PDEBUG(DEBUG_JOIN, "no relation back to the endpoint found, ignoring (join=%d, endpoint=%d)\n", j_serial, epoint_id);
		return;
	}

	/* count relations */
	num=joinpbx_countrelations(j_serial);

	/* process party line */
	if (message_type == MESSAGE_SETUP) if (param->setup.partyline && !j_partyline) {
		j_partyline = param->setup.partyline;
		j_partyline_jingle = param->setup.partyline_jingle;
	}
	if (j_partyline) {
		switch(message_type) {
			case MESSAGE_SETUP:
			PDEBUG(DEBUG_JOIN, "respsone with connect in partyline mode.\n");
			relation->type = RELATION_TYPE_CONNECT;
			message = message_create(j_serial, epoint_id, JOIN_TO_EPOINT, MESSAGE_CONNECT);
			SPRINT(message->param.connectinfo.id, "%d", j_partyline);
			message->param.connectinfo.ntype = INFO_NTYPE_UNKNOWN;
			message_put(message);
			trigger_work(&j_updatebridge);
			if (j_partyline_jingle)
			       play_jingle(1);
			break;
			
			case MESSAGE_AUDIOPATH:
			PDEBUG(DEBUG_JOIN, "join received channel message: %d.\n", param->audiopath);
			if (relation->channel_state != param->audiopath) {
				relation->channel_state = param->audiopath;
				trigger_work(&j_updatebridge);
				if (options.deb & DEBUG_JOIN)
					joinpbx_debug(this, "Join::message_epoint{after setting new channel state}");
			}
			break;

			/* track notify */
			case MESSAGE_NOTIFY:
			switch(param->notifyinfo.notify) {
				case INFO_NOTIFY_USER_SUSPENDED:
				case INFO_NOTIFY_USER_RESUMED:
				case INFO_NOTIFY_REMOTE_HOLD:
				case INFO_NOTIFY_REMOTE_RETRIEVAL:
				case INFO_NOTIFY_CONFERENCE_ESTABLISHED:
				case INFO_NOTIFY_CONFERENCE_DISCONNECTED:
				new_state = track_notify(relation->rx_state, param->notifyinfo.notify);
				if (new_state != relation->rx_state) {
					relation->rx_state = new_state;
					trigger_work(&j_updatebridge);
					if (options.deb & DEBUG_JOIN)
						joinpbx_debug(this, "Join::message_epoint{after setting new rx state}");
				}
				break;
			}
			break;

			case MESSAGE_DISCONNECT:
			PDEBUG(DEBUG_JOIN, "releasing after receiving disconnect, because join in partyline mode.\n");
			message = message_create(j_serial, epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE);
//.........这里部分代码省略.........
开发者ID:fairwaves,项目名称:lcr,代码行数:101,代码来源:joinpbx.cpp


示例11: while

void JoinPBX::bridge(void)
{
	struct join_relation *relation;
	struct lcr_msg *message;
	int numconnect = 0, relations = 0;
	class Endpoint *epoint;
	struct port_list *portlist;
	class Port *port;
	unsigned int bridge_id;
	class Join *join_3pty;
	class JoinPBX *joinpbx_3pty;
#ifdef DEBUG_COREBRIDGE
	int allmISDN = 0; // never set for debug purpose
#else
	int allmISDN = 1; // set until a non-mISDN relation is found
#endif

	/* bridge id is the serial of join
	 * if we have a 3pty with another join, we always use the lowest brigde id.
	 * this way we use common ids, so both joins share same bridge */
	if (j_3pty && j_3pty < j_serial)
		bridge_id = j_3pty;
	else
		bridge_id = j_serial;

	relation = j_relation;
	while(relation) {
		/* count all relations */
		relations++;

		/* check for relation's objects */
		epoint = find_epoint_id(relation->epoint_id);
		if (!epoint) {
			PERROR("software error: relation without existing endpoints.\n");
			relation = relation->next;
			continue;
		}
		portlist = epoint->ep_portlist;
		if (!portlist) {
			PDEBUG(DEBUG_JOIN, "join%d ignoring relation without port object.\n", j_serial);
//#warning testing: keep on hold until single audio stream available
			relation->channel_state = 0;
			relation = relation->next;
			continue;
		}
		if (portlist->next) {
			PDEBUG(DEBUG_JOIN, "join%d ignoring relation with ep%d due to port_list.\n", j_serial, epoint->ep_serial);
//#warning testing: keep on hold until single audio stream available
			relation->channel_state = 0;
			relation = relation->next;
			continue;
		}
		port = find_port_id(portlist->port_id);
		if (!port) {
			PDEBUG(DEBUG_JOIN, "join%d ignoring relation without existing port object.\n", j_serial);
			relation = relation->next;
			continue;
		}
		if ((port->p_type&PORT_CLASS_MASK)!=PORT_CLASS_mISDN) {
			PDEBUG(DEBUG_JOIN, "join%d ignoring relation ep%d because it's port is not mISDN.\n", j_serial, epoint->ep_serial);
			if (allmISDN) {
				PDEBUG(DEBUG_JOIN, "join%d not all endpoints are mISDN.\n", j_serial);
				allmISDN = 0;
			}
			relation = relation->next;
			continue;
		}

		relation = relation->next;
	}

	/* check if 3pty members have no mISDN, so bridging via mISDN/lcr will be selected correctly */
	join_3pty = find_join_id(j_3pty);
	if (join_3pty && join_3pty->j_type == JOIN_TYPE_PBX) {
		joinpbx_3pty = (class JoinPBX *)join_3pty;
		relation = joinpbx_3pty->j_relation;
		while(relation) {

#if 0
no need to count, because j_3pty is taken into account below when checking relations
			/* count all relations */
			relations++;
#endif

			/* check for relation's objects */
			epoint = find_epoint_id(relation->epoint_id);
			if (!epoint) {
				PERROR("software error: relation without existing endpoints.\n");
				relation = relation->next;
				continue;
			}
			portlist = epoint->ep_portlist;
			if (!portlist) {
				PDEBUG(DEBUG_JOIN, "other 3pty join %d: ignoring relation without port object.\n", joinpbx_3pty->j_serial);
//#warning testing: keep on hold until single audio stream available
				relation->channel_state = 0;
				relation = relation->next;
				continue;
			}
			if (portlist->next) {
//.........这里部分代码省略.........
开发者ID:fairwaves,项目名称:lcr,代码行数:101,代码来源:joinpbx.cpp


示例12: me8254_constr

me8254_subdevice_t* me8254_constr(uint16_t device_id, void* reg_base, unsigned int me8254_idx, unsigned int ctr_idx,
										me_lock_t* ctrl_reg_lock, me_lock_t* clk_src_reg_lock)
{
	me8254_subdevice_t *subdevice;

	PDEBUG("executed.\n");

/** @todo Checkings should be removed. We can safetly assume that data passed from upper level are correct.
*/
	// Check if counter index is out of range
	if (ctr_idx > 2)
	{
		PERROR("Counter index is out of range.\n");
		return NULL;
	}

	// Check device specific values.
	switch (device_id)
	{
		case PCI_DEVICE_ID_MEILHAUS_ME140A:
		case PCI_DEVICE_ID_MEILHAUS_ME14EA:

		case PCI_DEVICE_ID_MEILHAUS_ME4610:
		case PCI_DEVICE_ID_MEILHAUS_ME4660:
		case PCI_DEVICE_ID_MEILHAUS_ME4660I:
		case PCI_DEVICE_ID_MEILHAUS_ME4660S:
		case PCI_DEVICE_ID_MEILHAUS_ME4660IS:
		case PCI_DEVICE_ID_MEILHAUS_ME4670:
		case PCI_DEVICE_ID_MEILHAUS_ME4670I:
		case PCI_DEVICE_ID_MEILHAUS_ME4670S:
		case PCI_DEVICE_ID_MEILHAUS_ME4670IS:
		case PCI_DEVICE_ID_MEILHAUS_ME4680:
		case PCI_DEVICE_ID_MEILHAUS_ME4680I:
		case PCI_DEVICE_ID_MEILHAUS_ME4680S:
		case PCI_DEVICE_ID_MEILHAUS_ME4680IS:

		case PCI_DEVICE_ID_MEILHAUS_ME4560:
		case PCI_DEVICE_ID_MEILHAUS_ME4560I:
		case PCI_DEVICE_ID_MEILHAUS_ME4560S:
		case PCI_DEVICE_ID_MEILHAUS_ME4560IS:
		case PCI_DEVICE_ID_MEILHAUS_ME4570:
		case PCI_DEVICE_ID_MEILHAUS_ME4570I:
		case PCI_DEVICE_ID_MEILHAUS_ME4570S:
		case PCI_DEVICE_ID_MEILHAUS_ME4570IS:

		case PCI_DEVICE_ID_MEILHAUS_ME4760:
		case PCI_DEVICE_ID_MEILHAUS_ME4760I:
		case PCI_DEVICE_ID_MEILHAUS_ME4760S:
		case PCI_DEVICE_ID_MEILHAUS_ME4760IS:
		case PCI_DEVICE_ID_MEILHAUS_ME4770:
		case PCI_DEVICE_ID_MEILHAUS_ME4770I:
		case PCI_DEVICE_ID_MEILHAUS_ME4770S:
		case PCI_DEVICE_ID_MEILHAUS_ME4770IS:
		case PCI_DEVICE_ID_MEILHAUS_ME4780:
		case PCI_DEVICE_ID_MEILHAUS_ME4780I:
		case PCI_DEVICE_ID_MEILHAUS_ME4780S:
		case PCI_DEVICE_ID_MEILHAUS_ME4780IS:

		case PCI_DEVICE_ID_MEILHAUS_ME4860:
		case PCI_DEVICE_ID_MEILHAUS_ME4860I:
		case PCI_DEVICE_ID_MEILHAUS_ME4860S:
		case PCI_DEVICE_ID_MEILHAUS_ME4860IS:
		case PCI_DEVICE_ID_MEILHAUS_ME4870:
		case PCI_DEVICE_ID_MEILHAUS_ME4870I:
		case PCI_DEVICE_ID_MEILHAUS_ME4870S:
		case PCI_DEVICE_ID_MEILHAUS_ME4870IS:
		case PCI_DEVICE_ID_MEILHAUS_ME4880:
		case PCI_DEVICE_ID_MEILHAUS_ME4880I:
		case PCI_DEVICE_ID_MEILHAUS_ME4880S:
		case PCI_DEVICE_ID_MEILHAUS_ME4880IS:

		case PCI_DEVICE_ID_MEILHAUS_ME0752:
		case PCI_DEVICE_ID_MEILHAUS_ME0754:
		case PCI_DEVICE_ID_MEILHAUS_ME0762:
		case PCI_DEVICE_ID_MEILHAUS_ME0764:
		case PCI_DEVICE_ID_MEILHAUS_ME0772:
		case PCI_DEVICE_ID_MEILHAUS_ME0774:
		case PCI_DEVICE_ID_MEILHAUS_ME0782:
		case PCI_DEVICE_ID_MEILHAUS_ME0784:

		case PCI_DEVICE_ID_MEILHAUS_ME8100_A:
		case PCI_DEVICE_ID_MEILHAUS_ME8100_B:
			if (me8254_idx > 0)
			{
				PERROR("8254 index is out of range. Must be 0.\n");
				return NULL;
			}
			break;

		case PCI_DEVICE_ID_MEILHAUS_ME140B:
		case PCI_DEVICE_ID_MEILHAUS_ME14EB:
			if (me8254_idx > 1)
			{
				PERROR("8254 index is out of range. Must be 0 or 1.\n");
				return NULL;
			}
			break;

		case PCI_DEVICE_ID_MEILHAUS_ME140C:
			if (me8254_idx > 4)
//.........这里部分代码省略.........
开发者ID:imrehg,项目名称:meids,代码行数:101,代码来源:me8254.c


示例13: jpProcessos

//int  __attribute__((__section__(".text.main")))
int jpProcessos(void)
{
	int mypid,pid,ret;
	char buffer[16];
	int i;
	int j;
	int n;
	int tics;
	for(j=0; j<80*35; j++) write(1," ",1);
	PRINTF("\n****JP: Procesos********************\n");
	PRINTF("Probamos getpid\n");
	mypid=getpid();
	proso_itoa(mypid,buffer);
	PRINTF("PID PADRE: ");
	PRINTF(buffer);
	PRINTF("\nCreacion primer proceso \n");
	pid=fork();
	if (pid==0){
		PRINTF("HOLA SOY EL HIJO\n");
		proso_itoa(getpid(),buffer);
		PRINTF("El pid del hijo es ");
		PRINTF(buffer);
		PRINTF("\n");
		PRINTF("Soy el hijo y ME SUICIDO\n");
		exit();
	}else if (pid==-1){
		PERROR();
		FINJP;
	}else{
		PRINTF("SOY EL PADRE: Creacion primer proceso OK\n");
	}
	PRINTF("Creamos una jerarquia: un hijo y un nieto\n");
	switch(fork()){
		case 0:switch(fork()){
			       case 0:PRINTF("SOY EL NIETO: ");
				      proso_itoa(getpid(),buffer);
				      PRINTF(buffer);
				      PRINTF("\n");
			       	      PRINTF("SOY EL NIETO y me suicido ");
				      exit();
			       case -1:FINJP;
			       default:PRINTF("SOY EL HIJO: ");
				       proso_itoa(getpid(),buffer);
				       PRINTF(buffer);
				       PRINTF("\n");
			       	       PRINTF("SOY EL HIJO y me suicido ");
				       exit();
				       break;
		       }
		case -1:FINJP;break;
		default:break;
	}
	PRINTF("Creo N procesos concurrentes\n");
	for (i=0;i<4;i++){
		if (getpid()==mypid)	CERROR(fork());
	}
	for(i=0;i<100;i++){
		buffer[0]='A'+(getpid()%4);
		CERROR(write(1,buffer,1));
	}
	PRINTF("Dejo solo uno\n");
	if (getpid()!=mypid){
		PRINTF("SOY ");proso_itoa(getpid(),buffer);
		PRINTF(buffer);PRINTF(" Y Me suicido\n");
		exit();
	}
	PRINTF("Solo queda el proceso ");proso_itoa(getpid(),buffer);
	PRINTF(buffer);

	PRINTF(" y Deberia ser 0\n");
	CHECK( nice(-1),    -1, "Probando nice incorrecto(-1)");
	CHECK( nice(0),     -1, "Probando nice incorrecto(0)");
	PRINTF("Probando nice correcto(10):");
	n = nice(10);
	if (n < 0) {PRINTF("ERROR"); PERROR();}
	else {
		CHECK( nice(5),    10, "Probando nice correcto(5)");
		CHECK( get_stats(-1, &tics),    -1, "Probando get_stats pid incorrecto(-1)");
		CHECK( get_stats(mypid, (int*)0),    -1, "Probando get_stats @tics=0");
		CHECK( get_stats(mypid, (int*)10009999999999999999999), -1, "Probando get_stats @tics=1000");
		CHECK( get_stats(mypid, &tics), 0, "Probando get_stats OK");

	}

	PRINTF("Creamos N procesos\n");
	i=0;
#if 1
	while(((ret=fork())>0)&& (i<100)){
		PRINTF("Creo 1 proceso\n");
		i++;
	}
#endif
	PRINTF("Matamos todos los procesos excepto el primero\n");
	if (getpid()!=mypid)	exit();

	proso_itoa(i,buffer);
	PRINTF("Hemos creado ");PRINTF(buffer);PRINTF("procesos\n");

	PRINTF("\n**************FIN JP**************** PID: ");
//.........这里部分代码省略.........
开发者ID:Gawyn,项目名称:Zeos,代码行数:101,代码来源:userProc.c


示例14: capfs_file_create

/* capfs_file_create()
 */
int capfs_file_create(struct inode *dir, struct dentry *entry, int mode, struct nameidata *nd)
{
	int error = 0, len_dir, len_file;
	struct inode *inode;
	struct capfs_meta meta;
	struct capfs_phys phys;
	struct capfs_inode *pinode, *parent_pinode = NULL;
	char *ptr, *namebuf;

	/* update the statistics */
	if(capfs_collect_stats) capfs_vfs_stat.create++;
	PENTRY;
	parent_pinode = CAPFS_I(dir);
	if((error = write_lock_inode(parent_pinode)) < 0) {
		 d_drop(entry);
		 PEXIT;
		 return error;
	}
	if((error = may_create(dir, entry, nd))) {
		PDEBUG(D_FILE, "Not allowed to create file %d\n", error);
		d_drop(entry);
		write_unlock_inode(parent_pinode);
		 PEXIT;
		return error;
	}

	PDEBUG(D_FILE, "capfs_file_create called for %ld\n", dir->i_ino);

	len_dir = strlen(CAPFS_I(dir)->name);
	len_file = entry->d_name.len;
	namebuf = (char *) kmalloc(len_dir + len_file + 2, GFP_KERNEL);
	if (namebuf == NULL)
	{
		d_drop(entry);
		write_unlock_inode(parent_pinode);
		PEXIT;
		return -ENOMEM;
	}
	/* piece the whole file name together */
	ptr = namebuf;
	strcpy(ptr, CAPFS_I(dir)->name);
	ptr += len_dir;
	*ptr = '/';
	ptr++;
	strcpy(ptr, entry->d_name.name);

	/* do the create */
	meta.valid = V_MODE | V_UID | V_GID | V_TIMES;
	meta.uid = current->fsuid;
	meta.gid = current->fsgid;
	meta.mode = mode;
	meta.mtime = meta.atime = meta.ctime = CURRENT_TIME.tv_sec;

	phys.blksize = DEFAULT_BLKSIZE;
	phys.dist = DEFAULT_DIST;
	phys.nodect = DEFAULT_NODECT;
	
	PDEBUG(D_FILE, "capfs_file_create calling ll_capfs_create for %s [atime: %lu] [mtime: %lu] [ctime: %lu]\n", namebuf, 
			meta.atime, meta.mtime, meta.ctime);
	if ((error = ll_capfs_create(CAPFS_SB(dir->i_sb), namebuf,
					len_dir + len_file + 1, &meta, &phys)) < 0)
	{
		kfree(namebuf);
		d_drop(entry);
		write_unlock_inode(parent_pinode);
		PEXIT;
		return error;
	}

	/* do a lookup so we can fill in the inode. not special */
	if ((error = ll_capfs_lookup(CAPFS_SB(dir->i_sb), namebuf,
					len_dir + len_file + 1, &meta, 0)) < 0)
	{
		kfree(namebuf);
		d_drop(entry);
		write_unlock_inode(parent_pinode);
		PEXIT;
		return error;
	}

	/* fill in inode structure and remainder of capfs_inode */
	if ((inode = iget(dir->i_sb, meta.handle)) == NULL) 
	{
		kfree(namebuf);
		d_drop(entry);
		write_unlock_inode(parent_pinode);
		PEXIT;
		return -ENOMEM;
	}
	pinode = CAPFS_I(inode);
	if (pinode == NULL)
	{
		PERROR("found NULL pinode pointer\n");
		iput(inode);
		kfree(namebuf);
		d_drop(entry);
		write_unlock_inode(parent_pinode);
		PEXIT;
//.........这里部分代码省略.........
开发者ID:mnv104,项目名称:capfs,代码行数:101,代码来源:file.c


示例15: handle_one_cmd

/*
 * Return < 0 on error, 0 if OK, 1 on hangup.
 */
static
int handle_one_cmd(struct run_as_worker *worker)
{
	int ret = 0;
	struct run_as_data data;
	ssize_t readlen, writelen;
	struct run_as_ret sendret;
	run_as_fct cmd;
	uid_t prev_euid;

	memset(&sendret, 0, sizeof(sendret));
	sendret.fd = -1;

	/*
	 * Stage 1: Receive run_as_data struct from the master.
	 * The structure contains the command type and all the parameters needed for
	 * its execution
	 */
	readlen = lttcomm_recv_unix_sock(worker->sockpair[1], &data,
			sizeof(data));
	if (readlen == 0) {
		/* hang up */
		ret = 1;
		goto end;
	}
	if (readlen < sizeof(data)) {
		PERROR("lttcomm_recv_unix_sock error");
		ret = -1;
		goto end;
	}

	cmd = run_as_enum_to_fct(data.cmd);
	if (!cmd) {
		ret = -1;
		goto end;
	}

	/*
	 * Stage 2: Receive file descriptor from master.
	 * Some commands need a file descriptor as input so if it's needed we
	 * receive the fd using the Unix socket.
	 */
	ret = recv_fd_from_master(worker, data.cmd, &data.fd);
	if (ret < 0) {
		PERROR("recv_fd_from_master error");
		ret = -1;
		goto end;
	}

	prev_euid = getuid();
	if (data.gid != getegid()) {
		ret = setegid(data.gid);
		if (ret < 0) {
			sendret._error = true;
			sendret._errno = errno;
			PERROR("setegid");
			goto write_return;
		}
	}
	if (data.uid != prev_euid) {
		ret = seteuid(data.uid);
		if (ret < 0) {
			sendret._error = true;
			sendret._errno = errno;
			PERROR("seteuid");
			goto write_return;
		}
	}

	/*
	 * Also set umask to 0 for mkdir executable bit.
	 */
	umask(0);

	/*
	 * Stage 3: Execute the command
	 */
	ret = (*cmd)(&data, &sendret);
	if (ret < 0) {
		DBG("Execution of command returned an error");
	}

write_return:
	ret = cleanup_received_fd(data.cmd, data.fd);
	if (ret < 0) {
		ERR("Error cleaning up FD");
		goto end;
	}

	/*
	 * Stage 4: Send run_as_ret structure to the master.
	 * This structure contain the return value of the command and the errno.
	 */
	writelen = lttcomm_send_unix_sock(worker->sockpair[1], &sendret,
			sizeof(sendret));
	if (writelen < sizeof(sendret)) {
		PERROR("lttcomm_send_unix_sock error");
//.........这里部分代码省略.........
开发者ID:lttng,项目名称:lttng-tools,代码行数:101,代码来源:runas.c


示例16: run_as_cmd

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PERUSE_TRACE_COMM_EVENT函数代码示例发布时间:2022-05-30
下一篇:
C++ PERR函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap